aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJake McGinty <me@jake.su>2018-02-08 15:23:13 +0000
committerJake McGinty <me@jake.su>2018-02-08 15:23:20 +0000
commit34ba2cd5c5826d8d01c580b05e4c9a883f8a12a9 (patch)
tree07c25501172f4f7b07594de792cfb7075e230f36 /src
parenttake advantage of new snow API (diff)
downloadwireguard-rs-34ba2cd5c5826d8d01c580b05e4c9a883f8a12a9.tar.xz
wireguard-rs-34ba2cd5c5826d8d01c580b05e4c9a883f8a12a9.zip
drop error-chain in favor of Failure crate
Diffstat (limited to 'src')
-rw-r--r--src/error.rs27
-rw-r--r--src/interface/config.rs17
-rw-r--r--src/main.rs3
-rw-r--r--src/protocol/peer.rs8
4 files changed, 17 insertions, 38 deletions
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 */