github.com/johnathanhowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/modules/renter.go (about) 1 package modules 2 3 import ( 4 "io" 5 "time" 6 7 "github.com/NebulousLabs/Sia/crypto" 8 "github.com/NebulousLabs/Sia/types" 9 ) 10 11 const ( 12 // RenterDir is the name of the directory that is used to store the 13 // renter's persistent data. 14 RenterDir = "renter" 15 ) 16 17 // An ErasureCoder is an error-correcting encoder and decoder. 18 type ErasureCoder interface { 19 // NumPieces is the number of pieces returned by Encode. 20 NumPieces() int 21 22 // MinPieces is the minimum number of pieces that must be present to 23 // recover the original data. 24 MinPieces() int 25 26 // Encode splits data into equal-length pieces, with some pieces 27 // containing parity data. 28 Encode(data []byte) ([][]byte, error) 29 30 // Recover recovers the original data from pieces (including parity) and 31 // writes it to w. pieces should be identical to the slice returned by 32 // Encode (length and order must be preserved), but with missing elements 33 // set to nil. n is the number of bytes to be written to w; this is 34 // necessary because pieces may have been padded with zeros during 35 // encoding. 36 Recover(pieces [][]byte, n uint64, w io.Writer) error 37 } 38 39 // FileUploadParams contains the information used by the Renter to upload a 40 // file. 41 type FileUploadParams struct { 42 Source string 43 SiaPath string 44 ErasureCode ErasureCoder 45 } 46 47 // FileInfo provides information about a file. 48 type FileInfo struct { 49 SiaPath string `json:"siapath"` 50 Filesize uint64 `json:"filesize"` 51 Available bool `json:"available"` 52 Renewing bool `json:"renewing"` 53 Redundancy float64 `json:"redundancy"` 54 UploadProgress float64 `json:"uploadprogress"` 55 Expiration types.BlockHeight `json:"expiration"` 56 } 57 58 // DownloadInfo provides information about a file that has been requested for 59 // download. 60 type DownloadInfo struct { 61 SiaPath string `json:"siapath"` 62 Destination string `json:"destination"` 63 Filesize uint64 `json:"filesize"` 64 Received uint64 `json:"received"` 65 StartTime time.Time `json:"starttime"` 66 } 67 68 // An Allowance dictates how much the Renter is allowed to spend in a given 69 // period. Note that funds are spent on both storage and bandwidth. 70 type Allowance struct { 71 Funds types.Currency `json:"funds"` 72 Hosts uint64 `json:"hosts"` 73 Period types.BlockHeight `json:"period"` 74 RenewWindow types.BlockHeight `json:"renewwindow"` 75 } 76 77 // RenterFinancialMetrics contains metrics about how much the Renter has 78 // spent on storage, uploads, and downloads. 79 type RenterFinancialMetrics struct { 80 // ContractSpending is how much the Renter has paid into file contracts 81 // formed with hosts. Note that some of this money may be returned to the 82 // Renter when the contract ends. To calculate how much will be returned, 83 // subtract the storage, upload, and download metrics from 84 // ContractSpending. 85 ContractSpending types.Currency `json:"contractspending"` 86 87 DownloadSpending types.Currency `json:"downloadspending"` 88 StorageSpending types.Currency `json:"storagespending"` 89 UploadSpending types.Currency `json:"uploadspending"` 90 } 91 92 // A HostDBEntry represents one host entry in the Renter's host DB. It 93 // aggregates the host's external settings with its public key. 94 type HostDBEntry struct { 95 HostExternalSettings 96 PublicKey types.SiaPublicKey 97 } 98 99 // A RenterContract contains all the metadata necessary to revise or renew a 100 // file contract. 101 type RenterContract struct { 102 FileContract types.FileContract `json:"filecontract"` 103 ID types.FileContractID `json:"id"` 104 LastRevision types.FileContractRevision `json:"lastrevision"` 105 LastRevisionTxn types.Transaction `json:"lastrevisiontxn"` 106 MerkleRoots []crypto.Hash `json:"merkleroots"` 107 NetAddress NetAddress `json:"netaddress"` 108 SecretKey crypto.SecretKey `json:"secretkey"` 109 } 110 111 // A Renter uploads, tracks, repairs, and downloads a set of files for the 112 // user. 113 type Renter interface { 114 // Allowance returns the current allowance. 115 Allowance() Allowance 116 117 // ActiveHosts returns the list of hosts that are actively being selected 118 // from. 119 ActiveHosts() []HostDBEntry 120 121 // AllHosts returns the full list of hosts known to the renter. 122 AllHosts() []HostDBEntry 123 124 // Close closes the Renter. 125 Close() error 126 127 // Contracts returns the contracts formed by the renter. 128 Contracts() []RenterContract 129 130 // DeleteFile deletes a file entry from the renter. 131 DeleteFile(path string) error 132 133 // Download downloads a file to the given destination. 134 Download(path, destination string) error 135 136 // DownloadQueue lists all the files that have been scheduled for download. 137 DownloadQueue() []DownloadInfo 138 139 // FileList returns information on all of the files stored by the renter. 140 FileList() []FileInfo 141 142 // FinancialMetrics returns the financial metrics of the Renter. 143 FinancialMetrics() RenterFinancialMetrics 144 145 // LoadSharedFiles loads a '.sia' file into the renter. A .sia file may 146 // contain multiple files. The paths of the added files are returned. 147 LoadSharedFiles(source string) ([]string, error) 148 149 // LoadSharedFilesAscii loads an ASCII-encoded '.sia' file into the 150 // renter. 151 LoadSharedFilesAscii(asciiSia string) ([]string, error) 152 153 // Rename changes the path of a file. 154 RenameFile(path, newPath string) error 155 156 // SetAllowance sets the amount of money the Renter is allowed to spend on 157 // contracts over a given time period, divided among the number of hosts 158 // specified. Note that Renter can start forming contracts as soon as 159 // SetAllowance is called; that is, it may block. 160 SetAllowance(Allowance) error 161 162 // ShareFiles creates a '.sia' file that can be shared with others. 163 ShareFiles(paths []string, shareDest string) error 164 165 // ShareFilesAscii creates an ASCII-encoded '.sia' file. 166 ShareFilesAscii(paths []string) (asciiSia string, err error) 167 168 // Upload uploads a file using the input parameters. 169 Upload(FileUploadParams) error 170 }