@@ -12,6 +12,7 @@ use crate::{
1212 make_via_branch,
1313 transaction:: { Transaction , TransactionEventSender } ,
1414 } ,
15+ transport:: SipAddr ,
1516 Result ,
1617} ;
1718use rsip:: {
@@ -183,6 +184,7 @@ pub struct DialogInner {
183184 pub ( super ) state_sender : DialogStateSender ,
184185 pub ( super ) tu_sender : TransactionEventSender ,
185186 pub ( super ) initial_request : Request ,
187+ pub ( super ) initial_destination : Option < SipAddr > ,
186188}
187189
188190pub type DialogStateReceiver = UnboundedReceiver < DialogState > ;
@@ -259,6 +261,7 @@ impl DialogInner {
259261 tu_sender,
260262 state : Mutex :: new ( DialogState :: Calling ( id) ) ,
261263 initial_request,
264+ initial_destination : None ,
262265 local_contact,
263266 remote_contact : Mutex :: new ( None ) ,
264267 } )
@@ -456,21 +459,17 @@ impl DialogInner {
456459
457460 pub ( super ) async fn do_request ( & self , request : Request ) -> Result < Option < rsip:: Response > > {
458461 let method = request. method ( ) . to_owned ( ) ;
459- let mut destination = request. route_header ( ) . and_then ( |r| {
460- r. typed ( )
461- . ok ( )
462- . and_then ( |r| r. uris ( ) . first ( ) . map ( |u| u. uri . clone ( ) ) )
463- } ) ;
464-
465- if destination. is_none ( ) {
466- if let Some ( contact) = self . remote_contact . lock ( ) . unwrap ( ) . as_ref ( ) {
467- destination = contact. uri ( ) . ok ( ) ;
468- }
469- }
462+ let destination = self
463+ . remote_contact
464+ . lock ( )
465+ . unwrap ( )
466+ . as_ref ( )
467+ . and_then ( |c| c. uri ( ) . ok ( ) . as_ref ( ) ?. try_into ( ) . ok ( ) )
468+ . or_else ( || self . initial_destination . clone ( ) ) ;
470469
471470 let key = TransactionKey :: from_request ( & request, TransactionRole :: Client ) ?;
472471 let mut tx = Transaction :: new_client ( key, request, self . endpoint_inner . clone ( ) , None ) ;
473- tx. destination = destination. as_ref ( ) . map ( |d| d . try_into ( ) . ok ( ) ) . flatten ( ) ;
472+ tx. destination = destination;
474473
475474 match tx. send ( ) . await {
476475 Ok ( _) => {
@@ -576,7 +575,7 @@ impl DialogInner {
576575 }
577576 _ => { }
578577 }
579- info ! ( "transitioning state: {} -> {}" , old_state, state) ;
578+ debug ! ( "transitioning state: {} -> {}" , old_state, state) ;
580579 * old_state = state;
581580 Ok ( ( ) )
582581 }
0 commit comments