feat: return ip discovery data + minor update

This commit is contained in:
kozabrada123 2023-11-12 13:33:29 +01:00
parent 8e6eb9926e
commit 85ea88084e
2 changed files with 19 additions and 11 deletions

View File

@ -41,9 +41,9 @@ pub enum VoiceProtocol {
/// See <https://discord-userdoccers.vercel.app/topics/voice-connections#protocol-data-structure> /// See <https://discord-userdoccers.vercel.app/topics/voice-connections#protocol-data-structure>
pub struct SelectProtocolData { pub struct SelectProtocolData {
/// Our external ip /// Our external ip
pub address: Ipv4Addr, pub address: Vec<u8>,
/// Our external udp port /// Our external udp port
pub port: u32, pub port: u16,
/// The mode of encryption to use /// The mode of encryption to use
pub mode: VoiceEncryptionMode, pub mode: VoiceEncryptionMode,
} }
@ -51,7 +51,7 @@ pub struct SelectProtocolData {
impl Default for SelectProtocolData { impl Default for SelectProtocolData {
fn default() -> Self { fn default() -> Self {
SelectProtocolData { SelectProtocolData {
address: Ipv4Addr::UNSPECIFIED, address: Vec::new(),
port: 0, port: 0,
mode: Default::default(), mode: Default::default(),
} }

View File

@ -5,7 +5,10 @@ use std::net::SocketAddr;
use log::{info, warn}; use log::{info, warn};
use tokio::net::UdpSocket; use tokio::net::UdpSocket;
use discortp::{discord::IpDiscoveryPacket, MutablePacket, Packet}; use discortp::{
discord::{IpDiscovery, IpDiscoveryPacket},
MutablePacket, Packet,
};
#[derive(Debug)] #[derive(Debug)]
pub struct UdpHandler { pub struct UdpHandler {
@ -14,7 +17,7 @@ pub struct UdpHandler {
} }
impl 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 // 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(); let udp_socket = UdpSocket::bind("0.0.0.0:0").await.unwrap();
@ -77,6 +80,15 @@ impl UdpHandler {
tokio::spawn(async move { tokio::spawn(async move {
handler.listen_task().await; 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; /// The main listen task;
@ -99,12 +111,8 @@ impl UdpHandler {
continue; continue;
} }
if let Err(e) = msg { warn!("VUDP: Voice UDP is broken, closing connection");
warn!("VUDP: {:?}", e); break;
}
//warn!("VUDP: Voice UDP is broken, closing connection");
//break;
} }
} }