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) Connected(n network.Network, c network.Conn)
- func (cm *ConnManager) Disconnected(_ network.Network, c network.Conn)
- func (*ConnManager) GetTagInfo(peer.ID) *connmgr.TagInfo
- func (cm *ConnManager) IsProtected(id peer.ID, _ 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) Protect(id peer.ID, _ string)
- func (*ConnManager) TagPeer(peer.ID, string, int)
- func (*ConnManager) TrimOpenConns(context.Context)
- func (cm *ConnManager) Unprotect(id peer.ID, _ string) bool
- func (*ConnManager) UntagPeer(peer.ID, string)
- func (*ConnManager) UpsertTag(peer.ID, string, func(int) int)
- type ConsensusMessage
- type Handshake
- type HandshakeDecoder
- type HandshakeGetter
- type HandshakeValidator
- type LightRequest
- type LightResponse
- type Message
- type MessageDecoder
- type Notifee
- type NotificationsMessage
- type NotificationsMessageBatchHandler
- type NotificationsMessageHandler
- type Pair
- type Peer
- type PeerAdd
- type PeerRemove
- type PeerSetHandler
- type RemoteCallRequest
- type RemoteCallResponse
- type RemoteChangesRequest
- type RemoteChangesResponse
- type RemoteHeaderRequest
- type RemoteHeaderResponse
- type RemoteReadChildRequest
- type RemoteReadRequest
- type RemoteReadResponse
- type Service
- func (s *Service) AddReservedPeers(addrs ...string) error
- func (s *Service) DoBlockRequest(to peer.ID, req *BlockRequestMessage) (*BlockResponseMessage, error)
- func (s *Service) GossipMessage(msg NotificationsMessage)
- func (s *Service) Health() common.Health
- func (*Service) HighestBlock() int64
- func (s *Service) IsStopped() bool
- func (s *Service) IsSynced() bool
- func (s *Service) NetworkState() common.NetworkState
- func (s *Service) NodeRoles() common.Roles
- func (s *Service) Peers() []common.PeerInfo
- func (s *Service) RegisterNotificationsProtocol(protocolID protocol.ID, messageID byte, handshakeGetter HandshakeGetter, ...) error
- func (s *Service) RemoveReservedPeers(addrs ...string) error
- func (s *Service) ReportPeer(change peerset.ReputationChange, p peer.ID)
- func (s *Service) SendMessage(to peer.ID, msg NotificationsMessage) error
- func (s *Service) SetSyncer(syncer Syncer)
- func (s *Service) SetTransactionHandler(handler TransactionHandler)
- func (s *Service) Start() error
- func (*Service) StartingBlock() int64
- func (s *Service) Stop() error
- type SyncDirection
- type Syncer
- type TransactionHandler
- type TransactionMessage
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 = uint16(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 = common.FullNodeRole // DefaultMinPeerCount is the default minimum peer count DefaultMinPeerCount = 5 // DefaultMaxPeerCount is the default maximum peer count DefaultMaxPeerCount = 50 // DefaultDiscoveryInterval is the default interval for searching for DHT peers DefaultDiscoveryInterval = time.Minute * 5 )
const ( RequestedDataHeader = byte(1) RequestedDataBody = byte(2) RequestedDataReceipt = byte(4) RequestedDataMessageQueue = byte(8) RequestedDataJustification = byte(16) )
const (
ConsensusMsgType byte = 5
)
Message types for notifications protocol messages. Used internally to map message to protocol.
const MDNSPeriod = time.Minute
MDNSPeriod is 1 minute
const ( // MaxGrandpaNotificationSize is maximum size for a grandpa notification message. MaxGrandpaNotificationSize uint64 = 1024 * 1024 // 1mb )
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 common.Roles 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) IsValid ¶ added in v0.7.0
func (hs *BlockAnnounceHandshake) IsValid() bool
IsValid returns true if handshakes's role is valid.
func (*BlockAnnounceHandshake) String ¶ added in v0.2.0
func (hs *BlockAnnounceHandshake) String() string
String formats a BlockAnnounceHandshake as a string
type BlockAnnounceMessage ¶
type BlockAnnounceMessage struct { ParentHash common.Hash Number uint StateRoot common.Hash ExtrinsicsRoot common.Hash Digest scale.VaryingDataTypeSlice BestBlock bool }
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, error)
Hash returns the hash of the BlockAnnounceMessage
func (*BlockAnnounceMessage) String ¶
func (bm *BlockAnnounceMessage) String() string
string formats a BlockAnnounceMessage as a string
func (*BlockAnnounceMessage) Type ¶ added in v0.2.0
func (*BlockAnnounceMessage) Type() byte
Type returns blockAnnounceMsgType
type BlockRequestMessage ¶
type BlockRequestMessage struct { RequestedData byte StartingBlock variadic.Uint32OrHash // first byte 0 = block hash (32 byte), first byte 1 = block number (uint32) EndBlockHash *common.Hash Direction SyncDirection // 0 = ascending, 1 = descending Max *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
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
type BlockState ¶
type BlockState interface { BestBlockHeader() (*types.Header, error) BestBlockNumber() (blockNumber uint, err error) GenesisHash() common.Hash HasBlockBody(common.Hash) (bool, error) GetHighestFinalisedHeader() (*types.Header, error) GetHashByNumber(num uint) (common.Hash, error) }
BlockState interface for block state methods
type Config ¶
type Config struct { LogLvl log.Level 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 common.Roles // Service interfaces BlockState BlockState Syncer Syncer TransactionHandler TransactionHandler // Used to specify the address broadcasted to other peers, and avoids using pubip.Get PublicIP string // Used to specify the dns broadcasted to other peers, and avoids using pubip.Get. // Only PublicIP or PublicDNS will be used PublicDNS string // Port the network port used for listening Port uint16 // 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 DiscoveryInterval time.Duration // PersistentPeers is a list of multiaddrs which the node should remain connected to PersistentPeers []string // SlotDuration is the slot duration to produce a block SlotDuration time.Duration Telemetry telemetry.Client Metrics metrics.IntervalConfig // contains filtered or unexported fields }
Config is used to configure a network service
type ConnManager ¶
ConnManager implements connmgr.ConnManager
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(_ network.Network, c network.Conn)
Disconnected is called when a connection closed
func (*ConnManager) GetTagInfo ¶
func (*ConnManager) GetTagInfo(peer.ID) *connmgr.TagInfo
GetTagInfo is unimplemented
func (*ConnManager) IsProtected ¶ added in v0.2.0
func (cm *ConnManager) IsProtected(id peer.ID, _ 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) Protect ¶
func (cm *ConnManager) Protect(id peer.ID, _ string)
Protect peer will add the given peer to the protectedPeerMap which will protect the peer from pruning.
func (*ConnManager) TagPeer ¶
func (*ConnManager) TagPeer(peer.ID, string, int)
TagPeer is unimplemented
func (*ConnManager) TrimOpenConns ¶
func (*ConnManager) TrimOpenConns(context.Context)
TrimOpenConns is unimplemented
func (*ConnManager) Unprotect ¶
func (cm *ConnManager) Unprotect(id peer.ID, _ string) bool
Unprotect peer will remove the given peer from prune protection. returns true if we have successfully removed the peer from the protectedPeerMap. False otherwise.
type ConsensusMessage ¶
type ConsensusMessage struct {
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, error)
Hash returns the Hash of ConsensusMessage
func (*ConsensusMessage) Type ¶ added in v0.2.0
func (cm *ConsensusMessage) Type() byte
Type returns ConsensusMsgType
type Handshake ¶ added in v0.3.0
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 { *RemoteCallRequest *RemoteReadRequest *RemoteHeaderRequest *RemoteReadChildRequest *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
type LightResponse ¶ added in v0.3.0
type LightResponse struct { *RemoteCallResponse *RemoteReadResponse *RemoteHeaderResponse *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
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 NotificationsMessageBatchHandler ¶ added in v0.7.0
type NotificationsMessageBatchHandler = func(peer peer.ID, msg NotificationsMessage)
NotificationsMessageBatchHandler is called when a (non-handshake) message is received over a notifications stream in batch processing mode.
type NotificationsMessageHandler ¶ added in v0.3.0
type NotificationsMessageHandler = func(peer peer.ID, msg NotificationsMessage) (propagate bool, err error)
NotificationsMessageHandler is called when a (non-handshake) message is received over a notifications stream.
type Peer ¶ added in v0.7.0
type Peer interface { PeerReputation(peer.ID) (peerset.Reputation, error) SortedPeers(idx int) chan peer.IDSlice Messages() chan peerset.Message }
Peer is the interface used by the PeerSetHandler to get the peer data from peerSet.
type PeerAdd ¶ added in v0.7.0
type PeerAdd interface { Incoming(int, ...peer.ID) AddReservedPeer(int, ...peer.ID) AddPeer(int, ...peer.ID) SetReservedPeer(int, ...peer.ID) }
PeerAdd is the interface used by the PeerSetHandler to add peers in peerSet.
type PeerRemove ¶ added in v0.7.0
type PeerRemove interface { DisconnectPeer(int, ...peer.ID) RemoveReservedPeer(int, ...peer.ID) RemovePeer(int, ...peer.ID) }
PeerRemove is the interface used by the PeerSetHandler to remove peers from peerSet.
type PeerSetHandler ¶ added in v0.7.0
type PeerSetHandler interface { Start(context.Context) ReportPeer(peerset.ReputationChange, ...peer.ID) PeerAdd PeerRemove Peer }
PeerSetHandler is the interface used by the connection manager to handle peerset.
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 *common.Hash LastBlock *common.Hash Min []byte Max []byte StorageKey *[]byte // contains filtered or unexported fields }
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 []*types.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 { Metrics metrics.IntervalConfig // 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) AddReservedPeers ¶ added in v0.7.0
AddReservedPeers insert new peers to the peerstore with PermanentAddrTTL
func (*Service) DoBlockRequest ¶ added in v0.7.0
func (s *Service) DoBlockRequest(to peer.ID, req *BlockRequestMessage) (*BlockResponseMessage, error)
DoBlockRequest sends a request to the given peer. If a response is received within a certain time period, it is returned, otherwise an error is returned.
func (*Service) GossipMessage ¶ added in v0.7.0
func (s *Service) GossipMessage(msg NotificationsMessage)
GossipMessage gossips a notifications protocol message to our peers
func (*Service) HighestBlock ¶ added in v0.7.0
HighestBlock returns the highest known block number
func (*Service) IsSynced ¶ added in v0.7.0
IsSynced returns whether we are synced (no longer in bootstrap mode) or not
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( protocolID protocol.ID, messageID byte, handshakeGetter HandshakeGetter, handshakeDecoder HandshakeDecoder, handshakeValidator HandshakeValidator, messageDecoder MessageDecoder, messageHandler NotificationsMessageHandler, batchHandler NotificationsMessageBatchHandler, maxSize uint64, ) 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) RemoveReservedPeers ¶ added in v0.7.0
RemoveReservedPeers closes all connections with the target peers and remove it from the peerstore
func (*Service) ReportPeer ¶ added in v0.7.0
func (s *Service) ReportPeer(change peerset.ReputationChange, p peer.ID)
ReportPeer reports ReputationChange according to the peer behaviour.
func (*Service) SendMessage ¶ added in v0.2.0
func (s *Service) SendMessage(to peer.ID, msg NotificationsMessage) error
SendMessage sends a message to the given peer
func (*Service) SetTransactionHandler ¶ added in v0.3.0
func (s *Service) SetTransactionHandler(handler TransactionHandler)
SetTransactionHandler sets the TransactionHandler used by the network service
func (*Service) StartingBlock ¶ added in v0.7.0
StartingBlock return the starting block number that's currently being synced
type SyncDirection ¶ added in v0.7.0
type SyncDirection byte
SyncDirection is the direction of data in a block response
const ( // Ascending is used when block response data is in ascending order (ie parent to child) Ascending SyncDirection = iota // Descending is used when block response data is in descending order (ie child to parent) Descending )
func (SyncDirection) String ¶ added in v0.7.0
func (sd SyncDirection) String() string
type Syncer ¶ added in v0.2.0
type Syncer interface { HandleBlockAnnounceHandshake(from peer.ID, msg *BlockAnnounceHandshake) 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(from peer.ID, msg *BlockAnnounceMessage) error // IsSynced exposes the internal synced state IsSynced() bool // CreateBlockResponse is called upon receipt of a BlockRequestMessage to create the response CreateBlockResponse(*BlockRequestMessage) (*BlockResponseMessage, error) }
Syncer is implemented by the syncing service
type TransactionHandler ¶ added in v0.3.0
type TransactionHandler interface { HandleTransactionMessage(peer.ID, *TransactionMessage) (bool, error) TransactionsCount() int }
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, error)
Hash returns the hash of the TransactionMessage
func (*TransactionMessage) String ¶
func (tm *TransactionMessage) String() string
String returns the TransactionMessage extrinsics
func (*TransactionMessage) Type ¶ added in v0.2.0
func (*TransactionMessage) Type() byte
Type returns transactionMsgType