P2pcf: P2P WebRTC via Cloudflare Workers
github.com
github.com
Sadly both WebRTC and WebSockets seem to have been designed in such a way that excludes pure peer-to-peer operation.
What do you mean by pure peer-to-peer operation?
The standards are carefully defined in a way that creates server dependency. WebSocket outright does not allow connections to other browsers directly. WebRTC does, but you are extremely limited in how you could do discovery. I think both are intentional.
WebRTC needs info about where to try to connect. It doesn’t specify the signaling method which is how you get that information and share it.
If you’re already on the same subnet, use mDNS.
If you’re on different subnets it requires some kind of way to share the subnet info.
If you’re on different networks behind NAT then scanning isn’t very helpful. You’d need to scan IPs and ports because NAT randomizes the outbound ports. That’s what STUN helps you figure out. Once you’ve got that info and you build the session description structure you can send that to the other party however you want.
Public, free STUN servers exist. And people use them for all kinds of WebRTC stuff.
Neither WebRTC nor WebSockets prevent pure P2P. It sounds like your bigger issue is with NAT. IPv6 isn’t going to fix it though since the IP space will be too large to scan for peers.
You misunderstood, knowing subnet is an option for discovery of nearby peers. If you know your subnet you can scan it in reasonable amount of time. Otherwise you'd have to scan the whole IPv4 space (or worse IPv6 space).
> WebRTC needs info about where to try to connect. It doesn’t specify the signaling method which is how you get that information and share it.
Yes.
> If you’re already on the same subnet, use mDNS.
You can't - you are in the browser.
> If you’re on different subnets it requires some kind of way to share the subnet info.
Yes, that's how connections are established with an intermediary signaling service. The p2p question is about possibility of establishing WebRTC connection without a signaling service that runs over something else and/or requires a centralized server.
I have been working on WebRTC a lot lately. If you have ideas on how you’d solve this issue I’d take a stab at implementing them.
I’ve built a demo that lets you get two systems connected by copying and pasting the session description information. No third party systems required. But you still need to get your clipboard data to someone else. Which usually means SMS, Apple Messages, etc.
You'd literally have to scan QR codes on both devices, but that's the only option I have in mind
If you are interested I would love to work together! Join the Pion slack and would love to brainstorm
IIRC the P2pcf client polls the worker for new peers. Pubsub would let you use an ongoing websockets connection, plus all the channel management logic is built-in. The game-changer is that they've said they'll charge per-message as opposed to per-connection-second, unlike everyone else!
DO/D2 will likely perform better than R2 unless you’re storing everything in the metadata. KV will perform better than all of them although if the storage is to keep a list of peers the API as exists today won’t work well for that - you’ll have to do 1 key per connection and retrieve via a paged list - otherwise you can lose clients since KV has no mechanism to do durable updates of values stored within keys*. You could also do DO with background refresh of cache to maintain good performance while maintaining better bounds on how long a value stays in the cache.
* actually it is possible if you mediate updates to KV through a DO (with storage as the ground truth or without it and risk occasional lost writes if the CF infrastructure decides to kill and reset/relocate your DO).
Serverless computing is a cloud computing execution model in which the cloud provider allocates machine resources on demand
you should just start re-writing the word in your head to something less upsetting since it's not going anywhere and it actually does contain information
maybe we need better names for these kinds of computer configurations.