Skip to content

Commit 72f9426

Browse files
committed
refactor: change dialog storage key type to String and update related methods
1 parent 098cac1 commit 72f9426

File tree

5 files changed

+40
-27
lines changed

5 files changed

+40
-27
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.99"
3+
version = "0.3.0"
44
edition = "2021"
55
description = "SIP Stack Rust library for building SIP applications"
66
license = "MIT"

src/dialog/dialog_layer.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use tracing::info;
3333
/// * `dialogs` uses RwLock for concurrent read access with exclusive writes
3434
pub struct DialogLayerInner {
3535
pub(super) last_seq: AtomicU32,
36-
pub(super) dialogs: RwLock<HashMap<DialogId, Dialog>>,
36+
pub(super) dialogs: RwLock<HashMap<String, Dialog>>,
3737
}
3838
pub type DialogLayerInnerRef = Arc<DialogLayerInner>;
3939

@@ -154,7 +154,13 @@ impl DialogLayer {
154154
) -> Result<ServerInviteDialog> {
155155
let mut id = DialogId::try_from(&tx.original)?;
156156
if !id.to_tag.is_empty() {
157-
let dlg = self.inner.dialogs.read().unwrap().get(&id).cloned();
157+
let dlg = self
158+
.inner
159+
.dialogs
160+
.read()
161+
.unwrap()
162+
.get(&id.to_string())
163+
.cloned();
158164
match dlg {
159165
Some(Dialog::ServerInvite(dlg)) => return Ok(dlg),
160166
_ => {
@@ -195,7 +201,7 @@ impl DialogLayer {
195201
.dialogs
196202
.write()
197203
.unwrap()
198-
.insert(id.clone(), Dialog::ServerInvite(dialog.clone()));
204+
.insert(id.to_string(), Dialog::ServerInvite(dialog.clone()));
199205
info!(%id, "server invite dialog created");
200206
Ok(dialog)
201207
}
@@ -209,7 +215,7 @@ impl DialogLayer {
209215
self.inner.dialogs.read().unwrap().len()
210216
}
211217

212-
pub fn all_dialog_ids(&self) -> Vec<DialogId> {
218+
pub fn all_dialog_ids(&self) -> Vec<String> {
213219
self.inner
214220
.dialogs
215221
.read()
@@ -220,6 +226,10 @@ impl DialogLayer {
220226
}
221227

222228
pub fn get_dialog(&self, id: &DialogId) -> Option<Dialog> {
229+
self.get_dialog_with(&id.to_string())
230+
}
231+
232+
pub fn get_dialog_with(&self, id: &String) -> Option<Dialog> {
223233
match self.inner.dialogs.read() {
224234
Ok(dialogs) => match dialogs.get(id) {
225235
Some(dialog) => Some(dialog.clone()),
@@ -235,7 +245,7 @@ impl DialogLayer {
235245
.dialogs
236246
.write()
237247
.unwrap()
238-
.remove(id)
248+
.remove(&id.to_string())
239249
.map(|d| d.on_remove());
240250
}
241251

src/dialog/invitation.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl DialogGuard {
153153
impl Drop for DialogGuard {
154154
fn drop(&mut self) {
155155
let dlg = match self.dialog_layer_inner.dialogs.write() {
156-
Ok(mut dialogs) => match dialogs.remove(&self.id) {
156+
Ok(mut dialogs) => match dialogs.remove(&self.id.to_string()) {
157157
Some(dlg) => dlg,
158158
None => return,
159159
},
@@ -176,7 +176,7 @@ impl<'a> Drop for DialogGuardForUnconfirmed<'a> {
176176
fn drop(&mut self) {
177177
// If the dialog is still unconfirmed, we should try to cancel it
178178
match self.dialog_layer_inner.dialogs.write() {
179-
Ok(mut dialogs) => match dialogs.remove(self.id) {
179+
Ok(mut dialogs) => match dialogs.remove(&self.id.to_string()) {
180180
Some(dlg) => {
181181
info!(%self.id, "unconfirmed dialog dropped, cancelling it");
182182
let _ = tokio::spawn(async move {
@@ -421,7 +421,7 @@ impl DialogLayer {
421421
.dialogs
422422
.write()
423423
.as_mut()
424-
.map(|ds| ds.insert(id.clone(), Dialog::ClientInvite(dialog.clone())))
424+
.map(|ds| ds.insert(id.to_string(), Dialog::ClientInvite(dialog.clone())))
425425
.ok();
426426

427427
info!(%id, "client invite dialog created");
@@ -435,7 +435,7 @@ impl DialogLayer {
435435
.dialogs
436436
.write()
437437
.as_mut()
438-
.map(|ds| ds.remove(&id))
438+
.map(|ds| ds.remove(&id.to_string()))
439439
.ok();
440440

441441
match r {
@@ -451,7 +451,10 @@ impl DialogLayer {
451451
.write()
452452
.as_mut()
453453
.map(|ds| {
454-
ds.insert(new_dialog_id, Dialog::ClientInvite(dialog.clone()))
454+
ds.insert(
455+
new_dialog_id.to_string(),
456+
Dialog::ClientInvite(dialog.clone()),
457+
)
455458
})
456459
.ok();
457460
}

src/dialog/server_dialog.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -593,23 +593,23 @@ impl ServerInviteDialog {
593593
));
594594
}
595595
}
596-
} else {
597-
match tx.original.method {
598-
rsip::Method::PRack => return self.handle_prack(tx).await,
599-
rsip::Method::Ack => {
600-
self.inner.tu_sender.send(TransactionEvent::Received(
601-
tx.original.clone().into(),
602-
tx.connection.clone(),
603-
))?;
604-
}
605-
rsip::Method::Invite => {}
606-
_ => {
607-
// ignore other requests in non-confirmed state
608-
return Ok(());
609-
}
596+
}
597+
598+
match tx.original.method {
599+
rsip::Method::Invite => return self.handle_invite(tx).await,
600+
rsip::Method::PRack => return self.handle_prack(tx).await,
601+
rsip::Method::Ack => {
602+
self.inner.tu_sender.send(TransactionEvent::Received(
603+
tx.original.clone().into(),
604+
tx.connection.clone(),
605+
))?;
606+
return Ok(());
607+
}
608+
_ => {
609+
// ignore other requests in non-confirmed state
610+
return Ok(());
610611
}
611612
}
612-
self.handle_invite(tx).await
613613
}
614614

615615
async fn handle_bye(&mut self, tx: &mut Transaction) -> Result<()> {

src/transaction/endpoint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl Default for EndpointOption {
5151
fn default() -> Self {
5252
EndpointOption {
5353
t1: Duration::from_millis(500),
54-
t4: Duration::from_secs(4),
54+
t4: Duration::from_secs(5),
5555
t1x64: Duration::from_millis(64 * 500),
5656
timerc: Duration::from_secs(180),
5757
callid_suffix: None,

0 commit comments

Comments
 (0)