README.md 6.03 KB
Newer Older
Steven Allen's avatar
Steven Allen committed
1
# go-libp2p-pubsub
Richard Littauer's avatar
Richard Littauer committed
2

David Dias's avatar
David Dias committed
3 4 5 6 7 8 9 10
<p align="left">
  <a href="http://protocol.ai"><img src="https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square" /></a>
  <a href="http://libp2p.io/"><img src="https://img.shields.io/badge/project-libp2p-yellow.svg?style=flat-square" /></a>
  <a href="http://webchat.freenode.net/?channels=%23libp2p"><img src="https://img.shields.io/badge/freenode-%23libp2p-yellow.svg?style=flat-square" /></a>
  <a href="https://discuss.libp2p.io"><img src="https://img.shields.io/discourse/https/discuss.libp2p.io/posts.svg?style=flat-square"/></a>
</p>

<p align="left">
David Dias's avatar
David Dias committed
11
  <a href="https://codecov.io/gh/libp2p/go-libp2p-pubsub"><img src="https://codecov.io/gh/libp2p/go-libp2p-pubsub/branch/master/graph/badge.svg"></a>
vyzo's avatar
vyzo committed
12
  <a href="https://goreportcard.com/report/github.com/libp2p/go-libp2p-pubsub"><img src="https://goreportcard.com/badge/github.com/libp2p/go-libp2p-pubsub" /></a>
David Dias's avatar
David Dias committed
13 14 15 16 17
  <a href="https://github.com/RichardLitt/standard-readme"><img src="https://img.shields.io/badge/readme%20style-standard-brightgreen.svg?style=flat-square" /></a>
  <a href="https://godoc.org/github.com/libp2p/go-libp2p-pubsub"><img src="http://img.shields.io/badge/godoc-reference-5272B4.svg?style=flat-square" /></a>
  <a href=""><img src="https://img.shields.io/badge/golang-%3E%3D1.14.0-orange.svg?style=flat-square" /></a>
  <br>
</p>
Richard Littauer's avatar
Richard Littauer committed
18

19 20 21 22
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](https://github.com/libp2p/specs/tree/master/pubsub/gossipsub) and  [implementation](https://github.com/libp2p/go-libp2p-pubsub/blob/master/gossipsub.go) for more details.
Richard Littauer's avatar
Richard Littauer committed
23

24
**PSA: The Hardening Extensions for Gossipsub (Gossipsub V1.1) can be found under development at https://github.com/libp2p/go-libp2p-pubsub/pull/263**
25

David Dias's avatar
David Dias committed
26 27 28 29
## Repo Lead Maintainer

[@vyzo](https://github.com/vyzo/)

vyzo's avatar
vyzo committed
30
> This repo follows the [Repo Lead Maintainer Protocol](https://github.com/ipfs/team-mgmt/blob/master/LEAD_MAINTAINER_PROTOCOL.md)
David Dias's avatar
David Dias committed
31

Richard Littauer's avatar
Richard Littauer committed
32 33
## Table of Contents

David Dias's avatar
David Dias committed
34 35 36
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

Richard Littauer's avatar
Richard Littauer committed
37 38
- [Install](#install)
- [Usage](#usage)
David Dias's avatar
David Dias committed
39
- [Implementations](#implementations)
vyzo's avatar
vyzo committed
40
- [Documentation](#documentation)
vyzo's avatar
vyzo committed
41
- [Tracing](#tracing)
Richard Littauer's avatar
Richard Littauer committed
42 43 44
- [Contribute](#contribute)
- [License](#license)

David Dias's avatar
David Dias committed
45 46
<!-- END doctoc generated TOC please keep comment here to allow auto update -->

Richard Littauer's avatar
Richard Littauer committed
47 48 49
## Install

```
Steven Allen's avatar
Steven Allen committed
50
go get github.com/libp2p/go-libp2p-pubsub
Richard Littauer's avatar
Richard Littauer committed
51 52 53 54
```

## Usage

55
To be used for messaging in p2p instrastructure (as part of libp2p) such as IPFS, Ethereum, other blockchains, etc.
Richard Littauer's avatar
Richard Littauer committed
56

57
### Example
58

59
https://github.com/libp2p/go-libp2p/tree/master/examples/pubsub
60

vyzo's avatar
vyzo committed
61 62
## Documentation

David Dias's avatar
David Dias committed
63
See the [libp2p specs](https://github.com/libp2p/specs/tree/master/pubsub) for high level documentation and [godoc](https://godoc.org/github.com/libp2p/go-libp2p-pubsub) for API documentation.
vyzo's avatar
vyzo committed
64

David Dias's avatar
David Dias committed
65
### In this repo, you will find
vyzo's avatar
vyzo committed
66

David Dias's avatar
David Dias committed
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
```
.
├── 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
vyzo's avatar
vyzo committed
91
# Randomsub router
David Dias's avatar
David Dias committed
92
├── randomsub.go
vyzo's avatar
vyzo committed
93
# Gossipsub router
David Dias's avatar
David Dias committed
94
├── gossipsub.go
vyzo's avatar
vyzo committed
95 96
├── score.go
├── score_params.go
David Dias's avatar
David Dias committed
97 98 99 100
└── mcache.go
```

### Tracing
vyzo's avatar
vyzo committed
101

David Dias's avatar
David Dias committed
102
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.
vyzo's avatar
vyzo committed
103

David Dias's avatar
David Dias committed
104
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).
vyzo's avatar
vyzo committed
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
If you want to trace using a remote peer, you can do so using the `traced` daemon from [go-libp2p-pubsub-tracer](https://github.com/libp2p/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:
```go
pubsub.NewGossipSub(..., pubsub.NewEventTracer(pubsub.NewJSONTracer("/path/to/trace.json")))
```

To capture the trace as a protobuf, you can use the following option:
```go
pubsub.NewGossipSub(..., pubsub.NewEventTracer(pubsub.NewPBTracer("/path/to/trace.pb")))
```

Finally, to use the remote tracer, you can use the following incantations:
```go
// 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))
```

Richard Littauer's avatar
Richard Littauer committed
133 134
## Contribute

Steven Allen's avatar
Steven Allen committed
135
Contributions welcome. Please check out [the issues](https://github.com/libp2p/go-libp2p-pubsub/issues).
Richard Littauer's avatar
Richard Littauer committed
136 137 138 139 140 141 142

Check out our [contributing document](https://github.com/libp2p/community/blob/master/contributing.md) 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](https://github.com/ipfs/community/blob/master/code-of-conduct.md).

Small note: If editing the README, please conform to the [standard-readme](https://github.com/RichardLitt/standard-readme) specification.

## License

David Dias's avatar
David Dias committed
143
The go-libp2p-pubsub project is dual-licensed under Apache 2.0 and MIT terms:
144

David Dias's avatar
David Dias committed
145 146
- Apache License, Version 2.0, ([LICENSE-APACHE](./LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license ([LICENSE-MIT](./LICENSE-MIT) or http://opensource.org/licenses/MIT)