github.com/ZuluSpl0it/Sia@v1.3.7/node/api/client/host.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "net/url" 6 "strconv" 7 8 "github.com/NebulousLabs/Sia/crypto" 9 "github.com/NebulousLabs/Sia/modules" 10 "github.com/NebulousLabs/Sia/node/api" 11 ) 12 13 // HostParam is a parameter in the host's settings that can be changed via the 14 // API. It is primarily used as a helper struct to ensure type safety. 15 type HostParam string 16 17 const ( 18 // HostParamCollateralBudget is the collateral budget of the host in 19 // hastings. 20 HostParamCollateralBudget = HostParam("collateralbudget") 21 // HostParamMaxCollateral is the max collateral of the host in hastings. 22 HostParamMaxCollateral = HostParam("maxcollateral") 23 // HostParamMinContractPrice is the min contract price in hastings. 24 HostParamMinContractPrice = HostParam("mincontractprice") 25 // HostParamMinDownloadBandwidthPrice is the min download bandwidth price 26 // in hastings/byte. 27 HostParamMinDownloadBandwidthPrice = HostParam("mindownloadbandwidthprice") 28 // HostParamMinUploadBandwidthPrice is the min upload bandwidth price in 29 // hastings/byte. 30 HostParamMinUploadBandwidthPrice = HostParam("minuploadbandwidthprice") 31 // HostParamCollateral is the host's collateral in hastings/byte/block. 32 HostParamCollateral = HostParam("collateral") 33 // HostParamMinStoragePrice is the minimum storage price in 34 // hastings/byte/block. 35 HostParamMinStoragePrice = HostParam("minstorageprice") 36 // HostParamAcceptingContracts indicates if the host is accepting new 37 // contracts. 38 HostParamAcceptingContracts = HostParam("acceptingcontracts") 39 // HostParamMaxDuration is the max duration of a contract in blocks. 40 HostParamMaxDuration = HostParam("maxduration") 41 // HostParamWindowSize is the size of the proof window in blocks. 42 HostParamWindowSize = HostParam("windowsize") 43 // HostParamMaxDownloadBatchSize is the maximum size of the download batch 44 // size in bytes. 45 HostParamMaxDownloadBatchSize = HostParam("maxdownloadbatchsize") 46 // HostParamMaxReviseBatchSize is the maximum size of the revise batch size. 47 HostParamMaxReviseBatchSize = HostParam("maxrevisebatchsize") 48 // HostParamNetAddress is the announced netaddress of the host. 49 HostParamNetAddress = HostParam("netaddress") 50 ) 51 52 // HostAnnouncePost uses the /host/announce endpoint to announce the host to 53 // the network 54 func (c *Client) HostAnnouncePost() (err error) { 55 err = c.post("/host/announce", "", nil) 56 return 57 } 58 59 // HostAnnounceAddrPost uses the /host/anounce endpoint to announce the host to 60 // the network using the provided address. 61 func (c *Client) HostAnnounceAddrPost(address modules.NetAddress) (err error) { 62 err = c.post("/host/announce", "netaddress="+string(address), nil) 63 return 64 } 65 66 // HostContractInfoGet uses the /host/contracts endpoint to get information 67 // about contracts on the host. 68 func (c *Client) HostContractInfoGet() (cg api.ContractInfoGET, err error) { 69 err = c.get("/host/contracts", &cg) 70 return 71 } 72 73 // HostEstimateScoreGet requests the /host/estimatescore endpoint. 74 func (c *Client) HostEstimateScoreGet(param, value string) (eg api.HostEstimateScoreGET, err error) { 75 err = c.get(fmt.Sprintf("/host/estimatescore?%v=%v", param, value), &eg) 76 return 77 } 78 79 // HostGet requests the /host endpoint. 80 func (c *Client) HostGet() (hg api.HostGET, err error) { 81 err = c.get("/host", &hg) 82 return 83 } 84 85 // HostModifySettingPost uses the /host endpoint to change a param of the host 86 // settings to a certain value. 87 func (c *Client) HostModifySettingPost(param HostParam, value interface{}) (err error) { 88 err = c.post("/host", string(param)+"="+fmt.Sprint(value), nil) 89 return 90 } 91 92 // HostStorageFoldersAddPost uses the /host/storage/folders/add api endpoint to 93 // add a storage folder to a host 94 func (c *Client) HostStorageFoldersAddPost(path string, size uint64) (err error) { 95 values := url.Values{} 96 values.Set("path", path) 97 values.Set("size", strconv.FormatUint(size, 10)) 98 err = c.post("/host/storage/folders/add", values.Encode(), nil) 99 return 100 } 101 102 // HostStorageFoldersRemovePost uses the /host/storage/folders/remove api 103 // endpoint to remove a storage folder from a host. 104 func (c *Client) HostStorageFoldersRemovePost(path string) (err error) { 105 values := url.Values{} 106 values.Set("path", path) 107 err = c.post("/host/storage/folders/remove", values.Encode(), nil) 108 return 109 } 110 111 // HostStorageFoldersResizePost uses the /host/storage/folders/resize api 112 // endpoint to resize an existing storage folder. 113 func (c *Client) HostStorageFoldersResizePost(path string, size uint64) (err error) { 114 values := url.Values{} 115 values.Set("path", path) 116 values.Set("newsize", strconv.FormatUint(size, 10)) 117 err = c.post("/host/storage/folders/resize", values.Encode(), nil) 118 return 119 } 120 121 // HostStorageGet requests the /host/storage endpoint. 122 func (c *Client) HostStorageGet() (sg api.StorageGET, err error) { 123 err = c.get("/host/storage", &sg) 124 return 125 } 126 127 // HostStorageSectorsDeletePost uses the /host/storage/sectors/delete endpoint 128 // to delete a sector from the host. 129 func (c *Client) HostStorageSectorsDeletePost(root crypto.Hash) (err error) { 130 err = c.post("/host/storage/sectors/delete/"+root.String(), "", nil) 131 return 132 }