holepunchto / hyperswarm-dht-relay

Relaying the Hyperswarm DHT over other transport protocols to bring decentralized networking to everyone
ISC License
44 stars 10 forks source link

noiseStream.setKeepAlive is not a function with (Hypercore@^10.0.0-alpha.26) #11

Closed Nuhvi closed 2 years ago

Nuhvi commented 2 years ago

Replicating Hypercore over a websocket relay (node or browser) fails in the case of using hypercore@^10.0.0-alpha.26 probably because the new protomux?:

(node:83045) UnhandledPromiseRejectionWarning: TypeError: noiseStream.setKeepAlive is not a function
    at Function.createProtocolStream (/media/ward/two/code/play/test-dht-relay-replicate/node_modules/hypercore/index.js:125:21)
    at Hypercore.replicate (/media/ward/two/code/play/test-dht-relay-replicate/node_modules/hypercore/index.js:324:38)
    at Hyperswarm.<anonymous> (/media/ward/two/code/play/test-dht-relay-replicate/replicate.js:35:10)
    at Hyperswarm.emit (events.js:315:20)
    at Stream.<anonymous> (/media/ward/two/code/play/test-dht-relay-replicate/node_modules/hyperswarm/index.js:158:12)
    at Stream.emit (events.js:327:22)
    at ReadableState.afterOpen (/media/ward/two/code/play/test-dht-relay-replicate/node_modules/streamx/index.js:495:12)
    at Stream._open (/media/ward/two/code/play/test-dht-relay-replicate/node_modules/@hyperswarm/dht-relay/lib/stream.js:44:7)
    at Stream._continueOpen (/media/ward/two/code/play/test-dht-relay-replicate/node_modules/@hyperswarm/dht-relay/lib/stream.js:56:17)
    at Stream.onOpen (/media/ward/two/code/play/test-dht-relay-replicate/node_modules/@hyperswarm/dht-relay/lib/stream.js:118:8)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:83045) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:83045) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I made sure to test up to the latest working version hypercore@10.0.0-alpha.25 and it seems to work even with the latest versions of this package: https://github.com/Nazeh/test-hypercore-dht-relay/commit/2c9823b002ce399bca17ae6f8becd308b2f5e82a

packages used:

  "@hyperswarm/dht": "^5.0.17",
    "@hyperswarm/dht-relay": "^0.2.1",
    "b4a": "^1.3.1",
    "hypercore": "10.0.0-alpha.25",
    "isomorphic-ws": "^4.0.1",
    "random-access-memory": "^4.0.0"

Notice, Hyperswarm will throw an error in browser because of Buffer.equals, so you will have to manually change it in node_modules to use b4a

mafintosh commented 2 years ago

Did you update your deps? That method is in the latest minor bump of secret-stream which this module tracks.

mafintosh commented 2 years ago

Is there a pr we are missing for the Buffer.equals?

Nuhvi commented 2 years ago

@mafintosh

Is there a pr we are missing for the Buffer.equals?

I meant this https://github.com/hyperswarm/hyperswarm/pull/98

to solve these:

https://github.com/hyperswarm/hyperswarm/blob/master/index.js#L181 https://github.com/hyperswarm/hyperswarm/blob/master/index.js#L231

Nuhvi commented 2 years ago

Did you update your deps? That method is in the latest minor bump of secret-stream which this module tracks.

I made sure to update everything, but the moment I go higher than hypercore@10.0.0-alpha.25 I get the same error.

latest test, just now:

  "dependencies": {
    "@hyperswarm/dht": "^5.0.17",
    "@hyperswarm/dht-relay": "^0.2.1",
    "b4a": "^1.3.1",
    "hypercore": "^10.0.0-alpha.28",
    "isomorphic-ws": "^4.0.1",
    "random-access-memory": "^4.0.0"
  }
kasperisager commented 2 years ago

The relay is currently missing the changes introduced in https://github.com/hyperswarm/secret-stream/pull/10 and https://github.com/hyperswarm/secret-stream/pull/11. I'll add them ASAP.

mafintosh commented 2 years ago

Ah sorry, my bad

kasperisager commented 2 years ago

No worries! Fixed in e1b2440b3bbf8f53cacfd3f13d0e044f7abf6db4. I'm wondering if it would make sense to abstract common stream functionality like timeout and keep alive to avoid having to duplicate it for the relayed streams?

mafintosh commented 2 years ago

Yea totally, forgot we were "mirroring" it here.