Documentation ¶
Index ¶
- Constants
- Variables
- func AddrInfoToString(addr *peer.AddrInfo) string
- func GenerateAndEncodeLibp2pKey() (crypto.PrivKey, []byte, error)
- func GenerateTestLibp2pKey(t *testing.T) (crypto.PrivKey, string)
- func JoinAndWait(source, destination *Server, connectTimeout time.Duration, ...) error
- func LeaveAndWait(source, destination *Server, disconnectTimeout time.Duration) error
- func MeshJoin(servers ...*Server) []error
- func MultiAddrFromDNS(addr string, port int) (multiaddr.Multiaddr, error)
- func ParseLibp2pKey(key []byte) (crypto.PrivKey, error)
- func ReadLibp2pKey(manager secrets.SecretsManager) (crypto.PrivKey, error)
- func StringToAddrInfo(addr string) (*peer.AddrInfo, 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 CreateServerParams
- type Metrics
- type Peer
- type PeerEvent
- type PeerEventType
- type Protocol
- type Server
- func (s *Server) AddrInfo() *peer.AddrInfo
- func (s *Server) Close() error
- func (s *Server) Disconnect(peer peer.ID, reason string)
- func (s *Server) GetPeerInfo(peerID peer.ID) peer.AddrInfo
- func (s *Server) GetProtocols(peerID peer.ID) ([]string, error)
- func (s *Server) Join(addr *peer.AddrInfo, timeout time.Duration) error
- func (s *Server) JoinAddr(addr string, timeout time.Duration) error
- func (s *Server) NewProtoStream(proto string, id peer.ID) (interface{}, 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() []*Peer
- func (s *Server) Register(id string, p Protocol)
- func (s *Server) Start() error
- func (s *Server) Subscribe() (*Subscription, error)
- func (s *Server) SubscribeCh() (<-chan *PeerEvent, error)
- func (s *Server) SubscribeFn(handler func(evnt *PeerEvent)) error
- type Subscription
- type Topic
Constants ¶
const ( DefaultDialRatio = 0.2 DefaultLibp2pPort int = 1478 MinimumPeerConnections int64 = 1 MinimumBootNodes int = 1 // Priority for dial queue PriorityRequestedDial uint64 = 1 PriorityRandomDial uint64 = 10 )
const DNSRegex = `^/?(dns)(4|6)?/[^-|^/][A-Za-z0-9-]([^-|^/]?)+([\\-\\.]{1}[a-z0-9]+)*\\.[A-Za-z]{2,}(/?)$`
regex string to match against a valid dns/dns4/dns6 addr
const (
DefaultLeaveTimeout = 30 * time.Second
)
Variables ¶
var ( ErrInvalidChainID = errors.New("invalid chain ID") ErrNotReady = errors.New("not ready") ErrNoAvailableSlots = errors.New("no available Slots") )
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 = 40 * time.Second DefaultBufferTimeout = DefaultJoinTimeout + time.Second*5 )
Functions ¶
func AddrInfoToString ¶
AddrInfoToString converts an AddrInfo into a string representation that can be dialed from another node
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 LeaveAndWait ¶
LeaveAndWait is a helper method for leaving a destination server and waiting for the connection to be closed
func MultiAddrFromDNS ¶ added in v0.3.0
MultiAddrFromDNS constructs a multiAddr from the passed in DNS address and port combination
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 Addr *net.TCPAddr NatAddr net.IP DNS multiaddr.Multiaddr DataDir string MaxPeers int64 MaxInboundPeers int64 MaxOutboundPeers int64 Chain *chain.Chain SecretsManager secrets.SecretsManager Metrics *Metrics }
func DefaultConfig ¶
func DefaultConfig() *Config
type CreateServerParams ¶
type Metrics ¶
Metrics represents the network metrics
func GetPrometheusMetrics ¶
GetPrometheusMetrics return the network metrics instance
type PeerEvent ¶
type PeerEvent struct { // PeerID is the id of the peer that triggered // the event PeerID peer.ID // Type is the type of the event Type PeerEventType }
type PeerEventType ¶
type PeerEventType uint
const ( PeerConnected PeerEventType = iota // Emitted when a peer connected PeerFailedToConnect // Emitted when a peer failed to connect PeerDisconnected // Emitted when a peer disconnected from node PeerAlreadyConnected // Emitted when a peer already connected on dial PeerDialCompleted // Emitted when a peer completed dial PeerAddedToDialQueue // Emitted when a peer is added to dial queue )
func (PeerEventType) String ¶
func (s PeerEventType) String() string
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
func CreateServer ¶
func CreateServer(params *CreateServerParams) (*Server, error)
func (*Server) NewProtoStream ¶
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
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
func (*Subscription) GetCh ¶
func (s *Subscription) GetCh() chan *PeerEvent