diff options
author | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2020-02-12 21:38:25 +0100 |
---|---|---|
committer | Mathias Hall-Andersen <mathias@hall-andersen.dk> | 2020-02-12 21:38:25 +0100 |
commit | 5e6edb280e588397c3420d08cf46a52b34b58740 (patch) | |
tree | dee5854adb5adce3549e53d96b48f0ef16886f04 /src/wireguard/router/device.rs | |
parent | Squashed commit of the following: (diff) | |
download | wireguard-rs-5e6edb280e588397c3420d08cf46a52b34b58740.tar.xz wireguard-rs-5e6edb280e588397c3420d08cf46a52b34b58740.zip |
Bumped crate versions.
Diffstat (limited to 'src/wireguard/router/device.rs')
-rw-r--r-- | src/wireguard/router/device.rs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/wireguard/router/device.rs b/src/wireguard/router/device.rs index 6c59491..96b7d82 100644 --- a/src/wireguard/router/device.rs +++ b/src/wireguard/router/device.rs @@ -311,4 +311,17 @@ impl<E: Endpoint, C: Callbacks, T: tun::Writer, B: udp::Writer<E>> DeviceHandle< pub fn set_outbound_writer(&self, new: B) { self.state.outbound.write().1 = Some(new); } + + pub fn write(&self, msg: &[u8], endpoint: &mut E) -> Result<(), RouterError> { + let outbound = self.state.outbound.read(); + if outbound.0 { + outbound + .1 + .as_ref() + .ok_or(RouterError::SendError) + .and_then(|w| w.write(msg, endpoint).map_err(|_| RouterError::SendError)) + } else { + Ok(()) + } + } } |