Skip to content

Commit

Permalink
fix listener may have no mapped addr (EasyTier#389)
Browse files Browse the repository at this point in the history
  • Loading branch information
KKRainbow authored Oct 7, 2024
1 parent 37ceb77 commit d4e59ff
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
16 changes: 13 additions & 3 deletions easytier/src/connector/udp_hole_punch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -499,17 +499,27 @@ impl PunchHoleServerCommon {
use_last = true;
}

let locked = all_listener_sockets.lock().await;
let mut locked = all_listener_sockets.lock().await;

let listener = if use_last {
locked.last()?
locked.last_mut()?
} else {
// use the listener that is active most recently
locked
.iter()
.iter_mut()
.max_by_key(|listener| listener.last_active_time.load())?
};

if listener.mapped_addr.ip().is_unspecified() {
tracing::info!("listener mapped addr is unspecified, trying to get mapped addr");
listener.mapped_addr = self
.get_global_ctx()
.get_stun_info_collector()
.get_udp_port_mapping(listener.mapped_addr.port())
.await
.ok()?;
}

Some((listener.get_socket().await, listener.mapped_addr))
}

Expand Down
4 changes: 1 addition & 3 deletions easytier/src/peers/peer_conn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,7 @@ impl PeerConn {
tracing::error!(?e, "peer conn send ctrl resp error");
}
} else {
if zc_packet.is_lossy() {
let _ = sender.try_send(zc_packet);
} else if sender.send(zc_packet).await.is_err() {
if sender.send(zc_packet).await.is_err() {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion easytier/src/peers/peer_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl PeerManager {
) -> Self {
let my_peer_id = rand::random();

let (packet_send, packet_recv) = mpsc::channel(100);
let (packet_send, packet_recv) = mpsc::channel(128);
let peers = Arc::new(PeerMap::new(
packet_send.clone(),
global_ctx.clone(),
Expand Down

0 comments on commit d4e59ff

Please sign in to comment.