Fixing UDP protocol

This commit is contained in:
2026-08-26 14:31:14 +02:00
parent ccbe3c10f0
commit 4b7ef4e15b
+15 -20
View File
@@ -27,29 +27,24 @@ impl Server {
let pin_bytes: [u8; 8] = buf[..8].try_into().unwrap(); let pin_bytes: [u8; 8] = buf[..8].try_into().unwrap();
let pin = u64::from_be_bytes(pin_bytes); let pin = u64::from_be_bytes(pin_bytes);
let payload = &buf[8..len];
// Resolve the sender's identity + channel for this pin. // First packet carries the pin for authentication; subsequent packets
// First packet for a pin consumes it (single-use) and binds the address. // are raw audio identified by UDP address alone.
let sender = { let (sender_pubkey, channel_id, payload) = {
let mut pins = self.voice_pins.lock().await; let mut pins = self.voice_pins.lock().await;
if let Some((pubkey, channel_id)) = pins.remove(&pin) { if let Some((pubkey, channel_id)) = pins.remove(&pin) {
Some((pubkey, channel_id)) // First packet: pin consumed, strip 8-byte prefix
(pubkey, channel_id, &buf[8..len])
} else { } else {
None drop(pins);
// Not a first-time pin — match by address
match self.find_voice_sender(&addr).await {
Some((pubkey, channel_id)) => (pubkey, channel_id, &buf[..]),
None => continue,
}
} }
};
let (sender_pubkey, channel_id) = match sender {
Some(v) => v,
// Not a first-time pin — check if this addr is already a known
// voice participant, so we know who's speaking and where to relay.
None => match self.find_voice_sender(&addr).await {
Some(v) => v,
None => continue, // unknown pin, unknown addr — drop
},
}; };
let clients = self.clients.lock().await; let clients = self.clients.lock().await;
@@ -81,11 +76,11 @@ impl Server {
None None
} }
/// Sends `payload` to every other voice participant currently in `channel_id`. /// Sends `payload` to every voice participant currently in `channel_id`.
async fn relay_voice(&self, sender: &VerifyingKey, channel_id: &str, payload: &[u8]) { async fn relay_voice(&self, _sender: &VerifyingKey, channel_id: &str, payload: &[u8]) {
let clients = self.clients.lock().await; let clients = self.clients.lock().await;
for (pubkey, user) in clients.iter() { for (_pubkey, user) in clients.iter() {
// if pubkey == sender { // if pubkey == sender {
// continue; // continue;
// } // }