gitlab.com/SiaPrime/SiaPrime@v1.4.1/node/api/client/gateway.go (about)

     1  package client
     2  
     3  import (
     4  	"net/url"
     5  	"strconv"
     6  
     7  	"gitlab.com/NebulousLabs/errors"
     8  	"gitlab.com/SiaPrime/SiaPrime/modules"
     9  	"gitlab.com/SiaPrime/SiaPrime/node/api"
    10  )
    11  
    12  var (
    13  	// ErrPeerExists indicates that two peers are already connected. The string
    14  	// of this error needs to be updated if the string of errPeerExists in the
    15  	// gateway package is changed.
    16  	ErrPeerExists = errors.New("already connected to this peer")
    17  )
    18  
    19  // GatewayConnectPost uses the /gateway/connect/:address endpoint to connect to
    20  // the gateway at address
    21  func (c *Client) GatewayConnectPost(address modules.NetAddress) (err error) {
    22  	err = c.post("/gateway/connect/"+string(address), "", nil)
    23  	if err != nil && err.Error() == ErrPeerExists.Error() {
    24  		err = ErrPeerExists
    25  	}
    26  	return
    27  }
    28  
    29  // GatewayDisconnectPost uses the /gateway/disconnect/:address endpoint to
    30  // disconnect the gateway from a peer.
    31  func (c *Client) GatewayDisconnectPost(address modules.NetAddress) (err error) {
    32  	err = c.post("/gateway/disconnect/"+string(address), "", nil)
    33  	return
    34  }
    35  
    36  // GatewayGet requests the /gateway api resource
    37  func (c *Client) GatewayGet() (gwg api.GatewayGET, err error) {
    38  	err = c.get("/gateway", &gwg)
    39  	return
    40  }
    41  
    42  // GatewayRateLimitPost uses the /gateway endpoint to change the gateway's
    43  // bandwidth rate limit. downloadSpeed and uploadSpeed are interpreted as
    44  // bytes/second.
    45  func (c *Client) GatewayRateLimitPost(downloadSpeed, uploadSpeed int64) (err error) {
    46  	values := url.Values{}
    47  	values.Set("maxdownloadspeed", strconv.FormatInt(downloadSpeed, 10))
    48  	values.Set("maxuploadspeed", strconv.FormatInt(uploadSpeed, 10))
    49  	err = c.post("/gateway", values.Encode(), nil)
    50  	return
    51  }