rustun
A Rust library for implementing STUN server and client asynchronously.
The STUN protocol is defined in RFC 5389.
Examples
An example that issues a BINDING
request:
use UdpTransporter;
use Future;
use Channel;
use Client;
use Request;
use ;
use StunUdpTransporter;
use Error;
use ;
let addr = "127.0.0.1:0".parse.unwrap;
// Starts UDP server
let server = execute?;
let server_addr = server.local_addr;
spawn;
// Sents BINDING request
let response = bind
.map_err
.map
.map
.and_then;
// Waits BINDING response
let response = execute?;
assert!;
You can run example server and client which handle Binding
method as follows:
// Starts the STUN server in a shell.
$ cargo run --example binding_srv
// Executes a STUN client in another shell.
$ cargo run --example binding_cli -- 127.0.0.1
Ok(SuccessResponse(Message {
class: SuccessResponse,
method: Method(1),
transaction_id: TransactionId(0x344A403694972F5E53B69465),
attributes: [Known { inner: XorMappedAddress(XorMappedAddress(V4(127.0.0.1:54754))),
padding: Some(Padding([])) }]
}))