Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to do PubSub #11

Open
janus opened this issue Feb 22, 2021 · 1 comment
Open

How to do PubSub #11

janus opened this issue Feb 22, 2021 · 1 comment

Comments

@janus
Copy link
Contributor

janus commented Feb 22, 2021

I would like to use PubSub. But there is no example out there.

(def (start-pubsub-node host-addresses)
  (let* ((c (open-libp2p-client host-addresses: host-addresses options: ["-pubsub" "-pubsubRouter" "gossipsub"] wait: 20))
         (self (libp2p-identify c)))
    (pubsub-subscribe c "Never")
    (for (p (peer-info->string* self))
      (displayln "I am " p))
    (displayln "Listening for incoming connections")))

(def (start-pubsub-node host-addresses)
  (let* ((c (open-libp2p-client host-addresses: host-addresses options: ["-pubsub" "-pubsubRouter" "gossipsub"] wait: 20))
         (self (libp2p-identify c)))
    (pubsub-subscribe c "Never")
    (for (p (peer-info->string* self))
      (displayln "I am " p))
   (libp2p-connect c peer)
    (displayln "Listening for incoming connections")))

I also noticed that there is a channel out there.

(pubsub-subscribe c topic)
  c      := client
  topic: = string
=> (values sub cancel)
  sub    := channel; message channel
  cancel := lambda (); thunk to cancel the subscription
  message := (vector ID data seqno topics signature key)

How can I use it?

@bennewhall
Copy link
Contributor

Check out Pr #15 for how I used pubsub to create a chat similar to libp2pchat.

Open to feedback! Hopefully this helps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants