gossip

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2018 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"
	// 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

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 Gossip

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

Gossip represents the peer protocol

func NewGossip

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

NewGossip creates a new instance of the Gossip protocol

func (*Gossip) CheckRemotePeer

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

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

func (g *Gossip) 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 (*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) OnAddr

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

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

func (*Gossip) OnBlockBody

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

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

func (*Gossip) OnGetAddr

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

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

func (*Gossip) OnGetBlockBodies

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

OnGetBlockBodies handles GetBlockBodies requests

func (*Gossip) OnGetBlockHashes

func (g *Gossip) 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 (*Gossip) OnHandshake

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

OnHandshake handles incoming handshake requests

func (*Gossip) OnIntro

func (g *Gossip) OnIntro(s net.Stream, rp core.Engine) error

OnIntro handles incoming core.Intro messages. Received messages are relayed to 2 random peers.

func (*Gossip) OnPing

func (g *Gossip) 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 (*Gossip) OnRequestBlock

func (g *Gossip) 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 (*Gossip) OnTx

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

OnTx handles incoming transaction message

func (*Gossip) PM

func (g *Gossip) PM() *peermanager.Manager

PM returns the local peer's peer manager

func (*Gossip) PickBroadcasters

func (g *Gossip) PickBroadcasters(addresses []*core.Address, n int) *core.BroadcastPeers

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

func (g *Gossip) 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 (*Gossip) RelayBlock

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

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

func (*Gossip) RelayTx

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

RelayTx relays transactions to peers

func (*Gossip) RequestBlock

func (g *Gossip) 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 (*Gossip) SelfAdvertise

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

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

func (*Gossip) SendGetAddr

func (g *Gossip) 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 (*Gossip) SendGetAddrToPeer

func (g *Gossip) 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 (*Gossip) SendGetBlockBodies

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

SendGetBlockBodies sends a GetBlockBodies message requesting for whole bodies of a collection blocks.

func (*Gossip) SendGetBlockHashes

func (g *Gossip) SendGetBlockHashes(rp core.Engine, locators []util.Hash) 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) 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

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

SendHandshake sends an introductory message to a peer

func (*Gossip) SendIntro

func (g *Gossip) SendIntro(intro *core.Intro)

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

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

SendPing sends a ping message

func (*Gossip) SendPingToPeer

func (g *Gossip) 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 (*Gossip) SetPeerManager

func (g *Gossip) 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