Documentation ¶
Overview ¶
Package p2p defines types for P2P networking. It implements the host interface.
Index ¶
- Variables
- type Host
- func (h *Host) Addrs() []ma.Multiaddr
- func (h *Host) AllAddrs() []ma.Multiaddr
- func (h *Host) Close() error
- func (h *Host) ConnManager() ifconnmgr.ConnManager
- func (h *Host) Connect(ctx context.Context, pi pstore.PeerInfo) error
- func (h *Host) ID() peer.ID
- func (h *Host) IDService() *identify.IDService
- func (h *Host) Mux() *msmux.MultistreamMuxer
- func (h *Host) Network() inet.Network
- func (h *Host) NewStream(ctx context.Context, pid peer.ID, protocols ...protocol.ID) (s inet.Stream, err error)
- func (h *Host) Peerstore() pstore.Peerstore
- func (h *Host) RemoveStreamHandler(proto protocol.ID)
- func (h *Host) SetIDService(service *identify.IDService)
- func (h *Host) SetNATManager(natmgr bhost.NATManager)
- func (h *Host) SetRouter(router func(context.Context, peer.ID) (pstore.PeerInfo, error))
- func (h *Host) SetStreamHandler(proto protocol.ID, handler inet.StreamHandler)
- func (h *Host) SetStreamHandlerMatch(proto protocol.ID, match func(string) bool, handler inet.StreamHandler)
- type HostOption
- type MetricsReporter
- func (r *MetricsReporter) GetBandwidthForPeer(peer.ID) metrics.Stats
- func (r *MetricsReporter) GetBandwidthForProtocol(protocol.ID) metrics.Stats
- func (r *MetricsReporter) GetBandwidthTotals() metrics.Stats
- func (r *MetricsReporter) LogRecvMessage(b int64)
- func (r *MetricsReporter) LogRecvMessageStream(b int64, pid protocol.ID, peerID peer.ID)
- func (r *MetricsReporter) LogSentMessage(b int64)
- func (r *MetricsReporter) LogSentMessageStream(b int64, pid protocol.ID, peerID peer.ID)
Constants ¶
This section is empty.
Variables ¶
var ( BandwidthIn = &view.View{ Name: "stratumn-node/views/bandwidth-in", Description: "incoming messages bandwidth", Measure: bandwidthIn.Measure, TagKeys: []tag.Key{monitoring.PeerIDTag.OCTag, monitoring.ProtocolIDTag.OCTag}, Aggregation: view.Count(), } BandwidthOut = &view.View{ Name: "stratumn-node/views/bandwidth-out", Description: "outgoing messages bandwidth", Measure: bandwidthOut.Measure, TagKeys: []tag.Key{monitoring.PeerIDTag.OCTag, monitoring.ProtocolIDTag.OCTag}, Aggregation: view.Count(), } StreamsIn = &view.View{ Name: "stratumn-node/views/streams-in", Description: "incoming streams", Measure: streamsIn.Measure, TagKeys: []tag.Key{monitoring.PeerIDTag.OCTag, monitoring.ProtocolIDTag.OCTag}, Aggregation: view.Count(), } StreamsOut = &view.View{ Name: "stratumn-node/views/streams-out", Description: "outgoing streams", Measure: streamsOut.Measure, TagKeys: []tag.Key{monitoring.PeerIDTag.OCTag, monitoring.ProtocolIDTag.OCTag}, Aggregation: view.Count(), } StreamsErr = &view.View{ Name: "stratumn-node/views/streams-error", Description: "errored streams", Measure: streamsErr.Measure, TagKeys: []tag.Key{monitoring.PeerIDTag.OCTag, monitoring.ErrorTag.OCTag}, Aggregation: view.Count(), } )
Views exposed by the p2p layer.
var DefHostOpts = []HostOption{ OptConnManager(ifconnmgr.NullConnMgr{}), OptResolver(madns.DefaultResolver), OptNegTimeout(time.Minute), }
DefHostOpts are the default options for a host.
These options are set before the options passed to NewHost are processed.
var ( // ErrWrongPeerID is returned when the router returns addresses for // a different peer ID. ErrWrongPeerID = errors.New("addresses do not match peer ID") )
Functions ¶
This section is empty.
Types ¶
type Host ¶
type Host struct {
// contains filtered or unexported fields
}
Host implements the go-libp2p-host.Host interface.
TODO: Investigate data races durings tests when built with -race.
func (*Host) AllAddrs ¶
AllAddrs 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 (*Host) ConnManager ¶
func (h *Host) ConnManager() ifconnmgr.ConnManager
ConnManager returns the connection manager.
func (*Host) Connect ¶
Connect ensures there is a connection between this host and the peer with given peer.ID. 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 will absorb the addresses in pi into its internal peerstore. It will also resolve any /dns4, /dns6, and /dnsaddr addresses.
func (*Host) NewStream ¶
func (h *Host) NewStream(ctx context.Context, pid peer.ID, protocols ...protocol.ID) (s inet.Stream, err error)
NewStream opens a new stream to the given peer for the given protocols.
func (*Host) RemoveStreamHandler ¶
RemoveStreamHandler removes the stream handler of the given protocol.
func (*Host) SetIDService ¶
SetIDService sets the identity service.
func (*Host) SetNATManager ¶
func (h *Host) SetNATManager(natmgr bhost.NATManager)
SetNATManager sets the NAT manager.
func (*Host) SetStreamHandler ¶
func (h *Host) SetStreamHandler(proto protocol.ID, handler inet.StreamHandler)
SetStreamHandler sets the stream handler for the given protocol.
func (*Host) SetStreamHandlerMatch ¶
func (h *Host) SetStreamHandlerMatch(proto protocol.ID, match func(string) bool, handler inet.StreamHandler)
SetStreamHandlerMatch sets the protocol handler for protocols that match the given function.
type HostOption ¶
type HostOption func(*Host)
HostOption configures a host.
func OptAddrsFilters ¶
func OptAddrsFilters(filter *mafilter.Filters) HostOption
OptAddrsFilters adds addresses filters to a host.
func OptConnManager ¶
func OptConnManager(cmgr ifconnmgr.ConnManager) HostOption
OptConnManager adds a connection manager to a host.
func OptNegTimeout ¶
func OptNegTimeout(timeout time.Duration) HostOption
OptNegTimeout sets the negotiation timeout of a host.
func OptResolver ¶
func OptResolver(resolver *madns.Resolver) HostOption
OptResolver adds a resolver to a host.
type MetricsReporter ¶
type MetricsReporter struct{}
MetricsReporter collects stream and connection metrics.
func (*MetricsReporter) GetBandwidthForPeer ¶
func (r *MetricsReporter) GetBandwidthForPeer(peer.ID) metrics.Stats
GetBandwidthForPeer shouldn't be used.
func (*MetricsReporter) GetBandwidthForProtocol ¶
func (r *MetricsReporter) GetBandwidthForProtocol(protocol.ID) metrics.Stats
GetBandwidthForProtocol shouldn't be used.
func (*MetricsReporter) GetBandwidthTotals ¶
func (r *MetricsReporter) GetBandwidthTotals() metrics.Stats
GetBandwidthTotals shouldn't be used.
func (*MetricsReporter) LogRecvMessage ¶
func (r *MetricsReporter) LogRecvMessage(b int64)
LogRecvMessage records the bandwidth used.
func (*MetricsReporter) LogRecvMessageStream ¶
LogRecvMessageStream records the bandwidth used.
func (*MetricsReporter) LogSentMessage ¶
func (r *MetricsReporter) LogSentMessage(b int64)
LogSentMessage records the bandwidth used.
func (*MetricsReporter) LogSentMessageStream ¶
LogSentMessageStream records the bandwidth used.