p2p

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package p2p defines types for P2P networking. It implements the host interface.

Index

Constants

This section is empty.

Variables

View Source
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.

DefHostOpts are the default options for a host.

These options are set before the options passed to NewHost are processed.

View Source
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 NewHost

func NewHost(ctx context.Context, netw inet.Network, opts ...HostOption) *Host

NewHost creates a new host.

func (*Host) Addrs

func (h *Host) Addrs() []ma.Multiaddr

Addrs returns the filtered addresses of this host.

func (*Host) AllAddrs

func (h *Host) AllAddrs() []ma.Multiaddr

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) Close

func (h *Host) Close() error

Close shuts down the host and its network.

func (*Host) ConnManager

func (h *Host) ConnManager() ifconnmgr.ConnManager

ConnManager returns the connection manager.

func (*Host) Connect

func (h *Host) Connect(ctx context.Context, pi pstore.PeerInfo) error

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) ID

func (h *Host) ID() peer.ID

ID returns the peer ID of the host.

func (*Host) IDService added in v0.2.0

func (h *Host) IDService() *identify.IDService

IDService returns the identify service.

func (*Host) Mux

func (h *Host) Mux() *msmux.MultistreamMuxer

Mux returns the multistream muxer.

func (*Host) Network

func (h *Host) Network() inet.Network

Network returns the network interface.

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) Peerstore

func (h *Host) Peerstore() pstore.Peerstore

Peerstore returns the repository of known peers.

func (*Host) RemoveStreamHandler

func (h *Host) RemoveStreamHandler(proto protocol.ID)

RemoveStreamHandler removes the stream handler of the given protocol.

func (*Host) SetIDService

func (h *Host) SetIDService(service *identify.IDService)

SetIDService sets the identity service.

func (*Host) SetNATManager

func (h *Host) SetNATManager(natmgr bhost.NATManager)

SetNATManager sets the NAT manager.

func (*Host) SetRouter

func (h *Host) SetRouter(router func(context.Context, peer.ID) (pstore.PeerInfo, error))

SetRouter sets the router.

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

func (r *MetricsReporter) LogRecvMessageStream(b int64, pid protocol.ID, peerID peer.ID)

LogRecvMessageStream records the bandwidth used.

func (*MetricsReporter) LogSentMessage

func (r *MetricsReporter) LogSentMessage(b int64)

LogSentMessage records the bandwidth used.

func (*MetricsReporter) LogSentMessageStream

func (r *MetricsReporter) LogSentMessageStream(b int64, pid protocol.ID, peerID peer.ID)

LogSentMessageStream records the bandwidth used.

Jump to

Keyboard shortcuts

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