Crate rustun [] [src]

Asynchronous implementation of STUN [RFC 5389] server and client.

Examples

A client-side example that issues a Binding request:

extern crate fibers;
extern crate rustun;

use fibers::{Executor, InPlaceExecutor, Spawn};
use rustun::{Method, Client};
use rustun::client::UdpClient;
use rustun::rfc5389;

fn main() {
    let server_addr = "127.0.0.1:3478".parse().unwrap();
    let mut executor = InPlaceExecutor::new().unwrap();

    let mut client = UdpClient::new(&executor.handle(), server_addr);
    let request = rfc5389::methods::Binding.request::<rfc5389::Attribute>();
    let future = client.call(request);

    let monitor = executor.spawn_monitor(future);
    match executor.run_fiber(monitor).unwrap() {
        Ok(v) => println!("OK: {:?}", v),
        Err(e) => println!("ERROR: {}", e),
    }
}

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: Ok(SuccessResponse {
           method: Binding,
           transaction_id: [246, 217, 191, 180, 118, 246, 250, 168, 86, 124, 126, 130],
           attributes: [XorMappedAddress(XorMappedAddress(V4(127.0.0.1:61991)))]
      })

Reexports

pub use client::Client;
pub use server::HandleMessage;
pub use method::Method;
pub use attribute::Attribute;
pub use transport::Transport;

Modules

attribute

STUN attribute related components.

client

STUN client related components.

constants

Constant values related to STUN.

message

STUN message related components.

method

Traits that are used to represent STUN method.

rfc5389

RFC 5389 specific components.

server

STUN server related components.

transport

STUN message transport layer.

types

Miscellaneous types.

Structs

Error

The error type for this crate.

Enums

ErrorKind

A list of error kind.

Type Definitions

Result

A specialized Result type for this crate.