feat: add sans-io TFTP protocol crate
This commit is contained in:
44
crates/pfs-tftp-sync/src/client.rs
Normal file
44
crates/pfs-tftp-sync/src/client.rs
Normal 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
|
||||
}
|
||||
}
|
||||
13
crates/pfs-tftp-sync/src/lib.rs
Normal file
13
crates/pfs-tftp-sync/src/lib.rs
Normal 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};
|
||||
47
crates/pfs-tftp-sync/src/server.rs
Normal file
47
crates/pfs-tftp-sync/src/server.rs
Normal 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
|
||||
}
|
||||
}
|
||||
4
crates/pfs-tftp-sync/src/util.rs
Normal file
4
crates/pfs-tftp-sync/src/util.rs
Normal file
@@ -0,0 +1,4 @@
|
||||
#![forbid(unsafe_code)]
|
||||
|
||||
// Misc sync helpers live here.
|
||||
|
||||
Reference in New Issue
Block a user