Documentation ¶
Index ¶
- Constants
- Variables
- type Gateway
- func (g *Gateway) AddPeer(peer modules.NetAddress) error
- func (g *Gateway) Address() modules.NetAddress
- func (g *Gateway) Bootstrap(bootstrapPeer modules.NetAddress) (err error)
- func (g *Gateway) Close() error
- func (g *Gateway) Info() (info modules.GatewayInfo)
- func (g *Gateway) Ping(addr modules.NetAddress) bool
- func (g *Gateway) RPC(addr modules.NetAddress, name string, fn modules.RPCFunc) (err error)
- func (g *Gateway) RandomPeer() (modules.NetAddress, error)
- func (g *Gateway) RegisterRPC(name string, fn modules.RPCFunc)
- func (g *Gateway) RelayBlock(b consensus.Block)
- func (g *Gateway) RelayTransaction(t consensus.Transaction)
- func (g *Gateway) RemovePeer(peer modules.NetAddress) error
- func (g *Gateway) Synchronize(peer modules.NetAddress) error
Constants ¶
const (
MaxCatchUpBlocks = 50
)
Variables ¶
var (
ErrTimeout = errors.New("timeout")
)
Functions ¶
This section is empty.
Types ¶
type Gateway ¶
type Gateway struct {
// contains filtered or unexported fields
}
Gateway implements the modules.Gateway interface.
func (*Gateway) AddPeer ¶
func (g *Gateway) AddPeer(peer modules.NetAddress) error
AddPeer adds a peer to the Gateway's peer list.
func (*Gateway) Address ¶
func (g *Gateway) Address() modules.NetAddress
Address returns the NetAddress of the Gateway.
func (*Gateway) Bootstrap ¶
func (g *Gateway) Bootstrap(bootstrapPeer modules.NetAddress) (err error)
Bootstrap joins the Sia network and establishes an initial peer list.
Bootstrap handles mutexes manually to avoid having a lock during network communication.
func (*Gateway) Info ¶
func (g *Gateway) Info() (info modules.GatewayInfo)
Info returns metadata about the Gateway.
func (*Gateway) Ping ¶
func (g *Gateway) Ping(addr modules.NetAddress) bool
Ping returns whether an Address is reachable and responds correctly to the ping request -- in other words, whether it is a potential peer.
func (*Gateway) RPC ¶
RPC establishes a TCP connection to the NetAddress, writes the RPC identifier, and then hands off the connection to fn. When fn returns, the connection is closed.
func (*Gateway) RandomPeer ¶
func (g *Gateway) RandomPeer() (modules.NetAddress, error)
RandomPeer returns a random peer from the Gateway's peer list.
func (*Gateway) RegisterRPC ¶
RegisterRPC registers a function as an RPC handler for a given identifier. To call an RPC, use gateway.RPC, supplying the same identifier given to RegisterRPC. Identifiers should always use PascalCase.
func (*Gateway) RelayBlock ¶
RelayBlock relays a block to the network.
func (*Gateway) RelayTransaction ¶
func (g *Gateway) RelayTransaction(t consensus.Transaction)
RelayTransaction relays a transaction to the network.
func (*Gateway) RemovePeer ¶
func (g *Gateway) RemovePeer(peer modules.NetAddress) error
RemovePeer removes a peer from the Gateway's peer list.
func (*Gateway) Synchronize ¶
func (g *Gateway) Synchronize(peer modules.NetAddress) error
Synchronize synchronizes the local consensus set (i.e. the blockchain) with the network consensus set. The process is as follows: synchronize asks a peer for new blocks. The requester sends 32 block IDs, starting with the 12 most recent and then progressing exponentially backwards to the genesis block. The receiver uses these blocks to find the most recent block seen by both peers. From this starting height, it transmits blocks sequentially. The requester then integrates these blocks into its consensus set. Multiple such transmissions may be required to fully synchronize.
TODO: don't run two Synchronize threads at the same time