network

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2020 License: LGPL-3.0 Imports: 42 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StatusMsgType             = 0
	BlockRequestMsgType       = 1
	BlockResponseMsgType      = 2
	BlockAnnounceMsgType      = 3
	TransactionMsgType        = 4
	ConsensusMsgType          = 5
	RemoteCallRequestType     = 6
	RemoteCallResponseType    = 7
	RemoteReadRequestType     = 8
	RemoteReadResponseType    = 9
	RemoteHeaderRequestType   = 10
	RemoteHeaderResponseType  = 11
	RemoteChangesRequestType  = 12
	RemoteChangesResponseType = 13
	ChainSpecificMsgType      = 255
)

nolint

View Source
const DefaultBasePath = "~/.gossamer/gssmr"

DefaultBasePath the default value for Config.BasePath

View Source
const DefaultKeyFile = "node.key"

DefaultKeyFile the default value for KeyFile

View Source
const DefaultPort = uint32(7000)

DefaultPort the default value for Config.Port

View Source
const DefaultProtocolID = "/gossamer/gssmr/0"

DefaultProtocolID the default value for Config.ProtocolID

View Source
const DefaultProtocolVersion = 0

DefaultProtocolVersion the default value for Config.ProtocolVersion

View Source
const DefaultRandSeed = int64(0)

DefaultRandSeed the default value for Config.RandSeed (0 = non-deterministic)

View Source
const DefaultRoles = byte(1)

DefaultRoles the default value for Config.Roles (0 = no network, 1 = full node)

View Source
const ExpireStatusInterval = SendStatusInterval + time.Minute

ExpireStatusInterval is the time between expiring status messages

View Source
const MDNSPeriod = time.Minute

MDNSPeriod is 1 minute

View Source
const (
	// NetworkStateTimeout is the set time interval that we update network state
	NetworkStateTimeout = time.Minute
)
View Source
const RequestedDataBody = byte(2)

RequestedDataBody flag for requesting body data

View Source
const RequestedDataHeader = byte(1)

RequestedDataHeader flag for requesting header data

View Source
const RequestedDataJustification = byte(16)

RequestedDataJustification flag for requesting justification data

View Source
const RequestedDataMessageQueue = byte(8)

RequestedDataMessageQueue flag for requesting message queue data

View Source
const RequestedDataReceipt = byte(4)

RequestedDataReceipt flag for requesting receipt data

View Source
const SendStatusInterval = 5 * time.Minute

SendStatusInterval is the time between sending status messages

Variables

View Source
var DefaultBootnodes = []string(nil)

DefaultBootnodes the default value for Config.Bootnodes

Functions

This section is empty.

Types

type BlockAnnounceHandshake added in v0.2.0

type BlockAnnounceHandshake struct {
	Roles           byte
	BestBlockNumber uint64
	BestBlockHash   common.Hash
	GenesisHash     common.Hash
}

BlockAnnounceHandshake is exchanged by nodes that are beginning the BlockAnnounce protocol

func (*BlockAnnounceHandshake) Decode added in v0.2.0

func (hs *BlockAnnounceHandshake) Decode(r io.Reader) error

Decode the message into a BlockAnnounceHandshake

func (*BlockAnnounceHandshake) Encode added in v0.2.0

func (hs *BlockAnnounceHandshake) Encode() ([]byte, error)

Encode encodes a BlockAnnounceHandshake message using SCALE

func (*BlockAnnounceHandshake) IDString added in v0.2.0

func (hs *BlockAnnounceHandshake) IDString() string

IDString ...

func (*BlockAnnounceHandshake) String added in v0.2.0

func (hs *BlockAnnounceHandshake) String() string

String formats a BlockAnnounceHandshake as a string

func (*BlockAnnounceHandshake) Type added in v0.2.0

func (hs *BlockAnnounceHandshake) Type() int

Type ...

type BlockAnnounceMessage

type BlockAnnounceMessage struct {
	ParentHash     common.Hash
	Number         *big.Int
	StateRoot      common.Hash
	ExtrinsicsRoot common.Hash
	Digest         [][]byte // any additional block info eg. logs, seal
}

BlockAnnounceMessage is a state block header

func (*BlockAnnounceMessage) Decode

func (bm *BlockAnnounceMessage) Decode(r io.Reader) error

Decode the message into a BlockAnnounceMessage, it assumes the type byte has been removed

func (*BlockAnnounceMessage) Encode

func (bm *BlockAnnounceMessage) Encode() ([]byte, error)

Encode a BlockAnnounce Msg Type containing the BlockAnnounceMessage using scale.Encode

func (*BlockAnnounceMessage) IDString

func (bm *BlockAnnounceMessage) IDString() string

IDString returns the hash of the block

func (*BlockAnnounceMessage) String

func (bm *BlockAnnounceMessage) String() string

string formats a BlockAnnounceMessage as a string

func (*BlockAnnounceMessage) Type added in v0.2.0

func (bm *BlockAnnounceMessage) Type() int

Type returns BlockAnnounceMsgType

type BlockRequestMessage

type BlockRequestMessage struct {
	ID            uint64
	RequestedData byte
	StartingBlock *variadic.Uint64OrHash // first byte 0 = block hash (32 byte), first byte 1 = block number (int64)
	EndBlockHash  *optional.Hash
	Direction     byte
	Max           *optional.Uint32
}

BlockRequestMessage for optionals, if first byte is 0, then it is None otherwise it is Some

func (*BlockRequestMessage) Decode

func (bm *BlockRequestMessage) Decode(r io.Reader) error

Decode the message into a BlockRequestMessage, it assumes the type byte has been removed

func (*BlockRequestMessage) Encode

func (bm *BlockRequestMessage) Encode() ([]byte, error)

Encode encodes a block request message using SCALE and appends the type byte to the start

func (*BlockRequestMessage) IDString

func (bm *BlockRequestMessage) IDString() string

IDString Returns the ID of the block

func (*BlockRequestMessage) String

func (bm *BlockRequestMessage) String() string

String formats a BlockRequestMessage as a string

func (*BlockRequestMessage) Type added in v0.2.0

func (bm *BlockRequestMessage) Type() int

Type returns BlockRequestMsgType

type BlockResponseMessage

type BlockResponseMessage struct {
	ID        uint64
	BlockData []*types.BlockData
}

BlockResponseMessage struct

func (*BlockResponseMessage) Decode

func (bm *BlockResponseMessage) Decode(r io.Reader) error

Decode the message into a BlockResponseMessage, it assumes the type byte has been removed

func (*BlockResponseMessage) Encode

func (bm *BlockResponseMessage) Encode() ([]byte, error)

Encode encodes a block response message using SCALE and appends the type byte to the start

func (*BlockResponseMessage) IDString

func (bm *BlockResponseMessage) IDString() string

IDString returns the ID of BlockResponseMessage

func (*BlockResponseMessage) String

func (bm *BlockResponseMessage) String() string

String formats a BlockResponseMessage as a string

func (*BlockResponseMessage) Type added in v0.2.0

func (bm *BlockResponseMessage) Type() int

Type returns BlockResponseMsgType

type BlockState

type BlockState interface {
	BestBlockHeader() (*types.Header, error)
	GenesisHash() common.Hash
}

BlockState interface for block state methods

type Config

type Config struct {
	LogLvl log.Lvl

	ErrChan chan<- error

	// BasePath the data directory for the node
	BasePath string
	// Roles a bitmap value that represents the different roles for the sender node (see Table D.2)
	Roles byte

	// BlockState the block state's interface
	BlockState BlockState
	// NetworkState the network state's interface
	NetworkState NetworkState

	Syncer Syncer

	// Port the network port used for listening
	Port uint32
	// RandSeed the seed used to generate the network p2p identity (0 = non-deterministic random seed)
	RandSeed int64
	// Bootnodes the peer addresses used for bootstrapping
	Bootnodes []string
	// ProtocolID the protocol ID for network messages
	ProtocolID string
	// ProtocolVersion the protocol version for network messages (the third item in the ProtocolID)
	ProtocolVersion uint32
	// MinSupportedVersion the minimum supported protocol version (defaults to current ProtocolVersion)
	MinSupportedVersion uint32
	// NoBootstrap disables bootstrapping
	NoBootstrap bool
	// NoMDNS disables MDNS discovery
	NoMDNS bool
	// NoStatus disables the status message exchange protocol
	NoStatus bool

	MessageHandler MessageHandler
	// contains filtered or unexported fields
}

Config is used to configure a network service

type ConnManager

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

ConnManager implements connmgr.ConnManager

func (*ConnManager) Close

func (*ConnManager) Close() error

Close peer

func (*ConnManager) ClosedStream

func (cm *ConnManager) ClosedStream(n network.Network, s network.Stream)

ClosedStream is called when a stream closed

func (*ConnManager) Connected

func (cm *ConnManager) Connected(n network.Network, c network.Conn)

Connected is called when a connection opened

func (*ConnManager) Disconnected

func (cm *ConnManager) Disconnected(n network.Network, c network.Conn)

Disconnected is called when a connection closed

func (*ConnManager) GetTagInfo

func (*ConnManager) GetTagInfo(peer.ID) *connmgr.TagInfo

GetTagInfo peer

func (*ConnManager) IsProtected added in v0.2.0

func (*ConnManager) IsProtected(id peer.ID, tag string) (protected bool)

IsProtected ...

func (*ConnManager) Listen

func (cm *ConnManager) Listen(n network.Network, addr ma.Multiaddr)

Listen is called when network starts listening on an address

func (*ConnManager) ListenClose

func (cm *ConnManager) ListenClose(n network.Network, addr ma.Multiaddr)

ListenClose is called when network stops listening on an address

func (*ConnManager) Notifee

func (cm *ConnManager) Notifee() network.Notifiee

Notifee is used to monitor changes to a connection

func (*ConnManager) OpenedStream

func (cm *ConnManager) OpenedStream(n network.Network, s network.Stream)

OpenedStream is called when a stream opened

func (*ConnManager) Protect

func (*ConnManager) Protect(peer.ID, string)

Protect peer

func (*ConnManager) TagPeer

func (*ConnManager) TagPeer(peer.ID, string, int)

TagPeer peer

func (*ConnManager) TrimOpenConns

func (*ConnManager) TrimOpenConns(ctx context.Context)

TrimOpenConns peer

func (*ConnManager) Unprotect

func (*ConnManager) Unprotect(peer.ID, string) bool

Unprotect peer

func (*ConnManager) UntagPeer

func (*ConnManager) UntagPeer(peer.ID, string)

UntagPeer peer

func (*ConnManager) UpsertTag

func (*ConnManager) UpsertTag(peer.ID, string, func(int) int)

UpsertTag peer

type ConsensusMessage

type ConsensusMessage struct {
	// Identifies consensus engine.
	ConsensusEngineID types.ConsensusEngineID
	// Message payload.
	Data []byte
}

ConsensusMessage is mostly opaque to us

func (*ConsensusMessage) Decode

func (cm *ConsensusMessage) Decode(r io.Reader) error

Decode the message into a ConsensusMessage, it assumes the type byte has been removed

func (*ConsensusMessage) Encode

func (cm *ConsensusMessage) Encode() ([]byte, error)

Encode encodes a block response message using SCALE and appends the type byte to the start

func (*ConsensusMessage) IDString

func (cm *ConsensusMessage) IDString() string

IDString returns the Hash of ConsensusMessage

func (*ConsensusMessage) String

func (cm *ConsensusMessage) String() string

String is the string

func (*ConsensusMessage) Type added in v0.2.0

func (cm *ConsensusMessage) Type() int

Type returns ConsensusMsgType

type Message

type Message interface {
	Encode() ([]byte, error)
	Decode(io.Reader) error
	String() string
	Type() int
	IDString() string // TODO: this can be removed
}

Message interface

type MessageHandler added in v0.2.0

type MessageHandler interface {
	HandleMessage(Message)
}

MessageHandler interface for handling message passing

type MockNetworkState added in v0.2.0

type MockNetworkState struct {
	Health       common.Health
	NetworkState common.NetworkState
	Peers        []common.PeerInfo
}

MockNetworkState for testing purposes

func (*MockNetworkState) SetHealth added in v0.2.0

func (ns *MockNetworkState) SetHealth(health common.Health)

SetHealth sets network health in the database

func (*MockNetworkState) SetNetworkState added in v0.2.0

func (ns *MockNetworkState) SetNetworkState(networkState common.NetworkState)

SetNetworkState sets network state in the database

func (*MockNetworkState) SetPeers added in v0.2.0

func (ns *MockNetworkState) SetPeers(peers []common.PeerInfo)

SetPeers sets network state in the database

type NetworkState

type NetworkState interface {
	SetHealth(common.Health)
	SetNetworkState(common.NetworkState)
	SetPeers([]common.PeerInfo)
}

NetworkState interface for network state methods

type Notifee

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

Notifee See https://godoc.org/github.com/libp2p/go-libp2p/p2p/discovery#Notifee

func (Notifee) HandlePeerFound

func (n Notifee) HandlePeerFound(p peer.AddrInfo)

HandlePeerFound is event handler called when a peer is found

type Service

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

Service describes a network service

func NewService

func NewService(cfg *Config) (*Service, error)

NewService creates a new network service from the configuration and message channels

func (*Service) Health

func (s *Service) Health() common.Health

Health returns information about host needed for the rpc server

func (*Service) IsStopped added in v0.2.0

func (s *Service) IsStopped() bool

IsStopped returns true if the service is stopped

func (*Service) NetworkState

func (s *Service) NetworkState() common.NetworkState

NetworkState returns information about host needed for the rpc server and the runtime

func (*Service) NodeRoles

func (s *Service) NodeRoles() byte

NodeRoles Returns the roles the node is running as.

func (*Service) Peers

func (s *Service) Peers() []common.PeerInfo

Peers returns information about connected peers needed for the rpc server

func (*Service) SendMessage added in v0.2.0

func (s *Service) SendMessage(msg Message)

SendMessage implementation of interface to handle receiving messages

func (*Service) SetMessageHandler added in v0.2.0

func (s *Service) SetMessageHandler(handler MessageHandler)

SetMessageHandler sets the given MessageHandler for this service

func (*Service) Start

func (s *Service) Start() error

Start starts the network service

func (*Service) Stop

func (s *Service) Stop() error

Stop closes running instances of the host and network services as well as the message channel from the network service to the core service (services that are dependent on the host instance should be closed first)

type StatusMessage

type StatusMessage struct {
	ProtocolVersion     uint32
	MinSupportedVersion uint32
	Roles               byte
	BestBlockNumber     uint64
	BestBlockHash       common.Hash
	GenesisHash         common.Hash
	ChainStatus         []byte
}

StatusMessage struct

func (*StatusMessage) Decode

func (sm *StatusMessage) Decode(r io.Reader) error

Decode the message into a StatusMessage, it assumes the type byte has been removed

func (*StatusMessage) Encode

func (sm *StatusMessage) Encode() ([]byte, error)

Encode encodes a status message using SCALE and appends the type byte to the start

func (*StatusMessage) IDString

func (sm *StatusMessage) IDString() string

IDString Returns an empty string to ensure we don't rebroadcast it

func (*StatusMessage) String

func (sm *StatusMessage) String() string

String formats a StatusMessage as a string

func (*StatusMessage) Type added in v0.2.0

func (sm *StatusMessage) Type() int

Type returns StatusMsgType

type Syncer added in v0.2.0

type Syncer interface {
	// CreateBlockResponse is called upon receipt of a BlockRequestMessage to create the response
	CreateBlockResponse(*BlockRequestMessage) (*BlockResponseMessage, error)

	// HandleBlockResponse is called upon receipt of BlockResponseMessage to process it.
	// If another request needs to be sent to the peer, this function will return it.
	HandleBlockResponse(*BlockResponseMessage) *BlockRequestMessage

	// HandleBlockAnnounce is called upon receipt of a BlockAnnounceMessage to process it.
	// If a request needs to be sent to the peer to retrieve the full block, this function will return it.
	HandleBlockAnnounce(*BlockAnnounceMessage) *BlockRequestMessage

	// HandleSeenBlocks is called upon receiving a StatusMessage from a peer that has a higher chain head than us
	HandleSeenBlocks(*big.Int) *BlockRequestMessage
}

Syncer is implemented by the syncing service

type TransactionMessage

type TransactionMessage struct {
	Extrinsics []types.Extrinsic
}

TransactionMessage is a struct that holds reference to Extrinsics

func (*TransactionMessage) Decode

func (tm *TransactionMessage) Decode(r io.Reader) error

Decode the message into a TransactionMessage, it assumes the type byte han been removed

func (*TransactionMessage) Encode

func (tm *TransactionMessage) Encode() ([]byte, error)

Encode will encode TransactionMessage using scale.Encode

func (*TransactionMessage) IDString

func (tm *TransactionMessage) IDString() string

IDString returns the Hash of TransactionMessage

func (*TransactionMessage) String

func (tm *TransactionMessage) String() string

String returns the TransactionMessage extrinsics

func (*TransactionMessage) Type added in v0.2.0

func (tm *TransactionMessage) Type() int

Type returns TransactionMsgType

Jump to

Keyboard shortcuts

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