host

package
v0.0.0-...-d151d1d Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Components

type Components interface {
	// AttachHost attaches the given host to the components.
	AttachHost(host Host)
}

Components is an interface that represents a collection of components that can be attached to a host.

type ConnectionHandler

type ConnectionHandler func(conn network.Connection) (bool, error)

ConnectionHandler is a function for handling connections.

type Host

type Host interface {
	core.Switcher

	// Context returns the context of the host instance.
	Context() context.Context

	// ID returns the local peer ID.
	ID() peer.ID

	// RegisterMsgPayloadHandler registers a handler.MsgPayloadHandler for handling
	// messages received with the specified protocolID.
	RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error

	// UnregisterMsgPayloadHandler unregisters the handler.MsgPayloadHandler for
	// the specified protocolID.
	UnregisterMsgPayloadHandler(protocolID protocol.ID) error

	// SendMsg sends a message with the specified protocolID to the receiver
	// identified by receiverPID.
	SendMsg(protocolID protocol.ID, receiverPID peer.ID, msgPayload []byte) error

	// Dial attempts to establish a connection with a peer at the given remote address.
	Dial(remoteAddr ma.Multiaddr) (network.Connection, error)

	// PeerStore returns the store.PeerStore instance associated with the host.
	PeerStore() store.PeerStore

	// ConnectionManager returns the manager.ConnectionManager instance associated with the host.
	ConnectionManager() manager.ConnectionManager

	// ProtocolManager returns the manager.ProtocolManager instance associated with the host.
	ProtocolManager() manager.ProtocolManager

	// PeerBlackList returns the blacklist.PeerBlackList instance associated with the host.
	PeerBlackList() blacklist.PeerBlackList

	// PeerProtocols returns the list of connected peers and their supported protocol IDs.
	// If protocolIDs is nil, it returns information about all connected peers.
	// Otherwise, it returns information about connected peers that support the specified protocol IDs.
	PeerProtocols(protocolIDs []protocol.ID) ([]*PeerProtocols, error)

	// PeerSupportProtocol checks if the peer identified by pid supports the specified protocolID.
	// It returns true if the peer supports the protocol, otherwise it returns false.
	PeerSupportProtocol(pid peer.ID, protocolID protocol.ID) bool

	// Notify registers a Notifiee to receive notifications from the host.
	Notify(notifiee Notifiee)

	// AddDirectPeer appends a direct peer to the host.
	AddDirectPeer(dp ma.Multiaddr) error

	// ClearDirectPeers removes all direct peers from the host.
	ClearDirectPeers()

	// LocalAddresses returns a list of network addresses that the host is listening on.
	LocalAddresses() []ma.Multiaddr

	// Network returns the network.Network instance associated with the host.
	Network() network.Network

	// Logger returns the logger instance of the host.
	Logger() *rainbowlog.Logger
}

Host provides network capabilities.

type Notifiee

type Notifiee interface {
	// OnPeerConnected is invoked when a new connection is established.
	OnPeerConnected(pid peer.ID)

	// OnPeerDisconnected is invoked when a connection is disconnected.
	OnPeerDisconnected(pid peer.ID)

	// OnPeerProtocolSupported is invoked when a peer supports a new protocol.
	OnPeerProtocolSupported(protocolID protocol.ID, pid peer.ID)

	// OnPeerProtocolUnsupported is invoked when a peer stops supporting a new protocol.
	OnPeerProtocolUnsupported(protocolID protocol.ID, pid peer.ID)
}

Notifiee contains functions for host notification callbacks. Each callback implementation should not block and should return as quickly as possible to prevent degrading host performance.

type NotifieeBundle

type NotifieeBundle struct {
	OnPeerConnectedFunc           func(peer.ID)
	OnPeerDisconnectedFunc        func(peer.ID)
	OnPeerProtocolSupportedFunc   func(protocolID protocol.ID, pid peer.ID)
	OnPeerProtocolUnsupportedFunc func(protocolID protocol.ID, pid peer.ID)
}

NotifieeBundle is a bundle implementation of the Notifiee interface.

func (*NotifieeBundle) OnPeerConnected

func (n *NotifieeBundle) OnPeerConnected(pid peer.ID)

OnPeerConnected invokes the OnPeerConnectedFunc callback if it is set.

func (*NotifieeBundle) OnPeerDisconnected

func (n *NotifieeBundle) OnPeerDisconnected(pid peer.ID)

OnPeerDisconnected invokes the OnPeerDisconnectedFunc callback if it is set.

func (*NotifieeBundle) OnPeerProtocolSupported

func (n *NotifieeBundle) OnPeerProtocolSupported(protocolID protocol.ID, pid peer.ID)

OnPeerProtocolSupported invokes the OnPeerProtocolSupportedFunc callback if it is set.

func (*NotifieeBundle) OnPeerProtocolUnsupported

func (n *NotifieeBundle) OnPeerProtocolUnsupported(protocolID protocol.ID, pid peer.ID)

OnPeerProtocolUnsupported invokes the OnPeerProtocolUnsupportedFunc callback if it is set.

type PeerProtocols

type PeerProtocols struct {
	PID       peer.ID       // Peer ID
	Protocols []protocol.ID // List of supported protocol IDs
}

PeerProtocols stores the information about a peer's ID and the list of protocol IDs supported by the peer.

Jump to

Keyboard shortcuts

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