Skip to content

Commit

Permalink
feat: Implement MdnsDiscovery (#177)
Browse files Browse the repository at this point in the history
* WIP: MdnsDiscovery

Co-authored-by: tomasciccola <tomasciccola@users.noreply.github.com>

* feat: additions to discovery/mdns.js class add some tests

* chore: fixed bug on passing handler to net.connect

* feat: handle two sets for deduplication, various changes

* feat: add check for 'error' event and more checks to dedup

* feat: actually test mdns connections and matching keys

* chore: add type declarations for dnssd from digidem/multicast-service-discovery

try to use those declarations and failed

* feat: destroy noise sockets so connections don't hang

* trying to solve dedup

* WIP fixing bugs

Co-authored-by: tomasciccola <tomasciccola@users.noreply.github.com>

* fix types

* fix hanging open socket

I dunno if this is the best solution (or if `secretStream` and `server`
should share the same `close` handler), but it works...

* lets make the ci happy for a while

* only allow privateIps for mdns connections

* add getter for noise stream connections

* add more tests.

It seems that hypercore replication from on instance to another is failing.
There's probably a bug I haven't catch yet...

* solve dnssd type errors

* add initial testing of multiple connection of peers

* move server 'close' handler to `start` method

It was on the `handleConnection` which meant adding unnecessary handlers
for the same event (for each peer connected)

* various changes:

* remove `this.#socketConnections`
* attach listeners to `error` and `close` before `await once`
* remove type annotation solved by type guard
* start browser and advertiser 'together'
* `await` closing of server

* test connection between multiple peers

The test added can fail (and others too probably), because sometimes
`this.#browser.on('serviceUp')` will return a `service.addresses` with
a IPv6 which yields the following error:
```bash
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: connect EINVAL fe80::fa9a:552c:fcb8:f2fb:41373 - Local (:::0)
    at internalConnect (node:net:1041:16)
    at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
    at node:net:1134:9
    at processTicksAndRejections (node:internal/process/task_queues:78:11)
Emitted 'error' event on Socket instance at:
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -22,
  code: 'EINVAL',
  syscall: 'connect',
  address: 'fe80::fa9a:552c:fcb8:f2fb',
  port: 41373
}
```

* the tcp client now only connects to IPv4 addresses

* add comments to multiple peer tests and teardown

* put timeout on ci workflow, update lockfile

* merge and increase timeout

* add testing of multiple peers instanciated at - roughly - the same time

* cleanup

* Add DnsSd class, switch to bonjour-service

* Setup patch-package and update package-lock

* minor fix to test timing

* Update MdnsDiscovery and tests

* fix lint error

* cleanup and re-org some files

* private-ip -> bogon

* Make tests pass for now

* reduce peers in test to get test passing

---------

Co-authored-by: Gregor MacLennan <gmaclennan@digital-democracy.org>
Co-authored-by: tomasciccola <tomasciccola@users.noreply.github.com>
Co-authored-by: Tomás Ciccola <tciccola@digital-democracy.com>
  • Loading branch information
4 people committed Sep 19, 2023
1 parent 09d6ad0 commit ca3b6c7
Show file tree
Hide file tree
Showing 12 changed files with 1,872 additions and 3,685 deletions.
1 change: 1 addition & 0 deletions .github/workflows/node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
Expand Down
Loading

0 comments on commit ca3b6c7

Please sign in to comment.