diff options
author | Jake McGinty <me@jake.su> | 2018-02-08 15:23:13 +0000 |
---|---|---|
committer | Jake McGinty <me@jake.su> | 2018-02-08 15:23:20 +0000 |
commit | 34ba2cd5c5826d8d01c580b05e4c9a883f8a12a9 (patch) | |
tree | 07c25501172f4f7b07594de792cfb7075e230f36 | |
parent | take advantage of new snow API (diff) | |
download | wireguard-rs-34ba2cd5c5826d8d01c580b05e4c9a883f8a12a9.tar.xz wireguard-rs-34ba2cd5c5826d8d01c580b05e4c9a883f8a12a9.zip |
drop error-chain in favor of Failure crate
-rw-r--r-- | Cargo.lock | 33 | ||||
-rw-r--r-- | Cargo.toml | 32 | ||||
-rw-r--r-- | src/error.rs | 27 | ||||
-rw-r--r-- | src/interface/config.rs | 17 | ||||
-rw-r--r-- | src/main.rs | 3 | ||||
-rw-r--r-- | src/protocol/peer.rs | 8 |
6 files changed, 63 insertions, 57 deletions
@@ -182,6 +182,25 @@ dependencies = [ ] [[package]] +name = "failure" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "failure_derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -676,6 +695,15 @@ dependencies = [ ] [[package]] +name = "synstructure" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "syntex" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -890,7 +918,7 @@ dependencies = [ "bytes 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "daemonize 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", @@ -975,6 +1003,8 @@ dependencies = [ "checksum either 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "740178ddf48b1a9e878e6d6509a1442a2d42fd2928aae8e7a6f8a36fb01981b3" "checksum env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3ddf21e73e016298f5cb37d6ef8e8da8e39f91f9ec8b0df44b7deb16a9f8cd5b" "checksum error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ff511d5dc435d703f4971bc399647c9bc38e20cb41452e3b9feb4765419ed3f3" +"checksum failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "934799b6c1de475a012a02dab0ace1ace43789ee4b99bcfbf1a2e3e8ced5de82" +"checksum failure_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c7cdda555bb90c9bb67a3b670a0f42de8e73f5981524123ad8578aafec8ddb8b" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum futures 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0bab5b5e94f5c31fc764ba5dd9ad16568aae5d4825538c01d6bca680c9bf94a7" @@ -1036,6 +1066,7 @@ dependencies = [ "checksum structopt-derive 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "4da119c9a7a1eccb7c6de0c1eb3f7ed1c11138624d092b3687222aeed8f1375c" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" +"checksum synstructure 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a761d12e6d8dcb4dcf952a7a89b475e3a9d69e4a69307e01a470977642914bd" "checksum syntex 0.42.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0a30b08a6b383a22e5f6edc127d169670d48f905bb00ca79a00ea3e442ebe317" "checksum syntex_errors 0.42.0 (registry+https://github.com/rust-lang/crates.io-index)" = "04c48f32867b6114449155b2a82114b86d4b09e1bddb21c47ff104ab9172b646" "checksum syntex_pos 0.42.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd49988e52451813c61fecbe9abb5cfd4e1b7bb6cdbb980a6fbcbab859171a6" @@ -7,33 +7,29 @@ repository = "https://git.zx2c4.com/wireguard-rs/" description = "Userspace implementation of WireGuard, a fast, modern and secure VPN tunnel." [dependencies] +base64 = "^0.5" blake2-rfc = "0.2" byteorder = "^1.2" -structopt = "^0.1" -structopt-derive = "^0.1" +bytes = "0.4" daemonize = "0.2" -error-chain = "^0.11" +env_logger = "^0.4" +failure = "^0.1" +futures = "^0.1" +log = "^0.3" +hex = "^0.3" rand = "^0.4" libc = "0.2" nix = "0.9" rustc-serialize = "0.3.22" -treebitmap = "^0.2" - -env_logger = "^0.4" -log = "^0.3" - -bytes = "0.4" -futures = "^0.1" +pnet = "*" +snow = { git = "https://github.com/mcginty/snow", features = ["ring-accelerated"], branch = "wireguard" } +socket2 = "^0.3" +structopt = "^0.1" +structopt-derive = "^0.1" +time = "*" tokio-io = "^0.1" tokio-core = "^0.1" tokio-uds = "^0.1" tokio-utun = "^0.1" tokio-timer = "^0.1" - -socket2 = "^0.3" - -snow = { git = "https://github.com/mcginty/snow", features = ["ring-accelerated"], branch = "wireguard" } -base64 = "^0.5" -hex = "^0.3" -time = "*" -pnet = "*" +treebitmap = "^0.2" diff --git a/src/error.rs b/src/error.rs index 4492444..e69de29 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,27 +0,0 @@ -use daemonize; -use std::io; - - error_chain! { - foreign_links { - Io(io::Error) #[doc = "Error during IO"]; - Daemonize(daemonize::DaemonizeError) #[doc = "Error during IO"]; - } - - errors { -// Launch(phase: LaunchStage) { -// description("An error occurred during startup") -// display("Startup aborted: {:?} did not complete successfully", phase) -// } -// -// ConfigLoad(path: String) { -// description("Config file not found") -// display("Unable to read file `{}`", path) -// } - } - } - -// impl From<LaunchStage> for ErrorKind { -// fn from(v: LaunchStage) -> Self { -// ErrorKind::Launch(v) -// } -// } diff --git a/src/interface/config.rs b/src/interface/config.rs index 0efd4d9..277de08 100644 --- a/src/interface/config.rs +++ b/src/interface/config.rs @@ -4,7 +4,6 @@ // * Configuration service should use channels to report updates it receives over its interface. use bytes::BytesMut; -use error::Result; use std; use std::fs::{create_dir, remove_file}; use std::iter::Iterator; @@ -98,7 +97,7 @@ impl Decoder for ConfigurationCodec { type Item = Command; type Error = io::Error; - fn decode(&mut self, buf: &mut BytesMut) -> std::result::Result<Option<Self::Item>, Self::Error> { + fn decode(&mut self, buf: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> { // Determine we have a full command ready for parsing. let mut items = Vec::new(); let utf8 = String::from_utf8(buf.to_vec()).unwrap(); @@ -130,7 +129,7 @@ impl Encoder for ConfigurationCodec { type Item = String; type Error = io::Error; - fn encode(&mut self, msg: Self::Item, buf: &mut BytesMut) -> std::result::Result<(), Self::Error> { + fn encode(&mut self, msg: Self::Item, buf: &mut BytesMut) -> Result<(), Self::Error> { buf.extend(msg.as_bytes()); buf.extend(b"\n\n"); Ok(()) @@ -149,14 +148,14 @@ impl ConfigurationServiceManager { } /// Creates a new `WireGuard` instance - pub fn get_path(&self) -> Result<PathBuf> { + pub fn get_path(&self) -> Result<PathBuf, ()> { // let _tun = Tun::create(Some("hey")); // Create the socket directory if not existing let mut socket_path = Self::get_run_path().join("wireguard"); if !socket_path.exists() { debug!("Creating socket path: {}", socket_path.display()); - create_dir(&socket_path)?; + create_dir(&socket_path).map_err(|_|())?; } debug!("Setting chmod 0700 of socket path: {}", socket_path.display()); @@ -167,7 +166,7 @@ impl ConfigurationServiceManager { socket_path.set_extension("sock"); if socket_path.exists() { debug!("Removing existing socket: {}", socket_path.display()); - remove_file(&socket_path)?; + remove_file(&socket_path).map_err(|_|())?; } Ok(socket_path) @@ -175,16 +174,16 @@ impl ConfigurationServiceManager { #[cfg(unix)] /// Sets the permissions to a given `Path` - fn chmod(path: &Path, perms: u32) -> Result<()> { + fn chmod(path: &Path, perms: u32) -> Result<(), ()> { use std::os::unix::prelude::PermissionsExt; use std::fs::{set_permissions, Permissions}; - set_permissions(path, Permissions::from_mode(perms))?; + set_permissions(path, Permissions::from_mode(perms)).map_err(|_|())?; Ok(()) } #[cfg(windows)] /// Sets the permissions to a given `Path` - fn chmod(_path: &Path, _perms: u32) -> Result<()> { + fn chmod(_path: &Path, _perms: u32) -> Result<(), ()> { Ok(()) } diff --git a/src/main.rs b/src/main.rs index 2ebd052..c2dd16e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ #![feature(option_filter)] #![allow(unused_imports)] -#[macro_use] extern crate error_chain; +#[macro_use] extern crate failure; #[macro_use] extern crate futures; #[macro_use] extern crate log; #[macro_use] extern crate structopt_derive; @@ -38,7 +38,6 @@ mod anti_replay; use std::path::PathBuf; use daemonize::Daemonize; -use error::{ErrorKind, Error, Result}; use interface::Interface; use structopt::StructOpt; diff --git a/src/protocol/peer.rs b/src/protocol/peer.rs index 789ea8c..9507afc 100644 --- a/src/protocol/peer.rs +++ b/src/protocol/peer.rs @@ -192,6 +192,14 @@ impl Peer { initiation_packet } + /// Takes a new handshake packet (type 0x01), updates the internal peer state, + /// and generates a response. + /// + /// Returns: the response packet (type 0x02). + pub fn process_incoming_handshake(&mut self) -> Vec<u8> { + unimplemented!() + } + pub fn get_response_packet(&mut self) -> Vec<u8> { let mut packet = vec![0; 76]; packet[0] = 2; /* Type: Response */ |