network

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 6, 2022 License: LGPL-3.0 Imports: 39 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinimumPeerConnections int64 = 1
	MinimumBootNodes       int   = 2 // MinimumBootNodes Count is set to 2 so that, a bootnode can reconnect to the network using other bootnode after restarting.
)
View Source
const (
	PriorityRequestedDial uint64 = 1
	PriorityRandomDial    uint64 = 10
)

Priority for dial queue

View Source
const DefaultLibp2pPort int = 1478

Variables

View Source
var (
	ErrInvalidChainID   = errors.New("Invalid chain ID")
	ErrNotReady         = errors.New("Not ready")
	ErrNoAvailableSlots = errors.New("No available Slots")
)
View Source
var (
	DefaultJoinTimeout   = 40 * time.Second // Anything below 35s is prone to false timeouts, as seen from empirical test data
	DefaultBufferTimeout = DefaultJoinTimeout + time.Second*5
)

Functions

func AddrInfoToString

func AddrInfoToString(addr *peer.AddrInfo) string

AddrInfoToString converts an AddrInfo into a string representation that can be dialed from another node

func GenerateAndEncodeLibp2pKey

func GenerateAndEncodeLibp2pKey() (crypto.PrivKey, []byte, error)

GenerateAndEncodeLibp2pKey generates a new networking private key, and encodes it into hex

func GenerateTestLibp2pKey

func GenerateTestLibp2pKey(t *testing.T) (crypto.PrivKey, string)

func GenerateTestMultiAddr

func GenerateTestMultiAddr(t *testing.T) multiaddr.Multiaddr

func JoinAndWait added in v0.1.0

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 MeshJoin added in v0.1.0

func MeshJoin(servers ...*Server) []error

MeshJoin is a helper method for joining all the passed in servers into a mesh

func ParseLibp2pKey

func ParseLibp2pKey(key []byte) (crypto.PrivKey, error)

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 StringToAddrInfo

func StringToAddrInfo(addr string) (*peer.AddrInfo, error)

func WaitUntilPeerConnectsTo added in v0.1.0

func WaitUntilPeerConnectsTo(ctx context.Context, srv *Server, ids ...peer.ID) (bool, error)

func WaitUntilPeerDisconnectsFrom added in v0.1.0

func WaitUntilPeerDisconnectsFrom(ctx context.Context, srv *Server, ids ...peer.ID) (bool, error)

Types

type Config

type Config struct {
	NoDiscover     bool
	Addr           *net.TCPAddr
	NatAddr        net.IP
	Dns            multiaddr.Multiaddr
	DataDir        string
	MaxPeers       uint64
	Chain          *chain.Chain
	SecretsManager secrets.SecretsManager
}

func DefaultConfig

func DefaultConfig() *Config

type CreateServerParams added in v0.1.0

type CreateServerParams struct {
	ConfigCallback func(c *Config)      // Additional logic that needs to be executed on the configuration
	ServerCallback func(server *Server) // Additional logic that needs to be executed on the server before starting
	Logger         hclog.Logger
}

type Peer

type Peer struct {
	Info peer.AddrInfo
	// contains filtered or unexported fields
}

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 Protocol

type Protocol interface {
	Client(network.Stream) interface{}
	Handler() func(network.Stream)
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func CreateServer

func CreateServer(params *CreateServerParams) (*Server, error)

func NewServer

func NewServer(logger hclog.Logger, config *Config) (*Server, error)

func (*Server) AddrInfo

func (s *Server) AddrInfo() *peer.AddrInfo

func (*Server) Close

func (s *Server) Close() error

func (*Server) Disconnect

func (s *Server) Disconnect(peer peer.ID, reason string)

func (*Server) GetPeerInfo

func (s *Server) GetPeerInfo(peerID peer.ID) peer.AddrInfo

func (*Server) GetProtocols

func (s *Server) GetProtocols(peerID peer.ID) ([]string, error)

func (*Server) Join

func (s *Server) Join(addr *peer.AddrInfo, timeout time.Duration) error

func (*Server) JoinAddr

func (s *Server) JoinAddr(addr string, timeout time.Duration) error

func (*Server) NewProtoStream

func (s *Server) NewProtoStream(proto string, id peer.ID) (interface{}, error)

func (*Server) NewStream

func (s *Server) NewStream(proto string, id peer.ID) (network.Stream, error)

func (*Server) NewTopic

func (s *Server) NewTopic(protoID string, obj proto.Message) (*Topic, error)

func (*Server) Peers

func (s *Server) Peers() []*Peer

func (*Server) Register

func (s *Server) Register(id string, p Protocol)

func (*Server) Start

func (s *Server) Start() error

func (*Server) Subscribe

func (s *Server) Subscribe() (*Subscription, error)

Subscribe starts a PeerEvent subscription

func (*Server) SubscribeCh

func (s *Server) SubscribeCh() (<-chan *PeerEvent, error)

SubscribeCh returns an event of of subscription events

func (*Server) SubscribeFn

func (s *Server) SubscribeFn(handler func(evnt *PeerEvent)) error

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

type Topic

type Topic struct {
	// contains filtered or unexported fields
}

func (*Topic) Publish

func (t *Topic) Publish(obj proto.Message) error

func (*Topic) Subscribe

func (t *Topic) Subscribe(handler func(obj interface{})) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL