This is an implementation of a (js-)libp2p node running on Cloudflare Workers and using Cloudflare KV as the persistent datastore (peer-store and content-store).
There are a couple of reasons I wanted to do this:
- libp2p in serverless environments: I wanted to see if you could run libp2p in serverless environments, only starting when a connection is coming in.
- Building a better bootstrap node: Since this node should be, thanks to Cloudflare, geographically close to users it could decrease access latency when bootstrapping a node. I see the greatest possibilities for improvement here.
- Increasing general KAD performance by encouraging connections to physically close nodes: Although I don't do this yet I think Kademlias performance could be improved if the routing table would initially be filled with nodes that are geographically close to the bootstrapping node. I see queries that go around the world as a future/current performance bottleneck in DHT performance.
- Test limits and flexibility of js-libp2p
- Build a comprehensive map of libp2p nodes: Since Cloudflare provides IP location information for every incoming request it would now be possible to map out where nodes are connecting from. This could give insights in possible (future) performance improvements.
Yes!
At the time of writing you can access the node at /dns/libp2p-on-edge.dione.network/tcp/443/wss/p2p/12D3KooWEEh437zVGirT8xqBo7WxBJvXTEucFZRp7hUsK55pp1tt
.
When you read this the PeerID might have changed but otherwise, this should be it.
There are also some API routes.
# Get the Value (I assume UTF-8 encoded) for Hello
curl https://libp2p-on-edge.dione.network/api/v1/kad/hello
# Put the Value "world" into Kademlia under the Key "hello"
curl --request PUT --data '{"value": "world"}' https://libp2p-on-edge.dione.network/api/v1/kad/hello
# Find the closest peers to the key "hello"
curl https://libp2p-on-edge.dione.network/api/v1/kad/closest/hello
MIT License
Attribution to js-libp2p licensed under the MIT/Apache for the code of @libp2p/websockets
which was modified to work in cloudflare workers.