#candidate #ice #web-rtc #nat #extension #parser

candidateparser

A parser for the ICE Candidate SDP according to RFC5245

3 unstable releases

Uses old Rust 2015

0.2.0 Sep 25, 2017
0.1.1 Sep 22, 2017
0.1.0 Sep 22, 2017

#8 in #candidate

MIT/Apache

23KB
576 lines

candidateparser

CircleCI Crates.io Version Crates.io Downloads Rust

This is a parser for the ICE Candidate SDP, which is used for connectivity establishment and NAT traversal in communication systems like WebRTC. Bindings for C and Android (through JNI) are provided. Building a universal library for iOS is also possible.

Example candidate SDP:

candidate:842163049 1 udp 1686052607 1.2.3.4 46154 typ srflx raddr 10.0.0.17 rport 46154 generation 0 ufrag EEtu network-id 3 network-cost 10

It will parse the data into a struct with all components. The example above will result in the following object:

IceCandidate {
    foundation: "842163049",
    component_id: 1,
    transport: Udp,
    priority: 1686052607,
    connection_address: V4(1.2.3.4),
    port: 46154,
    candidate_type: Srflx,
    rel_addr: Some(V4(10.0.0.17)),
    rel_port: Some(46154),
    extensions: Some({
        [110, 101, 116, 119, 111, 114, 107, 45, 99, 111, 115, 116]: [49, 48],
        [103, 101, 110, 101, 114, 97, 116, 105, 111, 110]: [48],
        [117, 102, 114, 97, 103]: [69, 69, 116, 117],
        [110, 101, 116, 119, 111, 114, 107, 45, 105, 100]: [51]
    })
}

For more information, see RFC5245 (Interactive Connectivity Establishment (ICE)).

Crate docs: https://docs.rs/candidateparser/

Note: Due to build system issues, Rust 1.21+ is required.

FFI (C/C++17)

This library includes C and C++17 bindings, so you can use it from any language that supports the C calling convention. Example programs in C and C++17 can be found in the candidateparser-ffi/examples/ directory.

JNI bindings (Java / Android)

This library also contains JNI bindings, written with jni-rs. An Android library with a simple test is provided in the candidateparser-android directory.

Make sure to build the candidateparser-jni crate before building the Android library.

Building candidateparser-jni for Android

Requirements:

  • Android NDK
  • Rustup
  • Make

Add rustup targets:

$ rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android

Build standalone toolchains:

$ ./create-ndk-standalone.sh

Add toolchain config to your ~/.cargo/config:

$ cat cargo-config.toml >> ~/.cargo/config

Build Android libraries:

$ make android

Building the candidateparser-android library for Android

Build the library using gradle:

$ ./gradlew build

You will find the AAR file in the app/build/outputs/aar/ directory.

Linting

To run clippy lints, compile the library with --features clippy on a nightly compiler:

$ cargo build --features clippy

Note: Running this command from the workspace root won't work, you have to cd into the sub-crates!

Universal iOS library

If you want to build a universal iOS library, install cargo-lipo. Then, delete the Cargo.toml file in the root (cargo-lipo cannot deal with workspaces currently).

$ rm Cargo.toml

Finally, build the library:

$ make ios

Note that this only works on macOS at the moment.

License

Licensed under either of

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


lib.rs:

ICE Candidate parser following RFC5245.

The main entry point for this library is the parse function. See the docs of that function for more information.

Dependencies

~1.2–2.4MB
~50K SLoC