Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve peer discovery #245

Merged
merged 12 commits into from
Apr 15, 2024
Merged

fix: improve peer discovery #245

merged 12 commits into from
Apr 15, 2024

Conversation

EvanHahn
Copy link
Contributor

@EvanHahn EvanHahn commented Apr 11, 2024

Depends on digidem/comapeo-core#550.

I recommend reviewing this one commit at a time.

Our peer discovery system is unreliable on some networks. This replaces it with a native local service discovery system where we tell @mapeo/core about the peers we find.

Closes digidem/comapeo-core#474.

package.json Outdated Show resolved Hide resolved
@EvanHahn EvanHahn marked this pull request as ready for review April 11, 2024 15:16
@EvanHahn EvanHahn requested a review from achou11 April 11, 2024 15:17
EvanHahn added a commit to digidem/comapeo-core that referenced this pull request Apr 11, 2024
See also: <digidem/comapeo-mobile#245>.

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

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][1].

[0]: https://www.npmjs.com/package/react-native-zeroconf
[1]: #474
Copy link
Member

@achou11 achou11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall changes make sense and seems to work as expected when testing with a couple of devices (+ Wireshark)

although i think this is handled by the inclusion of other network-related deps, to be safe, may be worth updating the AndroidManifest.xml file with what the zeroconf dependency requires:

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />

Ping me for another review when core is updated!

src/frontend/contexts/LocalDiscoveryContext.tsx Outdated Show resolved Hide resolved
@EvanHahn
Copy link
Contributor Author

Added the Android permissions in e4bf013.

I'll let you know when I've updated @mapeo/core and IPC.

@EvanHahn
Copy link
Contributor Author

I think this is all ready to go!

@EvanHahn EvanHahn requested a review from achou11 April 11, 2024 22:26
Copy link
Member

@achou11 achou11 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

couple of non-blocking comments but changes look good 👍

src/backend/patches/README.md Outdated Show resolved Hide resolved
src/backend/patches/@mapeo+core+9.0.0-alpha.6.patch Outdated Show resolved Hide resolved
android/app/src/main/AndroidManifest.xml Show resolved Hide resolved
@EvanHahn EvanHahn merged commit 6d1b4d0 into main Apr 15, 2024
@EvanHahn EvanHahn deleted the zeroconf-peer-discovery branch April 15, 2024 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve local device discovery on different networks
2 participants