chore: clippy + other misc updates

This commit is contained in:
kozabrada123 2023-12-16 11:23:03 +01:00
parent 4ee96f53d5
commit 9a86282c9b
3 changed files with 17 additions and 36 deletions

View File

@ -1,5 +1,3 @@
use std::net::Ipv4Addr;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use super::VoiceEncryptionMode; use super::VoiceEncryptionMode;
@ -35,7 +33,7 @@ pub enum VoiceProtocol {
//Webrtc, //Webrtc,
} }
#[derive(Debug, Deserialize, Serialize, Clone)] #[derive(Debug, Default, Deserialize, Serialize, Clone)]
/// The data field of the SelectProtocol Event /// The data field of the SelectProtocol Event
/// ///
/// See <https://discord-userdoccers.vercel.app/topics/voice-connections#protocol-data-structure> /// See <https://discord-userdoccers.vercel.app/topics/voice-connections#protocol-data-structure>
@ -47,13 +45,3 @@ pub struct SelectProtocolData {
/// The mode of encryption to use /// The mode of encryption to use
pub mode: VoiceEncryptionMode, pub mode: VoiceEncryptionMode,
} }
impl Default for SelectProtocolData {
fn default() -> Self {
SelectProtocolData {
address: Vec::new(),
port: 0,
mode: Default::default(),
}
}
}

View File

@ -192,12 +192,11 @@ pub struct VoiceGateway {
>, >,
websocket_receive: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>, websocket_receive: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
kill_send: tokio::sync::broadcast::Sender<()>, kill_send: tokio::sync::broadcast::Sender<()>,
url: String,
} }
impl VoiceGateway { impl VoiceGateway {
#[allow(clippy::new_ret_no_self)] #[allow(clippy::new_ret_no_self)]
pub async fn new(websocket_url: String) -> Result<VoiceGatewayHandle, VoiceGatewayError> { pub async fn spawn(websocket_url: String) -> Result<VoiceGatewayHandle, VoiceGatewayError> {
// Append the needed things to the websocket url // Append the needed things to the websocket url
let processed_url = format!("wss://{}/?v=7", websocket_url); let processed_url = format!("wss://{}/?v=7", websocket_url);
trace!("Created voice socket url: {}", processed_url.clone()); trace!("Created voice socket url: {}", processed_url.clone());
@ -269,7 +268,6 @@ impl VoiceGateway {
websocket_send: shared_websocket_send.clone(), websocket_send: shared_websocket_send.clone(),
websocket_receive, websocket_receive,
kill_send: kill_send.clone(), kill_send: kill_send.clone(),
url: websocket_url.clone(),
}; };
// Now we can continuously check for messages in a different task, since we aren't going to receive another hello // Now we can continuously check for messages in a different task, since we aren't going to receive another hello
@ -501,13 +499,13 @@ impl VoiceGateway {
.unwrap(); .unwrap();
} }
VOICE_IDENTIFY | VOICE_SELECT_PROTOCOL | VOICE_RESUME => { VOICE_IDENTIFY | VOICE_SELECT_PROTOCOL | VOICE_RESUME => {
let error = VoiceGatewayError::UnexpectedOpcodeReceived { info!(
opcode: gateway_payload.op_code, "VGW: Received unexpected opcode ({}) for current state. This might be due to a faulty server implementation and is likely not the fault of chorus.",
}; gateway_payload.op_code
Err::<(), VoiceGatewayError>(error).unwrap(); );
} }
_ => { _ => {
warn!("Received unrecognized voice gateway op code ({})! Please open an issue on the chorus github so we can implement it", gateway_payload.op_code); warn!("VGW: Received unrecognized voice gateway op code ({})! Please open an issue on the chorus github so we can implement it", gateway_payload.op_code);
} }
} }
} }

View File

@ -3,13 +3,12 @@
use std::{net::SocketAddr, sync::Arc}; use std::{net::SocketAddr, sync::Arc};
use log::{info, warn}; use log::{info, warn};
use tokio::{net::UdpSocket, sync::Mutex}; use tokio::net::UdpSocket;
use discortp::{ use discortp::{
demux::{demux, Demuxed}, demux::{demux, Demuxed},
discord::{IpDiscovery, IpDiscoveryPacket}, discord::{IpDiscovery, IpDiscoveryPacket, IpDiscoveryType, MutableIpDiscoveryPacket},
rtp::RtpPacket, Packet,
MutablePacket, Packet,
}; };
/// Handle to a voice udp connection /// Handle to a voice udp connection
@ -24,20 +23,19 @@ pub struct UdpHandle {
#[derive(Debug)] #[derive(Debug)]
pub struct UdpHandler { pub struct UdpHandler {
url: SocketAddr,
socket: Arc<UdpSocket>, socket: Arc<UdpSocket>,
} }
impl UdpHandler { impl UdpHandler {
pub async fn new(url: SocketAddr, ssrc: u32) -> UdpHandle { pub async fn spawn(url: SocketAddr, ssrc: u32) -> UdpHandle {
// 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();
udp_socket.connect(url).await.unwrap(); udp_socket.connect(url).await.unwrap();
// First perform ip discovery // First perform ip discovery
let ip_discovery = discortp::discord::IpDiscovery { let ip_discovery = IpDiscovery {
pkt_type: discortp::discord::IpDiscoveryType::Request, pkt_type: IpDiscoveryType::Request,
ssrc, ssrc,
length: 70, length: 70,
address: Vec::new(), address: Vec::new(),
@ -54,8 +52,8 @@ impl UdpHandler {
} }
// TODO: Make this not panic everything // TODO: Make this not panic everything
let mut ip_discovery_packet = discortp::discord::MutableIpDiscoveryPacket::new(&mut buf) let mut ip_discovery_packet =
.expect("Mangled ip discovery packet"); MutableIpDiscoveryPacket::new(&mut buf).expect("Mangled ip discovery packet");
ip_discovery_packet.populate(&ip_discovery); ip_discovery_packet.populate(&ip_discovery);
@ -63,7 +61,7 @@ impl UdpHandler {
info!("VUDP: Sending Ip Discovery {:?}", &data); info!("VUDP: Sending Ip Discovery {:?}", &data);
udp_socket.send(&data).await.unwrap(); udp_socket.send(data).await.unwrap();
info!("VUDP: Sent packet discovery request"); info!("VUDP: Sent packet discovery request");
@ -76,7 +74,7 @@ impl UdpHandler {
receieved_size receieved_size
); );
let receieved_ip_discovery = discortp::discord::IpDiscoveryPacket::new(&buf).unwrap(); let receieved_ip_discovery = IpDiscoveryPacket::new(&buf).unwrap();
info!( info!(
"VUDP: Received ip discovery!!! {:?}", "VUDP: Received ip discovery!!! {:?}",
@ -86,7 +84,6 @@ impl UdpHandler {
let socket = Arc::new(udp_socket); let socket = Arc::new(udp_socket);
let mut handler = UdpHandler { let mut handler = UdpHandler {
url,
socket: socket.clone(), socket: socket.clone(),
}; };
@ -153,7 +150,5 @@ impl UdpHandler {
unreachable!() unreachable!()
} }
} }
return;
} }
} }