Documentation ¶
Index ¶
- Constants
- Variables
- func DisconnectAndWait(source *Server, target peer.ID, leaveTimeout time.Duration) error
- func GenerateAndEncodeLibp2pKey() (crypto.PrivKey, []byte, error)
- func GenerateTestLibp2pKey(t *testing.T) (crypto.PrivKey, string)
- func JoinAndWait(source, destination *Server, connectTimeout time.Duration, ...) error
- func JoinAndWaitMultiple(timeout time.Duration, servers ...*Server) error
- func MeshJoin(servers ...*Server) []error
- func ParseLibp2pKey(key []byte) (crypto.PrivKey, error)
- func ReadLibp2pKey(manager secrets.SecretsManager) (crypto.PrivKey, error)
- func WaitUntilPeerConnectsTo(ctx context.Context, srv *Server, ids ...peer.ID) (bool, error)
- func WaitUntilPeerDisconnectsFrom(ctx context.Context, srv *Server, ids ...peer.ID) (bool, error)
- func WaitUntilRoutingTableToBeFilled(ctx context.Context, srv *Server, size int) (bool, error)
- type Config
- type ConnectionInfo
- func (ci *ConnectionInfo) GetInboundConnCount() int64
- func (ci *ConnectionInfo) GetOutboundConnCount() int64
- func (ci *ConnectionInfo) GetPendingInboundConnCount() int64
- func (ci *ConnectionInfo) GetPendingOutboundConnCount() int64
- func (ci *ConnectionInfo) HasFreeConnectionSlot(direction network.Direction) bool
- func (ci *ConnectionInfo) HasFreeInboundConn() bool
- func (ci *ConnectionInfo) HasFreeOutboundConn() bool
- func (ci *ConnectionInfo) UpdateConnCountByDirection(delta int64, direction network.Direction)
- func (ci *ConnectionInfo) UpdatePendingConnCountByDirection(delta int64, direction network.Direction)
- type CreateServerParams
- type Metrics
- type PeerConnInfo
- type Protocol
- type Server
- func (s *Server) AddPeer(id peer.ID, direction network.Direction)
- func (s *Server) AddToPeerStore(peerInfo *peer.AddrInfo)
- func (s *Server) AddrInfo() *peer.AddrInfo
- func (s *Server) Close() error
- func (s *Server) CloseProtocolStream(protocol string, peerID peer.ID) error
- func (s *Server) DisconnectFromPeer(peer peer.ID, reason string)
- func (s *Server) EmitEvent(event *peerEvent.PeerEvent)
- func (s *Server) FetchOrSetTemporaryDial(peerID peer.ID, newValue bool) bool
- func (s *Server) GetBootnodeConnCount() int64
- func (s *Server) GetPeerDistance(peerID peer.ID) *big.Int
- func (s *Server) GetPeerInfo(peerID peer.ID) *peer.AddrInfo
- func (s *Server) GetProtocols(peerID peer.ID) ([]string, error)
- func (s *Server) GetRandomBootnode() *peer.AddrInfo
- func (s *Server) GetRandomPeer() *peer.ID
- func (s *Server) HasFreeConnectionSlot(direction network.Direction) bool
- func (s *Server) IsConnected(peerID peer.ID) bool
- func (s *Server) IsTemporaryDial(peerID peer.ID) bool
- func (s *Server) JoinPeer(rawPeerMultiaddr string) error
- func (s *Server) NewDiscoveryClient(peerID peer.ID) (proto.DiscoveryClient, error)
- func (s *Server) NewIdentityClient(peerID peer.ID) (proto.IdentityClient, error)
- func (s *Server) NewProtoConnection(protocol string, peerID peer.ID) (*rawGrpc.ClientConn, error)
- func (s *Server) NewStream(proto string, id peer.ID) (network.Stream, error)
- func (s *Server) NewTopic(protoID string, obj proto.Message) (*Topic, error)
- func (s *Server) Peers() []*PeerConnInfo
- func (s *Server) RegisterProtocol(id string, p Protocol)
- func (s *Server) RemoveFromPeerStore(peerInfo *peer.AddrInfo)
- func (s *Server) RemoveTemporaryDial(peerID peer.ID)
- func (s *Server) SaveProtocolStream(protocol string, stream *rawGrpc.ClientConn, peerID peer.ID)
- func (s *Server) Start() error
- func (s *Server) Subscribe() (*Subscription, error)
- func (s *Server) SubscribeCh() (<-chan *peerEvent.PeerEvent, error)
- func (s *Server) SubscribeFn(handler func(evnt *peerEvent.PeerEvent)) error
- func (s *Server) TemporaryDialPeer(peerAddrInfo *peer.AddrInfo)
- func (s *Server) UpdatePendingConnCount(delta int64, direction network.Direction)
- type Subscription
- type Topic
Constants ¶
const ( DefaultDialRatio = 0.2 DefaultLibp2pPort int = 1478 MinimumBootNodes int = 1 MinimumPeerConnections int64 = 1 )
const (
DefaultLeaveTimeout = 30 * time.Second
)
Variables ¶
var ( ErrNoBootnodes = errors.New("no bootnodes specified") ErrMinBootnodes = errors.New("minimum 1 bootnode is required") )
var ( // Anything below 35s is prone to false timeouts, as seen from empirical test data DefaultJoinTimeout = 100 * time.Second DefaultBufferTimeout = DefaultJoinTimeout + time.Second*5 )
Functions ¶
func DisconnectAndWait ¶
func GenerateAndEncodeLibp2pKey ¶
GenerateAndEncodeLibp2pKey generates a new networking private key, and encodes it into hex
func JoinAndWait ¶
func JoinAndWait( source, destination *Server, connectTimeout time.Duration, joinTimeout time.Duration, ) error
JoinAndWait is a helper method for joining a destination server and waiting for the connection to be successful (destination node is a peer of source)
func JoinAndWaitMultiple ¶
JoinAndWait is a helper method to make multiple servers connect to corresponding peer
func ParseLibp2pKey ¶
ParseLibp2pKey converts a byte array to a private key
func ReadLibp2pKey ¶
func ReadLibp2pKey(manager secrets.SecretsManager) (crypto.PrivKey, error)
ReadLibp2pKey reads the private networking key from the secrets manager
func WaitUntilPeerConnectsTo ¶
Types ¶
type Config ¶
type Config struct { NoDiscover bool // flag indicating if the discovery mechanism should be turned on Addr *net.TCPAddr // the base address NatAddr net.IP // the NAT address DNS multiaddr.Multiaddr // the DNS address DataDir string // the base data directory for the client MaxPeers int64 // the maximum number of peer connections MaxInboundPeers int64 // the maximum number of inbound peer connections MaxOutboundPeers int64 // the maximum number of outbound peer connections Chain *chain.Chain // the reference to the chain configuration SecretsManager secrets.SecretsManager // the secrets manager used for key storage Metrics *Metrics // the metrics reporting reference }
Config details the params for the base networking server
func DefaultConfig ¶
func DefaultConfig() *Config
type ConnectionInfo ¶
type ConnectionInfo struct {
// contains filtered or unexported fields
}
ConnectionInfo keeps track of current connection information for the networking server
func NewBlankConnectionInfo ¶
func NewBlankConnectionInfo( maxInboundConnCount int64, maxOutboundConnCount int64, ) *ConnectionInfo
NewBlankConnectionInfo returns a cleared ConnectionInfo instance
func (*ConnectionInfo) GetInboundConnCount ¶
func (ci *ConnectionInfo) GetInboundConnCount() int64
GetInboundConnCount returns the number of active inbound connections [Thread safe]
func (*ConnectionInfo) GetOutboundConnCount ¶
func (ci *ConnectionInfo) GetOutboundConnCount() int64
GetOutboundConnCount returns the number of active outbound connections [Thread safe]
func (*ConnectionInfo) GetPendingInboundConnCount ¶
func (ci *ConnectionInfo) GetPendingInboundConnCount() int64
GetPendingInboundConnCount returns the number of pending inbound connections [Thread safe]
func (*ConnectionInfo) GetPendingOutboundConnCount ¶
func (ci *ConnectionInfo) GetPendingOutboundConnCount() int64
GetPendingOutboundConnCount returns the number of pending outbound connections [Thread safe]
func (*ConnectionInfo) HasFreeConnectionSlot ¶
func (ci *ConnectionInfo) HasFreeConnectionSlot(direction network.Direction) bool
HasFreeConnectionSlot checks if there is a free connection slot in the specified direction [Thread safe]
func (*ConnectionInfo) HasFreeInboundConn ¶
func (ci *ConnectionInfo) HasFreeInboundConn() bool
HasFreeInboundConn checks if there are any open inbound connection slots. It takes into account the number of current (active) inbound connections and the number of pending inbound connections [Thread safe]
func (*ConnectionInfo) HasFreeOutboundConn ¶
func (ci *ConnectionInfo) HasFreeOutboundConn() bool
HasFreeOutboundConn checks if there are any open outbound connection slots. It takes into account the number of current (active) outbound connections and the number of pending outbound connections [Thread safe]
func (*ConnectionInfo) UpdateConnCountByDirection ¶
func (ci *ConnectionInfo) UpdateConnCountByDirection( delta int64, direction network.Direction, )
UpdateConnCountByDirection updates the connection count by delta in the specified direction [Thread safe]
func (*ConnectionInfo) UpdatePendingConnCountByDirection ¶
func (ci *ConnectionInfo) UpdatePendingConnCountByDirection( delta int64, direction network.Direction, )
UpdatePendingConnCountByDirection updates the pending connection count by delta in the specified direction [Thread safe]
type CreateServerParams ¶
type Metrics ¶
type Metrics struct { // Number of connected peers TotalPeerCount metrics.Gauge // Number of outbound connections OutboundConnectionsCount metrics.Gauge // Number of inbound connections InboundConnectionsCount metrics.Gauge // Number of pending outbound connections PendingOutboundConnectionsCount metrics.Gauge // Number of pending inbound connections PendingInboundConnectionsCount metrics.Gauge }
Metrics represents the network metrics
func GetPrometheusMetrics ¶
GetPrometheusMetrics return the network metrics instance
type PeerConnInfo ¶
PeerConnInfo holds the connection information about the peer
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func CreateServer ¶
func CreateServer(params *CreateServerParams) (*Server, error)
func (*Server) AddPeer ¶
AddPeer adds a new peer to the networking server's peer list, and updates relevant counters and metrics
func (*Server) AddToPeerStore ¶
AddToPeerStore adds peer information to the node's peer store
func (*Server) CloseProtocolStream ¶
CloseProtocolStream closes a protocol stream to the specified peer
func (*Server) DisconnectFromPeer ¶
DisconnectFromPeer disconnects the networking server from the specified peer
func (*Server) FetchOrSetTemporaryDial ¶
FetchOrSetTemporaryDial loads the temporary status of a peer connection, and sets a new value [Thread safe]
func (*Server) GetBootnodeConnCount ¶
GetBootnodeConnCount fetches the number of active bootnode connections [Thread safe]
func (*Server) GetPeerInfo ¶
GetPeerInfo fetches the information of a peer
func (*Server) GetProtocols ¶
GetProtocols fetches the list of node-supported protocols
func (*Server) GetRandomBootnode ¶
GetRandomBootnode fetches a random bootnode that's currently NOT connected, if any
func (*Server) GetRandomPeer ¶
GetRandomPeer fetches a random peer from the peers list
func (*Server) HasFreeConnectionSlot ¶
HasFreeConnectionSlot checks if there are free connection slots in the specified direction [Thread safe]
func (*Server) IsConnected ¶
IsConnected checks if the networking server is connected to a peer
func (*Server) IsTemporaryDial ¶
IsTemporaryDial checks if a peer connection is temporary [Thread safe]
func (*Server) NewDiscoveryClient ¶
NewDiscoveryClient returns a new or existing discovery service client connection
func (*Server) NewIdentityClient ¶
NewIdentityClient returns a new identity service client connection
func (*Server) NewProtoConnection ¶
NewProtoConnection opens up a new stream on the set protocol to the peer, and returns a reference to the connection
func (*Server) Peers ¶
func (s *Server) Peers() []*PeerConnInfo
Peers returns a copy of the networking server's peer connection info set. Only one (initial) connection (inbound OR outbound) per peer is contained [Thread safe]
func (*Server) RegisterProtocol ¶
func (*Server) RemoveFromPeerStore ¶
RemoveFromPeerStore removes peer information from the node's peer store
func (*Server) RemoveTemporaryDial ¶
RemoveTemporaryDial removes a peer connection as temporary [Thread safe]
func (*Server) SaveProtocolStream ¶
SaveProtocolStream saves the protocol stream to the peer protocol stream reference [Thread safe]
func (*Server) Subscribe ¶
func (s *Server) Subscribe() (*Subscription, error)
Subscribe starts a PeerEvent subscription
func (*Server) SubscribeCh ¶
SubscribeCh returns an event of of subscription events
func (*Server) SubscribeFn ¶
SubscribeFn is a helper method to run subscription of PeerEvents
func (*Server) TemporaryDialPeer ¶
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
func (*Subscription) Close ¶
func (s *Subscription) Close()
func (*Subscription) Get ¶
func (s *Subscription) Get() *peerEvent.PeerEvent
func (*Subscription) GetCh ¶
func (s *Subscription) GetCh() chan *peerEvent.PeerEvent