network

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: May 2, 2020 License: LGPL-3.0 Imports: 24 Imported by: 2

Documentation

Overview

Package network contains the implementation of network protocol handler for fractal.

Package p2p_handler contains the implementation of p2p handler for fractal.

Package p2p_handler contains the implementation of p2p handler for fractal.

Package network contains the implementation of network protocol handler for fractal.

Package p2p_handler contains the implementation of p2p handler for fractal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BlockWithVerifyFlag

type BlockWithVerifyFlag struct {
	Block  *types.Block
	Verify bool
}

type NodeInfo

type NodeInfo struct {
	Network uint64      `json:"network"` // Fractal network ID (1=Mainnet, 2=Testnet)
	Height  uint64      `json:"Height"`  // Height of the host's blockchain
	Genesis common.Hash `json:"genesis"` // SHA3 Hash of the host's genesis block
	Head    common.Hash `json:"head"`    // SHA3 Hash of the host's best owned block
}

NodeInfo represents a short summary of the Fractal sub-protocol metadata known about the host

type Peer

type Peer struct {
	*p2p.Peer
	// contains filtered or unexported fields
}

func NewPeer

func NewPeer(version int, p *p2p.Peer, rw p2p.MsgReadWriter) *Peer

func (*Peer) AsyncSendNewBlock

func (p *Peer) AsyncSendNewBlock(block *types.Block)

AsyncSendNewBlock queues an entire block for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*Peer) AsyncSendTransactions

func (p *Peer) AsyncSendTransactions(txs types.Transactions)

AsyncSendTransactions queues list of transactions propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*Peer) AsyncSendTxPackage

func (p *Peer) AsyncSendTxPackage(pkg *types.TxPackage)

AsyncSendTxPackage queues tx package propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*Peer) AsyncSendTxPackageHash

func (p *Peer) AsyncSendTxPackageHash(pkg *types.TxPackage)

AsyncSendTxPackageHash queues the availability of tx package for propagation to a remote peer. If the peer's broadcast queue is full, the event is silently dropped.

func (*Peer) Closed

func (p *Peer) Closed() bool

func (*Peer) CompareTo

func (p *Peer) CompareTo(simpleHash common.Hash, height uint64, round uint64) int

if peer's head is higher, return 1

func (*Peer) GetID

func (p *Peer) GetID() string

GetID return the id of current peer

func (*Peer) GetPeer

func (p *Peer) GetPeer() *Peer

func (*Peer) GetRW

func (p *Peer) GetRW() p2p.MsgReadWriter

func (*Peer) Handshake

func (p *Peer) Handshake(network uint64, height uint64, round uint64, head common.Hash, simpleHash common.Hash, genesis common.Hash) error

Handshake executes the ftl protocol handshake, negotiating version number, network IDs, difficulties, head and genesis blocks.

func (*Peer) HasBlock

func (p *Peer) HasBlock(hash common.Hash) bool

HasBlock tells whether current peer knows the block

func (*Peer) HasTransaction

func (p *Peer) HasTransaction(hash common.Hash) bool

HasTransaction tells whether current peer knows the transaction

func (*Peer) HasTxPackage

func (p *Peer) HasTxPackage(hash common.Hash) bool

HasTxPackage tells whether current peer knows the block

func (*Peer) Head

func (p *Peer) Head() (fullHash common.Hash, simpleHash common.Hash, height uint64, round uint64)

Head retrieves a copy of the current head block info of the peer.

func (*Peer) Info

func (p *Peer) Info() *PeerInfo

Info gathers and returns a collection of metadata known about a peer.

func (*Peer) MarkBlock

func (p *Peer) MarkBlock(hash common.Hash)

MarkBlock marks a block as known for the peer, ensuring that the block will never be propagated to this particular peer.

func (*Peer) MarkTransaction

func (p *Peer) MarkTransaction(hash common.Hash)

MarkTransaction marks a transaction as known for the peer, ensuring that it will never be propagated to this particular peer.

func (*Peer) MarkTxPackage

func (p *Peer) MarkTxPackage(hash common.Hash)

MarkTxPackage marks a tx package as known for the peer, ensuring that the tx package will never be propagated to this particular peer.

func (*Peer) Name

func (p *Peer) Name() string

func (*Peer) RequestBlocksByHash

func (p *Peer) RequestBlocksByHash(origin common.Hash, amount int, reverse bool) error

RequestBlocksByHash fetches a batch of blocks corresponding to the specified block query, based on the Hash of an origin block.

func (*Peer) RequestBlocksByRoundRange

func (p *Peer) RequestBlocksByRoundRange(roundFrom uint64, roundTo uint64) error

RequestBlocksByRoundRange fetches a batch of blocks corresponding to the specified block query, based on the Round of an origin block.

func (*Peer) RequestNodeData

func (p *Peer) RequestNodeData(hashes []common.Hash) error

RequestNodeData fetches a batch of arbitrary data from a node's known state data, corresponding to the specified hashes.

func (*Peer) RequestOneBlock

func (p *Peer) RequestOneBlock(hash common.Hash) error

RequestOneBlock is a wrapper around the block query functions to fetch a single block. It is used solely by the fetcher.

func (*Peer) RequestSyncBlocks

func (p *Peer) RequestSyncBlocks(stage protocol.SyncStage, roundFrom uint64, roundTo uint64) error

func (*Peer) RequestSyncHashList

func (p *Peer) RequestSyncHashList(syncStage protocol.SyncStage, hashType protocol.SyncHashType, hashEFrom protocol.HashElem, hashETo protocol.HashElem) error

func (*Peer) RequestSyncPkgs

func (p *Peer) RequestSyncPkgs(stage protocol.SyncStage, hashes []common.Hash) error

func (*Peer) RequestSyncPostBlocksForState

func (p *Peer) RequestSyncPostBlocksForState(hashEFrom protocol.HashElem, hashETo protocol.HashElem) error

func (*Peer) RequestSyncPreBlocksForState

func (p *Peer) RequestSyncPreBlocksForState(hash common.Hash) error

RequestSyncBlock fetches blocks for sync

func (*Peer) RequestTxPackage

func (p *Peer) RequestTxPackage(hash common.Hash) error

RequestTxPackage is a wrapper around the tx package query functions to fetch a single tx package.

func (*Peer) SendBlocks

func (p *Peer) SendBlocks(blocks types.Blocks) error

SendBlocks sends a batch of blocks to the remote peer.

func (*Peer) SendNewBlock

func (p *Peer) SendNewBlock(block *types.Block) error

SendNewBlock propagates an entire block to a remote peer.

func (*Peer) SendNodeData

func (p *Peer) SendNodeData(data [][]byte) error

SendNodeDataRLP sends a batch of arbitrary internal data, corresponding to the hashes requested.

func (*Peer) SendSyncBlocks

func (p *Peer) SendSyncBlocks(stage protocol.SyncStage, blocks types.Blocks, roundFrom uint64, roundTo uint64) error

func (*Peer) SendSyncHashList

func (p *Peer) SendSyncHashList(syncStage protocol.SyncStage, hashType protocol.SyncHashType, hashList protocol.HashElems) error

func (*Peer) SendSyncPkgs

func (p *Peer) SendSyncPkgs(fetchPkgsRsp protocol.SyncPkgsRsp) error

func (*Peer) SendSyncPostBlocksForState

func (p *Peer) SendSyncPostBlocksForState(blocks types.Blocks, pkgs []*types.TxPackage, round uint64, finished bool) error

func (*Peer) SendSyncPreBlocksForState

func (p *Peer) SendSyncPreBlocksForState(blocks []*types.Block, pkgs []*types.TxPackage) error

func (*Peer) SendTransactions

func (p *Peer) SendTransactions(txs types.Transactions) error

SendTransactions sends transactions to the peer and includes the hashes in its transaction Hash set for future reference.

func (*Peer) SendTxPackage

func (p *Peer) SendTxPackage(pkg *types.TxPackage) error

SendTxPackage sends tx package to the peer and includes the hashes in its tx package Hash set for future reference.

func (*Peer) SendTxPackageHash

func (p *Peer) SendTxPackageHash(hash common.Hash) error

SendTxPackageHash announces the availability of tx package through a Hash notification.

func (*Peer) SetHead

func (p *Peer) SetHead(fullHash common.Hash, simpleHash common.Hash, height uint64, round uint64)

SetHead updates the head block info.

func (*Peer) String

func (p *Peer) String() string

String implements fmt.Stringer.

type PeerInfo

type PeerInfo struct {
	Version    int    `json:"version"`    // Fractal protocol version negotiated
	Height     uint64 `json:"Height"`     // Height of the peer's best owned block
	Round      uint64 `json:"Round"`      // Round of the peer's best owned block
	FullHash   string `json:"fullHash"`   // SHA3 Hash of the peer's best owned block
	SimpleHash string `json:"simpleHash"` // SHA3 Hash of the peer's best owned block
}

PeerInfo represents a short summary of the Fractal sub-protocol metadata known about a connected peer.

type Peers

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

peers represents the collection of active peers

func NewPeers

func NewPeers() *Peers

newPeerSet creates a new peer set top track the active download sources.

func (*Peers) Close

func (ps *Peers) Close()

Close disconnects all peers. No new peers can be registered after Close has returned.

func (*Peers) GetPeers

func (ps *Peers) GetPeers() map[string]*Peer

func (*Peers) Len

func (ps *Peers) Len() int

Len returns if the current number of peers in the set.

func (*Peers) Peer

func (ps *Peers) Peer(id string) *Peer

Peer retrieves the registered peer with the given id.

func (*Peers) PeersWithTxPackage

func (ps *Peers) PeersWithTxPackage(hash common.Hash) []*Peer

PeersWithTxPackage retrieves a list of peers that have a given tx package in their set of known hashes.

func (*Peers) PeersWithoutBlock

func (ps *Peers) PeersWithoutBlock(hash common.Hash) []*Peer

PeersWithoutBlock retrieves a list of peers that do not have a given block in their set of known hashes.

func (*Peers) PeersWithoutTx

func (ps *Peers) PeersWithoutTx(hash common.Hash) []*Peer

PeersWithoutTx retrieves a list of peers that do not have a given transaction in their set of known hashes.

func (*Peers) PeersWithoutTxPackage

func (ps *Peers) PeersWithoutTxPackage(hash common.Hash) []*Peer

PeersWithoutTxPackage retrieves a list of peers that do not have a given tx package in their set of known hashes.

func (*Peers) Register

func (ps *Peers) Register(p *Peer) error

Register injects a new peer into the working set, or returns an error if the peer is already known. If a new peer it registered, its broadcast loop is also started.

func (*Peers) Unregister

func (ps *Peers) Unregister(id string) error

Unregister removes a remote peer from the active set, disabling any further actions to/from that particular entity.

type ProtocolManager

type ProtocolManager struct {

	// protocols
	SubProtocols []p2p.Protocol

	BlockProcessCh chan *BlockWithVerifyFlag
	// contains filtered or unexported fields
}

func NewProtocolManager

func NewProtocolManager(networkID uint64, miner Miner.Miner, blockchain blockChain, packer packer.Packer, txpool pool.Pool, txPkgPool pool.Pool) (*ProtocolManager, error)

NewProtocolManager returns a new Fractal sub protocol manager. The Fractal sub protocol manages peers capable with the Fractal network.

func (*ProtocolManager) BroadcastBlock

func (pm *ProtocolManager) BroadcastBlock(block *types.Block)

BroadcastBlock will propagate a block to all neighbors

func (*ProtocolManager) BroadcastTxPackage

func (pm *ProtocolManager) BroadcastTxPackage(pkg *types.TxPackage, propagate bool)

BroadcastTxPackage will either propagate a tx package to it's peers, or will only announce it's availability (depending what's requested).

func (*ProtocolManager) BroadcastTxs

func (pm *ProtocolManager) BroadcastTxs(txs types.Transactions)

BroadcastTxs will propagate a batch of transactions to all peers which are not known to already have the given transaction.

func (*ProtocolManager) FinishDepend

func (pm *ProtocolManager) FinishDepend(p *Peer)

func (*ProtocolManager) GetPacker

func (pm *ProtocolManager) GetPacker() packer.Packer

func (*ProtocolManager) MarkDepend

func (pm *ProtocolManager) MarkDepend(p *Peer)

func (*ProtocolManager) NodeInfo

func (pm *ProtocolManager) NodeInfo() *NodeInfo

NodeInfo retrieves some protocol metadata about the running host node.

func (*ProtocolManager) RemovePeer

func (pm *ProtocolManager) RemovePeer(id string, addBlack bool)

func (*ProtocolManager) SetSynchronizer

func (pm *ProtocolManager) SetSynchronizer(synchronizer synchronizer)

func (*ProtocolManager) Start

func (pm *ProtocolManager) Start(maxPeers int)

func (*ProtocolManager) Stop

func (pm *ProtocolManager) Stop()

Jump to

Keyboard shortcuts

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