Documentation ¶
Index ¶
- Constants
- func MakeTxHistoryKey(tx types.Transaction, peer core.Engine) []interface{}
- func ReadStream(s net.Stream, dest interface{}) error
- func WriteStream(s net.Stream, msg interface{}) error
- type Gossip
- func (g *Gossip) CheckRemotePeer(ws *core.WrappedStream, rp core.Engine) error
- func (g *Gossip) GetBlockchain() types.Blockchain
- func (g *Gossip) GetBroadcasters() *core.BroadcastPeers
- func (g *Gossip) Handle(handler func(s net.Stream, remotePeer core.Engine) error) func(net.Stream)
- func (g *Gossip) NewStream(remotePeer core.Engine, msgVersion string) (net.Stream, context.CancelFunc, error)
- func (g *Gossip) OnAddr(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnBlockBody(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnGetAddr(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnGetBlockBodies(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnGetBlockHashes(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnHandshake(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnIntro(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnPing(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnRequestBlock(s net.Stream, rp core.Engine) error
- func (g *Gossip) OnTx(s net.Stream, rp core.Engine) error
- func (g *Gossip) PM() *peermanager.Manager
- func (g *Gossip) PickBroadcasters(addresses []*core.Address, n int) *core.BroadcastPeers
- func (g *Gossip) RelayAddresses(addrs []*core.Address) []error
- func (g *Gossip) RelayBlock(block types.Block, remotePeers []core.Engine) error
- func (g *Gossip) RelayTx(tx types.Transaction, remotePeers []core.Engine) error
- func (g *Gossip) RequestBlock(rp core.Engine, blockHash util.Hash) error
- func (g *Gossip) SelfAdvertise(connectedPeers []core.Engine) int
- func (g *Gossip) SendGetAddr(remotePeers []core.Engine) error
- func (g *Gossip) SendGetAddrToPeer(rp core.Engine) ([]*core.Address, error)
- func (g *Gossip) SendGetBlockBodies(rp core.Engine, hashes []util.Hash) error
- func (g *Gossip) SendGetBlockHashes(rp core.Engine, locators []util.Hash) error
- func (g *Gossip) SendHandshake(rp core.Engine) error
- func (g *Gossip) SendIntro(intro *core.Intro)
- func (g *Gossip) SendPing(remotePeers []core.Engine)
- func (g *Gossip) SendPingToPeer(remotePeer core.Engine) error
- func (g *Gossip) 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" // EventTransactionProcessed describes an event about // a processed transaction EventTransactionProcessed = "event.transactionProcessed" // EventBlockProcessed describes an event about // a processed block EventBlockProcessed = "event.blockProcessed" // EventBlockBodiesProcessed describes an event about // processed block bodies EventBlockBodiesProcessed = "event.blockBodiesProcessed" //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 ¶
This section is empty.
Functions ¶
func MakeTxHistoryKey ¶
func MakeTxHistoryKey(tx types.Transaction, peer core.Engine) []interface{}
MakeTxHistoryKey creates an GetHistory() cache key for recording a received/sent transaction
func ReadStream ¶
ReadStream reads the content of a steam into dest
func WriteStream ¶
WriteStream writes msg to the given stream
Types ¶
type Gossip ¶
type Gossip struct {
// contains filtered or unexported fields
}
Gossip represents the peer protocol
func (*Gossip) CheckRemotePeer ¶
CheckRemotePeer performs validation against the remote peer.
func (*Gossip) GetBlockchain ¶
func (g *Gossip) GetBlockchain() types.Blockchain
GetBlockchain returns the blockchain manager
func (*Gossip) GetBroadcasters ¶
func (g *Gossip) GetBroadcasters() *core.BroadcastPeers
GetBroadcasters returns the broadcasters
func (*Gossip) Handle ¶
Handle wrappers a protocol handler providing an interface to perform pre and post handling operations.
func (*Gossip) NewStream ¶
func (g *Gossip) 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 (*Gossip) OnBlockBody ¶
OnBlockBody handles incoming BlockBody message. BlockBody messages contain information about a block. It will attempt to process the received block.
func (*Gossip) OnGetAddr ¶
OnGetAddr processes a core.GetAddr request. Sends a list of active addresses to the sender
func (*Gossip) OnGetBlockBodies ¶
OnGetBlockBodies handles GetBlockBodies requests
func (*Gossip) 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 (*Gossip) OnHandshake ¶
OnHandshake handles incoming handshake requests
func (*Gossip) OnIntro ¶
OnIntro handles incoming core.Intro messages. Received messages are relayed to 2 random peers.
func (*Gossip) 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 (*Gossip) OnRequestBlock ¶
OnRequestBlock handles RequestBlock message. A RequestBlock message includes information a bout a block that a remote node needs.
func (*Gossip) PM ¶
func (g *Gossip) PM() *peermanager.Manager
PM returns the local peer's peer manager
func (*Gossip) PickBroadcasters ¶
PickBroadcasters selects N random addresses from the given slice of addresses and caches them to be used as broadcasters. They are returned on subsequent calls and only renewed when there are less than N addresses or the cache is over 24 hours since it was last updated.
func (*Gossip) 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 (*Gossip) RelayBlock ¶
RelayBlock sends a given block to remote peers. The block is encapsulated in a BlockBody message.
func (*Gossip) 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 (*Gossip) SelfAdvertise ¶
SelfAdvertise sends an Addr message containing the address of the local peer to all connected peers.
func (*Gossip) 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 (*Gossip) 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 (*Gossip) SendGetBlockBodies ¶
SendGetBlockBodies sends a GetBlockBodies message requesting for whole bodies of a collection blocks.
func (*Gossip) SendGetBlockHashes ¶
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) on its main chain while the remote peer uses the locators to find the highest block they share in common, then it collects and sends block hashes after the selected shared block.
If the locators is not provided via the locator argument, they will be collected from the main chain.
func (*Gossip) SendHandshake ¶
SendHandshake sends an introductory message to a peer
func (*Gossip) SendIntro ¶
SendIntro sends a core.Intro message to random, connected peers. If intro is nil, a new core.Intro message is created and broadcast to the selected peers
func (*Gossip) 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 (*Gossip) SetPeerManager ¶
func (g *Gossip) SetPeerManager(pm *peermanager.Manager)
SetPeerManager sets the peer manager