mirror of
https://github.com/rustdesk/rustdesk-server.git
synced 2024-11-24 04:12:34 +08:00
working on punch hole protocol
This commit is contained in:
parent
d5e55b33d5
commit
52ea29bb94
@ -17,5 +17,5 @@ simple-error = "0.2"
|
||||
hbb_common = { path = "libs/hbb_common" }
|
||||
|
||||
[workspace]
|
||||
members = ['libs/hbb_common']
|
||||
members = ["libs/hbb_common"]
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 938076d06af0efa532ce2372a051ae69f2136720
|
||||
Subproject commit a9536bcc127a9d8057a9b7ffbe486506a7b963de
|
@ -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[..]
|
||||
))
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user