aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authoropen-trade <[email protected]>2020-03-09 13:55:12 +0800
committeropen-trade <[email protected]>2020-03-09 13:55:12 +0800
commit52ea29bb94a5e91842628d3351f302255edb5646 (patch)
tree58cc865c7c8f43fff8f890a6649ea3bb55610f69 /src
parentd5e55b33d57beb374984c2c4288835ee4773c11f (diff)
downloadrustdesk-server-52ea29bb94a5e91842628d3351f302255edb5646.tar.gz
rustdesk-server-52ea29bb94a5e91842628d3351f302255edb5646.zip
working on punch hole protocol
Diffstat (limited to 'src')
-rw-r--r--src/rendezvous_server.rs22
1 files changed, 17 insertions, 5 deletions
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[..]
))
);
}