[mio] 调整打洞策略

This commit is contained in:
lubeilin
2024-03-11 22:12:41 +08:00
parent e78994ceb4
commit 76b86bbd0f
2 changed files with 3 additions and 7 deletions
+2 -1
View File
@@ -453,7 +453,8 @@ impl RouteTable {
}
pub fn need_punch(&self, id: &Ipv4Addr) -> bool {
if let Some((_, v)) = self.route_table.read().get(id) {
if v.iter().filter(|(k, _)| k.is_p2p()).count() >= self.channel_num {
//存在p2p的通道则不再打洞
if v.iter().filter(|(k, _)| k.is_p2p()).count() >= 1 {
return false;
}
}
+1 -6
View File
@@ -350,11 +350,6 @@ impl Punch {
max: usize,
) -> io::Result<()> {
let mut count = 0;
let index = if self.context.channel_num() == 1 {
0
} else {
rand::thread_rng().gen_range(0..self.context.channel_num())
};
for port in ports {
for pub_ip in ips {
count += 1;
@@ -362,7 +357,7 @@ impl Punch {
return Ok(());
}
let addr = SocketAddr::V4(SocketAddrV4::new(*pub_ip, *port));
self.context.send_main_udp(index, buf, addr)?;
self.context.send_main_udp(0, buf, addr)?;
thread::sleep(Duration::from_millis(2));
}
}