github.com/fozzysec/SiaPrime@v0.0.0-20190612043147-66c8e8d11fe3/doc/api/Renter.md (about) 1 Renter API 2 ========== 3 4 This document contains detailed descriptions of the renter's API routes. For an 5 overview of the renter's API routes, see [API.md#renter](/doc/API.md#renter). For 6 an overview of all API routes, see [API.md](/doc/API.md) 7 8 There may be functional API calls which are not documented. These are not 9 guaranteed to be supported beyond the current release, and should not be used 10 in production. 11 12 Overview 13 -------- 14 15 The renter manages the user's files on the network. The renter's API endpoints 16 expose methods for managing files on the network and managing the renter's 17 allocated funds. 18 19 Index 20 ----- 21 22 | Route | HTTP verb | 23 | ------------------------------------------------------------------------------- | --------- | 24 | [/renter](#renter-get) | GET | 25 | [/renter](#renter-post) | POST | 26 | [/renter/contract/cancel](#rentercontractcancel-post) | POST | 27 | [/renter/contracts](#rentercontracts-get) | GET | 28 | [/renter/downloads](#renterdownloads-get) | GET | 29 | [/renter/downloads/clear](#renterdownloadsclear-post) | POST | 30 | [/renter/files](#renterfiles-get) | GET | 31 | [/renter/file/*___siapath___](#renterfilesiapath-get) | GET | 32 | [/renter/file/*__siapath__](#rentertrackingsiapath-post) | POST | 33 | [/renter/prices](#renterprices-get) | GET | 34 | [/renter/delete/___*siapath___](#renterdelete___siapath___-post) | POST | 35 | [/renter/download/___*siapath___](#renterdownload__siapath___-get) | GET | 36 | [/renter/downloadasync/___*siapath___](#renterdownloadasync__siapath___-get) | GET | 37 | [/renter/rename/___*siapath___](#renterrename___siapath___-post) | POST | 38 | [/renter/stream/___*siapath___](#renterstreamsiapath-get) | GET | 39 | [/renter/upload/___*siapath___](#renteruploadsiapath-post) | POST | 40 41 #### /renter [GET] 42 43 returns the current settings along with metrics on the renter's spending. 44 45 ###### JSON Response 46 ```javascript 47 { 48 // Settings that control the behavior of the renter. 49 "settings": { 50 // Allowance dictates how much the renter is allowed to spend in a given 51 // period. Note that funds are spent on both storage and bandwidth. 52 "allowance": { 53 // Amount of money allocated for contracts. Funds are spent on both 54 // storage and bandwidth. 55 "funds": "1234", // hastings 56 57 // Number of hosts that contracts will be formed with. 58 "hosts":24, 59 60 // Duration of contracts formed, in number of blocks. 61 "period": 6048, // blocks 62 63 // If the current blockheight + the renew window >= the height the 64 // contract is scheduled to end, the contract is renewed automatically. 65 // Is always nonzero. 66 "renewwindow": 3024 // blocks 67 }, 68 // MaxUploadSpeed by default is unlimited but can be set by the user to 69 // manage bandwidth 70 "maxuploadspeed": 1234, // bytes per second 71 72 // MaxDownloadSpeed by default is unlimited but can be set by the user to 73 // manage bandwidth 74 "maxdownloadspeed": 1234, // bytes per second 75 76 // The StreamCacheSize is the number of data chunks that will be cached during 77 // streaming 78 "streamcachesize": 4 79 }, 80 81 // Metrics about how much the Renter has spent on storage, uploads, and 82 // downloads. 83 "financialmetrics": { 84 // Amount of money spent on contract fees, transaction fees and siafund fees. 85 "contractfees": "1234", // hastings 86 87 // How much money, in hastings, the Renter has spent on file contracts, 88 // including fees. 89 "contractspending": "1234", // hastings, (deprecated, now totalallocated) 90 91 // Amount of money spent on downloads. 92 "downloadspending": "5678", // hastings 93 94 // Amount of money spend on storage. 95 "storagespending": "1234", // hastings 96 97 // Total amount of money that the renter has put into contracts. Includes 98 // spent money and also money that will be returned to the renter. 99 "totalallocated": "1234", // hastings 100 101 // Amount of money spent on uploads. 102 "uploadspending": "5678", // hastings 103 104 // Amount of money in the allowance that has not been spent. 105 "unspent": "1234" // hastings 106 }, 107 // Height at which the current allowance period began. 108 "currentperiod": 200 109 } 110 ``` 111 112 #### /renter [POST] 113 114 modify settings that control the renter's behavior. 115 116 ###### Query String Parameters 117 ``` 118 // Number of hastings allocated for file contracts in the given period. 119 funds // hastings 120 121 // Number of hosts that contracts should be formed with. Files cannot be 122 // uploaded to more hosts than you have contracts with, and it's generally good 123 // to form a few more contracts than you need. 124 hosts 125 126 // Duration of contracts formed. Must be nonzero. 127 period // block height 128 129 // Renew window specifies how many blocks before the expiration of the current 130 // contracts the renter will wait before renewing the contracts. A smaller 131 // renew window means that SiaPrime must be run more frequently, but also means 132 // fewer total transaction fees. Storage spending is not affected by the renew 133 // window size. 134 renewwindow // block height 135 136 // Max download speed permitted, speed provide in bytes per second 137 maxdownloadspeed 138 139 // Max upload speed permitted, speed provide in bytes per second 140 maxuploadspeed 141 142 // Stream cache size specifies how many data chunks will be cached while 143 // streaming. 144 streamcachesize 145 ``` 146 147 ###### Response 148 standard success or error response. See 149 [API.md#standard-responses](/doc/API.md#standard-responses). 150 151 #### /renter/contract/cancel [POST] 152 153 cancels a specific contract of the Renter. 154 155 ###### Query String Parameter 156 ``` 157 // ID of the file contract 158 id 159 ``` 160 161 ###### Response 162 standard success or error response. See 163 [API.md#standard-responses](/doc/API.md#standard-responses). 164 165 #### /renter/contracts [GET] 166 167 returns the renter's contracts. Active contracts are contracts that the Renter 168 is currently using to store, upload, and download data, and are returned by 169 default. Inactive contracts are contracts that are in the current period but are 170 marked as not good for renew, these contracts have the potential to become 171 active again but currently are not storing data. Expired contracts are 172 contracts not in the current period, where not more data is being stored and 173 excess funds have been released to the renter. 174 175 ###### Contract Parameters 176 ``` 177 inactive // true or false - Optional 178 expired // true or false - Optional 179 ``` 180 181 ###### JSON Response 182 ```javascript 183 { 184 "activecontracts": [ 185 { 186 // Amount of contract funds that have been spent on downloads. 187 "downloadspending": "1234", // hastings 188 189 // Block height that the file contract ends on. 190 "endheight": 50000, // block height 191 192 // Fees paid in order to form the file contract. 193 "fees": "1234", // hastings 194 195 // Public key of the host the contract was formed with. 196 "hostpublickey": { 197 "algorithm": "ed25519", 198 "key": "RW50cm9weSBpc24ndCB3aGF0IGl0IHVzZWQgdG8gYmU=" 199 }, 200 201 // ID of the file contract. 202 "id": "1234567890abcdef0123456789abcdef0123456789abcdef0123456789abcdef", 203 204 // A signed transaction containing the most recent contract revision. 205 "lasttransaction": {}, 206 207 // Address of the host the file contract was formed with. 208 "netaddress": "12.34.56.78:9", 209 210 // Remaining funds left for the renter to spend on uploads & downloads. 211 "renterfunds": "1234", // hastings 212 213 // Size of the file contract, which is typically equal to the number of 214 // bytes that have been uploaded to the host. 215 "size": 8192, // bytes 216 217 // Block height that the file contract began on. 218 "startheight": 50000, // block height 219 220 // DEPRECATED: This is the exact same value as StorageSpending, but it has 221 // incorrect capitalization. This was fixed in 1.3.2, but this field is kept 222 // to preserve backwards compatibility on clients who depend on the 223 // incorrect capitalization. This field will be removed in the future, so 224 // clients should switch to the StorageSpending field (above) with the 225 // correct lowercase name. 226 "StorageSpending": 0, 227 228 // Amount of contract funds that have been spent on storage. 229 "storagespending": "1234", // hastings 230 231 // Total cost to the wallet of forming the file contract. 232 // This includes both the fees and the funds allocated in the contract. 233 "totalcost": "1234", // hastings 234 235 // Amount of contract funds that have been spent on uploads. 236 "uploadspending": "1234" // hastings 237 238 // Signals if contract is good for uploading data 239 "goodforupload": true, 240 241 // Signals if contract is good for a renewal 242 "goodforrenew": false, 243 } 244 ], 245 "inactivecontracts": [], 246 "expiredcontracts": [], 247 } 248 ``` 249 250 #### /renter/downloads [GET] 251 252 lists all files in the download queue. 253 254 ###### JSON Response 255 ```javascript 256 { 257 "downloads": [ 258 { 259 // Local path that the file will be downloaded to. 260 "destination": "/home/users/alice", 261 262 // What type of destination was used. Can be "file", indicating a download 263 // to disk, can be "buffer", indicating a download to memory, and can be 264 // "http stream", indicating that the download was streamed through the 265 // http API. 266 "destinationtype": "file", 267 268 // Length of the download. If the download was a partial download, this 269 // will indicate the length of the partial download, and not the length of 270 // the full file. 271 "length": 8192, // bytes 272 273 // Offset within the file of the download. For full file downloads, the // 274 offset will be '0'. For partial downloads, the offset may be anywhere // 275 within the file. offset+length will never exceed the full file size. 276 "offset": 0, 277 278 // Siapath given to the file when it was uploaded. 279 "siapath": "foo/bar.txt", 280 281 // Whether or not the download has completed. Will be false initially, and 282 // set to true immediately as the download has been fully written out to 283 // the file, to the http stream, or to the in-memory buffer. Completed 284 // will also be set to true if there is an error that causes the download to 285 // fail. 286 "completed": true, 287 288 // Time at which the download completed. Will be zero if the download has 289 // not yet completed. 290 "endtime": "2009-11-10T23:00:00Z", // RFC 3339 time 291 292 // Error encountered while downloading. If there was no error (yet), it 293 // will be the empty string. 294 "error": "" 295 296 // Number of bytes downloaded thus far. Will only be updated as segments 297 // of the file complete fully. This typically has a resolution of tens of 298 // megabytes. 299 "received": 4096, // bytes 300 301 // Time at which the download was initiated. 302 "starttime": "2009-11-10T23:00:00Z", // RFC 3339 time 303 304 // The total amount of data transfered when downloading the file. This 305 // will eventually include data transferred during contract + payment 306 // negotiation, as well as data from failed piece downloads. 307 "totaldatatransfered": 10321, 308 } 309 ] 310 } 311 ``` 312 #### /renter/downloads/clear [POST] 313 314 Clears the download history of the renter for a range of unix time stamps. Both 315 parameters are optional, if no parameters are provided, the entire download 316 history will be cleared. To clear a single download, provide the timestamp for 317 the download as both parameters. Providing only the before parameter will clear 318 all downloads older than the timestamp. Conversely, providing only the after 319 parameter will clear all downloads newer than the timestamp. 320 321 ###### Timestamp Parameters [(with comments)] 322 ``` 323 before // Optional - unix timestamp found in the download history 324 after // Optional - unix timestamp found in the download history 325 ``` 326 327 ###### Response 328 standard success or error response. See 329 [API.md#standard-responses](/doc/API.md#standard-responses). 330 331 #### /renter/files [GET] 332 333 lists the status of all files. 334 335 ###### JSON Response 336 ```javascript 337 { 338 "files": [ 339 { 340 // Path to the file in the renter on the network. 341 "siapath": "foo/bar.txt", 342 343 // Path to the local file on disk. 344 "localpath": "/home/foo/bar.txt", 345 346 // Size of the file in bytes. 347 "filesize": 8192, // bytes 348 349 // true if the file is available for download. Files may be available 350 // before they are completely uploaded. 351 "available": true, 352 353 // true if the file's contracts will be automatically renewed by the 354 // renter. 355 "renewing": true, 356 357 // Average redundancy of the file on the network. Redundancy is 358 // calculated by dividing the amount of data uploaded in the file's open 359 // contracts by the size of the file. Redundancy does not necessarily 360 // correspond to availability. Specifically, a redundancy >= 1 does not 361 // indicate the file is available as there could be a chunk of the file 362 // with 0 redundancy. 363 "redundancy": 5, 364 365 // Total number of bytes successfully uploaded via current file contracts. 366 // This number includes padding and rendundancy, so a file with a size of 367 // 8192 bytes might be padded to 40 MiB and, with a redundancy of 5, 368 // encoded to 200 MiB for upload. 369 "uploadedbytes": 209715200, // bytes 370 371 // Percentage of the file uploaded, including redundancy. Uploading has 372 // completed when uploadprogress is 100. Files may be available for 373 // download before upload progress is 100. 374 "uploadprogress": 100, // percent 375 376 // Block height at which the file ceases availability. 377 "expiration": 60000 378 } 379 ] 380 } 381 ``` 382 383 #### /renter/file/*___siapath___ [GET] 384 385 lists the status of specified file. 386 387 ###### JSON Response 388 ```javascript 389 { 390 "file": { 391 // Path to the file in the renter on the network. 392 "siapath": "foo/bar.txt", 393 394 // Path to the local file on disk. 395 "localpath": "/home/foo/bar.txt", 396 397 // Size of the file in bytes. 398 "filesize": 8192, // bytes 399 400 // true if the file is available for download. Files may be available 401 // before they are completely uploaded. 402 "available": true, 403 404 // true if the file's contracts will be automatically renewed by the 405 // renter. 406 "renewing": true, 407 408 // Average redundancy of the file on the network. Redundancy is 409 // calculated by dividing the amount of data uploaded in the file's open 410 // contracts by the size of the file. Redundancy does not necessarily 411 // correspond to availability. Specifically, a redundancy >= 1 does not 412 // indicate the file is available as there could be a chunk of the file 413 // with 0 redundancy. 414 "redundancy": 5, 415 416 // Total number of bytes successfully uploaded via current file contracts. 417 // This number includes padding and rendundancy, so a file with a size of 418 // 8192 bytes might be padded to 40 MiB and, with a redundancy of 5, 419 // encoded to 200 MiB for upload. 420 "uploadedbytes": 209715200, // bytes 421 422 // Percentage of the file uploaded, including redundancy. Uploading has 423 // completed when uploadprogress is 100. Files may be available for 424 // download before upload progress is 100. 425 "uploadprogress": 100, // percent 426 427 // Block height at which the file ceases availability. 428 "expiration": 60000 429 } 430 } 431 ``` 432 433 #### /renter/file/*___siapath___ [POST] 434 435 endpoint for changing file metadata. 436 437 ###### Path Parameters [(with comments)](/doc/api/Renter.md#path-parameters-3) 438 ``` 439 // SiaPath of the file on the network. The path must be non-empty, may not 440 // include any path traversal strings ("./", "../"), and may not begin with a 441 // forward-slash character. 442 *siapath 443 ``` 444 445 ###### Query String Parameters [(with comments)](/doc/api/Renter.md#query-string-parameters-3) 446 ``` 447 // If provided, this parameter changes the tracking path of a file to the 448 // specified path. Useful if moving the file to a different location on disk. 449 trackingpath 450 ``` 451 452 ###### Response 453 standard success or error response. See 454 [#standard-responses](#standard-responses). 455 456 #### /renter/prices [GET] 457 458 lists the estimated prices of performing various storage and data operations. An 459 allowance can be submitted to provide a more personalized estimate. If no 460 allowance is submitted then the current set allowance will be used, if there is 461 no allowance set then sane defaults will be used. Submitting an allowance is 462 optional, but when submitting an allowance all the components of the allowance 463 are required. The allowance used to create the estimate is returned with the 464 estimate. 465 466 ###### Query String Parameters 5 467 ``` 468 all optional or all required 469 470 // Number of hastings allocated for file contracts in the given period. 471 funds // hastings 472 473 // Number of hosts that contracts should be formed with. Files cannot be 474 // uploaded to more hosts than you have contracts with, and it's generally good 475 // to form a few more contracts than you need. 476 hosts 477 478 // Duration of contracts formed. Must be nonzero. 479 period // block height 480 481 // Renew window specifies how many blocks before the expiration of the current 482 // contracts the renter will wait before renewing the contracts. A smaller 483 // renew window means that SiaPrime must be run more frequently, but also means 484 // fewer total transaction fees. Storage spending is not affected by the renew 485 // window size. 486 renewwindow // block height 487 ``` 488 489 ###### JSON Response 5 490 ```javascript 491 { 492 // The estimated cost of downloading one terabyte of data from the 493 // network. 494 "downloadterabyte": "1234", // hastings 495 496 // The estimated cost of forming a set of contracts on the network. This 497 // cost also applies to the estimated cost of renewing the renter's set of 498 // contracts. 499 "formcontracts": "1234", // hastings 500 501 // The estimated cost of storing one terabyte of data on the network for 502 // a month, including accounting for redundancy. 503 "storageterabytemonth": "1234", // hastings 504 505 // The estimated cost of uploading one terabyte of data to the network, 506 // including accounting for redundancy. 507 "uploadterabyte": "1234", // hastings 508 509 // Amount of money allocated for contracts. Funds are spent on both 510 // storage and bandwidth. 511 "funds": "1234", // hastings 512 513 // Number of hosts that contracts will be formed with. 514 "hosts":24, 515 516 // Duration of contracts formed, in number of blocks. 517 "period": 6048, // blocks 518 519 // If the current blockheight + the renew window >= the height the 520 // contract is scheduled to end, the contract is renewed automatically. 521 // Is always nonzero. 522 "renewwindow": 3024 // blocks 523 } 524 ``` 525 526 #### /renter/delete/___*siapath___ [POST] 527 528 deletes a renter file entry. Does not delete any downloads or original files, 529 only the entry in the renter. 530 531 ###### Path Parameters 532 ``` 533 // Location of the file in the renter on the network. 534 *siapath 535 ``` 536 537 ###### Response 538 standard success or error response. See 539 [API.md#standard-responses](/doc/API.md#standard-responses). 540 541 #### /renter/download/___*siapath___ [GET] 542 543 downloads a file to the local filesystem. The call will block until the file 544 has been downloaded. 545 546 ###### Path Parameters 547 ``` 548 // Location of the file in the renter on the network. 549 *siapath 550 ``` 551 552 ###### Query String Parameters 553 ``` 554 // If async is true, the http request will be non blocking. Can't be used with 555 async 556 // Location on disk that the file will be downloaded to. 557 destination 558 // If httresp is true, the data will be written to the http response. 559 httpresp 560 // Length of the requested data. Has to be <= filesize-offset. 561 length 562 // Offset relative to the file start from where the download starts. 563 offset 564 ``` 565 566 ###### Response 567 standard success or error response. See 568 [API.md#standard-responses](/doc/API.md#standard-responses). 569 570 #### /renter/downloadasync/___*siapath___ [GET] 571 572 downloads a file to the local filesystem. The call will return immediately. 573 574 ###### Path Parameters 575 ``` 576 *siapath 577 ``` 578 579 ###### Query String Parameters 580 ``` 581 destination 582 ``` 583 584 ###### Response 585 standard success or error response. See 586 [API.md#standard-responses](/doc/API.md#standard-responses). 587 588 #### /renter/rename/___*siapath___ [POST] 589 590 renames a file. Does not rename any downloads or source files, only renames the 591 entry in the renter. An error is returned if `siapath` does not exist or 592 `newsiapath` already exists. 593 594 ###### Path Parameters 595 ``` 596 // Current location of the file in the renter on the network. 597 *siapath 598 ``` 599 600 ###### Query String Parameters 601 ``` 602 // New location of the file in the renter on the network. 603 newsiapath 604 ``` 605 606 ###### Response 607 standard success or error response. See 608 [API.md#standard-responses](/doc/API.md#standard-responses). 609 610 #### /renter/stream/*___siapath___ [GET] 611 612 downloads a file using http streaming. This call blocks until the data is 613 received. 614 The streaming endpoint also uses caching internally to prevent siad from 615 re-downloading the same chunk multiple times when only parts of a file are 616 requested at once. This might lead to a substantial increase in ram usage and 617 therefore it is not recommended to stream multiple files in parallel at the 618 moment. This restriction will be removed together with the caching once partial 619 downloads are supported in the future. If you want to stream multiple files you 620 should increase the size of the Renter's `streamcachesize` to at least 2x the 621 number of files you are steaming. 622 623 ###### Path Parameters [(with comments)](/doc/api/Renter.md#path-parameters-1) 624 ``` 625 *siapath 626 ``` 627 628 ###### Response 629 standard success with the requested data in the body or error response. See 630 [#standard-responses](#standard-responses). 631 632 #### /renter/upload/___*siapath___ [POST] 633 634 starts a file upload to the SiaPrime network from the local filesystem. 635 636 ###### Path Parameters 637 638 ``` 639 // Location where the file will reside in the renter on the network. The path 640 // must be non-empty, may not include any path traversal strings ("./", "../"), 641 // and may not begin with a forward-slash character. 642 *siapath 643 ``` 644 645 ###### Query String Parameters 646 ``` 647 // The number of data pieces to use when erasure coding the file. 648 datapieces // int 649 650 // The number of parity pieces to use when erasure coding the file. Total 651 // redundancy of the file is (datapieces+paritypieces)/datapieces. 652 paritypieces // int 653 654 // Location on disk of the file being uploaded. 655 source // string - a filepath 656 ``` 657 658 ###### Response 659 standard success or error response. See 660 [API.md#standard-responses](/doc/API.md#standard-responses). A successful 661 response indicates that the upload started successfully. To confirm the upload 662 completed successfully, the caller must call [/renter/files](#renterfiles-get) 663 until that API returns success with an `uploadprogress` >= 100.0 for the file 664 at the given `siapath`.