Songbird: Tokio 1.0 (#36)

Migrates to the new version of tokio, requiring channel and sleep changes in a few locations. Additionally points to the in-tree v0.3 version of twilight.
This commit is contained in:
Kyle Simpson
2021-01-06 13:01:14 +00:00
committed by GitHub
parent d42e09f72b
commit f05b7414a0
14 changed files with 57 additions and 49 deletions

View File

@@ -18,7 +18,7 @@ use crate::{
use discortp::discord::{IpDiscoveryPacket, IpDiscoveryType, MutableIpDiscoveryPacket};
use error::{Error, Result};
use flume::Sender;
use std::{net::IpAddr, str::FromStr};
use std::{net::IpAddr, str::FromStr, sync::Arc};
use tokio::net::UdpSocket;
use tracing::{debug, info, instrument};
use url::Url;
@@ -97,7 +97,7 @@ impl Connection {
return Err(Error::CryptoModeUnavailable);
}
let mut udp = UdpSocket::bind("0.0.0.0:0").await?;
let 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.
@@ -161,7 +161,9 @@ impl Connection {
let (ws_msg_tx, ws_msg_rx) = flume::unbounded();
let (udp_sender_msg_tx, udp_sender_msg_rx) = flume::unbounded();
let (udp_receiver_msg_tx, udp_receiver_msg_rx) = flume::unbounded();
let (udp_rx, udp_tx) = udp.split();
let udp_rx = Arc::new(udp);
let udp_tx = Arc::clone(&udp_rx);
let ssrc = ready.ssrc;

View File

@@ -20,8 +20,8 @@ use discortp::{
PacketSize,
};
use flume::Receiver;
use std::collections::HashMap;
use tokio::net::udp::RecvHalf;
use std::{collections::HashMap, sync::Arc};
use tokio::net::UdpSocket;
use tracing::{error, info, instrument, warn};
use xsalsa20poly1305::XSalsa20Poly1305 as Cipher;
@@ -236,7 +236,7 @@ struct UdpRx {
config: Config,
packet_buffer: [u8; VOICE_PACKET_MAX],
rx: Receiver<UdpRxMessage>,
udp_socket: RecvHalf,
udp_socket: Arc<UdpSocket>,
}
impl UdpRx {
@@ -391,7 +391,7 @@ pub(crate) async fn runner(
rx: Receiver<UdpRxMessage>,
cipher: Cipher,
config: Config,
udp_socket: RecvHalf,
udp_socket: Arc<UdpSocket>,
) {
info!("UDP receive handle started.");

View File

@@ -2,14 +2,15 @@ use super::message::*;
use crate::constants::*;
use discortp::discord::MutableKeepalivePacket;
use flume::Receiver;
use std::sync::Arc;
use tokio::{
net::udp::SendHalf,
time::{timeout_at, Elapsed, Instant},
net::UdpSocket,
time::{timeout_at, Instant},
};
use tracing::{error, info, instrument, trace};
#[instrument(skip(udp_msg_rx))]
pub(crate) async fn runner(udp_msg_rx: Receiver<UdpTxMessage>, ssrc: u32, mut udp_tx: SendHalf) {
pub(crate) async fn runner(udp_msg_rx: Receiver<UdpTxMessage>, ssrc: u32, udp_tx: Arc<UdpSocket>) {
info!("UDP transmit handle started.");
let mut keepalive_bytes = [0u8; MutableKeepalivePacket::minimum_packet_size()];
@@ -22,7 +23,7 @@ pub(crate) async fn runner(udp_msg_rx: Receiver<UdpTxMessage>, ssrc: u32, mut ud
loop {
use UdpTxMessage::*;
match timeout_at(ka_time, udp_msg_rx.recv_async()).await {
Err(Elapsed { .. }) => {
Err(_) => {
trace!("Sending UDP Keepalive.");
if let Err(e) = udp_tx.send(&keepalive_bytes[..]).await {
error!("Fatal UDP keepalive send error: {:?}.", e);

View File

@@ -57,7 +57,7 @@ impl AuxNetwork {
let mut ws_error = false;
let mut should_reconnect = false;
let hb = time::delay_until(next_heartbeat);
let hb = time::sleep_until(next_heartbeat);
tokio::select! {
_ = hb => {