Skip to main content

Message

Struct Message 

Source
pub struct Message { /* private fields */ }
Expand description

A STUN message: the header, the attributes, and — once decoded — what the two integrity values said.

Implementations§

Source§

impl Message

Source

pub const fn new(class: Class, transaction: TransactionId) -> Self

An empty Binding message of this class.

Source

pub fn with(self, attribute: Attribute) -> Self

Append an attribute.

Order is preserved, and only two attributes have a normative position: the two Message::encode appends itself.

Source

pub const fn class(&self) -> Class

The message class.

Source

pub const fn transaction(&self) -> TransactionId

The transaction this message belongs to.

Source

pub fn attributes(&self) -> &[Attribute]

The attributes, in the order they appeared.

Source

pub fn encode(&self, key: Option<&str>) -> Result<Vec<u8>, Error>

Encode, appending MESSAGE-INTEGRITY keyed with key when there is one, and then FINGERPRINT, in that order and always last (RFC 5389 §15.4, §15.5).

key is None only for RFC 8445 §11’s keepalive, which “MUST NOT utilize any authentication mechanism”. FINGERPRINT is not optional: spec §11.1 puts it on every check, every response and every keepalive, and it is what lets the far end tell a check from RTP on the one port they share.

Source

pub fn decode(datagram: &[u8]) -> Result<Self, Error>

Read a datagram the media port’s demultiplexer called STUN (RFC 5764 §5.1.2, crate::dtls::classify).

Nothing here trusts the datagram. A FINGERPRINT that does not match is an error, per RFC 5389 §15.5, because a message whose CRC is wrong is not addressed to us however well formed it is; a MESSAGE-INTEGRITY cannot be checked yet, because which key applies depends on the USERNAME this message carries — see Message::verify_integrity.

Source

pub fn verify_integrity(&self, key: &str) -> bool

Whether this message’s MESSAGE-INTEGRITY was computed with key.

false when there is none at all: an unauthenticated check is not a check that happens to verify, and spec §11.3 requires that it move no state.

Which key to pass is the direction rule — Peering::inbound_key for a check that arrived, Peering::outbound_key for the response to one sipx sent.

Source

pub const fn has_integrity(&self) -> bool

Whether a MESSAGE-INTEGRITY was present at all.

Source

pub const fn has_fingerprint(&self) -> bool

Whether a FINGERPRINT was present. If it was, it matched — Message::decode rejects one that does not.

Source

pub fn username(&self) -> Option<&str>

The USERNAME, if there is one.

Source

pub fn priority(&self) -> Option<Priority>

The PRIORITY a check claims for the candidate the peer would learn from it (§7.1.1).

Source

pub fn use_candidate(&self) -> bool

Whether USE-CANDIDATE is set (§7.1.2).

Source

pub fn role(&self) -> Option<RoleAttribute>

The role attribute and its tiebreaker, if the peer sent one (§7.1.3).

A peer that sends neither is not doing role signalling, which spec §7.3’s last row says is not a conflict. nominate reports USE-CANDIDATE alongside ICE-CONTROLLING; a controlled peer that sets it anyway is violating §7.1.2, and the caller sees that as a Controlled role with Message::use_candidate true.

Source

pub fn error_code(&self) -> Option<u16>

The ERROR-CODE, if this is an error response. 487 is the role conflict of §7.3.1.1.

Source

pub fn mapped_address(&self) -> Option<SocketAddr>

The XOR-MAPPED-ADDRESS, unobfuscated.

Trait Implementations§

Source§

impl Clone for Message

Source§

fn clone(&self) -> Message

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Message

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Message

Source§

fn eq(&self, other: &Message) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Message

Source§

impl StructuralPartialEq for Message

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,