🚧 wip: finding a bug. It's in the udp_over_tcp code
When a TCP client disconnects, the rx loop gets confused and goes into an infinite loop without ever yielding.main
parent
ce7a539413
commit
200c07da2f
|
@ -2418,6 +2418,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"tracing",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
|
@ -100,7 +100,7 @@ pub struct P4EndServer {
|
||||||
|
|
||||||
impl P4EndServer {
|
impl P4EndServer {
|
||||||
pub (crate) async fn connect (conf: Config) -> anyhow::Result <(Self, watch::Sender <bool>)> {
|
pub (crate) async fn connect (conf: Config) -> anyhow::Result <(Self, watch::Sender <bool>)> {
|
||||||
trace! ("P4 end server making its QUIC endpoint");
|
debug! ("P4 end server making its QUIC endpoint");
|
||||||
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&conf.relay_cert])?;
|
let endpoint = make_client_endpoint ("0.0.0.0:0".parse ()?, &[&conf.relay_cert])?;
|
||||||
|
|
||||||
let conf = if conf.use_udp_over_tcp {
|
let conf = if conf.use_udp_over_tcp {
|
||||||
|
@ -128,7 +128,7 @@ impl P4EndServer {
|
||||||
conf
|
conf
|
||||||
};
|
};
|
||||||
|
|
||||||
trace! ("P4 end server connecting to P3 relay server");
|
debug! ("P4 end server connecting to P3 relay server");
|
||||||
let conn = protocol::p4_connect_to_p3 (
|
let conn = protocol::p4_connect_to_p3 (
|
||||||
&endpoint,
|
&endpoint,
|
||||||
conf.relay_addr,
|
conf.relay_addr,
|
||||||
|
|
|
@ -257,7 +257,7 @@ pub async fn p4_connect_to_p3 (
|
||||||
bail! ("Server ID is longer than MAX_ID_LENGTH");
|
bail! ("Server ID is longer than MAX_ID_LENGTH");
|
||||||
}
|
}
|
||||||
|
|
||||||
let new_conn = endpoint.connect (relay_addr, "localhost")?.await?;
|
let new_conn = endpoint.connect (relay_addr, "localhost")?.await.context ("UXTDVL2V quinn::Endpoint::connect")?;
|
||||||
let (mut send, mut recv) = new_conn.open_bi ().await?;
|
let (mut send, mut recv) = new_conn.open_bi ().await?;
|
||||||
let cmd_type = Command::CONNECT_P4_TO_P3.0;
|
let cmd_type = Command::CONNECT_P4_TO_P3.0;
|
||||||
|
|
||||||
|
@ -265,7 +265,7 @@ pub async fn p4_connect_to_p3 (
|
||||||
send_lv_string (&mut send, server_id).await?;
|
send_lv_string (&mut send, server_id).await?;
|
||||||
|
|
||||||
expect_exact_response (&mut recv, [Command::OKAY.0, cmd_type, 0, 0]).await
|
expect_exact_response (&mut recv, [Command::OKAY.0, cmd_type, 0, 0]).await
|
||||||
.context ("P4 didn't get OK response when connecting to P3")?;
|
.context ("WMGW2RXU P4 didn't get OK response when connecting to P3")?;
|
||||||
|
|
||||||
Ok (new_conn)
|
Ok (new_conn)
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,5 +6,6 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.38"
|
anyhow = "1.0.66"
|
||||||
tokio = { version = "1.8.1", features = ["full"] }
|
tokio = { version = "1.23.0", features = ["full"] }
|
||||||
|
tracing = "0.1.37"
|
||||||
|
|
|
@ -17,7 +17,12 @@ pub async fn rx (
|
||||||
udp_sock: Arc <UdpSocket>,
|
udp_sock: Arc <UdpSocket>,
|
||||||
mut tcp_read: tcp::OwnedReadHalf,
|
mut tcp_read: tcp::OwnedReadHalf,
|
||||||
) -> anyhow::Result <()> {
|
) -> anyhow::Result <()> {
|
||||||
loop {
|
for i in 0u64.. {
|
||||||
|
// Optimizes down to a bitwise AND
|
||||||
|
if i % 8_192 == 0 {
|
||||||
|
tracing::trace! ("rx loop");
|
||||||
|
}
|
||||||
|
|
||||||
let mut tag = [0u8, 0, 0, 0];
|
let mut tag = [0u8, 0, 0, 0];
|
||||||
let bytes_read = tcp_read.read (&mut tag).await?;
|
let bytes_read = tcp_read.read (&mut tag).await?;
|
||||||
if bytes_read != 4 {
|
if bytes_read != 4 {
|
||||||
|
@ -47,6 +52,8 @@ pub async fn rx (
|
||||||
|
|
||||||
udp_sock.send (&buf).await?;
|
udp_sock.send (&buf).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn tx (
|
pub async fn tx (
|
||||||
|
@ -54,7 +61,12 @@ pub async fn tx (
|
||||||
mut tcp_write: tcp::OwnedWriteHalf,
|
mut tcp_write: tcp::OwnedWriteHalf,
|
||||||
) -> anyhow::Result <()>
|
) -> anyhow::Result <()>
|
||||||
{
|
{
|
||||||
loop {
|
for i in 0u64.. {
|
||||||
|
// Optimizes down to a bitwise AND
|
||||||
|
if i % 8_192 == 0 {
|
||||||
|
tracing::trace! ("tx loop");
|
||||||
|
}
|
||||||
|
|
||||||
let mut buf = vec! [0u8; 8_192];
|
let mut buf = vec! [0u8; 8_192];
|
||||||
let bytes_read = udp_sock.recv (&mut buf).await?;
|
let bytes_read = udp_sock.recv (&mut buf).await?;
|
||||||
buf.truncate (bytes_read);
|
buf.truncate (bytes_read);
|
||||||
|
@ -66,4 +78,6 @@ pub async fn tx (
|
||||||
tcp_write.write_all (&length).await?;
|
tcp_write.write_all (&length).await?;
|
||||||
tcp_write.write_all (&buf).await?;
|
tcp_write.write_all (&buf).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok (())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue