p2p

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2021 License: AGPL-3.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadySubscribed = errors.New("topic is already subscribed")
View Source
var ErrConnectionClosed = errors.New("connection is closed")
View Source
var ErrNilMessage = errors.New("message is nil")
View Source
var ErrNotSubscribed = errors.New("topic is not subscribed")
View Source
var ErrPubSubDisabled = errors.New("pubsub protocol is disabled")

Functions

This section is empty.

Types

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is a single node in the P2P network. It wraps the libp2p library to provide an easier to use and use-case agnostic interface for the pubsub system.

func NewNode

func NewNode(ctx context.Context, opts ...Options) (*Node, error)

func (*Node) AddConnectionGater

func (n *Node) AddConnectionGater(connGaters ...coreConnmgr.ConnectionGater)

func (*Node) AddMessageHandler

func (n *Node) AddMessageHandler(messageHandlers ...sets.MessageHandler)

func (*Node) AddNodeEventHandler

func (n *Node) AddNodeEventHandler(eventHandler ...sets.NodeEventHandler)

func (*Node) AddNotifee

func (n *Node) AddNotifee(notifees ...network.Notifiee)

func (*Node) AddPubSubEventHandler

func (n *Node) AddPubSubEventHandler(eventHandler ...sets.PubSubEventHandler)

func (*Node) AddValidator

func (n *Node) AddValidator(validator sets.Validator)

func (*Node) Addrs

func (n *Node) Addrs() []multiaddr.Multiaddr

func (*Node) Connect

func (n *Node) Connect(maddr multiaddr.Multiaddr) error

func (*Node) Host

func (n *Node) Host() host.Host

func (*Node) Peerstore

func (n *Node) Peerstore() peerstore.Peerstore

func (*Node) PubSub

func (n *Node) PubSub() *pubsub.PubSub

func (*Node) RemoveNotifee added in v0.2.2

func (n *Node) RemoveNotifee(notifees ...network.Notifiee)

func (*Node) Start

func (n *Node) Start() error

func (*Node) Subscribe

func (n *Node) Subscribe(topic string, typ pkgTransport.Message) error

func (*Node) Subscription

func (n *Node) Subscription(topic string) (*Subscription, error)

func (*Node) Unsubscribe

func (n *Node) Unsubscribe(topic string) error

func (*Node) Wait added in v0.2.0

func (n *Node) Wait()

type Options

type Options func(n *Node) error

func ConnectionLimit

func ConnectionLimit(low, high int, grace time.Duration) Options

ConnectionLimit limits the number of connections. When the number of connections reaches a high value, then as many connections will be dropped until we reach a low number of connections.

func ConnectionLogger

func ConnectionLogger() Options

ConnectionLogger logs connected and disconnected hosts,

func Denylist

func Denylist(addrs []multiaddr.Multiaddr) Options

Denylist allows to block peer by their IP addresses or IDs.

func DirectPeers

func DirectPeers(addrs []multiaddr.Multiaddr) Options

DirectPeers enforces direct connection with given peers. Note that the direct connection should be symmetrically configured at both ends.

func DisablePubSub added in v0.2.0

func DisablePubSub() Options

DisablePubSub disables the pubsub system.

func Discovery

func Discovery(bootstrapAddrs []multiaddr.Multiaddr) Options

Discovery configures node to use kad-dht for node discovery.

func ListenAddrs

func ListenAddrs(addrs []multiaddr.Multiaddr) Options

ListenAddrs configures node to listen on the given addresses.

func Logger

func Logger(logger log.Logger) Options

Logger configures node to use given logger instance.

func MessageLogger

func MessageLogger() Options

MessageLogger logs published and received messages.

func MessagePrivKey

func MessagePrivKey(sk crypto.PrivKey) Options

MessagePrivKey configures node to use given key to sign messages.

func Monitor added in v0.1.3

func Monitor() Options

func PeerLogger

func PeerLogger() Options

PeerLogger logs all peers handled by libp2p's pubsub system.

func PeerPrivKey

func PeerPrivKey(sk crypto.PrivKey) Options

PeerPrivKey configures node to use given key as its identity.

func PeerScoring added in v0.1.3

func PeerScoring(
	params *pubsub.PeerScoreParams,
	thresholds *pubsub.PeerScoreThresholds,
	topicScoreParams func(topic string) *pubsub.TopicScoreParams) Options

PeerScoring configures peer scoring parameters used in a pubsub system.

func PubsubEventTracer added in v0.1.3

func PubsubEventTracer(tracer pubsub.EventTracer) Options

PubsubEventTracer provides a tracer for the pubsub system.

func RateLimiter added in v0.1.2

func RateLimiter(cfg RateLimiterConfig) Options

RateLimiter limits the number of bytes which is allowed to receive from the network using the token bucket algorithm: https://en.wikipedia.org/wiki/Token_bucket

bytesPerSecond is the maximum number of bytes/s that can be received from a single peer.

burstSize is a burst value in bytes applied for a messages received from a singe peer.

func UserAgent

func UserAgent(userAgent string) Options

UserAgent sets the libp2p user-agent sent along with the identify protocol.

type RateLimiterConfig added in v0.1.2

type RateLimiterConfig struct {
	// BytesPerSecond is the maximum rate of messages in bytes/s that can be
	// created by a single peer.
	BytesPerSecond float64
	// BurstSize is a burst value in bytes for a messages created from a singe
	// peer.
	BurstSize int
	// RelayBytesPerSecond is the maximum rate of messages in bytes/s that can
	// be relayed by a single relay.
	RelayBytesPerSecond float64
	// RelayBurstSize is a burst value in bytes for a messages relayed by
	// a singe peer.
	RelayBurstSize int
}

RateLimiterConfig is a configuration for the RateLimiter option.

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

func (*Subscription) Next

func (s *Subscription) Next() chan transport.ReceivedMessage

func (*Subscription) Publish

func (s *Subscription) Publish(message transport.Message) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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