Giter Site home page Giter Site logo

go-gossipsub-examples's Introduction

Libp2p GossipSub Examples

Libp2p GossipSub-based examples for getting skilled using GossipSub. You can run some example apps and open the source codes to understand how it works.

Examples

Chat App

GossipSub chatting application is based on go-libp2p pubsub example.

You can chat with another peers in the same LAN and topic (P2P network group) by running this simple chat app.

Users can set own nickname by nick flag --nickname=NICKNAME and room name by room flag --room=ROOMNAME. If you didn't set any names, your nickname would be $USER-RANDOM_TEXT and room name would be test by default.

Run chat app like this:

go run . --nick=docbull --room=ChatApp

And run another chat app user in a new terminal:

go run . --nick=watson --room=ChatApp

Enter any message in the terminal. The message will be sent to other peers using GossipSub. If you want to leave the chatting room, just enter /quit command.

Output A:

--------------------------
Room: ChatApp
Your name: docbull
--------------------------
hi, there!

Output B:

--------------------------
Room: ChatApp
Your name: watson
--------------------------
docbull : hi, there!
/quit

File Sharing

File sharing example transfer a file that you entered in the terminal. A receiver prints who sent the file and stores on own directory.

In this example, you don't need to setup your name, it only works by default. On the other hand, network group name would be set by network flag --network==NETWORK_NAME.

Run file sharing example like this:

go run . --network=FileSharing

Output:

--------------------------
Network Group: FileSharing
Your name: QmS...
--------------------------

Open a new terminal in local or in the same LAN nodes:

go run . --network=FileSharing

Now enter a name of file that you want to share.

Output A:

--------------------------
Network Group: FileSharing
Your name: QmS...
--------------------------
text.txt

Output B:

--------------------------
Network Group: FileSharing
Your name: QmP...
--------------------------
QmS... sent a file: text.txt

Multi-host Chat App

This multi-host chat app is based on go-libp2p example.

The simple chat app example above is only working on the same subnet peers like an intranet. That means, the messages cannot go outside and inside neither.

This example lets you experience running chat app that available communicate with peers outside of subnet.

Running peer options:

  • --port: Configures peer's listening port number
  • --mode: If you want to run your node as a bootstrap node, set this flag as bootstrap; --mode=bootstrap
  • --bootstrap: Decides connecting bootstrap peer using bootstrap peer's multiaddrs

Run bootstrap peer like this:

go run . --mode=bootstrap --port=4001

Output:

Listening on /ip4/BOOTSTRAP_IP/tcp/4001
Listening on /ip4/127.0.0.1/tcp/4001
Peer ID: QmS...
Copy and paste this multiaddrs for joining chat app in another peer: /ip4/BOOTSTRAP_IP/tcp/4001/p2p/QmS...

If you have bootstrap peer, lets run common peer to join in the chat:

go run . --bootstrap=/ip4/BOOTSTRAP_IP/tcp/4001/p2p/QmS...

Output:

Listening on /ip4/IP_ADDRESS/tcp/35021
Listening on /ip4/127.0.0.1/tcp/35021
Listening on /ip4/IP_ADDRESS/tcp/44693/ws
Listening on /ip4/127.0.0.1/tcp/44693/ws
Peer ID: QmT...
Connected to QmS...

Now, enter any message in the terminal, then it will be disseminated to all peers in the chat using GossipSub.

go-gossipsub-examples's People

Contributors

docbull avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.