Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
12 changes: 9 additions & 3 deletions src/transaction/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,13 +528,19 @@ impl EndpointInner {
.first()
.ok_or(Error::EndpointError("not sipaddrs".to_string()))
.cloned()?;
let mut uri: crate::sip::Uri = first_addr.into();
Ok(self.get_record_route_with_addr(first_addr))
}

/// Record-Route advertising `addr` instead of the endpoint's first listener, for an
/// endpoint with several listeners where the one a peer must use is not the first.
pub fn get_record_route_with_addr(&self, addr: SipAddr) -> crate::sip::typed::RecordRoute {
let mut uri: crate::sip::Uri = addr.into();
uri.params.push(crate::sip::Param::Lr);
Ok(crate::sip::typed::RecordRoute {
crate::sip::typed::RecordRoute {
display_name: None,
uri,
params: vec![],
})
}
}

pub fn get_via(
Expand Down
22 changes: 22 additions & 0 deletions src/transaction/tests/test_endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,25 @@ async fn test_endpoint_recvrequests() {
}
}
}

#[tokio::test]
async fn test_get_record_route_addr_override() {
let endpoint = super::create_test_endpoint(Some("127.0.0.1:15060"))
.await
.expect("create_test_endpoint");

let default_rr = endpoint.inner.get_record_route().expect("get_record_route");
assert_eq!(default_rr.uri.to_string(), "sip:127.0.0.1:15060;lr");

let override_addr = crate::transport::SipAddr {
r#type: Some(crate::sip::Transport::Udp),
addr: crate::sip::HostWithPort {
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(std::net::Ipv4Addr::new(
127, 0, 0, 1,
))),
port: Some(15061.into()),
},
};
let override_rr = endpoint.inner.get_record_route_with_addr(override_addr);
assert_eq!(override_rr.uri.to_string(), "sip:127.0.0.1:15061;lr");
}