Skip to content

Commit

Permalink
Fix UDP bug + add new /24 for South America
Browse files Browse the repository at this point in the history
  • Loading branch information
loriopatrick committed Aug 12, 2024
1 parent 2d02242 commit 8556325
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ members = [
]

[workspace.package]
version = "0.15.18"
version = "0.15.19"

[workspace.dependencies]
tokio = { version = "1.39", features = ["full"] }
Expand Down
4 changes: 4 additions & 0 deletions packages/agent_cli/src/match_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ impl MatchIp {
else if octs[0] == 23 && octs[1] == 133 && octs[2] == 216 {
6u16
}
/* 198.22.204.0/24 (6) */
else if octs[0] == 198 && octs[1] == 22 && octs[2] == 204 {
6u16
}
/* global IP */
else {
0
Expand Down
2 changes: 1 addition & 1 deletion packages/agent_core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "playit-agent-core"
version = "0.17.1"
version = "0.17.2"
edition = "2021"
description = "Contains the logic to create a playit.gg agent"
license = "BSD-2-Clause"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ impl<I: PacketIO, A: AuthResource> MaintainedControl<I, A> {

if let Some(udp) = &self.udp {
if udp.requires_auth() {
if 5_000 < now - self.last_udp_auth {
if 13_000 < now - self.last_udp_auth {
self.last_udp_auth = now;

if let Err(error) = self.control.send_setup_udp_channel(9000).await {
Expand Down
11 changes: 6 additions & 5 deletions packages/agent_core/src/agent_control/udp_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::net::{Ipv4Addr, Ipv6Addr, SocketAddr, SocketAddrV4, SocketAddrV6};
use std::sync::Arc;
use std::sync::atomic::{AtomicU32, Ordering};

use byteorder::{BigEndian, ByteOrder};

Check warning on line 6 in packages/agent_core/src/agent_control/udp_channel.rs

View workflow job for this annotation

GitHub Actions / build_linux (linux 32bit, ubuntu-latest, i686-unknown-linux-gnu, playit-linux-i686, i386)

unused imports: `BigEndian` and `ByteOrder`

Check warning on line 6 in packages/agent_core/src/agent_control/udp_channel.rs

View workflow job for this annotation

GitHub Actions / build_linux (linux arm7, ubuntu-latest, armv7-unknown-linux-gnueabihf, playit-linux-armv7, armhf)

unused imports: `BigEndian` and `ByteOrder`

Check warning on line 6 in packages/agent_core/src/agent_control/udp_channel.rs

View workflow job for this annotation

GitHub Actions / build_linux (linux 64bit, ubuntu-latest, x86_64-unknown-linux-musl, playit-linux-amd64, amd64)

unused imports: `BigEndian` and `ByteOrder`

Check warning on line 6 in packages/agent_core/src/agent_control/udp_channel.rs

View workflow job for this annotation

GitHub Actions / build_linux (linux arm64, ubuntu-latest, aarch64-unknown-linux-musl, playit-linux-aarch64, arm64)

unused imports: `BigEndian` and `ByteOrder`
use tokio::net::UdpSocket;

Check warning on line 7 in packages/agent_core/src/agent_control/udp_channel.rs

View workflow job for this annotation

GitHub Actions / build_linux (linux 32bit, ubuntu-latest, i686-unknown-linux-gnu, playit-linux-i686, i386)

unused import: `tokio::net::UdpSocket`

Check warning on line 7 in packages/agent_core/src/agent_control/udp_channel.rs

View workflow job for this annotation

GitHub Actions / build_linux (linux arm7, ubuntu-latest, armv7-unknown-linux-gnueabihf, playit-linux-armv7, armhf)

unused import: `tokio::net::UdpSocket`

Check warning on line 7 in packages/agent_core/src/agent_control/udp_channel.rs

View workflow job for this annotation

GitHub Actions / build_linux (linux 64bit, ubuntu-latest, x86_64-unknown-linux-musl, playit-linux-amd64, amd64)

unused import: `tokio::net::UdpSocket`

Check warning on line 7 in packages/agent_core/src/agent_control/udp_channel.rs

View workflow job for this annotation

GitHub Actions / build_linux (linux arm64, ubuntu-latest, aarch64-unknown-linux-musl, playit-linux-aarch64, arm64)

unused import: `tokio::net::UdpSocket`
use tokio::sync::RwLock;

Expand Down Expand Up @@ -75,6 +76,7 @@ impl<I: PacketIO> UdpChannel<I> {
return false;
}

/* send within the last 5 seconds */
let now = now_sec();
5 < now - last_send
}
Expand Down Expand Up @@ -151,8 +153,8 @@ impl<I: PacketIO> UdpChannel<I> {
}

pub async fn receive_from(&self, buffer: &mut [u8]) -> std::io::Result<UdpTunnelRx> {
let details = self.get_details().await?;
let (bytes, remote) = self.inner.packet_io.recv_from(buffer).await?;
let details = self.get_details().await?;

if details.tunnel_addr != remote {
let lock = self.inner.details.read().await;
Expand Down Expand Up @@ -185,10 +187,8 @@ impl<I: PacketIO> UdpChannel<I> {
let actual = hex::encode(&buffer[..bytes]);
let expected = hex::encode(&details.token[..]);

return Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
format!("unexpected UDP establish packet, actual: {}, expected: {}", actual, expected)
));
tracing::error!(%actual, %expected, "unexpected UDP establish packet");
return Ok(UdpTunnelRx::InvalidEstablishToken);
},
_ => return Err(std::io::Error::new(
std::io::ErrorKind::InvalidData,
Expand All @@ -206,4 +206,5 @@ impl<I: PacketIO> UdpChannel<I> {
pub enum UdpTunnelRx {
ReceivedPacket { bytes: usize, flow: UdpFlow },
ConfirmedConnection,
InvalidEstablishToken,
}
13 changes: 13 additions & 0 deletions packages/agent_core/src/playit_agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ impl<L: AddressLookup + Sync + Send> PlayitAgent<L> where L::Value: Into<SocketA
let mut buffer = vec![0u8; 2048];
let mut had_success = false;

let mut invalid_count = 0;

while udp_run.load(Ordering::SeqCst) {
let rx = match tokio::time::timeout(Duration::from_secs(1), udp.receive_from(&mut buffer)).await {
Ok(Ok(v)) => v,
Expand All @@ -157,7 +159,18 @@ impl<L: AddressLookup + Sync + Send> PlayitAgent<L> where L::Value: Into<SocketA
udp_clients.forward_packet(&flow, &buffer[..bytes]).await.unwrap();
}
UdpTunnelRx::ConfirmedConnection => {}
UdpTunnelRx::InvalidEstablishToken => {
invalid_count += 1;

if 5 <= invalid_count && invalid_count < 10 {
tracing::error!("have repeat invalid UDP establish tokens");
tokio::time::sleep(Duration::from_millis(100)).await;
}
continue;
}
}

invalid_count = 0;
}
});

Expand Down

0 comments on commit 8556325

Please sign in to comment.