Skip to content

Commit

Permalink
Driver, Gateway: Remove tokio 0.2 support (#118)
Browse files Browse the repository at this point in the history
* Remove tokio 0.2 compat
* Remove tokio 0.2 test
* Remove tokio 0.2 CI
  • Loading branch information
GnomedDev authored and FelixMcFelix committed Jul 22, 2022
1 parent fac6664 commit f2cd8a0
Show file tree
Hide file tree
Showing 21 changed files with 1 addition and 175 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,6 @@ jobs:
- name: gateway only
features: serenity-rustls
dont-test: true
- name: legacy tokio
features: serenity-rustls-tokio-02 driver-tokio-02
dont-test: true

steps:
- name: Checkout sources
Expand Down
39 changes: 0 additions & 39 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ features = ["tokio-runtime"]
optional = true
version = "0.14"

[dependencies.async-tungstenite-compat]
package = "async-tungstenite"
default-features = false
features = ["tokio-runtime"]
optional = true
version = "0.9"

[dependencies.audiopus]
optional = true
version = "0.2"
Expand Down Expand Up @@ -97,12 +90,6 @@ optional = true
version = "1.0"
default-features = false

[dependencies.tokio-compat]
optional = true
package = "tokio"
version = "0.2"
default-features = false

[dependencies.twilight-gateway]
optional = true
version = ">=0.9.0, <0.11.0"
Expand Down Expand Up @@ -195,32 +182,6 @@ serenity-deps = ["async-trait"]
rustls-marker = []
native-marker = []

# Tokio 0.2 Compatibility features
# These should probably be dropped around the same time as serenity drop them.
rustls-tokio-02 = ["async-tungstenite-compat/tokio-rustls", "rustls-marker", "tokio-02-marker"]
native-tokio-02 = ["async-tungstenite-compat/tokio-native-tls", "native-marker", "tokio-02-marker"]
serenity-rustls-tokio-02 = ["serenity/rustls_tokio_0_2_backend", "rustls-tokio-02", "gateway-tokio-02", "serenity-deps"]
serenity-native-tokio-02 = ["serenity/native_tls_tokio_0_2_backend", "native-tokio-02", "gateway-tokio-02", "serenity-deps"]
gateway-tokio-02 = [
"gateway-core",
"tokio-02-marker",
"tokio-compat/sync",
]
driver-tokio-02 = [
"async-tungstenite-compat",
"driver-core",
"tokio-02-marker",
"tokio-compat/fs",
"tokio-compat/io-util",
"tokio-compat/macros",
"tokio-compat/net",
"tokio-compat/process",
"tokio-compat/rt-core",
"tokio-compat/sync",
"tokio-compat/time",
]
tokio-02-marker = []

# Behaviour altering features.
youtube-dlc = []
yt-dlp = []
Expand Down
7 changes: 1 addition & 6 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@ args = ["build", "--no-default-features", "--features", "driver,rustls"]
command = "cargo"
dependencies = ["format"]

[tasks.build-old-tokio]
command = "cargo"
args = ["build", "--no-default-features", "--features", "serenity-rustls-tokio-02,driver-tokio-02"]
dependencies = ["format"]

[tasks.build-variants]
dependencies = ["build", "build-gateway", "build-driver", "build-old-tokio"]
dependencies = ["build", "build-gateway", "build-driver"]

[tasks.clippy]
args = ["clippy", "--features", "full-doc", "--", "-D", "warnings"]
Expand Down
3 changes: 0 additions & 3 deletions src/driver/connection/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ use crate::{
use flume::SendError;
use serde_json::Error as JsonError;
use std::{error::Error as StdError, fmt, io::Error as IoError};
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::time::error::Elapsed;
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::time::Elapsed;
use xsalsa20poly1305::aead::Error as CryptoError;

/// Errors encountered while connecting to a Discord voice server over the driver.
Expand Down
10 changes: 0 additions & 10 deletions src/driver/connection/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ use discortp::discord::{IpDiscoveryPacket, IpDiscoveryType, MutableIpDiscoveryPa
use error::{Error, Result};
use flume::Sender;
use std::{net::IpAddr, str::FromStr, sync::Arc};
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::{net::UdpSocket, spawn, time::timeout};
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::{net::UdpSocket, spawn, time::timeout};
use tracing::{debug, info, instrument};
use url::Url;
use xsalsa20poly1305::{aead::NewAead, XSalsa20Poly1305 as Cipher};
Expand Down Expand Up @@ -115,11 +112,7 @@ impl Connection {
return Err(Error::CryptoModeUnavailable);
}

#[cfg(not(feature = "tokio-02-marker"))]
let udp = UdpSocket::bind("0.0.0.0:0").await?;
#[cfg(feature = "tokio-02-marker")]
let mut udp = UdpSocket::bind("0.0.0.0:0").await?;

udp.connect((ready.ip, ready.port)).await?;

// Follow Discord's IP Discovery procedures, in case NAT tunnelling is needed.
Expand Down Expand Up @@ -184,14 +177,11 @@ impl Connection {
let (udp_sender_msg_tx, udp_sender_msg_rx) = flume::unbounded();
let (udp_receiver_msg_tx, udp_receiver_msg_rx) = flume::unbounded();

#[cfg(not(feature = "tokio-02-marker"))]
let (udp_rx, udp_tx) = {
let udp_rx = Arc::new(udp);
let udp_tx = Arc::clone(&udp_rx);
(udp_rx, udp_tx)
};
#[cfg(feature = "tokio-02-marker")]
let (udp_rx, udp_tx) = udp.split();

let ssrc = ready.ssrc;

Expand Down
3 changes: 0 additions & 3 deletions src/driver/tasks/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ mod ws;
pub use self::{core::*, disposal::*, events::*, mixer::*, udp_rx::*, udp_tx::*, ws::*};

use flume::Sender;
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::spawn;
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::spawn;
use tracing::trace;

#[derive(Clone, Debug)]
Expand Down
3 changes: 0 additions & 3 deletions src/driver/tasks/mixer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ use flume::{Receiver, Sender, TryRecvError};
use rand::random;
use spin_sleep::SpinSleeper;
use std::time::Instant;
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::runtime::Handle;
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::runtime::Handle;
use tracing::{debug, error, instrument};
use xsalsa20poly1305::TAG_SIZE;

Expand Down
3 changes: 0 additions & 3 deletions src/driver/tasks/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ use crate::{
};
use flume::{Receiver, RecvError, Sender};
use message::*;
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::{runtime::Handle, spawn, time::sleep as tsleep};
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::{runtime::Handle, spawn, time::delay_for as tsleep};
use tracing::{debug, instrument, trace};

pub(crate) fn start(config: Config, rx: Receiver<CoreMessage>, tx: Sender<CoreMessage>) {
Expand Down
32 changes: 0 additions & 32 deletions src/driver/tasks/udp_rx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ use discortp::{
};
use flume::Receiver;
use std::{collections::HashMap, sync::Arc};
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::{net::UdpSocket, select};
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::{net::udp::RecvHalf, select};
use tracing::{error, instrument, trace, warn};
use xsalsa20poly1305::XSalsa20Poly1305 as Cipher;

Expand Down Expand Up @@ -241,10 +238,7 @@ struct UdpRx {
packet_buffer: [u8; VOICE_PACKET_MAX],
rx: Receiver<UdpRxMessage>,

#[cfg(not(feature = "tokio-02-marker"))]
udp_socket: Arc<UdpSocket>,
#[cfg(feature = "tokio-02-marker")]
udp_socket: RecvHalf,
}

impl UdpRx {
Expand Down Expand Up @@ -396,7 +390,6 @@ impl UdpRx {
}
}

#[cfg(not(feature = "tokio-02-marker"))]
#[instrument(skip(interconnect, rx, cipher))]
pub(crate) async fn runner(
mut interconnect: Interconnect,
Expand All @@ -421,31 +414,6 @@ pub(crate) async fn runner(
trace!("UDP receive handle stopped.");
}

#[cfg(feature = "tokio-02-marker")]
#[instrument(skip(interconnect, rx, cipher))]
pub(crate) async fn runner(
mut interconnect: Interconnect,
rx: Receiver<UdpRxMessage>,
cipher: Cipher,
config: Config,
udp_socket: RecvHalf,
) {
trace!("UDP receive handle started.");

let mut state = UdpRx {
cipher,
decoder_map: Default::default(),
config,
packet_buffer: [0u8; VOICE_PACKET_MAX],
rx,
udp_socket,
};

state.run(&mut interconnect).await;

trace!("UDP receive handle stopped.");
}

#[inline]
fn rtp_valid(packet: RtpPacket<'_>) -> bool {
packet.get_version() == RTP_VERSION && packet.get_payload_type() == RTP_PROFILE_TYPE
Expand Down
26 changes: 0 additions & 26 deletions src/driver/tasks/udp_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,17 @@ use crate::constants::*;
use discortp::discord::MutableKeepalivePacket;
use flume::Receiver;
use std::sync::Arc;
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::{
net::UdpSocket,
time::{timeout_at, Instant},
};
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::{
net::udp::SendHalf,
time::{timeout_at, Instant},
};
use tracing::{error, instrument, trace};

struct UdpTx {
ssrc: u32,
rx: Receiver<UdpTxMessage>,

#[cfg(not(feature = "tokio-02-marker"))]
udp_tx: Arc<UdpSocket>,
#[cfg(feature = "tokio-02-marker")]
udp_tx: SendHalf,
}

impl UdpTx {
Expand Down Expand Up @@ -62,7 +53,6 @@ impl UdpTx {
}
}

#[cfg(not(feature = "tokio-02-marker"))]
#[instrument(skip(udp_msg_rx))]
pub(crate) async fn runner(udp_msg_rx: Receiver<UdpTxMessage>, ssrc: u32, udp_tx: Arc<UdpSocket>) {
trace!("UDP transmit handle started.");
Expand All @@ -77,19 +67,3 @@ pub(crate) async fn runner(udp_msg_rx: Receiver<UdpTxMessage>, ssrc: u32, udp_tx

trace!("UDP transmit handle stopped.");
}

#[cfg(feature = "tokio-02-marker")]
#[instrument(skip(udp_msg_rx))]
pub(crate) async fn runner(udp_msg_rx: Receiver<UdpTxMessage>, ssrc: u32, udp_tx: SendHalf) {
trace!("UDP transmit handle started.");

let mut txer = UdpTx {
ssrc,
rx: udp_msg_rx,
udp_tx,
};

txer.run().await;

trace!("UDP transmit handle stopped.");
}
9 changes: 0 additions & 9 deletions src/driver/tasks/ws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,14 @@ use crate::{
ws::{Error as WsError, ReceiverExt, SenderExt, WsStream},
ConnectionInfo,
};
#[cfg(not(feature = "tokio-02-marker"))]
use async_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
#[cfg(feature = "tokio-02-marker")]
use async_tungstenite_compat::tungstenite::protocol::frame::coding::CloseCode;
use flume::Receiver;
use rand::random;
use std::time::Duration;
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::{
select,
time::{sleep_until, Instant},
};
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::{
select,
time::{delay_until as sleep_until, Instant},
};
use tracing::{debug, info, instrument, trace, warn};

struct AuxNetwork {
Expand Down
3 changes: 0 additions & 3 deletions src/events/context/data/disconnect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use crate::{
model::{CloseCode as VoiceCloseCode, FromPrimitive},
ws::Error as WsError,
};
#[cfg(not(feature = "tokio-02-marker"))]
use async_tungstenite::tungstenite::protocol::frame::coding::CloseCode;
#[cfg(feature = "tokio-02-marker")]
use async_tungstenite_compat::tungstenite::protocol::frame::coding::CloseCode;

/// Voice connection details gathered at termination or failure.
///
Expand Down
3 changes: 0 additions & 3 deletions src/input/child.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ use std::{
mem,
process::Child,
};
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::runtime::Handle;
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::runtime::Handle;
use tracing::debug;

/// Handle for a child process which ensures that any subprocesses are properly closed
Expand Down
3 changes: 0 additions & 3 deletions src/input/dca.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
use super::{codec::OpusDecoderState, error::DcaError, Codec, Container, Input, Metadata, Reader};
use serde::Deserialize;
use std::{ffi::OsStr, mem};
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::{fs::File as TokioFile, io::AsyncReadExt};
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::{fs::File as TokioFile, io::AsyncReadExt};

/// Creates a streamed audio source from a DCA file.
/// Currently only accepts the [DCA1 format](https://github.com/bwmarrin/dca).
Expand Down
3 changes: 0 additions & 3 deletions src/input/ffmpeg_src.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use std::{
ffi::OsStr,
process::{Command, Stdio},
};
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::process::Command as TokioCommand;
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::process::Command as TokioCommand;
use tracing::debug;

/// Opens an audio file through `ffmpeg` and creates an audio source.
Expand Down
3 changes: 0 additions & 3 deletions src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ use audiopus::coder::GenericCtl;
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
use cached::OpusCompressor;
use error::{Error, Result};
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::runtime::Handle;
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::runtime::Handle;

use std::{
convert::TryFrom,
Expand Down
3 changes: 0 additions & 3 deletions src/input/ytdl_src.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ use std::{
io::{BufRead, BufReader, Read},
process::{Command, Stdio},
};
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::{process::Command as TokioCommand, task};
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::{process::Command as TokioCommand, task};
use tracing::trace;

const YOUTUBE_DL_COMMAND: &str = if cfg!(feature = "youtube-dlc") {
Expand Down
3 changes: 0 additions & 3 deletions src/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ use core::{
};
use flume::r#async::RecvFut;
use pin_project::pin_project;
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::time::{self, Timeout};
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::time::{self, Timeout};

#[cfg(feature = "driver-core")]
/// Future for a call to [`Call::join`].
Expand Down
3 changes: 0 additions & 3 deletions src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@ use serenity::{
},
};
use std::sync::Arc;
#[cfg(not(feature = "tokio-02-marker"))]
use tokio::sync::Mutex;
#[cfg(feature = "tokio-02-marker")]
use tokio_compat::sync::Mutex;
use tracing::debug;
#[cfg(feature = "twilight")]
use twilight_gateway::Cluster;
Expand Down
Loading

0 comments on commit f2cd8a0

Please sign in to comment.