DAOT Labs' fork of libp2p/go-libp2p-pubsub
This repo contains the canonical pubsub implementation for libp2p. We currently provide three message router options:
- Floodsub, which is the baseline flooding protocol.
- Randomsub, which is a simple probabilistic router that propagates to random subsets of peers.
- Gossipsub, which is a more advanced router with mesh formation and gossip propagation. See spec and implementation for more details.
go get github.com/daotl/go-libp2p-pubsub
And add the following line to your go.mod
:
replace github.com/libp2p/go-libp2p-pubsub => github.com/daotl/go-libp2p-pubsub {{VERSION}}
To be used for messaging in p2p infrastructure (as part of libp2p) such as IPFS, Ethereum, other blockchains, etc.
https://github.com/libp2p/go-libp2p/tree/master/examples/pubsub
See the libp2p specs for high level documentation and godoc for API documentation.
.
├── LICENSE
├── README.md
# Regular Golang repo set up
├── codecov.yml
├── pb
├── go.mod
├── go.sum
├── doc.go
# PubSub base
├── pubsub.go
├── blacklist.go
├── notify.go
├── comm.go
├── discovery.go
├── sign.go
├── subscription.go
├── topic.go
├── trace.go
├── tracer.go
├── validation.go
# Floodsub router
├── floodsub.go
# Randomsub router
├── randomsub.go
# Gossipsub router
├── gossipsub.go
├── score.go
├── score_params.go
└── mcache.go
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:
tracer, err := pubsub.NewJSONTracer("/path/to/trace.json")
if err != nil {
panic(err)
}
pubsub.NewGossipSub(..., pubsub.WithEventTracer(tracer))
To capture the trace as a protobuf, you can use the following option:
tracer, err := pubsub.NewPBTracer("/path/to/trace.pb")
if err != nil {
panic(err)
}
pubsub.NewGossipSub(..., pubsub.WithEventTracer(tracer))
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))
Contributions welcome. Please check out the issues.
Small note: If editing the README, please conform to the standard-readme specification.
The go-libp2p-pubsub project is dual-licensed under Apache 2.0 and MIT terms:
- Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Copyright for modified portions of this fork are held by [DAOT Labs, 2020].
All other copyright for this fork are held by [Jeromy Johnson, 2016] as part of the original go-libp2p-pubsub project.
All rights reserved.