internal

package
v0.15.4 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 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

func GetPeerProtocolVersion added in v0.13.5

func GetPeerProtocolVersion(ps peerstore.Peerstore, pid peer.ID) string

func GetPeerProtocols added in v0.13.5

func GetPeerProtocols(ps peerstore.Peerstore, pid peer.ID) []string

func GetPeerUserAgent added in v0.13.5

func GetPeerUserAgent(ps peerstore.Peerstore, pid peer.ID) string

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(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

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

func (*Node) Start

func (n *Node) Start(ctx context.Context) error

func (*Node) Subscribe

func (n *Node) Subscribe(topic string) (*Subscription, 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

func (n *Node) Wait() <-chan error

Wait waits until the context is canceled or until an error occurs.

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 DialTimeout

func DialTimeout(t time.Duration) Options

DialTimeout sets dial timeout for libp2p nodes.

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

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

func Monitor() Options

func PeerInfos added in v0.11.0

func PeerInfos(c chan<- PeerInfo) 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

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

func PubsubEventTracer(tracer pubsub.EventTracer) Options

PubsubEventTracer provides a tracer for the pubsub system.

func RateLimiter

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 PeerInfo added in v0.11.0

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

type RateLimiterConfig

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 *pubsub.Message

func (*Subscription) Publish

func (s *Subscription) Publish(msg []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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