From f5c5e1cc5ec9c3bf281a2ee37e06df9c1a9f31df Mon Sep 17 00:00:00 2001 From: kozabrada123 <59031733+kozabrada123@users.noreply.github.com> Date: Thu, 16 Nov 2023 10:17:45 +0100 Subject: [PATCH] fix: voice works again --- src/gateway/heartbeat.rs | 2 +- src/gateway/mod.rs | 2 +- src/voice/gateway.rs | 16 ++++++++++++---- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/gateway/heartbeat.rs b/src/gateway/heartbeat.rs index dd162b7..00fa090 100644 --- a/src/gateway/heartbeat.rs +++ b/src/gateway/heartbeat.rs @@ -3,7 +3,7 @@ use crate::types; use super::*; /// The amount of time we wait for a heartbeat ack before resending our heartbeat in ms -const HEARTBEAT_ACK_TIMEOUT: u64 = 2000; +pub const HEARTBEAT_ACK_TIMEOUT: u64 = 2000; /// Handles sending heartbeats to the gateway in another thread #[allow(dead_code)] // FIXME: Remove this, once HeartbeatHandler is used diff --git a/src/gateway/mod.rs b/src/gateway/mod.rs index ebd06cc..3a14a23 100644 --- a/src/gateway/mod.rs +++ b/src/gateway/mod.rs @@ -128,7 +128,7 @@ impl GatewayEvent { } /// Notifies the observers of the GatewayEvent. - async fn notify(&self, new_event_data: T) { + pub(crate) async fn notify(&self, new_event_data: T) { for observer in &self.observers { observer.update(&new_event_data).await; } diff --git a/src/voice/gateway.rs b/src/voice/gateway.rs index edca815..ec6019d 100644 --- a/src/voice/gateway.rs +++ b/src/voice/gateway.rs @@ -2,7 +2,6 @@ use futures_util::stream::{SplitSink, SplitStream}; use futures_util::SinkExt; use futures_util::StreamExt; use log::{debug, info, trace, warn}; -use native_tls::TlsConnector; use serde_json::json; use std::sync::Arc; use std::time::Duration; @@ -16,7 +15,7 @@ use tokio_tungstenite::MaybeTlsStream; use tokio_tungstenite::{connect_async_tls_with_config, Connector, WebSocketStream}; use crate::errors::VoiceGatewayError; -use crate::gateway::{GatewayEvent, HEARTBEAT_ACK_TIMEOUT}; +use crate::gateway::{heartbeat::HEARTBEAT_ACK_TIMEOUT, GatewayEvent}; use crate::types::{ self, SelectProtocol, Speaking, VoiceGatewayReceivePayload, VoiceGatewaySendPayload, VoiceIdentify, WebSocketEvent, VOICE_BACKEND_VERSION, VOICE_CLIENT_CONNECT_FLAGS, @@ -203,12 +202,21 @@ impl VoiceGateway { let processed_url = format!("wss://{}/?v=7", websocket_url); trace!("Created voice socket url: {}", processed_url.clone()); + let mut roots = rustls::RootCertStore::empty(); + for cert in rustls_native_certs::load_native_certs().expect("could not load platform certs") + { + roots.add(&rustls::Certificate(cert.0)).unwrap(); + } let (websocket_stream, _) = match connect_async_tls_with_config( &processed_url, None, false, - Some(Connector::NativeTls( - TlsConnector::builder().build().unwrap(), + Some(Connector::Rustls( + rustls::ClientConfig::builder() + .with_safe_defaults() + .with_root_certificates(roots) + .with_no_client_auth() + .into(), )), ) .await