digidem / mapeo-core-next

The upcoming version of Mapeo Core
MIT License
7 stars 1 forks source link

feat!: frontend should handle peer discovery #550

Closed EvanHahn closed 4 months ago

EvanHahn commented 4 months ago

See also: https://github.com/digidem/comapeo-mobile/pull/245.

I recommend reviewing this one commit at a time.

Our peer discovery system is unreliable on some networks. We'd like to replace it with a native local service discovery system.

To do this, the frontend needs to tell the backend about peers it finds. In other words, we need to "invert" peer discovery.

Here's pseudocode for what the frontend needs to do:

const { name, port } = await mapeoApi.startLocalPeerDiscoveryServer()
zeroconf.publishService({ name, port })
zeroconf.on('resolved', (peer) => {
  mapeoApi.connectPeer(peer)
})

This implements that by removing our mDNS system and replacing it with these public APIs.

Closes #474.