r_lanlib/
packet.rs

1//! Provides helpers for creating and sending packets
2
3use core::time;
4use std::error::Error;
5
6pub mod arp_packet;
7mod heartbeat_packet;
8pub mod rst_packet;
9pub mod syn_packet;
10pub mod wire;
11
12pub use heartbeat_packet::build as build_heartbeat_packet;
13
14/// Default timing for throttling packet sends to prevent packet loss
15pub const DEFAULT_PACKET_SEND_TIMING: time::Duration = time::Duration::from_micros(50);
16
17/// Trait describing a packet reader
18pub trait Reader: Send + Sync {
19    /// Should return the next packet off of the wire
20    fn next_packet(&mut self) -> Result<&[u8], Box<dyn Error>>;
21}
22
23/// Trait describing a packet sender
24pub trait Sender: Send + Sync {
25    /// Should send a packet over the wire
26    fn send(&mut self, packet: &[u8]) -> Result<(), Box<dyn Error>>;
27}
28
29#[cfg(test)]
30#[path = "./packet_tests.rs"]
31#[doc(hidden)]
32pub mod mocks;