Documentation ¶
Overview ¶
Package gateway connects a Sia node to the Sia flood network. The flood network is used to propagate blocks and transactions. The gateway is the primary avenue that a node uses to hear about transactions and blocks, and is the primary avenue used to tell the network about blocks that you have mined or about transactions that you have created.
Index ¶
- type Gateway
- func (g *Gateway) Address() modules.NetAddress
- func (g *Gateway) Broadcast(name string, obj interface{}, peers []modules.Peer)
- func (g *Gateway) Close() error
- func (g *Gateway) Connect(addr modules.NetAddress) error
- func (g *Gateway) Disconnect(addr modules.NetAddress) error
- func (g *Gateway) DiscoverAddress(cancel <-chan struct{}) (modules.NetAddress, error)
- func (g *Gateway) ForwardPort(port string) error
- func (g *Gateway) Online() bool
- func (g *Gateway) Peers() []modules.Peer
- func (g *Gateway) RPC(addr modules.NetAddress, name string, fn modules.RPCFunc) error
- func (g *Gateway) RandomPeer() (modules.Peer, error)
- func (g *Gateway) RegisterConnectCall(name string, fn modules.RPCFunc)
- func (g *Gateway) RegisterRPC(name string, fn modules.RPCFunc)
- func (g *Gateway) UnregisterConnectCall(name string)
- func (g *Gateway) UnregisterRPC(name string)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway implements the modules.Gateway interface.
func (*Gateway) Address ¶
func (g *Gateway) Address() modules.NetAddress
Address returns the NetAddress of the Gateway.
func (*Gateway) Broadcast ¶
Broadcast calls an RPC on all of the specified peers. The calls are run in parallel. Broadcasts are restricted to "one-way" RPCs, which simply write an object and disconnect. This is why Broadcast takes an interface{} instead of an RPCFunc.
func (*Gateway) Connect ¶
func (g *Gateway) Connect(addr modules.NetAddress) error
Connect establishes a persistent connection to a peer, and adds it to the Gateway's peer list.
func (*Gateway) Disconnect ¶
func (g *Gateway) Disconnect(addr modules.NetAddress) error
Disconnect terminates a connection to a peer and removes it from the Gateway's peer list. The peer's address remains in the node list.
func (*Gateway) DiscoverAddress ¶
func (g *Gateway) DiscoverAddress(cancel <-chan struct{}) (modules.NetAddress, error)
DiscoverAddress discovers and returns the current public IP address of the gateway. Contrary to Address, DiscoverAddress is blocking and might take multiple minutes to return. A channel to cancel the discovery can be supplied optionally. If nil is supplied, a reasonable timeout will be used by default.
func (*Gateway) ForwardPort ¶
ForwardPort adds a port mapping to the router.
func (*Gateway) Online ¶
Online returns true if the node is connected to the internet. During testing we always assume that the node is online
func (*Gateway) RPC ¶
RPC calls an RPC on the given address. RPC cannot be called on an address that the Gateway is not connected to.
func (*Gateway) RandomPeer ¶ added in v0.2.1
RandomPeer returns a random peer currently connected to the Gateway.
func (*Gateway) RegisterConnectCall ¶
RegisterConnectCall registers a name and RPCFunc to be called on a peer upon connecting.
func (*Gateway) RegisterRPC ¶
RegisterRPC registers an RPCFunc as a handler for a given identifier. To call an RPC, use gateway.RPC, supplying the same identifier given to RegisterRPC. Identifiers should always use PascalCase. The first 8 characters of an identifier should be unique, as the identifier used internally is truncated to 8 bytes.
func (*Gateway) UnregisterConnectCall ¶
UnregisterConnectCall unregisters an on-connect call and removes the corresponding RPCFunc from g.initRPCs. Future connections to peers will not trigger the RPC to be called on them.
func (*Gateway) UnregisterRPC ¶
UnregisterRPC unregisters an RPC and removes the corresponding RPCFunc from g.handlers. Future calls to the RPC by peers will fail.