Documentation ¶
Index ¶
- Constants
- Variables
- func ReadStream(s net.Stream, dest interface{}) error
- func WriteStream(s net.Stream, msg interface{}) error
- type Manager
- func (g *Manager) BroadcastBlock(block types.Block, remotePeers []core.Engine) []error
- func (g *Manager) BroadcastTx(tx types.Transaction, remotePeers []core.Engine) error
- func (g *Manager) CheckRemotePeer(ws *core.WrappedStream, rp core.Engine) error
- func (g *Manager) GetBlockchain() types.Blockchain
- func (g *Manager) GetBroadcasters() *core.BroadcastPeers
- func (g *Manager) GetRandBroadcasters() *core.BroadcastPeers
- func (g *Manager) Handle(handler func(s net.Stream, remotePeer core.Engine) error) func(net.Stream)
- func (g *Manager) NewStream(remotePeer core.Engine, msgVersion string) (net.Stream, context.CancelFunc, error)
- func (g *Manager) OnAddr(s net.Stream, rp core.Engine) error
- func (g *Manager) OnBlockBody(s net.Stream, rp core.Engine) error
- func (g *Manager) OnBlockInfo(s net.Stream, rp core.Engine) error
- func (g *Manager) OnGetAddr(s net.Stream, rp core.Engine) error
- func (g *Manager) OnGetBlockBodies(s net.Stream, rp core.Engine) error
- func (g *Manager) OnGetBlockHashes(s net.Stream, rp core.Engine) error
- func (g *Manager) OnHandshake(s net.Stream, rp core.Engine) error
- func (g *Manager) OnPing(s net.Stream, rp core.Engine) error
- func (g *Manager) OnRequestBlock(s net.Stream, rp core.Engine) error
- func (g *Manager) OnTx(s net.Stream, rp core.Engine) error
- func (g *Manager) PM() *peermanager.Manager
- func (g *Manager) PickBroadcasters(cache *core.BroadcastPeers, addresses []*core.Address, n int) *core.BroadcastPeers
- func (g *Manager) PickBroadcastersFromPeers(cache *core.BroadcastPeers, peers []core.Engine, n int) *core.BroadcastPeers
- func (g *Manager) RelayAddresses(addrs []*core.Address) []error
- func (g *Manager) RequestBlock(rp core.Engine, blockHash util.Hash) error
- func (g *Manager) SelfAdvertise(connectedPeers []core.Engine) int
- func (g *Manager) SendGetAddr(remotePeers []core.Engine) error
- func (g *Manager) SendGetAddrToPeer(rp core.Engine) ([]*core.Address, error)
- func (g *Manager) SendGetBlockBodies(rp core.Engine, hashes []util.Hash) (*core.BlockBodies, error)
- func (g *Manager) SendGetBlockHashes(rp core.Engine, locators []util.Hash, seek util.Hash) (*core.BlockHashes, error)
- func (g *Manager) SendHandshake(rp core.Engine) error
- func (g *Manager) SendPing(remotePeers []core.Engine)
- func (g *Manager) SendPingToPeer(remotePeer core.Engine) error
- func (g *Manager) SetPeerManager(pm *peermanager.Manager)
Constants ¶
const ( // EventReceivedBlockHashes describes an event about // a receiving block hashes EventReceivedBlockHashes = "event.receivedBlockHashes" // EventRequestedBlockHashes describes an event about // sending a request for block hashes EventRequestedBlockHashes = "event.requestedBlockHashes" //EventAddrProcessed describes an event about // a processed address EventAddrProcessed = "event.addrProcessed" // EventAddressesRelayed describes an event about // relayed addresses EventAddressesRelayed = "event.addressesRelayed" // EventReceivedAddr describes an event about a // received addresses EventReceivedAddr = "event.receivedAddr" // EventIntroReceived describes an event about // a received intro EventIntroReceived = "event.receivedIntro" )
Variables ¶
var ( // StreamReadDelay is the amount of time to // wait for data from a stream StreamReadDelay = time.Duration(1) * time.Minute )
Functions ¶
func ReadStream ¶
ReadStream reads the content of a steam into dest
func WriteStream ¶
WriteStream writes msg to the given stream
Types ¶
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager represents the peer protocol
func (*Manager) BroadcastBlock ¶
BroadcastBlock sends a given block to remote peers. The block is encapsulated in a BlockBody message.
func (*Manager) BroadcastTx ¶
BroadcastTx broadcast transactions to selected peers
func (*Manager) CheckRemotePeer ¶
CheckRemotePeer performs validation against the remote peer.
func (*Manager) GetBlockchain ¶
func (g *Manager) GetBlockchain() types.Blockchain
GetBlockchain returns the blockchain manager
func (*Manager) GetBroadcasters ¶
func (g *Manager) GetBroadcasters() *core.BroadcastPeers
GetBroadcasters returns the broadcasters
func (*Manager) GetRandBroadcasters ¶
func (g *Manager) GetRandBroadcasters() *core.BroadcastPeers
GetRandBroadcasters returns the random, possibly unacquainted broadcasters
func (*Manager) Handle ¶
Handle wrappers a protocol handler providing an interface to perform pre and post handling operations.
func (*Manager) NewStream ¶
func (g *Manager) NewStream(remotePeer core.Engine, msgVersion string) (net.Stream, context.CancelFunc, error)
NewStream creates a stream for a given protocol ID and between the local peer and the given remote peer.
func (*Manager) OnBlockBody ¶
OnBlockBody handles incoming BlockBody messages. BlockBody messages contain information about a block. It will attempt to process the received block.
func (*Manager) OnBlockInfo ¶
OnBlockInfo handles incoming BlockInfo messages. BlockInfo messages describe a block that a peer intends to send. The local peer responds with a BlockOk message if it accepts the block.
func (*Manager) OnGetAddr ¶
OnGetAddr processes a core.GetAddr request. Sends a list of active addresses to the sender
func (*Manager) OnGetBlockBodies ¶
OnGetBlockBodies handles GetBlockBodies requests
func (*Manager) OnGetBlockHashes ¶
OnGetBlockHashes processes a core.GetBlockHashes request. It will attempt to find a chain it shares in common using the locator block hashes provided in the message.
If it does not find a chain that is shared with the remote chain, it will assume the chains are not off same network and as such send an empty block hash response.
If it finds that the remote peer has a chain that is not the same as its main chain (a branch), it will send block hashes starting from the root parent block (oldest ancestor) which exists on the main chain.
func (*Manager) OnHandshake ¶
OnHandshake handles incoming handshake requests
func (*Manager) OnPing ¶
OnPing processes a Ping message sent by a remote peer. It sends back a Pong message containing information about the main block chain. It will start blockchain synchronization if the Ping message includes blockchain information that is better than the local blockchain
func (*Manager) OnRequestBlock ¶
OnRequestBlock handles RequestBlock message. A RequestBlock message includes information a bout a block that a remote node needs.
func (*Manager) PM ¶
func (g *Manager) PM() *peermanager.Manager
PM returns the local peer's peer manager
func (*Manager) PickBroadcasters ¶
func (g *Manager) PickBroadcasters(cache *core.BroadcastPeers, addresses []*core.Address, n int) *core.BroadcastPeers
PickBroadcasters selects N random addresses from the given slice of addresses and adds them to cache to be used as broadcasters.
They are returned on subsequent calls and only renewed when there are less than N addresses or when cache was last update at over 24 hours ago.
func (*Manager) PickBroadcastersFromPeers ¶
func (g *Manager) PickBroadcastersFromPeers(cache *core.BroadcastPeers, peers []core.Engine, n int) *core.BroadcastPeers
PickBroadcastersFromPeers is like PickBroadcasters except it accepts a slice of peer engine objects.
func (*Manager) RelayAddresses ¶
RelayAddresses relays core.Address under the following rules:
- core.Address message must contain not more than 10 addrs.
- all addresses must be valid and different from the local peer address
- Only addresses within 60 minutes from the current time.
- Only routable addresses are allowed.
func (*Manager) RequestBlock ¶
RequestBlock sends a RequestBlock message to remote peer. A RequestBlock message includes information about a specific block. It will attempt to process the requested block after receiving it from the remote peer. The block's validation context is set to ContextBlockSync which cause the transactions to not be required to exist in the transaction pool.
func (*Manager) SelfAdvertise ¶
SelfAdvertise sends an Addr message containing the address of the local peer to all connected peers.
func (*Manager) SendGetAddr ¶
SendGetAddr sends simultaneous GetAddr message to the given peers. GetAddr returns with a list of address that should be relayed to other peers.
func (*Manager) SendGetAddrToPeer ¶
SendGetAddrToPeer sends a core.GetAddr message to a remote peer. The remote peer will respond with a core.Addr message which must be processed using the OnAddr handler and return the response.
func (*Manager) SendGetBlockBodies ¶
SendGetBlockBodies sends a GetBlockBodies message requesting for whole bodies of a collection blocks.
func (*Manager) SendGetBlockHashes ¶
func (g *Manager) SendGetBlockHashes(rp core.Engine, locators []util.Hash, seek util.Hash) (*core.BlockHashes, error)
SendGetBlockHashes sends a GetBlockHashes message to the remotePeer asking for block hashes beginning from a block they share in common. The local peer sends the remote peer a list of hashes (locators) while the remote peer use the locators to find the highest block height they share in common, then it gathers and sends block hashes after the chosen shared block.
If the locators is not provided via the locator argument, they will be collected from the main chain.
func (*Manager) SendHandshake ¶
SendHandshake sends an introductory message to a peer
func (*Manager) SendPingToPeer ¶
SendPingToPeer sends a Ping message to the given peer. It receives the response Pong message and will start blockchain synchronization if the Pong message includes blockchain information that is better than the local blockchain
func (*Manager) SetPeerManager ¶
func (g *Manager) SetPeerManager(pm *peermanager.Manager)
SetPeerManager sets the peer manager