Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement MdnsDiscovery (#177)
* 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