Documentation ¶
Index ¶
- Constants
- Variables
- type BlockAnnounceHandshake
- func (hs *BlockAnnounceHandshake) Decode(in []byte) error
- func (hs *BlockAnnounceHandshake) Encode() ([]byte, error)
- func (hs *BlockAnnounceHandshake) Hash() common.Hash
- func (hs *BlockAnnounceHandshake) IsHandshake() bool
- func (hs *BlockAnnounceHandshake) String() string
- func (hs *BlockAnnounceHandshake) SubProtocol() string
- func (hs *BlockAnnounceHandshake) Type() byte
- type BlockAnnounceMessage
- func (bm *BlockAnnounceMessage) Decode(in []byte) error
- func (bm *BlockAnnounceMessage) Encode() ([]byte, error)
- func (bm *BlockAnnounceMessage) Hash() common.Hash
- func (bm *BlockAnnounceMessage) IsHandshake() bool
- func (bm *BlockAnnounceMessage) String() string
- func (bm *BlockAnnounceMessage) SubProtocol() string
- func (bm *BlockAnnounceMessage) Type() byte
- 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 (cm *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 (cm *ConnManager) Protect(id peer.ID, tag string)
- func (*ConnManager) TagPeer(peer.ID, string, int)
- func (*ConnManager) TrimOpenConns(ctx context.Context)
- func (cm *ConnManager) Unprotect(id peer.ID, tag string) bool
- func (*ConnManager) UntagPeer(peer.ID, string)
- func (*ConnManager) UpsertTag(peer.ID, string, func(int) int)
- type ConsensusMessage
- func (cm *ConsensusMessage) Decode(in []byte) error
- func (cm *ConsensusMessage) Encode() ([]byte, error)
- func (cm *ConsensusMessage) Hash() common.Hash
- func (cm *ConsensusMessage) IsHandshake() bool
- func (cm *ConsensusMessage) String() string
- func (cm *ConsensusMessage) SubProtocol() string
- func (cm *ConsensusMessage) Type() byte
- type Handshake
- type HandshakeDecoder
- type HandshakeGetter
- type HandshakeValidator
- type LightRequest
- type LightResponse
- type Message
- type MessageDecoder
- type Notifee
- type NotificationsMessage
- type NotificationsMessageHandler
- type Pair
- type RemoteCallRequest
- type RemoteCallResponse
- type RemoteChangesRequest
- type RemoteChangesResponse
- type RemoteHeaderRequest
- type RemoteHeaderResponse
- type RemoteReadChildRequest
- type RemoteReadRequest
- type RemoteReadResponse
- 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) RegisterNotificationsProtocol(sub protocol.ID, messageID byte, handshakeGetter HandshakeGetter, ...) error
- func (s *Service) SendMessage(msg NotificationsMessage)
- func (s *Service) SetSyncer(syncer Syncer)
- func (s *Service) SetTransactionHandler(handler TransactionHandler)
- func (s *Service) Start() error
- func (s *Service) Stop() error
- type Syncer
- type TransactionHandler
- type TransactionMessage
- func (tm *TransactionMessage) Decode(in []byte) error
- func (tm *TransactionMessage) Encode() ([]byte, error)
- func (tm *TransactionMessage) Hash() common.Hash
- func (tm *TransactionMessage) IsHandshake() bool
- func (tm *TransactionMessage) String() string
- func (tm *TransactionMessage) SubProtocol() string
- func (tm *TransactionMessage) Type() byte
Constants ¶
const ( // DefaultKeyFile the default value for KeyFile DefaultKeyFile = "node.key" // DefaultBasePath the default value for Config.BasePath DefaultBasePath = "~/.gossamer/gssmr" // DefaultPort the default value for Config.Port DefaultPort = uint32(7000) // DefaultRandSeed the default value for Config.RandSeed (0 = non-deterministic) DefaultRandSeed = int64(0) // DefaultProtocolID the default value for Config.ProtocolID DefaultProtocolID = "/gossamer/gssmr/0" // DefaultRoles the default value for Config.Roles (0 = no network, 1 = full node) DefaultRoles = byte(1) // DefaultMinPeerCount is the default minimum peer count DefaultMinPeerCount = 5 // DefaultMaxPeerCount is the default maximum peer count DefaultMaxPeerCount = 50 )
const ( BlockAnnounceMsgType byte = 3 TransactionMsgType byte = 4 ConsensusMsgType byte = 5 )
Message types for notifications protocol messages. Used internally to map message to protocol.
const ( RequestedDataHeader = byte(1) RequestedDataBody = byte(2) RequestedDataReceipt = byte(4) RequestedDataMessageQueue = byte(8) RequestedDataJustification = byte(16) )
nolint
const MDNSPeriod = time.Minute
MDNSPeriod is 1 minute
const ( // NetworkStateTimeout is the set time interval that we update network state NetworkStateTimeout = time.Minute )
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 uint32 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(in []byte) 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) Hash ¶ added in v0.3.0
func (hs *BlockAnnounceHandshake) Hash() common.Hash
Hash ...
func (*BlockAnnounceHandshake) IsHandshake ¶ added in v0.3.0
func (hs *BlockAnnounceHandshake) IsHandshake() bool
IsHandshake returns true
func (*BlockAnnounceHandshake) String ¶ added in v0.2.0
func (hs *BlockAnnounceHandshake) String() string
String formats a BlockAnnounceHandshake as a string
func (*BlockAnnounceHandshake) SubProtocol ¶ added in v0.3.0
func (hs *BlockAnnounceHandshake) SubProtocol() string
SubProtocol returns the block-announces sub-protocol
func (*BlockAnnounceHandshake) Type ¶ added in v0.2.0
func (hs *BlockAnnounceHandshake) Type() byte
Type ...
type BlockAnnounceMessage ¶
type BlockAnnounceMessage struct { ParentHash common.Hash Number *big.Int StateRoot common.Hash ExtrinsicsRoot common.Hash Digest types.Digest }
BlockAnnounceMessage is a state block header
func (*BlockAnnounceMessage) Decode ¶
func (bm *BlockAnnounceMessage) Decode(in []byte) error
Decode the message into a BlockAnnounceMessage
func (*BlockAnnounceMessage) Encode ¶
func (bm *BlockAnnounceMessage) Encode() ([]byte, error)
Encode a BlockAnnounce Msg Type containing the BlockAnnounceMessage using scale.Encode
func (*BlockAnnounceMessage) Hash ¶ added in v0.3.0
func (bm *BlockAnnounceMessage) Hash() common.Hash
Hash returns the hash of the BlockAnnounceMessage
func (*BlockAnnounceMessage) IsHandshake ¶ added in v0.3.0
func (bm *BlockAnnounceMessage) IsHandshake() bool
IsHandshake returns false
func (*BlockAnnounceMessage) String ¶
func (bm *BlockAnnounceMessage) String() string
string formats a BlockAnnounceMessage as a string
func (*BlockAnnounceMessage) SubProtocol ¶ added in v0.3.0
func (bm *BlockAnnounceMessage) SubProtocol() string
SubProtocol returns the block-announces sub-protocol
func (*BlockAnnounceMessage) Type ¶ added in v0.2.0
func (bm *BlockAnnounceMessage) Type() byte
Type returns BlockAnnounceMsgType
type BlockRequestMessage ¶
type BlockRequestMessage struct { RequestedData byte StartingBlock *variadic.Uint64OrHash // first byte 0 = block hash (32 byte), first byte 1 = block number (int64) EndBlockHash *optional.Hash Direction byte // 0 = ascending, 1 = descending Max *optional.Uint32 }
BlockRequestMessage is sent to request some blocks from a peer
func (*BlockRequestMessage) Decode ¶
func (bm *BlockRequestMessage) Decode(in []byte) error
Decode decodes the protobuf encoded input to a BlockRequestMessage
func (*BlockRequestMessage) Encode ¶
func (bm *BlockRequestMessage) Encode() ([]byte, error)
Encode returns the protobuf encoded BlockRequestMessage
func (*BlockRequestMessage) String ¶
func (bm *BlockRequestMessage) String() string
String formats a BlockRequestMessage as a string
func (*BlockRequestMessage) SubProtocol ¶ added in v0.3.0
func (bm *BlockRequestMessage) SubProtocol() string
SubProtocol returns the sync sub-protocol
type BlockResponseMessage ¶
BlockResponseMessage is sent in response to a BlockRequestMessage
func (*BlockResponseMessage) Decode ¶
func (bm *BlockResponseMessage) Decode(in []byte) (err error)
Decode decodes the protobuf encoded input to a BlockResponseMessage
func (*BlockResponseMessage) Encode ¶
func (bm *BlockResponseMessage) Encode() ([]byte, error)
Encode returns the protobuf encoded BlockResponseMessage
func (*BlockResponseMessage) String ¶
func (bm *BlockResponseMessage) String() string
String formats a BlockResponseMessage as a string
func (*BlockResponseMessage) SubProtocol ¶ added in v0.3.0
func (bm *BlockResponseMessage) SubProtocol() string
SubProtocol returns the sync sub-protocol
type BlockState ¶
type BlockState interface { BestBlockHeader() (*types.Header, error) BestBlockNumber() (*big.Int, error) GenesisHash() common.Hash HasBlockBody(common.Hash) (bool, error) }
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 // Service interfaces BlockState BlockState Syncer Syncer TransactionHandler TransactionHandler // 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 // NoBootstrap disables bootstrapping NoBootstrap bool // NoMDNS disables MDNS discovery NoMDNS bool MinPeers int MaxPeers int // contains filtered or unexported fields }
Config is used to configure a network service
type ConnManager ¶
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 (cm *ConnManager) IsProtected(id peer.ID, tag string) (protected bool)
IsProtected returns whether the given peer is protected from pruning or not.
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 (cm *ConnManager) Protect(id peer.ID, tag string)
Protect peer will add the given peer to the protectedPeerMap which will protect the peer from pruning.
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(in []byte) error
Decode the message into a ConsensusMessage
func (*ConsensusMessage) Encode ¶
func (cm *ConsensusMessage) Encode() ([]byte, error)
Encode encodes a block response message using SCALE
func (*ConsensusMessage) Hash ¶ added in v0.3.0
func (cm *ConsensusMessage) Hash() common.Hash
Hash returns the Hash of ConsensusMessage
func (*ConsensusMessage) IsHandshake ¶ added in v0.3.0
func (cm *ConsensusMessage) IsHandshake() bool
IsHandshake returns false
func (*ConsensusMessage) SubProtocol ¶ added in v0.3.0
func (cm *ConsensusMessage) SubProtocol() string
SubProtocol returns the empty, since consensus message sub-protocol is determined by the package using it
func (*ConsensusMessage) Type ¶ added in v0.2.0
func (cm *ConsensusMessage) Type() byte
Type returns ConsensusMsgType
type Handshake ¶ added in v0.3.0
type Handshake interface { NotificationsMessage }
Handshake is the interface all handshakes for notifications protocols must implement
type HandshakeDecoder ¶ added in v0.3.0
HandshakeDecoder is a custom decoder for a handshake
type HandshakeGetter ¶ added in v0.3.0
HandshakeGetter is a function that returns a custom handshake
type HandshakeValidator ¶ added in v0.3.0
HandshakeValidator validates a handshake. It returns an error if it is invalid
type LightRequest ¶ added in v0.3.0
type LightRequest struct { RmtCallRequest *RemoteCallRequest RmtReadRequest *RemoteReadRequest RmtHeaderRequest *RemoteHeaderRequest RmtReadChildRequest *RemoteReadChildRequest RmtChangesRequest *RemoteChangesRequest }
LightRequest is all possible light client related requests.
func NewLightRequest ¶ added in v0.3.0
func NewLightRequest() *LightRequest
NewLightRequest returns a new LightRequest
func (*LightRequest) Decode ¶ added in v0.3.0
func (l *LightRequest) Decode(in []byte) error
Decode the message into a LightRequest, it assumes the type byte has been removed
func (*LightRequest) Encode ¶ added in v0.3.0
func (l *LightRequest) Encode() ([]byte, error)
Encode encodes a LightRequest message using SCALE and appends the type byte to the start
func (LightRequest) String ¶ added in v0.3.0
func (l LightRequest) String() string
String formats a LightRequest as a string
func (*LightRequest) SubProtocol ¶ added in v0.3.0
func (l *LightRequest) SubProtocol() string
SubProtocol returns the light sub-protocol
type LightResponse ¶ added in v0.3.0
type LightResponse struct { RmtCallResponse *RemoteCallResponse RmtReadResponse *RemoteReadResponse RmtHeaderResponse *RemoteHeaderResponse RmtChangeResponse *RemoteChangesResponse }
LightResponse is all possible light client response messages.
func NewLightResponse ¶ added in v0.3.0
func NewLightResponse() *LightResponse
NewLightResponse returns a new LightResponse
func (*LightResponse) Decode ¶ added in v0.3.0
func (l *LightResponse) Decode(in []byte) error
Decode the message into a LightResponse, it assumes the type byte has been removed
func (*LightResponse) Encode ¶ added in v0.3.0
func (l *LightResponse) Encode() ([]byte, error)
Encode encodes a LightResponse message using SCALE and appends the type byte to the start
func (LightResponse) String ¶ added in v0.3.0
func (l LightResponse) String() string
String formats a RemoteReadRequest as a string
func (*LightResponse) SubProtocol ¶ added in v0.3.0
func (l *LightResponse) SubProtocol() string
SubProtocol returns the light sub-protocol
type Message ¶
type Message interface { SubProtocol() string Encode() ([]byte, error) Decode([]byte) error String() string }
Message must be implemented by all network messages
type MessageDecoder ¶ added in v0.3.0
type MessageDecoder = func([]byte) (NotificationsMessage, error)
MessageDecoder is a custom decoder for a message
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 NotificationsMessage ¶ added in v0.3.0
NotificationsMessage must be implemented by all messages sent over a notifications protocol
type NotificationsMessageHandler ¶ added in v0.3.0
type NotificationsMessageHandler = func(peer peer.ID, msg NotificationsMessage) error
NotificationsMessageHandler is called when a (non-handshake) message is received over a notifications stream.
type Pair ¶ added in v0.3.0
type Pair struct {
// contains filtered or unexported fields
}
Pair is a pair of arbitrary bytes.
type RemoteCallRequest ¶ added in v0.3.0
RemoteCallRequest ...
func (*RemoteCallRequest) String ¶ added in v0.3.0
func (rc *RemoteCallRequest) String() string
String formats a RemoteCallRequest as a string
type RemoteCallResponse ¶ added in v0.3.0
type RemoteCallResponse struct {
Proof []byte
}
RemoteCallResponse ...
func (*RemoteCallResponse) String ¶ added in v0.3.0
func (rc *RemoteCallResponse) String() string
String formats a RemoteCallResponse as a string
type RemoteChangesRequest ¶ added in v0.3.0
type RemoteChangesRequest struct { FirstBlock *optional.Hash LastBlock *optional.Hash Min []byte Max []byte StorageKey *optional.Bytes // contains filtered or unexported fields }
RemoteChangesRequest ...
func NewRemoteChangesRequest ¶ added in v0.3.0
func NewRemoteChangesRequest() *RemoteChangesRequest
NewRemoteChangesRequest returns a new RemoteChangesRequest
func (*RemoteChangesRequest) String ¶ added in v0.3.0
func (rc *RemoteChangesRequest) String() string
String formats a RemoteChangesRequest as a string
type RemoteChangesResponse ¶ added in v0.3.0
RemoteChangesResponse ...
func (*RemoteChangesResponse) String ¶ added in v0.3.0
func (rc *RemoteChangesResponse) String() string
String formats a RemoteChangesResponse as a string
type RemoteHeaderRequest ¶ added in v0.3.0
type RemoteHeaderRequest struct {
Block []byte
}
RemoteHeaderRequest ...
func (*RemoteHeaderRequest) String ¶ added in v0.3.0
func (rh *RemoteHeaderRequest) String() string
String formats a RemoteHeaderRequest as a string
type RemoteHeaderResponse ¶ added in v0.3.0
type RemoteHeaderResponse struct { Header []*optional.Header // contains filtered or unexported fields }
RemoteHeaderResponse ...
func (*RemoteHeaderResponse) String ¶ added in v0.3.0
func (rh *RemoteHeaderResponse) String() string
String formats a RemoteHeaderResponse as a string
type RemoteReadChildRequest ¶ added in v0.3.0
RemoteReadChildRequest ...
func (*RemoteReadChildRequest) String ¶ added in v0.3.0
func (rr *RemoteReadChildRequest) String() string
String formats a RemoteReadChildRequest as a string
type RemoteReadRequest ¶ added in v0.3.0
RemoteReadRequest ...
func (*RemoteReadRequest) String ¶ added in v0.3.0
func (rr *RemoteReadRequest) String() string
String formats a RemoteReadRequest as a string
type RemoteReadResponse ¶ added in v0.3.0
type RemoteReadResponse struct {
Proof []byte
}
RemoteReadResponse ...
func (*RemoteReadResponse) String ¶ added in v0.3.0
func (rr *RemoteReadResponse) String() string
String formats a RemoteReadResponse as a string
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) RegisterNotificationsProtocol ¶ added in v0.3.0
func (s *Service) RegisterNotificationsProtocol(sub protocol.ID, messageID byte, handshakeGetter HandshakeGetter, handshakeDecoder HandshakeDecoder, handshakeValidator HandshakeValidator, messageDecoder MessageDecoder, messageHandler NotificationsMessageHandler, ) error
RegisterNotificationsProtocol registers a protocol with the network service with the given handler messageID is a user-defined message ID for the message passed over this protocol.
func (*Service) SendMessage ¶ added in v0.2.0
func (s *Service) SendMessage(msg NotificationsMessage)
SendMessage implementation of interface to handle receiving messages
func (*Service) SetTransactionHandler ¶ added in v0.3.0
func (s *Service) SetTransactionHandler(handler TransactionHandler)
SetTransactionHandler sets the TransactionHandler used by the network service
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) // ProcessBlockData is called to process BlockData received in a BlockResponseMessage ProcessBlockData(data []*types.BlockData) error // 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) error // IsSynced exposes the internal synced state // TODO: use syncQueue for this IsSynced() bool }
Syncer is implemented by the syncing service
type TransactionHandler ¶ added in v0.3.0
type TransactionHandler interface {
HandleTransactionMessage(*TransactionMessage) error
}
TransactionHandler is the interface used by the transactions sub-protocol
type TransactionMessage ¶
TransactionMessage is a network message that is sent to notify of new transactions entering the network
func (*TransactionMessage) Decode ¶
func (tm *TransactionMessage) Decode(in []byte) error
Decode the message into a TransactionMessage
func (*TransactionMessage) Encode ¶
func (tm *TransactionMessage) Encode() ([]byte, error)
Encode will encode TransactionMessage using scale.Encode
func (*TransactionMessage) Hash ¶ added in v0.3.0
func (tm *TransactionMessage) Hash() common.Hash
Hash returns the hash of the TransactionMessage
func (*TransactionMessage) IsHandshake ¶ added in v0.3.0
func (tm *TransactionMessage) IsHandshake() bool
IsHandshake returns false
func (*TransactionMessage) String ¶
func (tm *TransactionMessage) String() string
String returns the TransactionMessage extrinsics
func (*TransactionMessage) SubProtocol ¶ added in v0.3.0
func (tm *TransactionMessage) SubProtocol() string
SubProtocol returns the transactions sub-protocol
func (*TransactionMessage) Type ¶ added in v0.2.0
func (tm *TransactionMessage) Type() byte
Type returns TransactionMsgType