From 85ea88084eb098ad4ef33d7eca884b6671757534 Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Sun, 12 Nov 2023 13:33:29 +0100 Subject: [PATCH] feat: return ip discovery data + minor update --- src/types/events/webrtc/select_protocol.rs | 6 +++--- src/voice/udp.rs | 24 ++++++++++++++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/types/events/webrtc/select_protocol.rs b/src/types/events/webrtc/select_protocol.rs index 3cda068..6d57bbf 100644 --- a/src/types/events/webrtc/select_protocol.rs +++ b/src/types/events/webrtc/select_protocol.rs @@ -41,9 +41,9 @@ pub enum VoiceProtocol { /// See pub struct SelectProtocolData { /// Our external ip - pub address: Ipv4Addr, + pub address: Vec, /// Our external udp port - pub port: u32, + pub port: u16, /// The mode of encryption to use pub mode: VoiceEncryptionMode, } @@ -51,7 +51,7 @@ pub struct SelectProtocolData { impl Default for SelectProtocolData { fn default() -> Self { SelectProtocolData { - address: Ipv4Addr::UNSPECIFIED, + address: Vec::new(), port: 0, mode: Default::default(), } diff --git a/src/voice/udp.rs b/src/voice/udp.rs index b974add..7543f71 100644 --- a/src/voice/udp.rs +++ b/src/voice/udp.rs @@ -5,7 +5,10 @@ use std::net::SocketAddr; use log::{info, warn}; use tokio::net::UdpSocket; -use discortp::{discord::IpDiscoveryPacket, MutablePacket, Packet}; +use discortp::{ + discord::{IpDiscovery, IpDiscoveryPacket}, + MutablePacket, Packet, +}; #[derive(Debug)] pub struct UdpHandler { @@ -14,7 +17,7 @@ pub struct UdpHandler { } impl UdpHandler { - pub async fn new(url: SocketAddr, ssrc: u32) { + pub async fn new(url: SocketAddr, ssrc: u32) -> IpDiscovery { // Bind with a port number of 0, so the os assigns this listener a port let udp_socket = UdpSocket::bind("0.0.0.0:0").await.unwrap(); @@ -77,6 +80,15 @@ impl UdpHandler { tokio::spawn(async move { handler.listen_task().await; }); + + return IpDiscovery { + pkt_type: receieved_ip_discovery.get_pkt_type(), + length: receieved_ip_discovery.get_length(), + ssrc: receieved_ip_discovery.get_ssrc(), + address: receieved_ip_discovery.get_address(), + port: receieved_ip_discovery.get_port(), + payload: Vec::new(), + }; } /// The main listen task; @@ -99,12 +111,8 @@ impl UdpHandler { continue; } - if let Err(e) = msg { - warn!("VUDP: {:?}", e); - } - - //warn!("VUDP: Voice UDP is broken, closing connection"); - //break; + warn!("VUDP: Voice UDP is broken, closing connection"); + break; } }