holepunchto / hyperswarm-secret-stream

Secret stream backed by Noise and libsodium's secretstream
Apache License 2.0
33 stars 14 forks source link

Invalid header received #5

Closed LuKks closed 2 years ago

LuKks commented 2 years ago
/self/like-p2p/node_modules/@hyperswarm/secret-stream/index.js:212
          this.destroy(new Error('Invalid header received'))
                       ^

Error: Invalid header received
    at NoiseSecretStream._incoming (/self/like-p2p/node_modules/@hyperswarm/secret-stream/index.js:212:24)
    at NoiseSecretStream._onrawdata (/self/like-p2p/node_modules/@hyperswarm/secret-stream/index.js:148:18)
    at Connection.emit (events.js:400:28)
    at addChunk (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:298:12)
    at readableAddChunk (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:280:11)
    at Connection.Readable.push (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:241:10)
    at Connection._onread (/self/like-p2p/node_modules/utp-native/lib/connection.js:143:8)
Emitted 'error' event on NoiseSecretStream instance at:
    at WritableState.afterDestroy (/self/like-p2p/node_modules/streamx/index.js:442:19)
    at NoiseSecretStream._destroy (/self/like-p2p/node_modules/@hyperswarm/secret-stream/index.js:367:5)
    at WritableState.updateNonPrimary (/self/like-p2p/node_modules/streamx/index.js:189:16)
    at WritableState.update (/self/like-p2p/node_modules/streamx/index.js:174:70)
    at WritableState.updateWriteNT (/self/like-p2p/node_modules/streamx/index.js:482:8)
    at processTicksAndRejections (internal/process/task_queues.js:77:11)

server.js

const UTP = require('utp-native')
const SecretStream = require('@hyperswarm/secret-stream')

const utp = UTP()

utp.on('connection', (rawStream) => {
  console.log('utp connection', rawStream.remoteAddress, rawStream.remotePort)
  const secret = new SecretStream(false, rawStream)
})

utp.listen(3000)

client.js

const UTP = require('utp-native')
const SecretStream = require('@hyperswarm/secret-stream')

const utp = UTP()

const rawStream = utp.connect(3000, '157.245.89.145')
const secret = new SecretStream(true, rawStream)

DigitalOcean as server and my computer as client doesn't work. Am I missing something?

Running all in localhost works. DigitalOcean as server and another DO as client also works.

I created a new DigitalOcean server and used my same computer and it's working, so maybe it's probably something related to the previous specific server.

Because it's difficult to reproduce I can give those logs:

utp-client-utp.on("listening", ...)
utp-client-rawStream.on("connect", ...)

utp-client-rawStream.on("data", ...) <Buffer 60 00 00 af 5d bb c0 87 7e bd fa 83 a8 ea b4 f7 f9 d0 68 ba f6 27 1b 61 74 3e a0 ec 9e 94 94 ae 9c e8 34 c3 8b d8 c4 be 1d d3 30 fc 59 2e 32 dd 10 dd ... 49 more bytes>
utp-client-secret.on("connect", ...)
utp-client-connect d9daff0428755d1e16248d657dde70a0f9b4f8e98b7e480e56c598403f5c30eb
utp-client-secret.on("open", ...)
utp-client-rawStream.on("data", ...) <Buffer 38 00 00 eb 60 89 b4 5a 42 85 08 bf bf 50 c7 91 26 c8 a7 02 67 c7 57 1b 95 d9 87 0f 3d da b3 d9 bb a2 dd 4c 51 6f e2 a9 a2 b8 51 92 99 1b 41 8b 2f 98 ... 9 more bytes>
utp-client-secret.on("error", ...) Error: Invalid header received
    at NoiseSecretStream._incoming (/self/like-p2p/node_modules/@hyperswarm/secret-stream/index.js:212:24)
    at NoiseSecretStream._onrawdata (/self/like-p2p/node_modules/@hyperswarm/secret-stream/index.js:148:18)
    at Connection.emit (events.js:412:35)
    at addChunk (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:298:12)
    at readableAddChunk (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:280:11)
    at Connection.Readable.push (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:241:10)
    at Connection._onread (/self/like-p2p/node_modules/utp-native/lib/connection.js:143:8)
utp-client-secret.on("close", ...)
utp-client-close d9daff0428755d1e16248d657dde70a0f9b4f8e98b7e480e56c598403f5c30eb

utp-client-rawStream.on("error", ...) Error: Invalid header received
    at NoiseSecretStream._incoming (/self/like-p2p/node_modules/@hyperswarm/secret-stream/index.js:212:24)
    at NoiseSecretStream._onrawdata (/self/like-p2p/node_modules/@hyperswarm/secret-stream/index.js:148:18)
    at Connection.emit (events.js:412:35)
    at addChunk (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:298:12)
    at readableAddChunk (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:280:11)
    at Connection.Readable.push (/self/like-p2p/node_modules/readable-stream/lib/_stream_readable.js:241:10)
    at Connection._onread (/self/like-p2p/node_modules/utp-native/lib/connection.js:143:8)
utp-client-rawStream.on("close", ...)

At least this shows that the handshake is happening before the final error.

In case you have any hints, I can test them in the current state (the specific DO server and my computer). I think I will try to replicate the issue in a new server but at the moment I couldn't.

In the specific DO server I had just one folder "like-p2p" which is a git repository, I was deleting .git/ and some other non related files, so only the related files remain and I can give you access. Now I can't reproduce it anymore.

Sorry if this is confusing, at least you can check the logs in case something makes sense. Feel free to close the issue.

LuKks commented 2 years ago

I think I was using different minor versions of secret-stream.

LuKks commented 2 years ago

Yep.

server using latest

mkdir secret-server
npm init -y
npm i utp-native @hyperswarm/secret-stream
nano server.js
const UTP = require('utp-native')
const SecretStream = require('@hyperswarm/secret-stream')

const utp = UTP()

utp.on('connection', (rawStream) => {
  console.log('utp connection', rawStream.remoteAddress, rawStream.remotePort)
  const secret = new SecretStream(false, rawStream)
})

utp.listen(3000)

client using 5.0.0

mkdir secret-client
npm init -y
npm i utp-native @hyperswarm/secret-stream@5.0.0
nano client.js
const UTP = require('utp-native')
const SecretStream = require('@hyperswarm/secret-stream')

const utp = UTP()

const rawStream = utp.connect(3000, '127.0.0.1')
const secret = new SecretStream(true, rawStream)

Later just run:

node secret-server/server.js
node secret-client/client.js

Is this intended?

mafintosh commented 2 years ago

Yep, that was a recent bug fix, always use the latest versions in general as we stabilise.