Skip to content

Commit 552e9b9

Browse files
authored
Merge pull request ChainSafe#2 from libp2p/feat/initial-implementation
feat: initial implementation
2 parents e5502e9 + 326d73d commit 552e9b9

14 files changed

+1146
-1
lines changed

.gitignore

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
docs
2+
**/node_modules/
3+
**/*.log
4+
test/repo-tests*
5+
6+
# Logs
7+
logs
8+
*.log
9+
10+
coverage
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
17+
# Directory for instrumented libs generated by jscoverage/JSCover
18+
lib-cov
19+
20+
# Coverage directory used by tools like istanbul
21+
coverage
22+
23+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
24+
.grunt
25+
26+
# node-waf configuration
27+
.lock-wscript
28+
29+
build
30+
31+
# Dependency directory
32+
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
33+
node_modules
34+
35+
dist
36+
37+
docs
38+
39+
package-lock.json
40+
yarn.lock

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2019 Protocol Labs, Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+82-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,82 @@
1-
# js-libp2p-pubsub
1+
js-libp2p-pubsub
2+
==================
3+
4+
[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
5+
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://libp2p.io/)
6+
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
7+
[![Coverage Status](https://coveralls.io/repos/github/libp2p/js-libp2p-pubsub/badge.svg?branch=master)](https://coveralls.io/github/libp2p/js-libp2p-pubsub?branch=master)
8+
[![Travis CI](https://travis-ci.org/libp2p/js-libp2p-pubsub.svg?branch=master)](https://travis-ci.org/libp2p/js-libp2p-pubsub)
9+
[![Circle CI](https://circleci.com/gh/libp2p/js-libp2p-pubsub.svg?style=svg)](https://circleci.com/gh/libp2p/js-libp2p-pubsub)
10+
[![Dependency Status](https://david-dm.org/libp2p/js-libp2p-pubsub.svg?style=flat-square)](https://david-dm.org/libp2p/js-libp2p-pubsub) [![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square)](https://github.com/feross/standard)
11+
[![standard-readme compliant](https://img.shields.io/badge/standard--readme-OK-green.svg?style=flat-square)](https://github.com/RichardLitt/standard-readme)
12+
[![](https://img.shields.io/badge/pm-waffle-yellow.svg?style=flat-square)](https://waffle.io/libp2p/js-libp2p-pubsub)
13+
14+
> libp2p-pubsub consits on the base protocol for libp2p pubsub implementation. This module is responsible for all the logic regarding peer connections.
15+
16+
## Lead Maintainer
17+
18+
[Vasco Santos](https://github.com/vasco-santos).
19+
20+
## Table of Contents
21+
22+
- [Install](#install)
23+
- [Usage](#usage)
24+
- [Contribute](#contribute)
25+
- [License](#license)
26+
27+
## Install
28+
29+
```sh
30+
> npm install libp2p-pubsub
31+
```
32+
33+
## Usage
34+
35+
A pubsub implementation **MUST** override the `_processConnection`, `publish`, `subscribe` and `unsubscribe` functions. `add_peer` and `remove_peer` may be overwritten if the pubsub implementation needs to add custom logic when peers are added and remove. All the remaining functions **MUST NOT** be overwritten.
36+
37+
The following example aims to show how to create your pubsub implementation extending this base protocol. The pubsub implementation will handle the subscriptions logic.
38+
39+
```JavaScript
40+
const Pubsub = require('libp2p-pubsub')
41+
42+
class PubsubImplementation extends Pubsub {
43+
constructor(libp2p) {
44+
super('libp2p:pubsub', '/pubsub-implementation/1.0.0', libp2p)
45+
}
46+
47+
_processConnection(idB58Str, conn, peer) {
48+
// Required to be implemented by the subclass
49+
// Process each message accordingly
50+
}
51+
52+
publish() {
53+
// Required to be implemented by the subclass
54+
}
55+
56+
subscribe() {
57+
// Required to be implemented by the subclass
58+
}
59+
60+
unsubscribe() {
61+
// Required to be implemented by the subclass
62+
}
63+
}
64+
```
65+
66+
## Implementations using this base protocol
67+
68+
You can use the following implementations as examples for building your own pubsub implementation.
69+
70+
- [libp2p/js-libp2p-floodsub](https://github.com/libp2p/js-libp2p-floodsub)
71+
72+
## Contribute
73+
74+
Feel free to join in. All welcome. Open an [issue](https://github.com/libp2p/js-libp2p-pubsub/issues)!
75+
76+
This repository falls under the IPFS [Code of Conduct](https://github.com/ipfs/community/blob/master/code-of-conduct.md).
77+
78+
[![](https://cdn.rawgit.com/jbenet/contribute-ipfs-gif/master/img/contribute.gif)](https://github.com/ipfs/community/blob/master/contributing.md)
79+
80+
## License
81+
82+
Copyright (c) Protocol Labs, Inc. under the **MIT License**. See [LICENSE file](./LICENSE) for details.

ci/Jenkinsfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Warning: This file is automatically synced from https://github.com/ipfs/ci-sync so if you want to change it, please change it there and ask someone to sync all repositories.
2+
javascript()

package.json

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"name": "libp2p-pubsub",
3+
"version": "0.0.0",
4+
"description": "Pubsub base protocol for libp2p pubsub routers",
5+
"leadMaintainer": "Vasco Santos <[email protected]>",
6+
"main": "src/index.js",
7+
"scripts": {
8+
"lint": "aegir lint",
9+
"test": "aegir test -t node",
10+
"test:node": "aegir test -t node",
11+
"build": "aegir build",
12+
"docs": "aegir-docs",
13+
"release": "aegir release --docs",
14+
"release-minor": "aegir release --type minor --docs",
15+
"release-major": "aegir release --type major --docs",
16+
"coverage": "aegir coverage",
17+
"coverage-publish": "aegir coverage --provider coveralls"
18+
},
19+
"files": [
20+
"src",
21+
"dist"
22+
],
23+
"pre-push": [
24+
"lint"
25+
],
26+
"repository": {
27+
"type": "git",
28+
"url": "git+https://github.com/libp2p/js-libp2p-pubsub.git"
29+
},
30+
"keywords": [
31+
"IPFS",
32+
"libp2p",
33+
"pubsub",
34+
"gossip",
35+
"flood",
36+
"flooding"
37+
],
38+
"license": "MIT",
39+
"bugs": {
40+
"url": "https://github.com/libp2p/js-libp2p-pubsub/issues"
41+
},
42+
"homepage": "https://github.com/libp2p/js-libp2p-pubsub#readme",
43+
"devDependencies": {
44+
"aegir": "^18.0.3",
45+
"benchmark": "^2.1.4",
46+
"chai": "^4.2.0",
47+
"chai-spies": "^1.0.0",
48+
"dirty-chai": "^2.0.1",
49+
"libp2p": "~0.24.4",
50+
"libp2p-secio": "~0.11.0",
51+
"libp2p-spdy": "~0.13.1",
52+
"libp2p-tcp": "~0.13.0",
53+
"lodash": "^4.17.11",
54+
"peer-id": "~0.12.2",
55+
"peer-info": "~0.15.1"
56+
},
57+
"dependencies": {
58+
"async": "^2.6.1",
59+
"debug": "^4.1.1",
60+
"err-code": "^1.1.2",
61+
"length-prefixed-stream": "^1.6.0",
62+
"protons": "^1.0.1",
63+
"pull-pushable": "^2.2.0"
64+
},
65+
"contributors": []
66+
}

0 commit comments

Comments
 (0)