All Projects → processone → Stun

processone / Stun

Licence: apache-2.0
STUN and TURN library for Erlang / Elixir

Programming Languages

erlang
1774 projects

Labels

Projects that are alternatives of or similar to Stun

kvazzup
Open software for HEVC video calls
Stars: ✭ 30 (-84.37%)
Mutual labels:  ice
Webrtc
A pure Rust implementation of WebRTC API
Stars: ✭ 922 (+380.21%)
Mutual labels:  ice
Vue Materials
🎯High quality Vue materials maintained by the community.
Stars: ✭ 128 (-33.33%)
Mutual labels:  ice
Ice
AWS Usage Tool
Stars: ✭ 2,784 (+1350%)
Mutual labels:  ice
Re
Generic library for real-time communications with async IO support
Stars: ✭ 444 (+131.25%)
Mutual labels:  ice
Ice
WIP RFC 8445 ICE implementation in go
Stars: ✭ 95 (-50.52%)
Mutual labels:  ice
libjuice
JUICE is a UDP Interactive Connectivity Establishment library
Stars: ✭ 197 (+2.6%)
Mutual labels:  ice
Stun
A Go implementation of STUN
Stars: ✭ 141 (-26.56%)
Mutual labels:  ice
Sipsorcery
A WebRTC, SIP and VoIP library for C# and .NET Core. Designed for real-time communications apps.
Stars: ✭ 449 (+133.85%)
Mutual labels:  ice
Webrtc Data Channel Demo
WebRTC Data Channel demo
Stars: ✭ 116 (-39.58%)
Mutual labels:  ice
Ice Demos
Sample programs for Ice
Stars: ✭ 285 (+48.44%)
Mutual labels:  ice
Iceworks
Visual Intelligent Development Pack(可视化智能开发套件)
Stars: ✭ 390 (+103.13%)
Mutual labels:  ice
Mongooseice
STUN/TURN server written in Elixir
Stars: ✭ 103 (-46.35%)
Mutual labels:  ice
hoice
An ICE-based predicate synthesizer for Horn clauses.
Stars: ✭ 41 (-78.65%)
Mutual labels:  ice
Ice
Comprehensive RPC framework with support for C++, C#, Java, JavaScript, Python and more.
Stars: ✭ 1,772 (+822.92%)
Mutual labels:  ice
werift-webrtc
WebRTC Implementation for TypeScript (Node.js), includes ICE/DTLS/SCTP/RTP/SRTP
Stars: ✭ 228 (+18.75%)
Mutual labels:  ice
Icememe
Roblox Exploit Source Code Called IceMeme with some cmds, lua c and limited lua execution with simple ui in c#
Stars: ✭ 42 (-78.12%)
Mutual labels:  ice
React Materials
Migrate to: https://github.com/alibaba-fusion/materials
Stars: ✭ 189 (-1.56%)
Mutual labels:  ice
Pastcode
Stars: ✭ 135 (-29.69%)
Mutual labels:  ice
Ice
A Go implementation of ICE
Stars: ✭ 114 (-40.62%)
Mutual labels:  ice

STUN

Build Status Coverage Status Hex version

STUN and TURN library for Erlang / Elixir.

Both STUN (Session Traversal Utilities for NAT) and TURN standards are used as technics to establish media connection between peers for VoIP (for example using SIP or Jingle) and WebRTC.

They are part of a more general negotiation technique know as ICE (Interactive Connectivity Establishment).

To summarize:

  • A STUN server is used to get an external network address. It does not serve as a relay for the media traffic.
  • TURN servers are used to relay traffic if direct (peer to peer) connection fails.

Build

This is a pure Erlang implementation, so you do not need to have specific C libraries installed for the STUN, TURN, ICE code.

However, this code depends on ProcessOne Fast TLS, which depends on OpenSSL 1.0.0+ library.

Generic build

You can trigger build with:

make

Usage

The following sequence describe a STUN establishment.

First, start the application and stun listener at 127.0.0.1:

1> application:start(stun).
ok
2> stun_listener:add_listener({127, 0, 0, 1}, 3478, udp, []).
ok

Then, you can form and send a BindRequest:

3> rr(stun).
[state,stun,turn]
4> random:seed(erlang:timestamp()).
undefined

You can form a transaction id. Should be always 96 bit:

5> TrID = random:uniform(1 bsl 96).
41809861624941132369239212033

You then create a BindRequest message.

16#001 is ?STUN_METHOD_BINDING, defined in include/stun.hrl

6> Msg = #stun{method = 16#001, class = request, trid = TrID}.
#stun{class = request,method = 1,magic = 554869826,
     trid = 41809861624941132369239212033,raw = <<>>,
     unsupported = [],'ALTERNATE-SERVER' = undefined,
     'CHANNEL-NUMBER' = undefined,'DATA' = undefined,
     'DONT-FRAGMENT' = false,'ERROR-CODE' = undefined,
     'LIFETIME' = undefined,'MAPPED-ADDRESS' = undefined,
     'MESSAGE-INTEGRITY' = undefined,'NONCE' = undefined,
     'REALM' = undefined,'REQUESTED-TRANSPORT' = undefined,
     'SOFTWARE' = undefined,'UNKNOWN-ATTRIBUTES' = [],
     'USERNAME' = undefined,'XOR-MAPPED-ADDRESS' = undefined,
     'XOR-PEER-ADDRESS' = [],'XOR-RELAYED-ADDRESS' = undefined}

You can then establish connection to running server:

7> {ok, Socket} = gen_udp:open(0, [binary, {ip,
7> {127,0,0,1}},{active,false}]).
{ok,#Port<0.1020>}
8> {ok, Addr} = inet:sockname(Socket).
{ok,{{127,0,0,1},41906}}

The following call is for encoding BindRequest:

9> PktOut = stun_codec:encode(Msg).
<<0,1,0,0,33,18,164,66,135,24,78,148,65,4,128,0,0,0,0,1>>

The BindRequest can then be send:

10> gen_udp:send(Socket, {127,0,0,1}, 3478, PktOut).
ok

The follow code receives the BindResponse:

11> {ok, {_, _, PktIn}} = gen_udp:recv(Socket, 0).
{ok,{{127,0,0,1},
    3478,
    <<1,1,0,32,33,18,164,66,135,24,78,148,65,4,128,0,0,0,0,
      1,128,34,0,15,...>>}}

You can then decode the BindResponse:

12> {ok, Response} = stun_codec:decode(PktIn, datagram).
{ok,#stun{class = response,method = 1,magic = 554869826,
         trid = 41809861624941132369239212033,raw = <<>>,
         unsupported = [],'ALTERNATE-SERVER' = undefined,
         'CHANNEL-NUMBER' = undefined,'DATA' = undefined,
         'DONT-FRAGMENT' = false,'ERROR-CODE' = undefined,
         'LIFETIME' = undefined,'MAPPED-ADDRESS' = undefined,
         'MESSAGE-INTEGRITY' = undefined,'NONCE' = undefined,
         'REALM' = undefined,'REQUESTED-TRANSPORT' = undefined,
         'SOFTWARE' = <<"P1 STUN library">>,
         'UNKNOWN-ATTRIBUTES' = [],'USERNAME' = undefined,
         'XOR-MAPPED-ADDRESS' = {{127,0,0,1},41906},
         'XOR-PEER-ADDRESS' = [],'XOR-RELAYED-ADDRESS' = undefined}}

Finally, checking 'XOR-MAPPED-ADDRESS' attribute, should be equal to locally binded address:

13> Addr == Response#stun.'XOR-MAPPED-ADDRESS'.
true

Development

Test

Unit test

You can run eunit test with the command:

make test

References

You can refer to IETF specifications to learn more:

  • RFC 5389: Session Traversal Utilities for NAT (STUN).
  • RFC 5766: Traversal Using Relays around NAT (TURN): Relay Extensions to STUN.
  • RFC 5245: Interactive Connectivity Establishment (ICE): A Protocol for NAT Traversal for Offer/Answer Protocols.
  • RFC 6544: TCP Candidates with Interactive Connectivity Establishment (ICE)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].