https://github.com/sile/stun_codec
Decoders and encoders for STUN (RFC 5389) and its extensions
https://github.com/sile/stun_codec
rust stun turn
Last synced: about 1 year ago
JSON representation
Decoders and encoders for STUN (RFC 5389) and its extensions
- Host: GitHub
- URL: https://github.com/sile/stun_codec
- Owner: sile
- License: mit
- Created: 2018-08-30T10:05:44.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-04-03T09:57:44.000Z (about 2 years ago)
- Last Synced: 2025-03-24T11:54:52.494Z (about 1 year ago)
- Topics: rust, stun, turn
- Language: Rust
- Homepage:
- Size: 180 KB
- Stars: 29
- Watchers: 5
- Forks: 17
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
stun_codec
===========
[](https://crates.io/crates/stun_codec)
[](https://docs.rs/stun_codec)
[](https://github.com/sile/stun_codec/actions)
[](https://coveralls.io/github/sile/stun_codec?branch=master)
[](LICENSE)
Encoders and decoders for [STUN (RFC 5389)][RFC 5389] and its extensions.
[Documentation](https://docs.rs/stun_codec)
Examples
--------
```rust
use bytecodec::{DecodeExt, EncodeExt, Error};
use stun_codec::{Message, MessageClass, MessageDecoder, MessageEncoder, TransactionId};
use stun_codec::rfc5389::{attributes::Software, methods::BINDING, Attribute};
// Creates a message
let mut message = Message::new(MessageClass::Request, BINDING, TransactionId::new([3; 12]));
message.add_attribute(Attribute::Software(Software::new("foo".to_owned())?));
// Encodes the message
let mut encoder = MessageEncoder::new();
let bytes = encoder.encode_into_bytes(message.clone())?;
assert_eq!(
bytes,
[
0, 1, 0, 8, 33, 18, 164, 66, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 128, 34, 0, 3,
102, 111, 111, 0
]
);
// Decodes the message
let mut decoder = MessageDecoder::::new();
let decoded = decoder.decode_from_bytes(&bytes)?.map_err(Error::from)?;
assert_eq!(decoded.class(), message.class());
assert_eq!(decoded.method(), message.method());
assert_eq!(decoded.transaction_id(), message.transaction_id());
assert!(decoded.attributes().eq(message.attributes()));
```
References
----------
- [RFC 5245 - Interactive Connectivity Establishment (ICE)][RFC 5245]
- [RFC 5389 - Session Traversal Utilities for NAT (STUN)][RFC 5389]
- [RFC 5769 - Test Vectors for Session Traversal Utilities for NAT (STUN)][RFC 5769]
- [RFC 5780 - NAT Behavior Discovery Using Session Traversal Utilities for NAT][RFC 5780]
- [RFC 8016 - Mobility with Traversal Using Relays around NAT (TURN)][RFC 8016]
- [RFC 8656 - Traversal Using Relays around NAT (TURN): Relay Extensions to Session Traversal Utilities for NAT (STUN)][RFC 8656]
[RFC 5245]: https://tools.ietf.org/html/rfc5245
[RFC 5389]: https://tools.ietf.org/html/rfc5389
[RFC 5769]: https://tools.ietf.org/html/rfc5769
[RFC 5780]: https://tools.ietf.org/html/rfc5780
[RFC 8016]: https://tools.ietf.org/html/rfc8016
[RFC 8656]: https://tools.ietf.org/html/rfc8656