diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-09 15:08:26 +0200 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2019-10-09 15:08:26 +0200 |
commit | 761c46064d7510303f08cde27c9e13b07293f3af (patch) | |
tree | 7b914169725952e557223972b3f0b611c54e6829 /src/types/tun.rs | |
parent | Restructure dummy implementations (diff) | |
download | wireguard-rs-761c46064d7510303f08cde27c9e13b07293f3af.tar.xz wireguard-rs-761c46064d7510303f08cde27c9e13b07293f3af.zip |
Restructure IO traits.
Diffstat (limited to 'src/types/tun.rs')
-rw-r--r-- | src/types/tun.rs | 43 |
1 files changed, 28 insertions, 15 deletions
diff --git a/src/types/tun.rs b/src/types/tun.rs index fc8044a..2ba16ff 100644 --- a/src/types/tun.rs +++ b/src/types/tun.rs @@ -1,18 +1,22 @@ -use std::error; +use std::error::Error; -pub trait Tun: Send + Sync + Clone + 'static { - type Error: error::Error; +pub trait Writer: Send + Sync + 'static { + type Error: Error; - /// Returns the MTU of the device + /// Receive a cryptkey routed IP packet /// - /// This function needs to be efficient (called for every read). - /// The goto implementation strategy is to .load an atomic variable, - /// then use e.g. netlink to update the variable in a separate thread. + /// # Arguments + /// + /// - src: Buffer containing the IP packet to be written /// /// # Returns /// - /// The MTU of the interface in bytes - fn mtu(&self) -> usize; + /// Unit type or an error + fn write(&self, src: &[u8]) -> Result<(), Self::Error>; +} + +pub trait Reader: Send + 'static { + type Error: Error; /// Reads an IP packet into dst[offset:] from the tunnel device /// @@ -29,15 +33,24 @@ pub trait Tun: Send + Sync + Clone + 'static { /// /// The size of the IP packet (ignoring the header) or an std::error::Error instance: fn read(&self, buf: &mut [u8], offset: usize) -> Result<usize, Self::Error>; +} - /// Writes an IP packet to the tunnel device - /// - /// # Arguments +pub trait MTU: Send + Sync + Clone + 'static { + /// Returns the MTU of the device /// - /// - src: Buffer containing the IP packet to be written + /// This function needs to be efficient (called for every read). + /// The goto implementation strategy is to .load an atomic variable, + /// then use e.g. netlink to update the variable in a separate thread. /// /// # Returns /// - /// Unit type or an error - fn write(&self, src: &[u8]) -> Result<(), Self::Error>; + /// The MTU of the interface in bytes + fn mtu(&self) -> usize; +} + +pub trait Tun: Send + Sync + 'static { + type Writer: Writer; + type Reader: Reader; + type MTU: MTU; + type Error: Error; } |