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