Serve command #27
+1
-1
@@ -111,7 +111,7 @@ async fn main() -> Result<(), Error> {
|
|||||||
let re = Regex::new(r"talos/(?<cluster>.+)/(?<node>.+)\.ya?ml")
|
let re = Regex::new(r"talos/(?<cluster>.+)/(?<node>.+)\.ya?ml")
|
||||||
.expect("regex should be valid");
|
.expect("regex should be valid");
|
||||||
|
|
||||||
tftp::serve(move |filename| {
|
tftp::serve(move |filename, _| {
|
||||||
let filename = filename.to_owned();
|
let filename = filename.to_owned();
|
||||||
let re = re.clone();
|
let re = re.clone();
|
||||||
|
|
||||||
|
|||||||
+4
-4
@@ -1,5 +1,5 @@
|
|||||||
use std::io;
|
use std::io;
|
||||||
use std::net::{Ipv4Addr, SocketAddr, SocketAddrV4};
|
use std::net::{IpAddr, Ipv4Addr, SocketAddr, SocketAddrV4};
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use socket_pktinfo::{PktInfo, PktInfoUdpSocket};
|
use socket_pktinfo::{PktInfo, PktInfoUdpSocket};
|
||||||
@@ -37,7 +37,7 @@ pub async fn handle_connection<F, Fut>(
|
|||||||
callback: F,
|
callback: F,
|
||||||
) -> Result<(), Error>
|
) -> Result<(), Error>
|
||||||
where
|
where
|
||||||
F: Fn(&str) -> Fut,
|
F: Fn(&str, IpAddr) -> Fut,
|
||||||
Fut: Future<Output = Option<Vec<u8>>>,
|
Fut: Future<Output = Option<Vec<u8>>>,
|
||||||
{
|
{
|
||||||
let src = info.addr_src;
|
let src = info.addr_src;
|
||||||
@@ -59,7 +59,7 @@ where
|
|||||||
let filename = request.filename();
|
let filename = request.filename();
|
||||||
println!("{src}: {filename} [{:?}]", request.mode());
|
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")
|
Packet::error(ErrorCode::FileNotFound, "Unknown file")
|
||||||
.send_to(&socket, &src)
|
.send_to(&socket, &src)
|
||||||
.await?;
|
.await?;
|
||||||
@@ -152,7 +152,7 @@ where
|
|||||||
|
|
||||||
pub async fn serve<F, Fut>(callback: F) -> Result<!, Error>
|
pub async fn serve<F, Fut>(callback: F) -> Result<!, Error>
|
||||||
where
|
where
|
||||||
F: Fn(&str) -> Fut + Clone + Send + 'static,
|
F: Fn(&str, IpAddr) -> Fut + Clone + Send + 'static,
|
||||||
Fut: Future<Output = Option<Vec<u8>>> + Send + 'static,
|
Fut: Future<Output = Option<Vec<u8>>> + Send + 'static,
|
||||||
{
|
{
|
||||||
let socket = PktInfoUdpSocket::new(Domain::IPV4)?;
|
let socket = PktInfoUdpSocket::new(Domain::IPV4)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user