turn-js icon indicating copy to clipboard operation
turn-js copied to clipboard

MOAR DOCS

Open 44203 opened this issue 8 years ago • 11 comments

Hey! Nice work! I'd love to incorporate TURN as a transport middleware for [kad](github.com/gordon writescode/kad). Any ideas when you might have some documentation to help?

For now I'll use the source!

44203 avatar Dec 24 '15 05:12 44203

Thx!

Sure, will add a README file later on this week.

nicojanssens avatar Dec 24 '15 09:12 nicojanssens

And how to use this stuff?

Globik avatar Mar 26 '16 16:03 Globik

@Globik The easiest way to get started is by checking out the example scripts -- you can find them in the examples dir. Both scripts setup relay connections between two sockets, and use these connections to exchange messages. One script exchanges these messages via STUN data packets, while the other example binds a TURN channel first to transmit data messages.

To test these example scripts, run node channel_data.js --addr=TURN_ADDR --port=TURN_PORT --user=TURN_USER --pwd=TURN_PWD or node channel_bind.js --addr=TURN_HOST --port=TURN_PORT --user=TURN_USER --pwd=TURN_PWD

If you're not running a TURN server yourself, you can create an account on the Numb STUN/TURN server and use these credentials when launching my example scripts.

nicojanssens avatar Mar 27 '16 20:03 nicojanssens

@globik also, feel free to use turn.counterpointhackers.org - no credentials required

44203 avatar Mar 27 '16 20:03 44203

@nicojanssens , you said that one script exchanges via STUN and another via TURN, which one is STUN and which is TURN ??

sendToChannel == STUN sendToRelay == TURN

???

ghost avatar Apr 22 '16 18:04 ghost

And where do we need mappedAddress ??

ghost avatar Apr 22 '16 18:04 ghost

@iMihael That was a typo. Both scripts establish TURN connections. (The TURN protocol uses STUN packets, that's probably where my lapsus originates from).

  • examples/channel_bind.js exchanges data over a negotiated TURN channel -- use sendToChannel() to transmit data over such a channel
  • examples/channel_data.js uses TURN data packets to relay packets between two endpoints -- you need to use sendToRelay to send these TURN data packets

nicojanssens avatar Apr 22 '16 18:04 nicojanssens

@iMihael The mappedAddress is not required to establish a bidirectional connection between two clients. It specifies a client's mapped public address -- which is the address of the NAT box a client is located behind.

nicojanssens avatar Apr 22 '16 18:04 nicojanssens

If it possible to use (establish) stun connection between two peers, will your lib use this variant to decrease turn server load ??

ghost avatar Apr 22 '16 19:04 ghost

@iMihael you mean a direct connection between two nodes located behind a NAT box? Nope, this lib does relaying only. It does not iterate over various connectivity strategies like WebRTC does using ICE -- first trying to connect two peers using their private addresses, then using their server reflexive address and finally establishing a relay connection if all other options failed.

It's on my todo list (I implemented a udp hole punching lib for that purpose, see https://github.com/nicojanssens/udp-hole-puncher-js) but I didn't find the time yet to complete this.

Btw, you may want to have a look at the kad-traverse module of @gordonwritescode. Gordon implemented a strategy like the one I explained above, such that TURN connections are only used if all other connection attempts have failed. GH repo: https://github.com/kadtools/kad-traverse

nicojanssens avatar Apr 22 '16 19:04 nicojanssens

Thank you for answer!

ghost avatar Apr 22 '16 19:04 ghost