Categorygithub.com/rairyx/go-libp2p-pubsub
modulepackage
0.1.3
Repository: https://github.com/rairyx/go-libp2p-pubsub.git
Documentation: pkg.go.dev

# README

go-libp2p-pubsub

Discourse posts

A pubsub system with flooding and gossiping variants.

This is the canonical pubsub implementation for libp2p.

We currently provide three implementations:

  • floodsub, which is the baseline flooding protocol.
  • gossipsub, which is a more advanced router with mesh formation and gossip propagation. See spec and implementation for more details.
  • randomsub, which is a simple probabilistic router that propagates to random subsets of peers.

Table of Contents

Install

go get github.com/libp2p/go-libp2p-pubsub

Usage

To be used for messaging in p2p instrastructure (as part of libp2p) such as IPFS, Ethereum, other blockchains, etc.

Implementations

See libp2p/specs/pubsub#Implementations.

Documentation

See the libp2p specs for high level documentation and godoc for API documentation.

Tracing

The pubsub system supports tracing, which collects all events pertaining to the internals of the system. This allows you to recreate the complete message flow and state of the system for analysis purposes.

To enable tracing, instantiate the pubsub system using the WithEventTracer option; the option accepts a tracer with three available implementations in-package (trace to json, pb, or a remote peer). If you want to trace using a remote peer, you can do so using the traced daemon from go-libp2p-pubsub-tracer. The package also includes a utility program, tracestat, for analyzing the traces collected by the daemon.

For instance, to capture the trace as a json file, you can use the following option:

pubsub.NewGossipSub(..., pubsub.NewEventTracer(pubsub.NewJSONTracer("/path/to/trace.json")))

To capture the trace as a protobuf, you can use the following option:

pubsub.NewGossipSub(..., pubsub.NewEventTracer(pubsub.NewPBTracer("/path/to/trace.pb")))

Finally, to use the remote tracer, you can use the following incantations:

// assuming that your tracer runs in x.x.x.x and has a peer ID of QmTracer
pi, err := peer.AddrInfoFromP2pAddr(ma.StringCast("/ip4/x.x.x.x/tcp/4001/p2p/QmTracer"))
if err != nil {
  panic(err)
}

tracer, err := pubsub.NewRemoteTracer(ctx, host, pi)
if err != nil {
  panic(err)
}

ps, err := pubsub.NewGossipSub(..., pubsub.WithEventTracer(tracer))

Contribute

Contributions welcome. Please check out the issues.

Check out our contributing document for more information on how we work, and about contributing in general. Please be aware that all interactions related to multiformats are subject to the IPFS Code of Conduct.

Small note: If editing the README, please conform to the standard-readme specification.

License

MIT © Jeromy Johnson


The last gx published version of this module was: 0.11.16: QmfB4oDUTiaGEqT13P1JqCEhqW7cB1wpKtq3PP4BN8PhQd

# Packages

No description provided by the author

# Functions

msgID returns a unique ID of the passed Message.
MinTopicSize returns a function that checks if a router is ready for publishing based on the topic size.
NewFloodSub returns a new PubSub object using the FloodSubRouter.
NewFloodsubWithProtocols returns a new floodsub-enabled PubSub objecting using the protocols specified in ps.
NewGossipSub returns a new PubSub object using GossipSubRouter as the router.
NewJsonTracer creates a new JSONTracer writing traces to file.
NewMapBlacklist creates a new MapBlacklist.
NewMessageCache creates a sliding window cache that remembers messages for as long as `history` slots.
No description provided by the author
NewPubSub returns a new PubSub management object.
NewRandomSub returns a new PubSub object using RandomSubRouter as the router.
NewRemoteTracer constructs a RemoteTracer, tracing to the peer identified by pi.
NewTimeCachedBlacklist creates a new TimeCachedBlacklist with the given expiry duration.
OpenJSONTracer creates a new JSONTracer, with explicit control of OpenFile flags and permissions.
OpenPBTracer creates a new PBTracer, with explicit control of OpenFile flags and permissions.
No description provided by the author
WithBlacklist provides an implementation of the blacklist; the default is a MapBlacklist.
WithDiscoverConnector adds a custom connector that deals with how the discovery subsystem connects to peers.
WithDiscovery provides a discovery mechanism used to bootstrap and provide peers into PubSub.
WithDiscoveryOpts passes libp2p Discovery options into the PubSub discovery subsystem.
WithEventTracer provides a tracer for the pubsub system.
WithMaxMessageSize sets the global maximum message size for pubsub wire messages.
WithMessageAuthor sets the author for outbound messages to the given peer ID (defaults to the host's ID).
WithMessageIdFn is an option to customize the way a message ID is computed for a pubsub message.
WithMessageSigning enables or disables message signing (enabled by default).
WithPeerOutboundQueueSize is an option to set the buffer size for outbound messages to a peer We start dropping messages to a peer if the outbound queue if full.
WithReadiness returns a publishing option for only publishing when the router is ready.
WithStrictSignatureVerification is an option to enable or disable strict message signing.
WithValidateQueueSize sets the buffer of validate queue.
WithValidateThrottle sets the upper bound on the number of active validation goroutines across all topics.
WithValidateWorkers sets the number of synchronous validation worker goroutines.
WithValidatorConcurrency is an option that sets the topic validator throttle.
WithValidatorInline is an option that sets the validation disposition to synchronous: it will be executed inline in validation front-end, without spawning a new goroutine.
WithValidatorTimeout is an option that sets a timeout for an (asynchronous) topic validator.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
DefaultMaximumMessageSize is 1mb.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

DiscoveryPollInitialDelay is how long the discovery system waits after it first starts before polling.
DiscoveryPollInterval is approximately how long the discovery system waits in between checks for whether the more peers are needed for any topic.
ErrTopicClosed is returned if a Topic is utilized after it has been closed.
overlay parameters.
No description provided by the author
No description provided by the author
fanout ttl.
heartbeat interval.
No description provided by the author
No description provided by the author
gossip parameters.
No description provided by the author
No description provided by the author
No description provided by the author
64K ought to be enough for everyone; famous last words.

# Structs

No description provided by the author
No description provided by the author
GossipSubRouter is a router that implements the gossipsub protocol.
JSONTracer is a tracer that writes events to a file, encoded in ndjson.
No description provided by the author
No description provided by the author
PBTracer is a tracer that writes events to a file, as delimited protobufs.
No description provided by the author
No description provided by the author
PubSub is the implementation of the pubsub system.
RandomSubRouter is a router that implements a random propagation strategy.
RemoteTracer is a tracer that sends trace events to a remote peer.
No description provided by the author
No description provided by the author
Subscription handles the details of a particular Topic subscription.
TimeCachedBlacklist is a blacklist implementation using a time cache.
Topic is the handle for a pubsub topic.
TopicEventHandler is used to manage topic specific events.
No description provided by the author

# Interfaces

Blacklist is an interface for peer blacklisting.
Generic event tracer interface.
PubSubRouter is the message router component of PubSub.

# Type aliases

BackoffConnectorFactory creates a BackoffConnector that is attached to a given host.
No description provided by the author
No description provided by the author
MapBlacklist is a blacklist implementation using a perfect map.
MsgIdFunction returns a unique ID for the passed Message, and PubSub can be customized to use any implementation of this function by configuring it with the Option from WithMessageIdFn.
No description provided by the author
No description provided by the author
No description provided by the author
RouterReady is a function that decides if a router is ready to publish.
No description provided by the author
No description provided by the author
No description provided by the author
Validator is a function that validates a message.
ValidatorOpt is an option for RegisterTopicValidator.