network

package
v1.0.0-beta.5 Latest Latest
Warning

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

Go to latest
Published: May 20, 2024 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	CoreProtocolID = "iota-core/1.0.0"
)
View Source
const DefaultReconnectInterval = 5 * time.Second

Variables

View Source
var (
	// ErrNotRunning is returned when a peer is added to a stopped or not yet started network manager.
	ErrNotRunning = ierrors.New("manager not running")
	// ErrUnknownPeer is returned when the specified peer is not known to the network manager.
	ErrUnknownPeer = ierrors.New("unknown peer")
	// ErrLoopbackPeer is returned when the own peer is added.
	ErrLoopbackPeer = ierrors.New("loopback connection not allowed")
	// ErrDuplicatePeer is returned when the same peer is added more than once.
	ErrDuplicatePeer = ierrors.New("already connected")
	// ErrMaxAutopeeringPeersReached is returned when the maximum number of autopeering peers is reached.
	ErrMaxAutopeeringPeersReached = ierrors.New("max autopeering peers reached")
)

Functions

This section is empty.

Types

type AddressFilter

type AddressFilter = func([]multiaddr.Multiaddr) []multiaddr.Multiaddr

func PublicOnlyAddressesFilter

func PublicOnlyAddressesFilter(allowLocalNetworks bool) AddressFilter

type ConnectionStatus

type ConnectionStatus string

ConnectionStatus is an enum for the peer connection status in the gossip layer.

const (
	// ConnStatusDisconnected means that there is no real connection established in the gossip layer for that peer.
	ConnStatusDisconnected ConnectionStatus = "disconnected"
	// ConnStatusConnected means that there is a real connection established in the gossip layer for that peer.
	ConnStatusConnected ConnectionStatus = "connected"
)

type Endpoint

type Endpoint interface {
	LocalPeerID() peer.ID
	RegisterProtocol(factory func() proto.Message, handler func(peer.ID, proto.Message) error)
	UnregisterProtocol()
	Send(packet proto.Message, to ...peer.ID)
	Shutdown()
}

type Manager

type Manager interface {
	Endpoint

	// DialPeer connects to a peer.
	DialPeer(ctx context.Context, peer *Peer) error
	// RemovePeer disconnects the peer with the given ID
	// and removes it from manual peering in case it was added manually.
	RemovePeer(peerID peer.ID) error
	// AddManualPeer adds a manual peer to the list of known peers.
	AddManualPeer(multiAddress multiaddr.Multiaddr) (*Peer, error)
	// ManualPeer returns the manual peer with the given ID.
	ManualPeer(peerID peer.ID) (*Peer, error)
	// ManualPeers returns all the manual peers.
	ManualPeers(onlyConnected ...bool) []*Peer

	// OnNeighborAdded registers a callback that gets triggered when a neighbor is added.
	OnNeighborAdded(handler func(Neighbor)) *event.Hook[func(Neighbor)]
	// OnNeighborRemoved registers a callback that gets triggered when a neighbor is removed.
	OnNeighborRemoved(handler func(Neighbor)) *event.Hook[func(Neighbor)]

	// Neighbor returns the neighbor with the given ID.
	Neighbor(peerID peer.ID) (Neighbor, error)
	// NeighborExists checks if a neighbor with the given ID exists.
	NeighborExists(peerID peer.ID) bool
	// DisconnectNeighbor disconnects the neighbor with the given ID.
	DisconnectNeighbor(peerID peer.ID) error

	// Neighbors returns all the neighbors that are currently connected.
	Neighbors() []Neighbor
	// AutopeeringNeighbors returns all the neighbors that are currently connected via autopeering.
	AutopeeringNeighbors() []Neighbor

	P2PHost() host.Host

	Start(ctx context.Context, networkID string, bootstrapPeers []peer.AddrInfo) error
	Shutdown()
}

Manager is the network manager interface. Peer is a known node in the network. Neighbor is a Peer with an established connection in the gossip layer.

type Neighbor

type Neighbor interface {
	Peer() *Peer
	PacketsRead() uint64
	PacketsWritten() uint64
}

Neighbor is a Peer with an established connection in the gossip layer.

type Peer

type Peer struct {
	ID            peer.ID
	PublicKey     ed25519.PublicKey
	PeerAddresses []multiaddr.Multiaddr
	ConnStatus    *atomic.Value
	RemoveCh      chan struct{}
	DoneCh        chan struct{}
}

Peer is a known node in the network.

func NewPeerFromAddrInfo

func NewPeerFromAddrInfo(addrInfo *peer.AddrInfo) *Peer

func NewPeerFromMultiAddr

func NewPeerFromMultiAddr(peerAddrs multiaddr.Multiaddr) (*Peer, error)

func (*Peer) GetConnStatus

func (p *Peer) GetConnStatus() ConnectionStatus

func (*Peer) SetConnStatus

func (p *Peer) SetConnStatus(cs ConnectionStatus)

func (*Peer) String

func (p *Peer) String() string

func (*Peer) ToAddrInfo

func (p *Peer) ToAddrInfo() *peer.AddrInfo

Directories

Path Synopsis
p2p
protocols

Jump to

Keyboard shortcuts

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