p2p

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2018 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:        "indigo-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:        "indigo-node/views/bandwidth-out",
		Description: "outgoing messages bandwidth",
		Measure:     bandwidthOut.Measure,
		TagKeys:     []tag.Key{monitoring.PeerIDTag.OCTag, monitoring.ProtocolIDTag.OCTag},
		Aggregation: view.Count(),
	}

	Connections = &view.View{
		Name:        "indigo-node/views/connections",
		Description: "open connections",
		Measure:     connections.Measure,
		Aggregation: view.LastValue(),
	}

	Peers = &view.View{
		Name:        "indigo-node/views/peers",
		Description: "connected peers",
		Measure:     peers.Measure,
		Aggregation: view.LastValue(),
	}

	StreamsIn = &view.View{
		Name:        "indigo-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:        "indigo-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:        "indigo-node/views/streams-error",
		Description: "errored streams",
		Measure:     streamsErr.Measure,
		TagKeys:     []tag.Key{monitoring.PeerIDTag.OCTag, monitoring.ErrorTag.OCTag},
		Aggregation: view.Count(),
	}

	Latency = &view.View{
		Name:        "indigo-node/views/latency",
		Description: "peer latency distribution",
		Measure:     latency.Measure,
		TagKeys:     []tag.Key{monitoring.PeerIDTag.OCTag},
		Aggregation: monitoring.DefaultLatencyDistribution,
	}
)

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 the host and the given peer.

func (*Host) ID

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

ID returns the peer ID of the host.

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 OptMetricsInterval

func OptMetricsInterval(interval time.Duration) HostOption

OptMetricsInterval sets the interval at which metrics are collected.

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