webrtc-rs / webrtc

A pure Rust implementation of WebRTC
https://webrtc.rs
Apache License 2.0
4.08k stars 363 forks source link

If TURN bind request fails with "Stale nonce", retry with refreshed nonce #543

Open marcbrevoort-cyberhive opened 7 months ago

marcbrevoort-cyberhive commented 7 months ago

If a channel bind (refresh) fails with a stale nonce error, the nonce should be refreshed and the attempt should be retried.

This seeks to fix https://github.com/webrtc-rs/webrtc/issues/542

marcbrevoort-cyberhive commented 7 months ago

Okay, while this demonstrates what needs to happen, bind is actually an associated function rather than a method so it doesn't have access to self so the line

self.set_nonce_from_msg(&res);

throws an error.

Now, this line doesn't have to be run during the bind; it can also be excuted by the caller. To avoid confusion, instead of a TryAgain I could define a new error StaleNonce(Message) which allows communicating back the nonce to be set in an error. However since the caller is itself an async block, it too doesn't have access to self (unless I move it into the block which of course causes all sorts of borrow checker complaints.

What needs to happen here is clear enough: if the channel bind fails with "stale nonce", it needs to be retried with a refreshed nonce, but at this point my knowledge of the webrtc source is insufficient to figure out how the missing re-bind can be added without upsetting the architecture of the crate, so I'll leave #542 open as a bug.