-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from richardschneider/pubsub
PubSubApi implementation
- Loading branch information
Showing
10 changed files
with
364 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# IPFS PubSub system | ||
|
||
The publish/subscribe system allows a `message` to be sent to a group of peers that | ||
are subsctibed to a `topic` via the [PubAub API](xref:Ipfs.CoreApi.IPubSubApi). | ||
The `topic` is just a name that indicates a group of related messages. | ||
The [message](xref:Ipfs.IPublishedMessage) contains the author, topic(s), | ||
sequence number and content. | ||
|
||
|
||
|
||
### Publishing | ||
|
||
[PublishAsync](xref:Ipfs.CoreApi.IPubSubApi.PublishAsync*) sends a | ||
message to a group of peers that are subscribed to a topic. | ||
|
||
The following, sends a "hello world" to all peers subscribed to "nz". | ||
|
||
```csharp | ||
await ipfs.PubSub.PublishAsync("nz", "tēnā koutou"); | ||
``` | ||
|
||
### Subscribing | ||
|
||
[SubscribeAsync](xref:Ipfs.CoreApi.IPubSubApi.SubscribeAsync*) indicates interest | ||
in messages for the specified topic. The `handler` is invoked when a [unique | ||
message](pubsub/dupmsg.md) is received. | ||
|
||
```csharp | ||
var cs = new CancellationTokenSource(); | ||
await ipfs.PubSub.SubscribeAsync("nz", msg => | ||
{ | ||
// do something with msg.DataBytes | ||
}, cs.Token); | ||
``` | ||
|
||
To unsubscribe, simply cancel the subscribe | ||
|
||
```csharp | ||
cs.Cancel(); | ||
``` | ||
|
||
### Implementation | ||
|
||
The peer talk [notification service](xref:PeerTalk.PubSub.NotificationService) | ||
with a [floodsub router](xref:PeerTalk.PubSub.FloodRouter) is currently | ||
used. In the future a [gossip router](https://github.com/richardschneider/peer-talk/issues/25) will be used. | ||
|
||
See also | ||
- [PubSub interface for libp2p](https://github.com/libp2p/specs/tree/master/pubsub) | ||
- [In the beginning was floodsub](https://github.com/libp2p/specs/tree/master/pubsub/gossipsub#in-the-beginning-was-floodsub) | ||
- [And then there is gossipsub](https://github.com/libp2p/specs/tree/master/pubsub/gossipsub#the-gossipsub-protocol) | ||
- [Proximity Aware Epidemic PubSub for libp2p](https://github.com/libp2p/specs/blob/master/pubsub/gossipsub/episub.md) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Duplicate Message | ||
|
||
The message [sequence number](xref:Ipfs.IPublishedMessage.SequenceNumber) is a monotonically | ||
increasing number that is unique among | ||
[messages](xref:Ipfs.IPublishedMessage) originating from a peer. | ||
No two messages from the same peer have the same sequence number. | ||
|
||
However, messages from different peers can have the same sequence number, | ||
so this number alone cannot be used to uniquely identify a message. | ||
A peer id is unique, so the `unique message ID` is the concatenation of the | ||
message [author id](xref:Ipfs.IPublishedMessage.Sender) and [sequence number](xref:Ipfs.IPublishedMessage.SequenceNumber) | ||
fields. | ||
|
||
Maintaining a list of all message IDs seen by the peer is not scalable. | ||
A [timed cached](xref:PeerTalk.MessageTracker) is used to detect duplicate messages seen in the last | ||
the 10 minutes. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Encrypting a Message | ||
|
||
This is not yet implemented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Signing a Message | ||
|
||
This is not yet implemented. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.