From a3ad3cce0baf1ef837d2a1121844522b21953d75 Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Sat, 16 Dec 2023 11:23:03 +0100 Subject: [PATCH] chore: clippy + other misc updates --- .../events/voice_gateway/select_protocol.rs | 14 +---------- src/voice/gateway.rs | 14 +++++------ src/voice/udp.rs | 25 ++++++++----------- 3 files changed, 17 insertions(+), 36 deletions(-) diff --git a/src/types/events/voice_gateway/select_protocol.rs b/src/types/events/voice_gateway/select_protocol.rs index 6d57bbf..38d674a 100644 --- a/src/types/events/voice_gateway/select_protocol.rs +++ b/src/types/events/voice_gateway/select_protocol.rs @@ -1,5 +1,3 @@ -use std::net::Ipv4Addr; - use serde::{Deserialize, Serialize}; use super::VoiceEncryptionMode; @@ -35,7 +33,7 @@ pub enum VoiceProtocol { //Webrtc, } -#[derive(Debug, Deserialize, Serialize, Clone)] +#[derive(Debug, Default, Deserialize, Serialize, Clone)] /// The data field of the SelectProtocol Event /// /// See @@ -47,13 +45,3 @@ pub struct SelectProtocolData { /// The mode of encryption to use pub mode: VoiceEncryptionMode, } - -impl Default for SelectProtocolData { - fn default() -> Self { - SelectProtocolData { - address: Vec::new(), - port: 0, - mode: Default::default(), - } - } -} diff --git a/src/voice/gateway.rs b/src/voice/gateway.rs index 8e66033..00bebe4 100644 --- a/src/voice/gateway.rs +++ b/src/voice/gateway.rs @@ -192,12 +192,11 @@ pub struct VoiceGateway { >, websocket_receive: SplitStream>>, kill_send: tokio::sync::broadcast::Sender<()>, - url: String, } impl VoiceGateway { #[allow(clippy::new_ret_no_self)] - pub async fn new(websocket_url: String) -> Result { + pub async fn spawn(websocket_url: String) -> Result { // Append the needed things to the websocket url let processed_url = format!("wss://{}/?v=7", websocket_url); trace!("Created voice socket url: {}", processed_url.clone()); @@ -269,7 +268,6 @@ impl VoiceGateway { websocket_send: shared_websocket_send.clone(), websocket_receive, 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 @@ -501,13 +499,13 @@ impl VoiceGateway { .unwrap(); } VOICE_IDENTIFY | VOICE_SELECT_PROTOCOL | VOICE_RESUME => { - let error = VoiceGatewayError::UnexpectedOpcodeReceived { - opcode: gateway_payload.op_code, - }; - Err::<(), VoiceGatewayError>(error).unwrap(); + info!( + "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 + ); } _ => { - 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); } } } diff --git a/src/voice/udp.rs b/src/voice/udp.rs index b12b431..29b690b 100644 --- a/src/voice/udp.rs +++ b/src/voice/udp.rs @@ -3,13 +3,12 @@ use std::{net::SocketAddr, sync::Arc}; use log::{info, warn}; -use tokio::{net::UdpSocket, sync::Mutex}; +use tokio::net::UdpSocket; use discortp::{ demux::{demux, Demuxed}, - discord::{IpDiscovery, IpDiscoveryPacket}, - rtp::RtpPacket, - MutablePacket, Packet, + discord::{IpDiscovery, IpDiscoveryPacket, IpDiscoveryType, MutableIpDiscoveryPacket}, + Packet, }; /// Handle to a voice udp connection @@ -24,20 +23,19 @@ pub struct UdpHandle { #[derive(Debug)] pub struct UdpHandler { - url: SocketAddr, socket: Arc, } 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 let udp_socket = UdpSocket::bind("0.0.0.0:0").await.unwrap(); udp_socket.connect(url).await.unwrap(); // First perform ip discovery - let ip_discovery = discortp::discord::IpDiscovery { - pkt_type: discortp::discord::IpDiscoveryType::Request, + let ip_discovery = IpDiscovery { + pkt_type: IpDiscoveryType::Request, ssrc, length: 70, address: Vec::new(), @@ -54,8 +52,8 @@ impl UdpHandler { } // TODO: Make this not panic everything - let mut ip_discovery_packet = discortp::discord::MutableIpDiscoveryPacket::new(&mut buf) - .expect("Mangled ip discovery packet"); + let mut ip_discovery_packet = + MutableIpDiscoveryPacket::new(&mut buf).expect("Mangled ip discovery packet"); ip_discovery_packet.populate(&ip_discovery); @@ -63,7 +61,7 @@ impl UdpHandler { info!("VUDP: Sending Ip Discovery {:?}", &data); - udp_socket.send(&data).await.unwrap(); + udp_socket.send(data).await.unwrap(); info!("VUDP: Sent packet discovery request"); @@ -76,7 +74,7 @@ impl UdpHandler { receieved_size ); - let receieved_ip_discovery = discortp::discord::IpDiscoveryPacket::new(&buf).unwrap(); + let receieved_ip_discovery = IpDiscoveryPacket::new(&buf).unwrap(); info!( "VUDP: Received ip discovery!!! {:?}", @@ -86,7 +84,6 @@ impl UdpHandler { let socket = Arc::new(udp_socket); let mut handler = UdpHandler { - url, socket: socket.clone(), }; @@ -153,7 +150,5 @@ impl UdpHandler { unreachable!() } } - - return; } }