Source File
host.go
Belonging Package
github.com/libp2p/go-libp2p/core/host
// Package host provides the core Host interface for libp2p.//// Host represents a single libp2p node in a peer-to-peer network.package hostimport (ma)// Host is an object participating in a p2p network, which// implements protocols or provides services. It handles// requests like a Server, and issues requests like a Client.// It is called Host because it is both Server and Client (and Peer// may be confusing).type Host interface {// ID returns the (local) peer.ID associated with this HostID() peer.ID// Peerstore returns the Host's repository of Peer Addresses and Keys.Peerstore() peerstore.Peerstore// Addrs returns the listen addresses of the HostAddrs() []ma.Multiaddr// Network returns the Network interface of the HostNetwork() network.Network// Mux returns the Mux multiplexing incoming streams to protocol handlersMux() protocol.Switch// Connect ensures there is a connection between this host and the peer with// given peer.ID. Connect will absorb the addresses in pi into its internal// peerstore. If there is not an active connection, Connect will issue a// h.Network.Dial, and block until a connection is open, or an error is// returned.Connect(ctx context.Context, pi peer.AddrInfo) error// SetStreamHandler sets the protocol handler on the Host's Mux.// This is equivalent to:// host.Mux().SetHandler(proto, handler)// (Thread-safe)SetStreamHandler(pid protocol.ID, handler network.StreamHandler)// SetStreamHandlerMatch sets the protocol handler on the Host's Mux// using a matching function for protocol selection.SetStreamHandlerMatch(protocol.ID, func(protocol.ID) bool, network.StreamHandler)// RemoveStreamHandler removes a handler on the mux that was set by// SetStreamHandlerRemoveStreamHandler(pid protocol.ID)// NewStream opens a new stream to given peer p, and writes a p2p/protocol// header with given ProtocolID. If there is no connection to p, attempts// to create one. If ProtocolID is "", writes no header.// (Thread-safe)NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (network.Stream, error)// Close shuts down the host, its Network, and services.Close() error// ConnManager returns this hosts connection managerConnManager() connmgr.ConnManager// EventBus returns the hosts eventbusEventBus() event.Bus}
![]() |
The pages are generated with Golds v0.8.2. (GOOS=linux GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds. |