Message

Struct Message 

Source
pub struct Message<'a> { /* private fields */ }

Implementations§

Source§

impl<'a> Message<'a>

Source

pub fn method(&self) -> Method

message method.

Source

pub fn transaction_id(&self) -> &'a [u8]

message transaction id.

Source

pub fn get<T: Attribute<'a>>(&self) -> Option<T::Item>

get attribute.

get attribute from message attribute list.

§Test
use std::convert::TryFrom;
use turn_server::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;

let buffer = [
    0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
    0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];

let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();

assert!(message.get::<UserName>().is_none());
Source

pub fn get_for_type(&self, attr_type: AttributeType) -> Option<&'a [u8]>

get attribute for type.

get attribute from message attribute list.

§Test
use std::convert::TryFrom;
use turn_server::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;

let buffer = [
    0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
    0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];

let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();

assert!(message.get_for_type(AttributeType::UserName).is_none());
Source

pub fn get_all<T: Attribute<'a>>(&self) -> impl Iterator<Item = T::Item>

Gets all the values of an attribute from a list.

Normally a stun message can have multiple attributes with the same name, and this function will all the values of the current attribute.

§Test
use std::convert::TryFrom;
use turn_server::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;

let buffer = [
    0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
    0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];

let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();

assert_eq!(message.get_all::<UserName>().next(), None);
Source

pub fn verify(&self, password: &Password) -> Result<(), Error>

check MessageRefIntegrity attribute.

return whether the MessageRefIntegrity attribute contained in the message can pass the check.

§Test
use std::convert::TryFrom;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;

let buffer = [
    0x00u8, 0x03, 0x00, 0x50, 0x21, 0x12, 0xa4, 0x42, 0x64, 0x4f, 0x5a,
    0x78, 0x6a, 0x56, 0x33, 0x62, 0x4b, 0x52, 0x33, 0x31, 0x00, 0x19, 0x00,
    0x04, 0x11, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x05, 0x70, 0x61, 0x6e,
    0x64, 0x61, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x09, 0x72, 0x61, 0x73,
    0x70, 0x62, 0x65, 0x72, 0x72, 0x79, 0x00, 0x00, 0x00, 0x00, 0x15, 0x00,
    0x10, 0x31, 0x63, 0x31, 0x33, 0x64, 0x32, 0x62, 0x32, 0x34, 0x35, 0x62,
    0x33, 0x61, 0x37, 0x33, 0x34, 0x00, 0x08, 0x00, 0x14, 0xd6, 0x78, 0x26,
    0x99, 0x0e, 0x15, 0x56, 0x15, 0xe5, 0xf4, 0x24, 0x74, 0xe2, 0x3c, 0x26,
    0xc5, 0xb1, 0x03, 0xb2, 0x6d,
];

let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();
let result = message
    .verify(&turn_server::codec::crypto::generate_password(
        "panda",
        "panda",
        "raspberry",
        turn_server::codec::message::attributes::PasswordAlgorithm::Md5,
    ))
    .is_ok();

assert!(result);
Source

pub fn decode( bytes: &'a [u8], attributes: &'a mut Attributes, ) -> Result<Self, Error>

§Test
use std::convert::TryFrom;
use turn_server::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;

let buffer: [u8; 20] = [
    0x00, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49, 0x42,
    0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];

let mut attributes = Attributes::default();
let message = Message::decode(&buffer[..], &mut attributes).unwrap();

assert_eq!(
    message.method(),
    Method::Binding(MethodType::Request)
);

assert!(message.get::<UserName>().is_none());
Source

pub fn message_size(buffer: &[u8]) -> Result<usize, Error>

§Test
use turn_server::codec::message::*;

let buffer: [u8; 20] = [
    0x00, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49, 0x42,
    0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];

let size = Message::message_size(&buffer[..]).unwrap();

assert_eq!(size, 20);

Auto Trait Implementations§

§

impl<'a> Freeze for Message<'a>

§

impl<'a> RefUnwindSafe for Message<'a>

§

impl<'a> Send for Message<'a>

§

impl<'a> Sync for Message<'a>

§

impl<'a> Unpin for Message<'a>

§

impl<'a> UnwindSafe for Message<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,