feat: add sans-io TFTP protocol crate

This commit is contained in:
2025-12-21 11:14:59 +01:00
parent d537ad4ee2
commit 890443fdc2
11 changed files with 677 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
[package]
name = "pfs-tftp-sync"
version = "0.1.0"
edition = "2024"
[lints.rust]
unsafe_code = "forbid"
[lints.clippy]
pedantic = { level = "warn", priority = -1 }
todo = "warn"
unwrap_used = "warn"
[dependencies]
pfs-tftp-proto = { path = "../pfs-tftp-proto" }

View File

@@ -0,0 +1,44 @@
#![forbid(unsafe_code)]
use std::net::SocketAddr;
use std::time::Duration;
/// Configuration for a synchronous TFTP client.
#[derive(Debug, Clone)]
pub struct ClientConfig {
pub timeout: Duration,
pub retries: u32,
}
impl Default for ClientConfig {
fn default() -> Self {
Self {
timeout: Duration::from_secs(5),
retries: 5,
}
}
}
/// A synchronous TFTP client.
#[derive(Debug)]
pub struct Client {
pub(crate) server: SocketAddr,
pub(crate) config: ClientConfig,
}
impl Client {
#[must_use]
pub fn new(server: SocketAddr, config: ClientConfig) -> Self {
Self { server, config }
}
#[must_use]
pub fn server(&self) -> SocketAddr {
self.server
}
#[must_use]
pub fn config(&self) -> &ClientConfig {
&self.config
}
}

View File

@@ -0,0 +1,13 @@
//! Synchronous TFTP client/server helpers built on `pfs-tftp-proto`.
//!
//! This crate provides small, blocking APIs built on `std::net::UdpSocket`.
//! It intentionally avoids async runtimes for simplicity.
#![forbid(unsafe_code)]
pub mod client;
pub mod server;
pub mod util;
pub use client::{Client, ClientConfig};
pub use server::{Server, ServerConfig};

View File

@@ -0,0 +1,47 @@
#![forbid(unsafe_code)]
use std::net::SocketAddr;
use std::path::PathBuf;
use std::time::Duration;
/// Configuration for a synchronous TFTP server.
#[derive(Debug, Clone)]
pub struct ServerConfig {
pub bind: SocketAddr,
pub root: PathBuf,
pub allow_write: bool,
pub overwrite: bool,
pub timeout: Duration,
pub retries: u32,
}
impl Default for ServerConfig {
fn default() -> Self {
Self {
bind: SocketAddr::from(([0, 0, 0, 0], 6969)),
root: PathBuf::from("."),
allow_write: false,
overwrite: false,
timeout: Duration::from_secs(5),
retries: 5,
}
}
}
/// A synchronous TFTP server.
#[derive(Debug)]
pub struct Server {
pub(crate) config: ServerConfig,
}
impl Server {
#[must_use]
pub fn new(config: ServerConfig) -> Self {
Self { config }
}
#[must_use]
pub fn config(&self) -> &ServerConfig {
&self.config
}
}

View File

@@ -0,0 +1,4 @@
#![forbid(unsafe_code)]
// Misc sync helpers live here.