An Experiment that forms p2p Kademlia DHT network using WebSocket and WebRTC
If possible, will try to make this work with IPFS
- join room
- broadcast messages in the room
- listen to memeber join / leave and other peer's broadcasted messages
https://static.pastleo.me/unamed-network-202201-demo/
- There are 2 type of node in the network, namely
serviceNodeandclientNode- a
serviceNodeis a nodejs runninglib/unamed-network.js - a
clientNodeis a browser runninglib/unamed-network.js
- a
- on a normal Kademlia DHT network, location in the network of each node is based on its peerId, here is based on
hash(room.name); nodes within the same room use full-connected (for now)- when
serviceNodestarts, it will join a room that name is their peerId
- when
- websocket for connecting to a
serviceNode, while WebRTC for aclientNodeconnecting to aclientNode- websocket connection can be directly established with addr, and thus can be stored as
knownServiceAddrfor boostraping into network
- websocket connection can be directly established with addr, and thus can be stored as
- to join a room, a node send out a find room packet (RPC between nodes) containing
hash(room.name)to search for a room (or more precisely, a room member node), this packet can hop through many nodes, each node route the packet based on DHT- after finding room, the packet is responded with route of each peerId it traveled
- with route of each peerId, a connect request packet is sent to the room member, so do WebRTC signal packets between the two
- to prevent a node with too many connection, k-bucket will tell if there are redundant connections to other rooms
Not properly tested yet
- work with IPFS (IPFS pubsub is used as transport for now)
- able to find, join room and connect to other nodes
-
serviceNode->serviceNode -
clientNode->serviceNode -
serviceNode->clientNode -
clientNode->clientNode(WebRTC)
-
- provided as a library (for unamed-world)
- detect peer connection lost and leaving
- use
k-bucketto close redundant connections to other rooms not joined - manage number of connections (especially for
clientNode) - retry on finding room
- other improvements to be add here
git clone https://github.com/pastleo/unamed-network.gitandcd unamed-networknpm installcp env.js.dev env.jsnpm run weband open http://localhost:8888 in your browser
You can open multiple tabs and try out room, messaging feature