Skip to content

Commit c933498

Browse files
committed
Add: timeout for await connect
1 parent 3b8dffa commit c933498

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

core/src/p2p.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
use std::{error::Error, net::SocketAddr, fmt::Display, str::FromStr};
1+
use std::{error::Error, net::SocketAddr, fmt::Display, str::FromStr, time::Duration};
22

33
use quinn::{Endpoint, SendStream, RecvStream};
4-
use tokio::net::{tcp::{ReadHalf, WriteHalf}, TcpStream};
4+
use tokio::{net::{tcp::{ReadHalf, WriteHalf}, TcpStream}, time::timeout};
55

66
use crate::{p2p_utils::{make_client_endpoint, make_server_endpoint}, unsafe_quic_client, *};
77

@@ -143,7 +143,11 @@ pub async fn bridge(udp: Endpoint, my_nat_type: NatType, my_udp_addr: &str, peer
143143
// quic server
144144
let udp = get_server_endpoint(Some(&hole_addr.to_string())).unwrap();
145145
i!("UDP({my_udp_addr}) -> await connect");
146-
let incoming_conn = udp.accept().await.unwrap();
146+
let Ok(Some(incoming_conn)) = timeout(Duration::from_millis(10000), udp.accept()).await
147+
else {
148+
e!("UDP({my_udp_addr}) -> timeout");
149+
return;
150+
};
147151
let visitor = incoming_conn.remote_address().to_string();
148152
i!("UDP({my_udp_addr}) -> {visitor} incoming");
149153
// assert_eq!(visitor, udp_addr);

0 commit comments

Comments
 (0)