{"id":20388275,"url":"https://github.com/libp2p/demo-multi-lang","last_synced_at":"2025-04-12T10:36:23.445Z","repository":{"id":33358785,"uuid":"144769119","full_name":"libp2p/demo-multi-lang","owner":"libp2p","description":"Simple libp2p demos implemented in Go, JS and Rust","archived":false,"fork":false,"pushed_at":"2024-01-31T16:49:42.000Z","size":4488,"stargazers_count":20,"open_issues_count":9,"forks_count":11,"subscribers_count":18,"default_branch":"master","last_synced_at":"2025-03-26T05:23:51.500Z","etag":null,"topics":["demo","go","javascript","libp2p","rust","sample","tutorial"],"latest_commit_sha":null,"homepage":"https://libp2p.io/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libp2p.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-14T20:30:09.000Z","updated_at":"2024-03-23T13:33:17.000Z","dependencies_parsed_at":"2024-06-21T15:16:03.901Z","dependency_job_id":"1fc1c1d8-74b1-4e5d-b634-820b7cf71a08","html_url":"https://github.com/libp2p/demo-multi-lang","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fdemo-multi-lang","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fdemo-multi-lang/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fdemo-multi-lang/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libp2p%2Fdemo-multi-lang/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libp2p","download_url":"https://codeload.github.com/libp2p/demo-multi-lang/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248554169,"owners_count":21123613,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["demo","go","javascript","libp2p","rust","sample","tutorial"],"created_at":"2024-11-15T03:08:27.304Z","updated_at":"2025-04-12T10:36:23.207Z","avatar_url":"https://github.com/libp2p.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libp2p Demos\n\n## Demo 1:  DHT for Connecting Peers \u0026 Sharing Content (Go and JS nodes)\n\n**Directory**:  `content-dht-provide-find`\n\n**What it demonstrates:**  A new DHT is created by the Go program `dht-interop`.  In a separate terminal or machine, a Node.js program connects to this DHT.  One connected, each verifies that it can find the other's content via the DHT.\n\n**First terminal:**\n```\ncd content-dht-provide-find\nmake\n./dht-interop -b ../util/private_key.bin.bootstrapper.Wa\n```\n\n`-b` means bootstrap mode.  In this example, the go program is always the bootstrap node, so `-b` is always required. (***TODO***:  eliminate this superfluous option)\n\nNote that the node ID of `dht-interop` is always `Qm...6aJ9oRuEzWa` because it is being read in from `../util/private_key.bin.bootstrapper.Wa` (a private key marshalled to X.509 generated by the program `util/private-key-gen`).  This is to keep the peer id of the bootstrap server stable across invocations.\n\n**Second terminal:**  run the command printed out by dht-interop, replacing 127.0.0.1 with the IP of the server where dht-interop is listening.  Example:\n\nRunning the Node.js program:\n```\ncd content-dht-provide-find/js-dht-test\nnpm install  # first time only\nnode js-dht-test/index.js /ip4/127.0.0.1/tcp/5555/ipfs/QmehVYruznbyDZuHBV4vEHESpDevMoAovET6aJ9oRuEzWa\n```\n\n\n\n## Demo 2:  PubSub\n\n**Directory**:  `pubsub`\n\n**What it demonstrates**:  Two Go peers, one JS peer, and one Rust peer are all created and run a chat server using a shared PubSub topic.  Typing text in any peer sends it to all the other peers.\n\n**Quick test**:  `cd pubsub` and then run `./test/test.sh`.  Requires Terminator (eg, `sudo apt-get install terminator`).  The rest of this section describes how to test manually.\n\n(**TODO**:  maybe eliminate centralized bootstrapper; any peer could then bootstrap from any other peer and peers could start in any order; downside is the code will be more complex in all peers)\n\n**First terminal**:  Create the bootstrapper node\n\n```\ncd pubsub\n./pubsub-interop ../util/private_key.bin.bootstrapper.Wa --bootstrapper\n```\n\nThe bootstrapper creates a new libp2p node, subscribes to the shared topic string, spawns a go routine to emit any publishes to that topic, and then waits forever.\n\n(Note that the node ID of `pubsub-interop` is going to be `Qm...6aJ9oRuEzWa`.  Node IDs in libp2p are just public keys, and the public key `Qm...6aJ9oRuEzWa` is derived from the private key file `../util/private_key.bin.bootstrapper.Wa`.  That file is just an X.509 keypair generated by the included program `util/private-key-gen`).  We use fixed public/private keypairs for each node in this example to keep things simple.)\n\n**Second terminal**:  Create a go peer to connect to bootstrapper and publish on the topic\n\n```\ncd pubsub\n./pubsub-interop ../util/private_key.bin.peer.Sk\n```\n\nThis peer, which is not in bootstrapper mode, creates a node, subscribes to the shared topic string, spawns the same go routine, and then loops forever requesting user input and publishing each line to the topic.\n\n**Third terminal**:  Create a JS peer to connect to bootstrap and publish on topic\n\n```\ncd pubsub/js\nnpm install  # first time only\nnode index.js /ip4/127.0.0.1/tcp/5555/ipfs/QmehVYruznbyDZuHBV4vEHESpDevMoAovET6aJ9oRuEzWa\n```\n\nThis JS peer will accept lines of text typed on stdin, and publish them on the PubSub topic.\n\n(Note that the JS peer generates a new identity (public/private keypair) each time, and prints its public key to stdout.  This is a deficiency in the demo; to be consistent with the Go code it should accept a private key on the CLI.)\n\n**Fourth terminal**:  Creates a Rust peer to connect to the bootstrap node and then subscribe and publish on the topic:\n\n```\ncd pubsub/rust\ncargo run\n```\n\nThe Rust peer starts up, listens on port 6002, and then dials the boostrap peer.  (TODO:  rust-libp2p#471)  It is now subscribed to the same topic as the other peers.\n\nIf you return to the second, third or fourth terminals and type a message, the bootstrapper and the other 2 peers will all print your message.\n\n**Conclusion**\n\nYou now have a chat app on a private libp2p network where each node can exchange messages using PubSub.\n\n## Debugging Notes\n\n**JS** To see debug messages from the Node.js program, use the `DEBUG` environment variable:\n```\nDEBUG=\"libp2p:floodsub*,libp2p:switch*,mss:*\" node index.js [args...]\n```\n\n**Go** To see debug messages in Go programs, do this at runtime:\n```\nIPFS_LOGGING=debug ./pubsub-interop [args...]\n```\n\n(**TODO**:  describe custom instrumenting the local go code for complex debugging)\n\nIf you instrument your go code with custom `fmt.Println`'s, then revert back like this:\n```\ncd $GOPATH\ngo get -u ./...\n```\n\nOther useful commands:\n```\ngo get -u github.com/libp2p/go-libp2p-kad-dht   # fetch just Kad DHT repo\n```\n\n\n_Acknowledgements:  @jhiesey for DHT (content \u0026 peer routing) JS+Go interop, @stebalien for PubSub_\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibp2p%2Fdemo-multi-lang","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibp2p%2Fdemo-multi-lang","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibp2p%2Fdemo-multi-lang/lists"}