network

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: LGPL-3.0 Imports: 41 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 = time.Minute

NetworkStateTimeout is the set time interval that we update network state

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

func (bm *BlockAnnounceMessage) GetType() int

GetType int

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

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

func (bm *BlockRequestMessage) GetType() int

GetType int

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

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

func (bm *BlockResponseMessage) GetType() int

GetType int

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

type BlockState

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

BlockState interface for block state methods

type Config

type Config struct {
	// 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

	// 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

	// MsgRec is the message channel from the core service to the network service
	MsgRec <-chan Message
	// MsgSend is the message channel from the network service to the core service
	MsgSend chan<- Message
	// SyncChan is the channel for syncing
	SyncChan chan<- *big.Int
	// contains filtered or unexported fields
}

Config is used to configure a network service

type ConnManager

type ConnManager struct{}

ConnManager implement 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) 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) GetType

func (cm *ConsensusMessage) GetType() int

GetType returns the type

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

type Message

type Message interface {
	Encode() ([]byte, error)
	Decode(io.Reader) error
	String() string
	GetType() int
	IDString() string
}

Message interface

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

func (sm *StatusMessage) GetType() int

GetType returns the StatusMsgType int

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

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

func (tm *TransactionMessage) GetType() int

GetType returns the TransactionMsgType

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

Jump to

Keyboard shortcuts

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