Skip to content

Commit 9180764

Browse files
committed
fix: update version to 0.2.82 and refactor dialog handling for clarity
1 parent beaeebf commit 9180764

File tree

7 files changed

+17
-84
lines changed

7 files changed

+17
-84
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rsipstack"
3-
version = "0.2.81"
3+
version = "0.2.82"
44
edition = "2021"
55
description = "SIP Stack Rust library for building SIP applications"
66
license = "MIT"

examples/proxy.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,14 +291,12 @@ async fn process_incoming_request(
291291
ack_tx.send().await?;
292292
}
293293
rsip::Method::Options => {
294-
if tx.endpoint_inner.option.ignore_out_of_dialog_option {
295-
info!(
296-
"ignoring out of dialog OPTIONS request: {:?}",
297-
tx.original.method
298-
);
299-
continue;
300-
}
301-
tx.reply(rsip::StatusCode::NotAcceptable).await?;
294+
info!(
295+
"ignoring out of dialog OPTIONS request: {:?}",
296+
tx.original.method
297+
);
298+
// do nothing for OPTIONS, may be a attack from scanner
299+
// tx.reply(rsip::StatusCode::NotAcceptable).await?;
302300
}
303301
_ => {
304302
tx.reply(rsip::StatusCode::NotAcceptable).await?;

src/dialog/client_dialog.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::dialog::DialogInnerRef;
22
use super::DialogId;
3-
use crate::dialog::dialog::DialogInner;
43
use crate::dialog::{
54
authenticate::handle_client_authenticate,
65
dialog::{DialogState, TerminatedReason},
@@ -552,7 +551,6 @@ impl ClientInviteDialog {
552551
resp.remote_uri(tx.destination.as_ref())?;
553552
self.inner
554553
.transition(DialogState::Confirmed(dialog_id.clone(), resp))?;
555-
DialogInner::serve_keepalive_options(self.inner.clone());
556554
}
557555
_ => {
558556
self.inner.transition(DialogState::Terminated(

src/dialog/dialog.rs

Lines changed: 3 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,13 @@ use rsip::{
1919
headers::Route,
2020
prelude::{HeadersExt, ToTypedHeader, UntypedHeader},
2121
typed::{CSeq, Contact, Via},
22-
Header, Param, Request, Response, SipMessage, StatusCode, StatusCodeKind,
22+
Header, Param, Request, Response, SipMessage, StatusCode,
2323
};
2424
use std::sync::{
2525
atomic::{AtomicU32, Ordering},
2626
Arc, Mutex,
2727
};
28-
use tokio::{
29-
sync::mpsc::{UnboundedReceiver, UnboundedSender},
30-
time::interval,
31-
};
28+
use tokio::sync::mpsc::{UnboundedReceiver, UnboundedSender};
3229
use tokio_util::sync::CancellationToken;
3330
use tracing::{debug, info, warn};
3431

@@ -180,6 +177,7 @@ pub struct DialogInner {
180177

181178
pub credential: Option<Credential>,
182179
pub route_set: Mutex<Vec<Route>>,
180+
183181
pub(super) endpoint_inner: EndpointInnerRef,
184182
pub(super) state_sender: DialogStateSender,
185183
pub(super) tu_sender: TransactionEventSender,
@@ -587,61 +585,6 @@ impl DialogInner {
587585
*old_state = state;
588586
Ok(())
589587
}
590-
591-
pub(super) fn serve_keepalive_options(dlg_inner: Arc<Self>) {
592-
let keepalive = match dlg_inner.endpoint_inner.option.dialog_keepalive_duration {
593-
Some(k) => k,
594-
None => return,
595-
};
596-
let token = dlg_inner.cancel_token.child_token();
597-
let dlg_ref = dlg_inner.clone();
598-
599-
tokio::spawn(async move {
600-
let mut ticker = interval(keepalive);
601-
// skip first tick, which will be reached immediately
602-
ticker.tick().await;
603-
let keepalive_loop = async {
604-
loop {
605-
ticker.tick().await;
606-
if !dlg_ref.is_confirmed() {
607-
return Ok(());
608-
}
609-
let options = dlg_ref.make_request(
610-
rsip::Method::Options,
611-
None,
612-
None,
613-
None,
614-
None,
615-
None,
616-
)?;
617-
let id = dlg_ref.id.lock().unwrap().clone();
618-
match dlg_ref.do_request(options).await {
619-
Ok(Some(resp)) => match resp.status_code.kind() {
620-
StatusCodeKind::Provisional | StatusCodeKind::Successful => {
621-
continue;
622-
}
623-
_ => {
624-
info!(%id, status = %resp.status_code, "keepalive options failed");
625-
}
626-
},
627-
Ok(None) => {
628-
continue;
629-
}
630-
Err(_) => {}
631-
}
632-
dlg_ref
633-
.transition(DialogState::Terminated(id, TerminatedReason::Timeout))
634-
.ok();
635-
break;
636-
}
637-
Ok::<(), crate::Error>(())
638-
};
639-
tokio::select! {
640-
_ = token.cancelled() => {}
641-
_ = keepalive_loop =>{}
642-
};
643-
});
644-
}
645588
}
646589

647590
impl std::fmt::Display for DialogState {

src/dialog/server_dialog.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use super::dialog::{Dialog, DialogInnerRef, DialogState, TerminatedReason};
22
use super::DialogId;
3-
use crate::dialog::dialog::DialogInner;
43
use crate::transport::SipConnection;
54
use crate::{
65
transaction::transaction::{Transaction, TransactionEvent},
@@ -684,7 +683,6 @@ impl ServerInviteDialog {
684683
self.id(),
685684
tx.last_response.clone().unwrap_or_default(),
686685
))?;
687-
DialogInner::serve_keepalive_options(self.inner.clone());
688686
break;
689687
}
690688
rsip::Method::Cancel => {

src/transaction/endpoint.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ pub struct EndpointOption {
3939
pub t4: Duration,
4040
pub t1x64: Duration,
4141
pub timerc: Duration,
42-
pub ignore_out_of_dialog_option: bool,
4342
pub callid_suffix: Option<String>,
44-
pub dialog_keepalive_duration: Option<Duration>,
4543
}
4644

4745
impl Default for EndpointOption {
@@ -51,9 +49,7 @@ impl Default for EndpointOption {
5149
t4: Duration::from_secs(4),
5250
t1x64: Duration::from_millis(64 * 500),
5351
timerc: Duration::from_secs(180),
54-
ignore_out_of_dialog_option: true,
5552
callid_suffix: None,
56-
dialog_keepalive_duration: Some(Duration::from_secs(60)),
5753
}
5854
}
5955
}

src/transaction/transaction.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub type TransactionEventSender = UnboundedSender<TransactionEvent>;
4646
/// TransactionEvent::Respond(response) => {
4747
/// // Send response
4848
/// },
49-
/// TransactionEvent::Terminate => {
49+
/// TransactionEvent::Terminate(key) => {
5050
/// // Clean up transaction
5151
/// }
5252
/// }
@@ -56,7 +56,7 @@ pub enum TransactionEvent {
5656
Received(SipMessage, Option<SipConnection>),
5757
Timer(TransactionTimer),
5858
Respond(Response),
59-
Terminate,
59+
Terminate(TransactionKey),
6060
}
6161

6262
/// SIP Transaction
@@ -499,8 +499,8 @@ impl Transaction {
499499
TransactionEvent::Respond(response) => {
500500
self.respond(response).await.ok();
501501
}
502-
TransactionEvent::Terminate => {
503-
info!("received terminate event");
502+
TransactionEvent::Terminate(key) => {
503+
info!(%key, "received terminate event");
504504
return None;
505505
}
506506
}
@@ -672,7 +672,6 @@ impl Transaction {
672672
None,
673673
);
674674
self.inform_tu_response(timeout_response)?;
675-
self.transition(TransactionState::Terminated)?;
676675
}
677676
}
678677
}
@@ -685,7 +684,6 @@ impl Transaction {
685684
None,
686685
);
687686
self.inform_tu_response(timeout_response)?;
688-
self.transition(TransactionState::Terminated)?;
689687
}
690688
}
691689
TransactionState::Completed => {
@@ -841,7 +839,9 @@ impl Transaction {
841839
}
842840
TransactionState::Terminated => {
843841
self.cleanup();
844-
self.tu_sender.send(TransactionEvent::Terminate).ok(); // tell TU to terminate
842+
self.tu_sender
843+
.send(TransactionEvent::Terminate(self.key.clone()))
844+
.ok(); // tell TU to terminate
845845
}
846846
}
847847
debug!(

0 commit comments

Comments
 (0)