host

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Host

type Host interface {
	basic.Switcher

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

	// PrivateKey of the crypto private key.
	PrivateKey() crypto.PrivateKey

	// ID is local peer id.
	ID() peer.ID

	// RegisterMsgPayloadHandler register a handler.MsgPayloadHandler for handling
	// the msg received with the protocol which id is the given protocolID.
	RegisterMsgPayloadHandler(protocolID protocol.ID, handler handler.MsgPayloadHandler) error
	// UnregisterMsgPayloadHandler unregister the handler.MsgPayloadHandler for
	// handling the msg received with the protocol which id is the given protocolID.
	UnregisterMsgPayloadHandler(protocolID protocol.ID) error

	// SendMsg will send a msg with the protocol which id is the given protocolID
	// to the receiver whose peer.ID is the given receiverPID.
	SendMsg(protocolID protocol.ID, receiverPID peer.ID, msgPayload []byte) error

	// Dial try to establish a connection with peer whose address is the given.
	Dial(remoteAddr ma.Multiaddr) (network.Conn, error)

	// CheckClosedConnWithErr return whether the connection has closed.
	// If conn.IsClosed() is true, return true.
	// If err contains closed info, return true.
	// Otherwise, return false.
	CheckClosedConnWithErr(conn network.Conn, err error) bool

	// PeerStore return the store.PeerStore instance of the host.
	PeerStore() store.PeerStore

	// ConnMgr return the mgr.ConnMgr instance of the host.
	ConnMgr() mgr.ConnMgr

	// ProtocolMgr return the mgr.ProtocolManager instance of the host.
	ProtocolMgr() mgr.ProtocolManager

	// Blacklist return the blacklist.BlackList instance of the host.
	Blacklist() blacklist.BlackList

	// PeerProtocols query peer.ID and the protocol.ID list supported by peer.
	// If protocolIDs is nil ,return the list of all connected to us.
	// Otherwise, return the list of part of all which support the protocols
	// that id contains in the given protocolIDs.
	PeerProtocols(protocolIDs []protocol.ID) ([]*PeerProtocols, error)

	// IsPeerSupportProtocol return true if peer which id is the given pid
	// support the given protocol. Otherwise, return false.
	IsPeerSupportProtocol(pid peer.ID, protocolID protocol.ID) bool

	// Notify registers a Notifiee to host.
	Notify(notifiee Notifiee)

	// AddDirectPeer append a direct peer.
	AddDirectPeer(dp ma.Multiaddr)

	// ClearDirectPeers remove all direct peers.
	ClearDirectPeers()

	// LocalAddresses return the list of net addresses for listener listening.
	LocalAddresses() []ma.Multiaddr
}

Host provides the capabilities of network.

type Notifiee

type Notifiee interface {
	// PeerConnected will be invoked when a new connection established.
	PeerConnected(pid peer.ID)
	// PeerDisconnected will be invoked when a connection disconnected.
	PeerDisconnected(pid peer.ID)
	// PeerProtocolSupported will be invoked when a peer support a new protocol.
	PeerProtocolSupported(protocolID protocol.ID, pid peer.ID)
	// PeerProtocolUnsupported will be invoked when a peer cancel supporting a new protocol.
	PeerProtocolUnsupported(protocolID protocol.ID, pid peer.ID)
}

Notifiee contains functions for host notifying call back.

type NotifieeBundle

type NotifieeBundle struct {
	PeerConnectedFunc           func(peer.ID)
	PeerDisconnectedFunc        func(peer.ID)
	PeerProtocolSupportedFunc   func(protocolID protocol.ID, pid peer.ID)
	PeerProtocolUnsupportedFunc func(protocolID protocol.ID, pid peer.ID)
}

NotifieeBundle is a bundle implementation of Notifee interface.

func (*NotifieeBundle) PeerConnected

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

func (*NotifieeBundle) PeerDisconnected

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

func (*NotifieeBundle) PeerProtocolSupported

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

func (*NotifieeBundle) PeerProtocolUnsupported

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

type PeerProtocols

type PeerProtocols struct {
	PID       peer.ID
	Protocols []protocol.ID
}

PeerProtocols store the peer.ID and the protocol.ID list that supported by peer.

Jump to

Keyboard shortcuts

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