Skip to content

Commit 75f03ee

Browse files
committed
Fix: recv hello msg
1 parent bc9003e commit 75f03ee

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

core/src/p2p.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pub async fn bridge(udp: Endpoint, my_nat_type: NatType, my_udp_addr: &str, peer
114114
udp.wait_idle().await;
115115
let udp = get_server_endpoint(Some(&hole_addr.to_string())).unwrap();
116116
i!("UDP({my_udp_addr}) -> await connect");
117-
let incoming_conn = udp.accept().await.unwrap();
117+
let incoming_conn = udp.accept().await.unwrap(); // 非开放型NAT可能堵塞
118118
let visitor = incoming_conn.remote_address().to_string();
119119
i!("UDP({my_udp_addr}) -> {visitor} incoming");
120120
// assert_eq!(visitor, udp_addr);
@@ -129,9 +129,10 @@ pub async fn bridge(udp: Endpoint, my_nat_type: NatType, my_udp_addr: &str, peer
129129
let udp_conn = udp.connect(peer_udp_addr.parse().unwrap(), "localhost").unwrap()
130130
.await.expect("无法连接UDP服务器");
131131
let (s, mut r) = udp_conn.accept_bi().await.expect("无法读取UDP数据");
132-
let mut buf = vec![0; 64];
133-
let le = r.read(&mut buf).await.unwrap().unwrap();
134-
let _hello = String::from_utf8_lossy(&buf[..le]).to_string();
132+
let mut buf = vec![0; 5];
133+
r.read_exact(&mut buf).await.unwrap();
134+
let _hello = String::from_utf8_lossy(&buf).to_string();
135+
// wtf!(_hello);
135136
// assert_eq!(_hello, "Hello");
136137
let a = tcp.split();
137138
let b = (s, r);

0 commit comments

Comments
 (0)