network

package
v1.0.0-alpha.9 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 18 Imported by: 0

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 neighbor")
	// 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")
	// ErrFirstPacketNotReceived is returned when the first packet from a peer is not received.
	ErrFirstPacketNotReceived = ierrors.New("first packet not received")
	// 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 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 DB

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

DB is the peer database, storing previously seen peers and any collected properties of them.

func NewDB

func NewDB(store kvstore.KVStore) *DB

NewDB creates a new peer database.

func (*DB) Close

func (db *DB) Close()

Close closes the peer database.

func (*DB) Peer

func (db *DB) Peer(id peer.ID) (*Peer, error)

Peer retrieves a peer from the database.

func (*DB) SeedPeers

func (db *DB) SeedPeers() []*Peer

SeedPeers retrieves random nodes to be used as potential bootstrap peers.

func (*DB) UpdatePeer

func (db *DB) UpdatePeer(p *Peer) error

UpdatePeer updates a peer in the database.

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(context.Context, *Peer) error

	OnNeighborAdded(func(Neighbor)) *event.Hook[func(Neighbor)]
	OnNeighborRemoved(func(Neighbor)) *event.Hook[func(Neighbor)]

	AllNeighbors() []Neighbor
	AutopeeringNeighbors() []Neighbor

	DropNeighbor(peer.ID) error
	NeighborExists(peer.ID) bool

	P2PHost() host.Host

	Start(ctx context.Context, networkID string) error
	Shutdown()

	AddManualPeers(...multiaddr.Multiaddr) error
}

type Neighbor

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

type Peer

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

func NewPeerFromAddrInfo

func NewPeerFromAddrInfo(addrInfo *peer.AddrInfo) *Peer

func NewPeerFromMultiAddr

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

func (*Peer) Bytes

func (p *Peer) Bytes() ([]byte, 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

type PeerDescriptor

type PeerDescriptor struct {
	Addresses []multiaddr.Multiaddr `json:"addresses"`
}

PeerDescriptor defines a peer record in the manual peering layer.

Directories

Path Synopsis
p2p
protocols

Jump to

Keyboard shortcuts

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