Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

feature: add pubsub (tests and API Spec) #101

Merged
merged 9 commits into from
Dec 21, 2016
73 changes: 73 additions & 0 deletions API/pubsub/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
pubsub API
==========

#### `pubsub.subscribe`

> Subscribe to a pubsub topic.

##### `Go` **WIP**

##### `JavaScript` - ipfs.pubsub.subscribe(topic, options, handler, callback)

- `topic: string`
- `options: Object` - (Optional), might contain the following properties:
- `discover`: type: Boolean - Will use the DHT to find other peers.
- `handler: (msg) => ()` - Event handler which will be called with a message object everytime one is received. The `msg` has the format `{from: string, seqno: Buffer, data: Buffer, topicCIDs: Array<string>}`.
- `callback: (Error) => ()` (Optional) Called once the subscription is established.

If no `callback` is passed, a [promise][] is returned.

> _In the future, topic can also be type of TopicDescriptor (https://github.com/libp2p/pubsub-notes/blob/master/flooding/flooding.proto#L23). However, for now, only strings are supported._

#### `pubsub.unsubscribe`

> Unsubscribes from a pubsub topic.

##### `Go` **WIP**

##### `JavaScript` - `ipfs.pubsub.unsubscribe(topic, handler)`

- `topic: string` - The topic to unsubscribe from
- `handler: (msg) => ()` - The handler to remove.

This works like `EventEmitter.removeListener`, as that only the `handler` passed to a `subscribe` call before is removed from listening. The underlying subscription will only be canceled once all listeners for a topic have been removed.

#### `pubsub.publish`

> Publish a data message to a pubsub topic.

##### `Go` **WIP**

##### `JavaScript` - ipfs.pubsub.publish(topic, data, callback)

- `topic: string`
- `data: buffer` - The actual message to send
- `callback: (Error) => ()` - Calls back with an error or nothing if the publish was successfull.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is missing the description of data

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛎

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed


If no `callback` is passed, a promise is returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please complete

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#### `pubsub.ls`

> Returns the list of subscriptions the peer is subscribed to.

##### `Go` **WIP**

##### `JavaScript` - ipfs.pubsub.ls(topic, callback)

- `topic: string`
- `callback: (Error, Array<string>>) => ()` - Calls back with an error or a list of topicCIDs that this peer is subscribed to.

If no `callback` is passed, a promise is returned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing docs on the value that is resolved

#### `pubsub.peers`

> Returns the peers that are subscribed to one topic.

##### `Go` **WIP**

##### `JavaScript` - ipfs.pubsub.peers(topic, callback)

- `topic: string`
- `callback: (Error, Array<string>>) => ()` - Calls back with an error or a list of peer ids subscribed to the `topic`.

If no `callback` is passed, a promise is returned.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
<a name="0.22.1"></a>
## [0.22.1](https://github.com/ipfs/interface-ipfs-core/compare/v0.22.0...v0.22.1) (2016-12-10)


### Features

* **object:** add template option to object.new ([2f23617](https://github.com/ipfs/interface-ipfs-core/commit/2f23617))
Copy link
Contributor

@dignifiedquire dignifiedquire Dec 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a changelog in a pr?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that is from a rebase




<a name="0.22.0"></a>
# [0.22.0](https://github.com/ipfs/interface-ipfs-core/compare/v0.21.0...v0.22.0) (2016-11-24)

Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "interface-ipfs-core",
"version": "0.22.0",
"version": "0.22.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is there a version bump in a PR?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as #101 (comment)

"description": "A test suite and interface you can use to implement a IPFS core interface.",
"main": "src/index.js",
"scripts": {
Expand Down Expand Up @@ -28,26 +28,26 @@
"dependencies": {
"async": "^2.1.4",
"bl": "^1.1.2",
"bs58": "^3.0.0",
"bs58": "^3.1.0",
"chai": "^3.5.0",
"concat-stream": "^1.5.2",
"detect-node": "^2.0.3",
"ipfs-block": "^0.5.0",
"ipld-dag-pb": "^0.9.0",
"ipfs-block": "^0.5.3",
"ipld-dag-pb": "^0.9.3",
"multiaddr": "^2.1.1",
"multihashes": "^0.3.0",
"readable-stream": "2.1.5"
"multihashes": "^0.3.1",
"readable-stream": "2.2.2"
},
"devDependencies": {
"aegir": "^9.2.1"
"aegir": "^9.3.0"
},
"contributors": [
"David Dias <daviddias.p@gmail.com>",
"Friedel Ziegelmayer <dignifiedquire@gmail.com>",
"Greenkeeper <support@greenkeeper.io>",
"Richard Littauer <richard.littauer@gmail.com>",
"Stephen Whitmore <stephen.whitmore@gmail.com>",
"Victor Bjelkholm <victorbjelkholm@gmail.com>",
"greenkeeperio-bot <support@greenkeeper.io>",
"nginnever <ginneversource@gmail.com>"
]
}
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ exports.generic = require('./generic')
exports.swarm = require('./swarm')
exports.block = require('./block')
exports.dht = require('./dht')
exports.pubsub = require('./pubsub')
Loading