fix timeout
This commit is contained in:
parent
6a3324563c
commit
ca06a02306
@ -465,11 +465,11 @@ async fn connection_handler(
|
||||
break Result::Packet { packet }
|
||||
}
|
||||
},
|
||||
_ = sleep(now.saturating_duration_since(last_ping_sent_at).saturating_sub(SEND_PING_INTERVAL)) => {
|
||||
_ = sleep(SEND_PING_INTERVAL.saturating_sub(now.saturating_duration_since(last_ping_sent_at))) => {
|
||||
writer.write_all(bytemuck::bytes_of(& Header { kind: PacketKind::Ping.raw(), length: 0 })).await?;
|
||||
last_ping_sent_at = now;
|
||||
}
|
||||
_ = sleep(now.saturating_duration_since(last_ping_received_at).saturating_sub(PING_TIMEOUT)) => {
|
||||
_ = sleep(PING_TIMEOUT.saturating_sub(now.saturating_duration_since(last_ping_received_at))) => {
|
||||
writer.write_all(REJECT_TIMEOUT).await?;
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -157,6 +157,8 @@ impl Packet {
|
||||
}
|
||||
|
||||
pub async fn dyn_ip_update(number: u32, pin: u16, port: u16) -> anyhow::Result<std::net::Ipv4Addr> {
|
||||
println!("dyn ip update: number={number} port={port}...");
|
||||
|
||||
let mut packet = Packet::default();
|
||||
packet.header = Header {
|
||||
kind: PacketKind::DynIpUpdate.raw(),
|
||||
@ -169,8 +171,7 @@ pub async fn dyn_ip_update(number: u32, pin: u16, port: u16) -> anyhow::Result<s
|
||||
packet.data.extend_from_slice(&pin.to_le_bytes());
|
||||
packet.data.extend_from_slice(&port.to_le_bytes());
|
||||
|
||||
let mut socket = tokio::net::TcpStream::connect(("tlnserv.teleprinter.net", 11811)).await?;
|
||||
// 127.0.0.1
|
||||
let mut socket = tokio::net::TcpStream::connect(("127.0.0.1", 11811)).await?;
|
||||
|
||||
let (mut reader, mut writer) = socket.split();
|
||||
|
||||
@ -178,7 +179,7 @@ pub async fn dyn_ip_update(number: u32, pin: u16, port: u16) -> anyhow::Result<s
|
||||
|
||||
packet.recv_into(&mut reader).await?;
|
||||
|
||||
match packet.kind() {
|
||||
let res = match packet.kind() {
|
||||
PacketKind::DynIpUpdateResponse => Ok(<[u8; 4]>::try_from(packet.data)
|
||||
.map_err(|err| {
|
||||
anyhow::anyhow!(
|
||||
@ -205,5 +206,9 @@ pub async fn dyn_ip_update(number: u32, pin: u16, port: u16) -> anyhow::Result<s
|
||||
}
|
||||
|
||||
_ => bail!("server returned unexpected packet"),
|
||||
}
|
||||
};
|
||||
|
||||
println!("dyn ip update result: {res:?}");
|
||||
|
||||
res
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user