Skip to content

Commit af9198b

Browse files
committed
agent: clarify when a request is added and removed from the agent
1 parent af3bb72 commit af9198b

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

stun-proto/src/agent.rs

+16-7
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ impl StunAgent {
134134
send_data(self.transport, bytes, self.local_addr, to)
135135
}
136136

137-
/// Perform any operations needed to be able to send a [`Message`] to a peer
137+
/// Perform any operations needed to be able to send a [`Message`] to a peer.
138+
///
139+
/// If a request message is successfully sent, then [`StunAgent::poll`] needs to be called.
138140
pub fn send(&mut self, msg: Message, to: SocketAddr) -> Result<Transmit<'_>, StunError> {
139141
let data = msg.to_bytes();
140142
if msg.has_class(MessageClass::Request) {
@@ -185,7 +187,8 @@ impl StunAgent {
185187
/// Provide data received on a socket from a peer for handling by the [`StunAgent`].
186188
/// The returned value indicates what the caller must do with the data.
187189
///
188-
/// After this call, any outstanding [`StunRequest`] may need to be `poll()`ed again.
190+
/// If this function returns [`HandleStunReply::StunResponse`], then this agent needs to be
191+
/// `poll()`ed again.
189192
#[tracing::instrument(
190193
name = "stun_incoming_data"
191194
level = "info",
@@ -303,7 +306,10 @@ impl StunAgent {
303306
}
304307
}
305308

306-
/// Retrieve a reference to an outstanding STUN request
309+
/// Retrieve a reference to an outstanding STUN request. Outstanding requests are kept until
310+
/// either `handle_incoming_data` receives the associated response, or `poll()` returns
311+
/// [`StunAgentPollRet::TransactionCancelled`] or a [`StunAgentPollRet::TransactionTimedOut`]
312+
/// for the request.
307313
pub fn request_transaction(&self, transaction_id: TransactionId) -> Option<StunRequest> {
308314
if self.outstanding_requests.contains_key(&transaction_id) {
309315
Some(StunRequest {
@@ -315,7 +321,10 @@ impl StunAgent {
315321
}
316322
}
317323

318-
/// Retrieve a mutable reference to an outstanding STUN request
324+
/// Retrieve a mutable reference to an outstanding STUN request. Outstanding requests are kept
325+
/// until either `handle_incoming_data` receives the associated response, or `poll()` returns
326+
/// [`StunAgentPollRet::TransactionCancelled`] or a [`StunAgentPollRet::TransactionTimedOut`]
327+
/// for the request.
319328
pub fn mut_request_transaction(
320329
&mut self,
321330
transaction_id: TransactionId,
@@ -341,7 +350,7 @@ impl StunAgent {
341350
self.outstanding_requests.get(&transaction_id)
342351
}
343352

344-
/// Poll the agent for making further progress on any outstanding requests. The returned value
353+
/// Poll the agent for making further progress on any outstanding requests. The returned value
345354
/// indicates the current state and anything the caller needs to perform.
346355
#[tracing::instrument(
347356
name = "stun_request_poll"
@@ -391,9 +400,9 @@ impl StunAgent {
391400
/// Return value for [`StunAgent::poll`]
392401
#[derive(Debug)]
393402
pub enum StunAgentPollRet<'a> {
394-
/// An oustanding transaction timed out.
403+
/// An oustanding transaction timed out and has been removed from the agent.
395404
TransactionTimedOut(Message),
396-
/// An oustanding transaction was cancelled.
405+
/// An oustanding transaction was cancelled and has been removed from the agent.
397406
TransactionCancelled(Message),
398407
/// Send data using the specified 5-tuple
399408
SendData(Transmit<'a>),

0 commit comments

Comments
 (0)