Show / Hide Table of Contents

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. The topic is just a name that indicates a group of related messages. The message contains the author, topic(s), sequence number and content.

Publishing

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".

await ipfs.PubSub.PublishAsync("nz", "tēnā koutou");

Subscribing

SubscribeAsync indicates interest in messages for the specified topic. The handler is invoked when a unique message is received.

var cs = new CancellationTokenSource();
await ipfs.PubSub.SubscribeAsync("nz", msg =>
{
    // do something with msg.DataBytes
}, cs.Token);

To unsubscribe, simply cancel the subscribe

cs.Cancel();

Implementation

The peer talk notification service with a floodsub router is currently used. In the future a gossip router will be used.

See also

  • PubSub interface for libp2p
  • In the beginning was floodsub
  • And then there is gossipsub
  • Proximity Aware Epidemic PubSub for libp2p
  • Improve this Doc
Back to top Generated by DocFX