gossip

package
v0.1.8-alpha.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 27, 2019 License: GPL-3.0 Imports: 21 Imported by: 1

Documentation

Index

Constants

View Source
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

View Source
var (
	// StreamReadDelay is the amount of time to
	// wait for data from a stream
	StreamReadDelay = time.Duration(1) * time.Minute
)

Functions

func ReadStream

func ReadStream(s net.Stream, dest interface{}) error

ReadStream reads the content of a steam into dest

func WriteStream

func WriteStream(s net.Stream, msg interface{}) error

WriteStream writes msg to the given stream

Types

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager represents the peer protocol

func NewGossip

func NewGossip(p core.Engine, log logger.Logger) *Manager

NewGossip creates a new instance of the Gossip protocol

func (*Manager) BroadcastBlock

func (g *Manager) BroadcastBlock(block types.Block, remotePeers []core.Engine) []error

BroadcastBlock sends a given block to remote peers. The block is encapsulated in a BlockBody message.

func (*Manager) BroadcastTx

func (g *Manager) BroadcastTx(tx types.Transaction, remotePeers []core.Engine) error

BroadcastTx broadcast transactions to selected peers

func (*Manager) CheckRemotePeer

func (g *Manager) CheckRemotePeer(ws *core.WrappedStream, rp core.Engine) error

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

func (g *Manager) Handle(handler func(s net.Stream, remotePeer core.Engine) error) func(net.Stream)

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) OnAddr

func (g *Manager) OnAddr(s net.Stream, rp core.Engine) error

OnAddr handles incoming core.Addr message. Received addresses are relayed.

func (*Manager) OnBlockBody

func (g *Manager) OnBlockBody(s net.Stream, rp core.Engine) error

OnBlockBody handles incoming BlockBody messages. BlockBody messages contain information about a block. It will attempt to process the received block.

func (*Manager) OnBlockInfo

func (g *Manager) OnBlockInfo(s net.Stream, rp core.Engine) error

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

func (g *Manager) OnGetAddr(s net.Stream, rp core.Engine) error

OnGetAddr processes a core.GetAddr request. Sends a list of active addresses to the sender

func (*Manager) OnGetBlockBodies

func (g *Manager) OnGetBlockBodies(s net.Stream, rp core.Engine) error

OnGetBlockBodies handles GetBlockBodies requests

func (*Manager) OnGetBlockHashes

func (g *Manager) OnGetBlockHashes(s net.Stream, rp core.Engine) error

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

func (g *Manager) OnHandshake(s net.Stream, rp core.Engine) error

OnHandshake handles incoming handshake requests

func (*Manager) OnPing

func (g *Manager) OnPing(s net.Stream, rp core.Engine) error

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

func (g *Manager) OnRequestBlock(s net.Stream, rp core.Engine) error

OnRequestBlock handles RequestBlock message. A RequestBlock message includes information a bout a block that a remote node needs.

func (*Manager) OnTx

func (g *Manager) OnTx(s net.Stream, rp core.Engine) error

OnTx handles incoming transaction message

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

func (g *Manager) RelayAddresses(addrs []*core.Address) []error

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

func (g *Manager) RequestBlock(rp core.Engine, blockHash util.Hash) error

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

func (g *Manager) SelfAdvertise(connectedPeers []core.Engine) int

SelfAdvertise sends an Addr message containing the address of the local peer to all connected peers.

func (*Manager) SendGetAddr

func (g *Manager) SendGetAddr(remotePeers []core.Engine) error

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

func (g *Manager) SendGetAddrToPeer(rp core.Engine) ([]*core.Address, error)

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

func (g *Manager) SendGetBlockBodies(rp core.Engine, hashes []util.Hash) (*core.BlockBodies, error)

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

func (g *Manager) SendHandshake(rp core.Engine) error

SendHandshake sends an introductory message to a peer

func (*Manager) SendPing

func (g *Manager) SendPing(remotePeers []core.Engine)

SendPing sends a ping message

func (*Manager) SendPingToPeer

func (g *Manager) SendPingToPeer(remotePeer core.Engine) error

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL