feat!: Pass connected to ip to serve callback

This commit is contained in:
2026-10-15 03:43:37 +02:00
parent 5552013eeb
commit 5a5df6bfc3
2 changed files with 5 additions and 5 deletions
+4 -4
View File
@@ -1,5 +1,5 @@
use std::io;
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
use std::time::Duration;
use socket_pktinfo::{PktInfo, PktInfoUdpSocket};
@@ -37,7 +37,7 @@ pub async fn handle_connection<F, Fut>(
callback: F,
) -> Result<(), Error>
where
F: Fn(&str) -> Fut,
F: Fn(&str, IpAddr) -> Fut,
Fut: Future<Output = Option<Vec<u8>>>,
{
let src = info.addr_src;
@@ -59,7 +59,7 @@ where
let filename = request.filename();
println!("{src}: {filename} [{:?}]", request.mode());
let Some(data) = callback(filename).await else {
let Some(data) = callback(filename, info.addr_dst).await else {
Packet::error(ErrorCode::FileNotFound, "Unknown file")
.send_to(&socket, &src)
.await?;
@@ -152,7 +152,7 @@ where
pub async fn serve<F, Fut>(callback: F) -> Result<!, Error>
where
F: Fn(&str) -> Fut + Clone + Send + 'static,
F: Fn(&str, IpAddr) -> Fut + Clone + Send + 'static,
Fut: Future<Output = Option<Vec<u8>>> + Send + 'static,
{
let socket = PktInfoUdpSocket::new(Domain::IPV4)?;