Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/client/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ async fn process_incoming_request(
info!("Received transaction: {:?}", tx.key);

match tx.original.to_header()?.tag()?.as_ref() {
Some(_) => match dialog_layer.match_dialog(&tx.original) {
Some(_) => match dialog_layer.match_dialog(&tx) {
Some(mut d) => {
tokio::spawn(async move {
d.handle(&mut tx).await?;
Expand Down
6 changes: 3 additions & 3 deletions examples/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ async fn process_incoming_request(
}
rsip::Method::Ack => {
info!(method = ?tx.original.method, "received out of transaction ack");
let dialog_id = DialogId::try_from(&tx.original)?;
let dialog_id = DialogId::try_from(&tx)?;
if !state_ref.inner.sessions.lock().await.contains(&dialog_id) {
tx.reply(rsip::StatusCode::NotAcceptable).await?;
continue;
Expand Down Expand Up @@ -458,7 +458,7 @@ async fn handle_invite(state: AppState, mut tx: Transaction) -> Result<()> {
header_pop!(resp.headers, rsip::Header::Via);
resp.headers.push_front(record_route.clone().into());
if resp.status_code.kind() == rsip::StatusCodeKind::Successful {
let dialog_id = DialogId::try_from(&resp)?;
let dialog_id = DialogId::try_from((&resp, TransactionRole::Client))?;
info!(id = %dialog_id, "add session");
state.inner.sessions.lock().await.insert(dialog_id);
}
Expand Down Expand Up @@ -523,7 +523,7 @@ async fn handle_bye(state: AppState, mut tx: Transaction) -> Result<()> {

bye_tx.send().await?;

let dialog_id = DialogId::try_from(&bye_tx.original)?;
let dialog_id = DialogId::try_from(&bye_tx)?;
if state.inner.sessions.lock().await.remove(&dialog_id) {
info!(id = %dialog_id, "removed session");
}
Expand Down
2 changes: 1 addition & 1 deletion src/bin/bench_ua.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ async fn run_server(
});
}
rsip::Method::Bye => {
if let Ok(dialog_id) = DialogId::try_from(&tx.original) {
if let Ok(dialog_id) = DialogId::try_from(&tx) {
stats.active_calls.lock().unwrap().remove(&dialog_id);
tx.reply(rsip::StatusCode::OK).await.ok();
dialog_layer.remove_dialog(&dialog_id);
Expand Down
2 changes: 1 addition & 1 deletion src/dialog/authenticate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ pub async fn handle_client_authenticate(
let proxy_header = rsip::header_opt!(resp.headers().iter(), Header::ProxyAuthenticate);
let proxy_header = proxy_header.ok_or(crate::Error::DialogError(
"missing proxy/www authenticate".to_string(),
DialogId::from_uac_request(&tx.original)?,
DialogId::try_from(tx)?,
code,
))?;
Header::ProxyAuthenticate(proxy_header.clone())
Expand Down
15 changes: 9 additions & 6 deletions src/dialog/client_dialog.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use super::dialog::DialogInnerRef;
use super::DialogId;
use crate::dialog::{
authenticate::handle_client_authenticate,
dialog::{DialogState, TerminatedReason, TransactionHandle},
subscription::ClientSubscriptionDialog,
};
use crate::rsip_ext::RsipResponseExt;
use crate::transaction::transaction::Transaction;
use crate::Result;
use crate::{
dialog::{
authenticate::handle_client_authenticate,
dialog::{DialogState, TerminatedReason, TransactionHandle},
subscription::ClientSubscriptionDialog,
},
transaction::key::TransactionRole,
};
use rsip::prelude::HasHeaders;
use rsip::{prelude::HeadersExt, Header};
use rsip::{Response, SipMessage, StatusCode};
Expand Down Expand Up @@ -768,7 +771,7 @@ impl ClientInviteDialog {
None => {}
}

if let Ok(id) = DialogId::from_uac_response(&resp) {
if let Ok(id) = DialogId::try_from((&resp, TransactionRole::Client)) {
dialog_id = id;
}
match resp.status_code {
Expand Down
13 changes: 7 additions & 6 deletions src/dialog/dialog.rs
Comment thread
adamchol marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -432,12 +432,13 @@ impl DialogInner {
let from = initial_request.from_header()?.typed()?;
let mut to = initial_request.to_header()?.typed()?;
if !to.params.iter().any(|p| matches!(p, Param::Tag(_))) {
let tag = match role {
TransactionRole::Client => &id.remote_tag,
TransactionRole::Server => &id.local_tag,
};
if !tag.is_empty() {
to.params.push(rsip::Param::Tag(tag.clone().into()));
match role {
TransactionRole::Client => to
.params
.push(rsip::Param::Tag(id.remote_tag.clone().into())),
TransactionRole::Server => to
.params
.push(rsip::Param::Tag(id.local_tag.clone().into())),
}
}

Expand Down
39 changes: 19 additions & 20 deletions src/dialog/dialog_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::transaction::transaction::transaction_event_sender_noop;
use crate::transaction::{endpoint::EndpointInnerRef, transaction::Transaction};
use crate::Result;
use rsip::prelude::HeadersExt;
use rsip::Request;
use std::sync::atomic::{AtomicU32, Ordering};
use std::{
collections::HashMap,
Expand Down Expand Up @@ -94,11 +93,11 @@ pub type DialogLayerInnerRef = Arc<DialogLayerInner>;
/// # async fn example() -> rsipstack::Result<()> {
/// # let dialog_layer: DialogLayer = todo!();
/// # let request = todo!();
/// # let transaction = todo!();
/// # let mut transaction = todo!();
/// // Find existing dialog for incoming request
/// if let Some(mut dialog) = dialog_layer.match_dialog(&request) {
/// if let Some(mut dialog) = dialog_layer.match_dialog(&transaction) {
/// // Route to existing dialog
/// dialog.handle(transaction).await?;
/// dialog.handle(&mut transaction).await?;
/// } else {
/// // Create new dialog or reject
/// }
Expand Down Expand Up @@ -156,7 +155,7 @@ impl DialogLayer {
credential: Option<Credential>,
local_contact: Option<rsip::Uri>,
) -> Result<ServerInviteDialog> {
let mut id = DialogId::from_uas_request(&tx.original)?;
let mut id = DialogId::try_from(tx)?;
if !id.local_tag.is_empty() {
let dlg = self
.inner
Expand All @@ -176,7 +175,7 @@ impl DialogLayer {
}
}
}
id.local_tag = make_tag().to_string(); // generate local tag
id.local_tag = make_tag().to_string(); // generate to tag

let mut local_contact = local_contact;
if local_contact.is_none() {
Expand Down Expand Up @@ -217,7 +216,7 @@ impl DialogLayer {
credential: Option<Credential>,
local_contact: Option<rsip::Uri>,
) -> Result<ServerSubscriptionDialog> {
let mut id = DialogId::from_uas_request(&tx.original)?;
let mut id = DialogId::try_from(tx)?;
if !id.local_tag.is_empty() {
let dlg = self
.inner
Expand All @@ -237,7 +236,7 @@ impl DialogLayer {
}
}
}
id.local_tag = make_tag().to_string(); // generate local tag
id.local_tag = make_tag().to_string(); // generate to tag

let mut local_contact = local_contact;
if local_contact.is_none() {
Expand Down Expand Up @@ -278,7 +277,7 @@ impl DialogLayer {
credential: Option<Credential>,
local_contact: Option<rsip::Uri>,
) -> Result<ServerPublicationDialog> {
let mut id = DialogId::from_uas_request(&tx.original)?;
let mut id = DialogId::try_from(tx)?;
if !id.local_tag.is_empty() {
let dlg = self
.inner
Expand All @@ -298,7 +297,7 @@ impl DialogLayer {
}
}
}
id.local_tag = make_tag().to_string(); // generate local tag
id.local_tag = make_tag().to_string(); // generate to tag

let mut local_contact = local_contact;
if local_contact.is_none() {
Expand Down Expand Up @@ -333,17 +332,17 @@ impl DialogLayer {
pub fn get_or_create_client_publication(
&self,
call_id: String,
local_tag: String,
remote_tag: String,
from_tag: String,
to_tag: String,
initial_request: rsip::Request,
state_sender: DialogStateSender,
credential: Option<Credential>,
local_contact: Option<rsip::Uri>,
) -> Result<ClientPublicationDialog> {
let id = DialogId {
call_id,
local_tag: local_tag,
remote_tag: remote_tag,
local_tag: from_tag,
remote_tag: to_tag,
};

if let Some(Dialog::ClientPublication(dlg)) = self.get_dialog(&id) {
Expand Down Expand Up @@ -383,17 +382,17 @@ impl DialogLayer {
pub fn get_or_create_client_subscription(
&self,
call_id: String,
local_tag: String,
remote_tag: String,
from_tag: String,
to_tag: String,
initial_request: rsip::Request,
state_sender: DialogStateSender,
credential: Option<Credential>,
local_contact: Option<rsip::Uri>,
) -> Result<ClientSubscriptionDialog> {
let id = DialogId {
call_id,
local_tag: local_tag,
remote_tag: remote_tag,
local_tag: from_tag,
remote_tag: to_tag,
};

if let Some(Dialog::ClientSubscription(dlg)) = self.get_dialog(&id) {
Expand Down Expand Up @@ -543,8 +542,8 @@ impl DialogLayer {
.map(|d| d.on_remove());
}

pub fn match_dialog(&self, req: &Request) -> Option<Dialog> {
let id = DialogId::try_from(req).ok()?;
pub fn match_dialog(&self, tx: &Transaction) -> Option<Dialog> {
let id = DialogId::try_from(tx).ok()?;
self.get_dialog(&id)
}

Expand Down
2 changes: 1 addition & 1 deletion src/dialog/invitation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ impl DialogLayer {
}
}

let id = DialogId::from_uac_request(&request)?;
let id = DialogId::try_from(&tx)?;
let dlg_inner = DialogInner::new(
TransactionRole::Client,
id.clone(),
Expand Down
Loading