pub struct Client { /* private fields */ }Expand description
Client is a STUN client
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(config: ClientConfig) -> Result<Self>
pub fn new(config: ClientConfig) -> Result<Self>
new returns a new Client instance. listeningAddress is the address and port to listen on, default “0.0.0.0:0”
Sourcepub fn relay(&mut self, relayed_addr: SocketAddr) -> Result<Relay<'_>>
pub fn relay(&mut self, relayed_addr: SocketAddr) -> Result<Relay<'_>>
Borrows the allocation for relayed_addr so data can be sent or permissions created.
§Errors
Fails if this client has no allocation for that address — it was never allocated, or has already been closed.
Sourcepub fn send_binding_request_to(
&mut self,
to: SocketAddr,
) -> Result<TransactionId>
pub fn send_binding_request_to( &mut self, to: SocketAddr, ) -> Result<TransactionId>
send_binding_request_to sends a new STUN request to the given transport address return key to find out corresponding Event either BindingResponse or BindingRequestTimeout
Sourcepub fn send_binding_request(&mut self) -> Result<TransactionId>
pub fn send_binding_request(&mut self) -> Result<TransactionId>
send_binding_request sends a new STUN request to the STUN server return key to find out corresponding Event either BindingResponse or BindingRequestTimeout
Sourcepub fn update_credentials(&mut self, username: String, password: String)
pub fn update_credentials(&mut self, username: String, password: String)
Replaces the long-term credential used to sign subsequent requests, keeping any existing allocation.
A TURN allocation is a property of the 5-tuple, not of the credential that created
it: RFC 5766 §6.2 identifies an allocation by 5-tuple, and a server’s
Refresh handling looks it up the same way. So when credentials are rotated on the
same server there is no need to give up the allocation and re-Allocate — which
would in fact be rejected with 437 (Allocation Mismatch), since the server still
holds the previous allocation for that 5-tuple. Re-signing the existing allocation is
both correct and seamless: permissions and channel bindings survive.
The realm is not re-negotiated. It was learned from the server’s 401 during the
first Allocate, and a credential rotation keeps the same server, so it still
applies. Follow this with [Relay::refresh] so the server sees the new credential
before the allocation would otherwise expire.
Sourcepub fn refresh_allocations(&mut self) -> Result<()>
pub fn refresh_allocations(&mut self) -> Result<()>
Refreshes every live allocation, re-signing each with the current credential.
Each allocation is refreshed with its own current lifetime, so this extends rather
than changes it. Intended to follow update_credentials.
Sourcepub fn allocate(&mut self) -> Result<TransactionId>
pub fn allocate(&mut self) -> Result<TransactionId>
Allocate sends a TURN allocation request to the given transport address