Documentation
¶
Index ¶
- Constants
- Variables
- type BlockAnnounceHandshake
- type BlockAnnounceMessage
- type BlockRequestMessage
- type BlockResponseMessage
- type BlockState
- type Config
- type ConnManager
- func (*ConnManager) Close() error
- func (cm *ConnManager) ClosedStream(n network.Network, s network.Stream)
- func (cm *ConnManager) Connected(n network.Network, c network.Conn)
- func (cm *ConnManager) Disconnected(n network.Network, c network.Conn)
- func (*ConnManager) GetTagInfo(peer.ID) *connmgr.TagInfo
- func (*ConnManager) IsProtected(id peer.ID, tag string) (protected bool)
- func (cm *ConnManager) Listen(n network.Network, addr ma.Multiaddr)
- func (cm *ConnManager) ListenClose(n network.Network, addr ma.Multiaddr)
- func (cm *ConnManager) Notifee() network.Notifiee
- func (cm *ConnManager) OpenedStream(n network.Network, s network.Stream)
- func (*ConnManager) Protect(peer.ID, string)
- func (*ConnManager) TagPeer(peer.ID, string, int)
- func (*ConnManager) TrimOpenConns(ctx context.Context)
- func (*ConnManager) Unprotect(peer.ID, string) bool
- func (*ConnManager) UntagPeer(peer.ID, string)
- func (*ConnManager) UpsertTag(peer.ID, string, func(int) int)
- type ConsensusMessage
- type Message
- type MessageHandler
- type MockNetworkState
- type NetworkState
- type Notifee
- type Service
- func (s *Service) Health() common.Health
- func (s *Service) IsStopped() bool
- func (s *Service) NetworkState() common.NetworkState
- func (s *Service) NodeRoles() byte
- func (s *Service) Peers() []common.PeerInfo
- func (s *Service) SendMessage(msg Message)
- func (s *Service) SetMessageHandler(handler MessageHandler)
- func (s *Service) Start() error
- func (s *Service) Stop() error
- type StatusMessage
- type Syncer
- type TransactionMessage
Constants ¶
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
const DefaultBasePath = "~/.gossamer/gssmr"
DefaultBasePath the default value for Config.BasePath
const DefaultKeyFile = "node.key"
DefaultKeyFile the default value for KeyFile
const DefaultPort = uint32(7000)
DefaultPort the default value for Config.Port
const DefaultProtocolID = "/gossamer/gssmr/0"
DefaultProtocolID the default value for Config.ProtocolID
const DefaultProtocolVersion = 0
DefaultProtocolVersion the default value for Config.ProtocolVersion
const DefaultRandSeed = int64(0)
DefaultRandSeed the default value for Config.RandSeed (0 = non-deterministic)
const DefaultRoles = byte(1)
DefaultRoles the default value for Config.Roles (0 = no network, 1 = full node)
const ExpireStatusInterval = SendStatusInterval + time.Minute
ExpireStatusInterval is the time between expiring status messages
const MDNSPeriod = time.Minute
MDNSPeriod is 1 minute
const ( // NetworkStateTimeout is the set time interval that we update network state NetworkStateTimeout = time.Minute )
const RequestedDataBody = byte(2)
RequestedDataBody flag for requesting body data
const RequestedDataHeader = byte(1)
RequestedDataHeader flag for requesting header data
const RequestedDataJustification = byte(16)
RequestedDataJustification flag for requesting justification data
const RequestedDataMessageQueue = byte(8)
RequestedDataMessageQueue flag for requesting message queue data
const RequestedDataReceipt = byte(4)
RequestedDataReceipt flag for requesting receipt data
const SendStatusInterval = 5 * time.Minute
SendStatusInterval is the time between sending status messages
Variables ¶
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 ¶
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 ¶
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) 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) TrimOpenConns ¶
func (*ConnManager) TrimOpenConns(ctx context.Context)
TrimOpenConns 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) 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 ¶
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 ¶
NewService creates a new network service from the configuration and message channels
func (*Service) NetworkState ¶
func (s *Service) NetworkState() common.NetworkState
NetworkState returns information about host needed for the rpc server and the runtime
func (*Service) SendMessage ¶ added in v0.2.0
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
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 ¶
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