nicojanssens / turn-js

TURN (Traversal Using Relay NAT) library written entirely in JavaScript
MIT License
30 stars 4 forks source link

Magic cookie field has incorrect value #7

Closed ghost closed 8 years ago

ghost commented 8 years ago

I'm trying to send file via turn server, and got this error:

/home/mihael/Projects/cloud-compute/node_modules/turn-js/node_modules/stun-js/src/packet.js:79 throw new Error(incorrectMagicCookieError) ^

Error: magic cookie field has incorrect value at Function.Packet.decode (/home/mihael/Projects/cloud-compute/node_modules/turn-js/node_modules/stun-js/src/packet.js:79:11) at TcpWrapper._onMessage (/home/mihael/Projects/cloud-compute/node_modules/turn-js/node_modules/stun-js/src/stun_comm.js:94:29) at Socket. (/home/mihael/Projects/cloud-compute/node_modules/stun-js/src/transports/tcp.js:24:10) at emitOne (events.js:77:13) at Socket.emit (events.js:169:7) at readableAddChunk (_stream_readable.js:146:16) at Socket.Readable.push (_stream_readable.js:110:10) at TCP.onread (net.js:523:20)

Can you help me with it ?

nicojanssens commented 8 years ago

Sure, will have a look at this asap. Thanks for reporting.

nicojanssens commented 8 years ago

@iMihael I did some more tests, and this may become a nasty issue. Some observations:

So far, I only managed to transfer a large file using UDP + with a turn server running locally -- i.e. on the same machine as where I run my client test scripts, so very low latency communication.

When I use UDP + one of my cloud turn servers, I only receive part of the file chunks that are transmitted. Need to check if coturn does some sort of rate control.

When I use TCP + larger chunk size (65535 bytes), then none of these file chunks get delivered -- turn server seems to discard them. Don't fragement flag was set to false.

When I use TCP + smaller chunk size, then some of the incoming chunk packets get concatenated causing the magic cookie error while parsing them.

So there seems to be more than one obstacle to transfer a file. Will need to dive deeper into this.

Anyway, good catch!

ghost commented 8 years ago

Thank you for replay.

nicojanssens commented 8 years ago

@iMihael I think most of the issues preventing file transfer are fixed. I added a file_transfer.js script to the examples dir that you can use to upload/download a file through your turn server.

node file_transfer.js --addr=<turn address> --port=<turn port> --user=<turn user> --pwd=<turn pwd> --file=<file to transfer>

Not sure anymore what turn server that you're using, but mind that coturn's congestion avoidance seems to drop messages when its queues are growing. So you may need a retransmission protocol to guarantee that all chunks of a file get transferred.