Documentation ¶
Index ¶
- Variables
- type BasicHost
- func (h *BasicHost) Addrs() []ma.Multiaddr
- func (h *BasicHost) Close() error
- func (h *BasicHost) Connect(ctx context.Context, pi pstore.PeerInfo) error
- func (h *BasicHost) GetBandwidthReporter() metrics.Reporter
- func (h *BasicHost) ID() peer.ID
- func (h *BasicHost) IDService() *identify.IDService
- func (h *BasicHost) Mux() *msmux.MultistreamMuxer
- func (h *BasicHost) Network() inet.Network
- func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (inet.Stream, error)
- func (h *BasicHost) Peerstore() pstore.Peerstore
- func (h *BasicHost) RemoveStreamHandler(pid protocol.ID)
- func (h *BasicHost) SetStreamHandler(pid protocol.ID, handler inet.StreamHandler)
- func (h *BasicHost) SetStreamHandlerMatch(pid protocol.ID, m func(string) bool, handler inet.StreamHandler)
- type Option
Constants ¶
This section is empty.
Variables ¶
var NegotiateTimeout = time.Second * 60
Functions ¶
This section is empty.
Types ¶
type BasicHost ¶
BasicHost is the basic implementation of the host.Host interface. This particular host implementation:
- uses a protocol muxer to mux per-protocol streams
- uses an identity service to send + receive node information
- uses a nat service to establish NAT port mappings
func (*BasicHost) Addrs ¶
Addrs returns all the addresses of BasicHost at this moment in time. It's ok to not include addresses if they're not available to be used now.
func (*BasicHost) Connect ¶
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.
func (*BasicHost) GetBandwidthReporter ¶
GetBandwidthReporter exposes the Host's bandiwth metrics reporter
func (*BasicHost) Mux ¶
func (h *BasicHost) Mux() *msmux.MultistreamMuxer
Mux returns the Mux multiplexing incoming streams to protocol handlers
func (*BasicHost) NewStream ¶
func (h *BasicHost) NewStream(ctx context.Context, p peer.ID, pids ...protocol.ID) (inet.Stream, error)
NewStream opens a new stream to given peer p, and writes a p2p/protocol header with given protocol.ID. If there is no connection to p, attempts to create one. If ProtocolID is "", writes no header. (Threadsafe)
func (*BasicHost) RemoveStreamHandler ¶
RemoveStreamHandler returns ..
func (*BasicHost) SetStreamHandler ¶
func (h *BasicHost) SetStreamHandler(pid protocol.ID, handler inet.StreamHandler)
SetStreamHandler sets the protocol handler on the Host's Mux. This is equivalent to:
host.Mux().SetHandler(proto, handler)
(Threadsafe)
func (*BasicHost) SetStreamHandlerMatch ¶
func (h *BasicHost) SetStreamHandlerMatch(pid protocol.ID, m func(string) bool, handler inet.StreamHandler)
SetStreamHandlerMatch sets the protocol handler on the Host's Mux using a matching function to do protocol comparisons
type Option ¶
type Option int
Option is a type used to pass in options to the host.
const ( // NATPortMap makes the host attempt to open port-mapping in NAT devices // for all its listeners. Pass in this option in the constructor to // asynchronously a) find a gateway, b) open port mappings, c) republish // port mappings periodically. The NATed addresses are included in the // Host's Addrs() list. NATPortMap Option = iota )