Skip to content

Commit

Permalink
implement OnlineRequest for ws
Browse files Browse the repository at this point in the history
  • Loading branch information
IamTaoChen authored and tonylu00 committed Dec 6, 2024
1 parent b7f0165 commit 0e750ac
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/rendezvous_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,28 @@ impl RendezvousServer {
msg_out.set_test_nat_response(res);
Self::send_to_sink(sink, msg_out).await;
}
Some(rendezvous_message::Union::OnlineRequest(or)) => {
log::debug!("OnlineRequest payload={:?}", or);
// copy from function handle_online_request()
let mut states = BytesMut::zeroed((or.peers.len() + 7) / 8);
for (i, peer_id) in or.peers.iter().enumerate() {
if let Some(peer) = self.pm.get_in_memory(peer_id).await {
let elapsed = peer.read().await.last_reg_time.elapsed().as_millis() as i32;
// bytes index from left to right
let states_idx = i / 8;
let bit_idx = 7 - i % 8;
if elapsed < REG_TIMEOUT {
states[states_idx] |= 0x01 << bit_idx;
}
}
}
let mut msg_out = RendezvousMessage::new();
msg_out.set_online_response(OnlineResponse {
states: states.into(),
..Default::default()
});
Self::send_to_sink(sink, msg_out).await;
}
Some(rendezvous_message::Union::RegisterPk(rk)) => {
let response = self.handle_register_pk(rk, addr).await;
match response {
Expand Down

0 comments on commit 0e750ac

Please sign in to comment.