log client name

This commit is contained in:
soruh 2023-03-28 13:52:58 +02:00
parent 1340e87c15
commit c01e18f5f2
3 changed files with 9 additions and 13 deletions

View File

@ -2,7 +2,7 @@ use std::net::SocketAddr;
use eyre::eyre;
use tracing::{debug, instrument};
use zerocopy::{AsBytes, FromBytes, LittleEndian, Unaligned};
use zerocopy::{AsBytes, LittleEndian};
use crate::packets::{Header, Packet, PacketKind};

View File

@ -329,9 +329,9 @@ pub async fn handler(
info!(%addr, number, port, "authenticated");
let res = peer_query(&config.dyn_ip_server, number).await;
let name = peer_query(&config.dyn_ip_server, number).await?;
dbg!(&res);
info!(%name, "found client name");
let Some(listener) = handler_metadata.listener.as_mut() else {
unreachable!("client sucessfully authenticated but did not set handler_metadata.listener");

View File

@ -101,13 +101,9 @@ pub async fn peer_query(server: &SocketAddr, number: u32) -> eyre::Result<Option
packet.recv_into(&mut reader).await?;
dbg!(&packet);
if packet.kind().raw() == 5 {
Ok(if packet.kind().raw() == 5 {
// PeerReply
let reply = PeerReply::read_from(packet.data.as_slice());
dbg!(&reply);
Ok(reply.and_then(|x| {
PeerReply::read_from(packet.data.as_slice()).and_then(|x| {
let i = x
.name
.iter()
@ -115,9 +111,9 @@ pub async fn peer_query(server: &SocketAddr, number: u32) -> eyre::Result<Option
.find_map(|(i, c)| (*c == 0).then_some(i))
.unwrap_or(x.name.len());
std::str::from_utf8(&x.name[..i]).ok().map(|x| x.to_owned())
}))
Some(std::str::from_utf8(&x.name[..i]).ok()?.to_owned())
})
} else {
Ok(None)
}
None
})
}