Skip to content

Commit 1498398

Browse files
committed
fix: fmt check
1 parent 508aa21 commit 1498398

6 files changed

Lines changed: 96 additions & 68 deletions

File tree

src/dialog/dialog_layer.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,14 @@ impl DialogLayer {
193193
let transport = conn.transport();
194194
if !matches!(transport, crate::sip::Transport::Udp) {
195195
let mut remote_uri = dlg_inner.remote_uri.lock();
196-
if !remote_uri.params.iter().any(|p| matches!(p, crate::sip::Param::Transport(_))) {
197-
remote_uri.params.push(crate::sip::Param::Transport(transport));
196+
if !remote_uri
197+
.params
198+
.iter()
199+
.any(|p| matches!(p, crate::sip::Param::Transport(_)))
200+
{
201+
remote_uri
202+
.params
203+
.push(crate::sip::Param::Transport(transport));
198204
}
199205
}
200206
}

src/dialog/invitation.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,9 @@ impl DialogLayer {
331331
.iter()
332332
.any(|p| matches!(p, crate::sip::Param::Transport(_)))
333333
{
334-
uri.params
335-
.push(crate::sip::Param::Transport(addr.r#type.unwrap_or(
336-
crate::sip::Transport::Tcp,
337-
)));
334+
uri.params.push(crate::sip::Param::Transport(
335+
addr.r#type.unwrap_or(crate::sip::Transport::Tcp),
336+
));
338337
}
339338
if addr.r#type == Some(crate::sip::Transport::Tls) {
340339
uri.scheme = Some(crate::sip::Scheme::Sips);

src/dialog/tests/test_dialog_layer.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module contains tests for dialog management and lifecycle
44
55
use crate::dialog::{dialog_layer::DialogLayer, DialogId};
6-
use crate::sip::{headers::*, prelude::HeadersExt, HostWithPort, Param, Transport, Request};
6+
use crate::sip::{headers::*, prelude::HeadersExt, HostWithPort, Param, Request, Transport};
77
use crate::transaction::{
88
endpoint::EndpointBuilder,
99
key::{TransactionKey, TransactionRole},
@@ -412,9 +412,9 @@ async fn test_server_invite_dialog_with_tcp_transport() -> crate::Result<()> {
412412
let tcp_addr = SipAddr {
413413
r#type: Some(Transport::Tcp),
414414
addr: HostWithPort {
415-
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(
416-
std::net::Ipv4Addr::new(127, 0, 0, 1),
417-
)),
415+
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(std::net::Ipv4Addr::new(
416+
127, 0, 0, 1,
417+
))),
418418
port: Some(5060.into()),
419419
},
420420
};
@@ -424,12 +424,7 @@ async fn test_server_invite_dialog_with_tcp_transport() -> crate::Result<()> {
424424
// Create INVITE request
425425
let invite_req = create_invite_request("alice-tcp-tag", "", "call-id-tcp", "z9hG4bKtcp");
426426
let key = TransactionKey::from_request(&invite_req, TransactionRole::Server)?;
427-
let tx = Transaction::new_server(
428-
key,
429-
invite_req.clone(),
430-
endpoint.inner.clone(),
431-
Some(conn),
432-
);
427+
let tx = Transaction::new_server(key, invite_req.clone(), endpoint.inner.clone(), Some(conn));
433428

434429
let (state_sender, _state_receiver) = unbounded_channel();
435430

@@ -467,9 +462,9 @@ async fn test_make_invite_request_with_tcp_transport() -> crate::Result<()> {
467462
let tcp_addr = SipAddr {
468463
r#type: Some(Transport::Tcp),
469464
addr: HostWithPort {
470-
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(
471-
std::net::Ipv4Addr::new(192, 168, 1, 10),
472-
)),
465+
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(std::net::Ipv4Addr::new(
466+
192, 168, 1, 10,
467+
))),
473468
port: Some(5060.into()),
474469
},
475470
};
@@ -485,9 +480,9 @@ async fn test_make_invite_request_with_tcp_transport() -> crate::Result<()> {
485480
let destination = SipAddr {
486481
r#type: Some(Transport::Tcp),
487482
addr: HostWithPort {
488-
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(
489-
std::net::Ipv4Addr::new(10, 0, 0, 1),
490-
)),
483+
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(std::net::Ipv4Addr::new(
484+
10, 0, 0, 1,
485+
))),
491486
port: Some(5060.into()),
492487
},
493488
};
@@ -505,8 +500,7 @@ async fn test_make_invite_request_with_tcp_transport() -> crate::Result<()> {
505500
// Verify Contact header has the transport layer's TCP address and transport param
506501
let contact = request.contact_header()?.typed()?;
507502
assert_eq!(
508-
contact.uri.host_with_port,
509-
tcp_addr.addr,
503+
contact.uri.host_with_port, tcp_addr.addr,
510504
"Contact URI should use the transport layer's TCP address"
511505
);
512506
assert!(
@@ -570,9 +564,9 @@ async fn test_make_invite_request_with_tls_transport_uses_sips_scheme() -> crate
570564
let tls_addr = SipAddr {
571565
r#type: Some(Transport::Tls),
572566
addr: HostWithPort {
573-
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(
574-
std::net::Ipv4Addr::new(192, 168, 1, 10),
575-
)),
567+
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(std::net::Ipv4Addr::new(
568+
192, 168, 1, 10,
569+
))),
576570
port: Some(5061.into()),
577571
},
578572
};
@@ -588,9 +582,9 @@ async fn test_make_invite_request_with_tls_transport_uses_sips_scheme() -> crate
588582
let destination = SipAddr {
589583
r#type: Some(Transport::Tls),
590584
addr: HostWithPort {
591-
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(
592-
std::net::Ipv4Addr::new(10, 0, 0, 1),
593-
)),
585+
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(std::net::Ipv4Addr::new(
586+
10, 0, 0, 1,
587+
))),
594588
port: Some(5061.into()),
595589
},
596590
};

src/error.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ mod tests {
6868
drop(rx);
6969
let err = tx.try_send(1).unwrap_err();
7070
let error: Error = err.into();
71-
assert!(error.to_string().contains("closed"), "expected 'closed' in error, got: {}", error);
71+
assert!(
72+
error.to_string().contains("closed"),
73+
"expected 'closed' in error, got: {}",
74+
error
75+
);
7276
}
7377
}

src/transport/channel.rs

Lines changed: 55 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,8 @@ impl ChannelConnection {
3333
addr: SipAddr,
3434
cancel_token: Option<CancellationToken>,
3535
) -> Result<Self> {
36-
Self::create_connection_inner(
37-
incoming,
38-
Outgoing::Unbounded(outgoing),
39-
addr,
40-
cancel_token,
41-
)
42-
.await
36+
Self::create_connection_inner(incoming, Outgoing::Unbounded(outgoing), addr, cancel_token)
37+
.await
4338
}
4439

4540
pub async fn create_connection_bounded(
@@ -48,13 +43,8 @@ impl ChannelConnection {
4843
addr: SipAddr,
4944
cancel_token: Option<CancellationToken>,
5045
) -> Result<Self> {
51-
Self::create_connection_inner(
52-
incoming,
53-
Outgoing::Bounded(outgoing),
54-
addr,
55-
cancel_token,
56-
)
57-
.await
46+
Self::create_connection_inner(incoming, Outgoing::Bounded(outgoing), addr, cancel_token)
47+
.await
5848
}
5949

6050
async fn create_connection_inner(
@@ -143,7 +133,9 @@ mod tests {
143133
SipAddr {
144134
r#type: None,
145135
addr: HostWithPort {
146-
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(std::net::Ipv4Addr::new(127, 0, 0, 1))),
136+
host: crate::sip::Host::IpAddr(std::net::IpAddr::V4(std::net::Ipv4Addr::new(
137+
127, 0, 0, 1,
138+
))),
147139
port: Some(5060.into()),
148140
},
149141
}
@@ -163,9 +155,14 @@ mod tests {
163155
async fn test_create_connection_bounded_send_receive() {
164156
let (_incoming_tx, incoming_rx) = mpsc::unbounded_channel();
165157
let (outgoing_tx, mut outgoing_rx) = mpsc::channel(16);
166-
let conn = ChannelConnection::create_connection_bounded(incoming_rx, outgoing_tx, test_sip_addr(), None)
167-
.await
168-
.expect("create_connection_bounded");
158+
let conn = ChannelConnection::create_connection_bounded(
159+
incoming_rx,
160+
outgoing_tx,
161+
test_sip_addr(),
162+
None,
163+
)
164+
.await
165+
.expect("create_connection_bounded");
169166

170167
let msg = test_message();
171168
conn.send(msg).await.expect("send via bounded channel");
@@ -178,9 +175,14 @@ mod tests {
178175
async fn test_try_send_on_bounded() {
179176
let (_incoming_tx, incoming_rx) = mpsc::unbounded_channel();
180177
let (outgoing_tx, mut outgoing_rx) = mpsc::channel(2);
181-
let conn = ChannelConnection::create_connection_bounded(incoming_rx, outgoing_tx, test_sip_addr(), None)
182-
.await
183-
.expect("create_connection_bounded");
178+
let conn = ChannelConnection::create_connection_bounded(
179+
incoming_rx,
180+
outgoing_tx,
181+
test_sip_addr(),
182+
None,
183+
)
184+
.await
185+
.expect("create_connection_bounded");
184186

185187
let msg = test_message();
186188
conn.try_send(msg).expect("try_send on bounded");
@@ -193,9 +195,10 @@ mod tests {
193195
async fn test_try_send_on_unbounded() {
194196
let (_incoming_tx, incoming_rx) = mpsc::unbounded_channel();
195197
let (outgoing_tx, mut outgoing_rx) = mpsc::unbounded_channel();
196-
let conn = ChannelConnection::create_connection(incoming_rx, outgoing_tx, test_sip_addr(), None)
197-
.await
198-
.expect("create_connection");
198+
let conn =
199+
ChannelConnection::create_connection(incoming_rx, outgoing_tx, test_sip_addr(), None)
200+
.await
201+
.expect("create_connection");
199202

200203
let msg = test_message();
201204
conn.try_send(msg).expect("try_send on unbounded");
@@ -208,22 +211,35 @@ mod tests {
208211
async fn test_try_send_bounded_full() {
209212
let (_incoming_tx, incoming_rx) = mpsc::unbounded_channel();
210213
let (outgoing_tx, _outgoing_rx) = mpsc::channel(1);
211-
let conn = ChannelConnection::create_connection_bounded(incoming_rx, outgoing_tx, test_sip_addr(), None)
212-
.await
213-
.expect("create_connection_bounded");
214+
let conn = ChannelConnection::create_connection_bounded(
215+
incoming_rx,
216+
outgoing_tx,
217+
test_sip_addr(),
218+
None,
219+
)
220+
.await
221+
.expect("create_connection_bounded");
214222

215223
conn.try_send(test_message()).expect("first send");
216224
let result = conn.try_send(test_message());
217-
assert!(result.is_err(), "try_send on full bounded channel should return error");
225+
assert!(
226+
result.is_err(),
227+
"try_send on full bounded channel should return error"
228+
);
218229
}
219230

220231
#[tokio::test]
221232
async fn test_bounded_connection_serve_loop() {
222233
let (incoming_tx, incoming_rx) = mpsc::unbounded_channel::<super::super::TransportEvent>();
223234
let (outgoing_tx, _outgoing_rx) = mpsc::channel(16);
224-
let conn = ChannelConnection::create_connection_bounded(incoming_rx, outgoing_tx, test_sip_addr(), None)
225-
.await
226-
.expect("create_connection_bounded");
235+
let conn = ChannelConnection::create_connection_bounded(
236+
incoming_rx,
237+
outgoing_tx,
238+
test_sip_addr(),
239+
None,
240+
)
241+
.await
242+
.expect("create_connection_bounded");
227243

228244
// Serve loop in background, forwarding events
229245
let (event_tx, _event_rx) = mpsc::unbounded_channel();
@@ -247,9 +263,14 @@ mod tests {
247263
async fn test_bounded_serve_loop_twice_returns_error() {
248264
let (incoming_tx, incoming_rx) = mpsc::unbounded_channel::<super::super::TransportEvent>();
249265
let (outgoing_tx, _outgoing_rx) = mpsc::channel(16);
250-
let conn = ChannelConnection::create_connection_bounded(incoming_rx, outgoing_tx, test_sip_addr(), None)
251-
.await
252-
.expect("create_connection_bounded");
266+
let conn = ChannelConnection::create_connection_bounded(
267+
incoming_rx,
268+
outgoing_tx,
269+
test_sip_addr(),
270+
None,
271+
)
272+
.await
273+
.expect("create_connection_bounded");
253274

254275
// Drop the sender so the incoming channel is closed
255276
drop(incoming_tx);

src/transport/connection.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,9 @@ impl From<WebSocketListenerConnection> for SipConnection {
467467
#[cfg(test)]
468468
mod tests {
469469
use super::*;
470+
use crate::sip::HostWithPort;
470471
use crate::transport::channel::ChannelConnection;
471472
use crate::transport::tcp_listener::TcpListenerConnection;
472-
use crate::sip::HostWithPort;
473473
use std::net::Ipv4Addr;
474474

475475
fn test_sip_addr() -> SipAddr {
@@ -486,7 +486,9 @@ mod tests {
486486
async fn test_transport_channel_returns_udp() -> crate::Result<()> {
487487
let (_incoming_tx, incoming_rx) = tokio::sync::mpsc::unbounded_channel();
488488
let (outgoing_tx, _outgoing_rx) = tokio::sync::mpsc::unbounded_channel();
489-
let conn = ChannelConnection::create_connection(incoming_rx, outgoing_tx, test_sip_addr(), None).await?;
489+
let conn =
490+
ChannelConnection::create_connection(incoming_rx, outgoing_tx, test_sip_addr(), None)
491+
.await?;
490492
let sip_conn = SipConnection::Channel(conn);
491493
assert_eq!(sip_conn.transport(), Transport::Udp);
492494
Ok(())
@@ -519,7 +521,9 @@ mod tests {
519521
async fn test_transport_channel_send() -> crate::Result<()> {
520522
let (_incoming_tx, incoming_rx) = tokio::sync::mpsc::unbounded_channel();
521523
let (outgoing_tx, mut outgoing_rx) = tokio::sync::mpsc::unbounded_channel();
522-
let conn = ChannelConnection::create_connection(incoming_rx, outgoing_tx, test_sip_addr(), None).await?;
524+
let conn =
525+
ChannelConnection::create_connection(incoming_rx, outgoing_tx, test_sip_addr(), None)
526+
.await?;
523527
let sip_conn = SipConnection::Channel(conn);
524528

525529
let req = crate::sip::Request {

0 commit comments

Comments
 (0)