feat!: Pass connected to ip to serve callback
This commit is contained in:
+1
-1
@@ -111,7 +111,7 @@ async fn main() -> Result<(), Error> {
|
||||
let re = Regex::new(r"talos/(?<cluster>.+)/(?<node>.+)\.ya?ml")
|
||||
.expect("regex should be valid");
|
||||
|
||||
tftp::serve(move |filename| {
|
||||
tftp::serve(move |filename, _| {
|
||||
let filename = filename.to_owned();
|
||||
let re = re.clone();
|
||||
|
||||
|
||||
+4
-4
@@ -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)?;
|
||||
|
||||
Reference in New Issue
Block a user