chore: clippy + other misc updates

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

View File

@ -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 <https://discord-userdoccers.vercel.app/topics/voice-connections#protocol-data-structure>
@ -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(),
}
}
}

View File

@ -192,12 +192,11 @@ pub struct VoiceGateway {
>,
websocket_receive: SplitStream<WebSocketStream<MaybeTlsStream<TcpStream>>>,
kill_send: tokio::sync::broadcast::Sender<()>,
url: String,
}
impl VoiceGateway {
#[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
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);
}
}
}

View File

@ -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<UdpSocket>,
}
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;
}
}