diff options
-rw-r--r-- | Cargo.toml | 2 | ||||
m--------- | libs/hbb_common | 0 | ||||
-rw-r--r-- | src/rendezvous_server.rs | 22 |
3 files changed, 18 insertions, 6 deletions
@@ -17,5 +17,5 @@ simple-error = "0.2" hbb_common = { path = "libs/hbb_common" } [workspace] -members = ['libs/hbb_common'] +members = ["libs/hbb_common"] diff --git a/libs/hbb_common b/libs/hbb_common -Subproject 938076d06af0efa532ce2372a051ae69f213672 +Subproject a9536bcc127a9d8057a9b7ffbe486506a7b963d diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index a37c278..396f896 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -60,16 +60,27 @@ impl RendezvousServer { ); } } - Some(Message_oneof_union::peek_peer(pp)) => { - if let Some(peer) = self.peer_map.get(&pp.hbb_addr) { + Some(Message_oneof_union::punch_hole_request(ph)) => { + // punch hole request from A, forward to B + if let Some(peer) = self.peer_map.get(&ph.hbb_addr) { let mut msg_out = Message::new(); - msg_out.set_peek_peer_response(PeekPeerResponse { + msg_out.set_punch_hole(PunchHole { socket_addr: V4AddrMangle::encode(&peer.socket_addr), ..Default::default() }); send_to(&msg_out, addr, socket).await?; } } + Some(Message_oneof_union::punch_hole_sent(phs)) => { + // punch hole sent from B, tell A that B ready + let addr_a = V4AddrMangle::decode(&phs.socket_addr); + let mut msg_out = Message::new(); + msg_out.set_punch_hole_response(PunchHoleResponse { + socket_addr: V4AddrMangle::encode(&addr_v4), + ..Default::default() + }); + send_to(&msg_out, SocketAddr::V4(addr_a), socket).await?; + } _ => {} } } @@ -86,6 +97,7 @@ pub async fn send_to(msg: &Message, addr: SocketAddr, socket: &mut FramedSocket) Ok(()) } +#[inline] pub async fn sleep(sec: f32) { delay_for(Duration::from_secs_f32(sec)).await; } @@ -110,7 +122,7 @@ mod tests { ..Default::default() }); send_to(&msg_out, to_addr, &mut socket).await; - msg_out.set_peek_peer(PeekPeer { + msg_out.set_punch_hole_request(PunchHoleRequest { hbb_addr: "123".to_string(), ..Default::default() }); @@ -122,7 +134,7 @@ mod tests { assert_eq!( local_addr, SocketAddr::V4(V4AddrMangle::decode( - &msg_in.get_peek_peer_response().socket_addr[..] + &msg_in.get_punch_hole_response().socket_addr[..] )) ); } |