A Rust library for implementing STUN server and client asynchronously.
The STUN protocol is defined in RFC 5389.
An example that issues a BINDING
request:
```rust use futures::Future; use rustun::channel::Channel; use rustun::client::Client; use rustun::message::Request; use rustun::server::{BindingHandler, UdpServer}; use rustun::transport::{RetransmitTransporter, UdpTransporter, StunUdpTransporter}; use stun_codec::rfc5389;
let serveraddr = "127.0.0.1:3478".parse().unwrap(); let clientaddr = "127.0.0.1:0".parse().unwrap();
// Starts UDP server let server = UdpServer::start(fibersglobal::handle(), serveraddr, BindingHandler); fibersglobal::spawn(server.map(|| ()).map_err(|e| panic!("{}", e)));
// Sents BINDING request
let response = UdpTransporter::bind(clientaddr)
.map(RetransmitTransporter::new)
.map(Channel::new)
.andthen(move |channel: Channel<_, StunUdpTransporter<_>>| {
let client = Client::new(&fibersglobal::handle(), channel);
let request = Request::
// Waits BINDING response let response = fibersglobal::execute(response)?; assert!(response.isok()); ```
You can run example server and client which handle Binding
method as follows:
```console // Starts the STUN server in a shell. $ cargo run --example binding_srv
// Executes a STUN client in another shell. $ cargo run --example bindingcli -- 127.0.0.1 Ok(SuccessResponse(Message { class: SuccessResponse, method: Method(1), transactionid: TransactionId(0x344A403694972F5E53B69465), attributes: [Known { inner: XorMappedAddress(XorMappedAddress(V4(127.0.0.1:54754))), padding: Some(Padding([])) }] })) ```