[mio] 调整打洞策略
This commit is contained in:
@@ -453,7 +453,8 @@ impl RouteTable {
|
|||||||
}
|
}
|
||||||
pub fn need_punch(&self, id: &Ipv4Addr) -> bool {
|
pub fn need_punch(&self, id: &Ipv4Addr) -> bool {
|
||||||
if let Some((_, v)) = self.route_table.read().get(id) {
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -350,11 +350,6 @@ impl Punch {
|
|||||||
max: usize,
|
max: usize,
|
||||||
) -> io::Result<()> {
|
) -> io::Result<()> {
|
||||||
let mut count = 0;
|
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 port in ports {
|
||||||
for pub_ip in ips {
|
for pub_ip in ips {
|
||||||
count += 1;
|
count += 1;
|
||||||
@@ -362,7 +357,7 @@ impl Punch {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let addr = SocketAddr::V4(SocketAddrV4::new(*pub_ip, *port));
|
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));
|
thread::sleep(Duration::from_millis(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user