aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJake McGinty <me@jake.su>2017-12-31 02:38:26 -0800
committerJake McGinty <me@jake.su>2017-12-31 02:38:26 -0800
commit8a93e2bdbbacfd69e7e1ae7bd09f92721260df90 (patch)
treebe951abef133787ee1f68afb60ac11d1b3d6311e /src
parentmove outgoing peer logic to PeerServer as well (diff)
downloadwireguard-rs-8a93e2bdbbacfd69e7e1ae7bd09f92721260df90.tar.xz
wireguard-rs-8a93e2bdbbacfd69e7e1ae7bd09f92721260df90.zip
clear out warnings
Diffstat (limited to 'src')
-rw-r--r--src/interface/config.rs95
-rw-r--r--src/interface/mod.rs18
-rw-r--r--src/interface/peer_server.rs6
-rw-r--r--src/main.rs44
4 files changed, 38 insertions, 125 deletions
diff --git a/src/interface/config.rs b/src/interface/config.rs
index 6a76a23..0efd4d9 100644
--- a/src/interface/config.rs
+++ b/src/interface/config.rs
@@ -137,95 +137,6 @@ impl Encoder for ConfigurationCodec {
}
}
-
-//pub struct ConfigurationService {
-// interface_name: String,
-// peers: Rc<RefCell<HashMap<[u8; 32], Rc<RefCell<Peer>>>>>,
-// interface_info: Rc<RefCell<InterfaceInfo>>,
-// tx: mpsc::Sender<UpdateEvent>,
-//}
-
-//impl Service for ConfigurationService {
-// type Request = Command;
-// type Response = String;
-// type Error = io::Error;
-// type Future = Box<Future<Item=Self::Response, Error=Self::Error>>;
-//
-// fn call(&self, req: Self::Request) -> Self::Future {
-// debug!("{:?}", req);
-// match req {
-// Command::Get(version) => {
-// // see: https://www.wireguard.com/xplatform/
-// // this is just bullshit fillin
-// let buf = "private_key=e84b5a6d2717c1003a13b431570353dbaca9146cf150c5f8575680feba52027a
-//listen_port=12912
-//public_key=b85996fecc9c7f1fc6d2572a76eda11d59bcd20be8e543b15ce4bd85a8e75a33
-//preshared_key=188515093e952f5f22e865cef3012e72f8b5f0b598ac0309d5dacce3b70fcf52
-//allowed_ip=192.168.4.4/32
-//endpoint=[abcd:23::33%2]:51820
-//public_key=58402e695ba1772b1cc9309755f043251ea77fdcf10fbe63989ceb7e19321376
-//tx_bytes=38333
-//rx_bytes=2224
-//allowed_ip=192.168.4.6/32
-//persistent_keepalive_interval=111
-//endpoint=182.122.22.19:3233
-//public_key=662e14fd594556f522604703340351258903b64f35553763f19426ab2a515c58
-//endpoint=5.152.198.39:51820
-//allowed_ip=192.168.4.10/32
-//allowed_ip=192.168.4.11/32
-//tx_bytes=1212111
-//rx_bytes=1929999999
-//errno=0
-//\n";
-// Box::new(future::ok(buf.into()))
-// },
-// Command::Set(version, items) => {
-// let mut public_key = None;
-// let mut preshared_key = None;
-// let mut allowed_ips: Vec<(IpAddr, u32)> = vec![];
-// let mut persistent_keepalive_interval: Option<u16> = None;
-// let mut endpoint: Option<SocketAddr> = None;
-//
-// for (key, value) in items {
-// match key.as_ref() {
-//// "private_key" => { config.key = Some(value); },
-//// "fwmark" => { config.fwmark = Some(value.parse().unwrap()); },
-//// "listen_port" => { config.listen_port = Some(value.parse().unwrap()); },
-// "public_key" => {
-// if let Some(ref pubkey) = public_key {
-//// config.peers.push(Peer {
-//// peer_pubkey: [0u8; 32],
-//// psk: preshared_key,
-//// endpoint: endpoint,
-//// allowed_ips: allowed_ips.clone(),
-//// keep_alive_interval: persistent_keepalive_interval,
-//// });
-// }
-// public_key = Some(value);
-// },
-// "preshared_key" => { preshared_key = Some([0u8; 32]); },
-// "allowed_ip" => {
-// let (ip, cidr) = value.split_at(value.find('/').unwrap());
-// debug!("parsed allowed ip as ({}, {})", ip, &cidr[1..]);
-// allowed_ips.push((ip.parse().unwrap(), (&cidr[1..]).parse().unwrap()))
-// },
-// "persistent_keepalive_interval" => {
-// debug!("persistent_keepalive_interval");
-// persistent_keepalive_interval = Some(value.parse().unwrap());
-// },
-// "endpoint" => { endpoint = Some(value.parse().unwrap()); },
-// _ => {}
-// }
-// }
-// Box::new(future::ok("errno=0\nerrno=0\n\n".into()))
-// },
-// _ => {
-// Box::new(future::ok("errno=1\nerrno=1\n\n".into()))
-// }
-// }
-// }
-//}
-
pub struct ConfigurationServiceManager {
interface_name: String,
}
@@ -238,7 +149,7 @@ impl ConfigurationServiceManager {
}
/// Creates a new `WireGuard` instance
- pub fn get_path(name: &str) -> 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");
@@ -252,7 +163,7 @@ impl ConfigurationServiceManager {
Self::chmod(&socket_path, 0o700)?;
// Finish the socket path
- socket_path.push(&name);
+ socket_path.push(&self.interface_name);
socket_path.set_extension("sock");
if socket_path.exists() {
debug!("Removing existing socket: {}", socket_path.display());
@@ -293,7 +204,7 @@ impl Drop for ConfigurationServiceManager {
socket_path.push(&self.interface_name);
socket_path.set_extension("sock");
if socket_path.exists() {
- debug!("Removing socket on drop: {}", socket_path.display());
+ info!("Removing socket on drop: {}", socket_path.display());
let _ = remove_file(&socket_path);
}
}
diff --git a/src/interface/mod.rs b/src/interface/mod.rs
index 76a6430..e10ce8e 100644
--- a/src/interface/mod.rs
+++ b/src/interface/mod.rs
@@ -96,17 +96,19 @@ impl Interface {
let utun_stream = UtunStream::connect(&self.name, &core.handle()).unwrap().framed(VecUtunCodec{});
let (utun_writer, utun_reader) = utun_stream.split();
-
- let utun_read_fut = peer_server.tx().sink_map_err(|_| ()).send_all(
- utun_reader.map_err(|_|())).map_err(|_|());
-
- let utun_write_fut = utun_writer.sink_map_err(|_| ()).send_all(
- utun_rx.map_err(|_| ())).map_err(|_| ());
-
+ let utun_read_fut = peer_server.tx()
+ .sink_map_err(|_| ())
+ .send_all(utun_reader.map_err(|_|()))
+ .map_err(|_|());
+ let utun_write_fut = utun_writer
+ .sink_map_err(|_| ())
+ .send_all(utun_rx.map_err(|_| ()))
+ .map_err(|_| ());
let utun_fut = utun_write_fut.join(utun_read_fut);
+ let config_manager = ConfigurationServiceManager::new(&self.name);
let handle = core.handle();
- let listener = UnixListener::bind(ConfigurationServiceManager::get_path(&self.name).unwrap(), &handle).unwrap();
+ let listener = UnixListener::bind(config_manager.get_path().unwrap(), &handle).unwrap();
let (config_tx, config_rx) = sync::mpsc::channel::<UpdateEvent>(1024);
let h = handle.clone();
let config_server = listener.incoming().for_each({
diff --git a/src/interface/peer_server.rs b/src/interface/peer_server.rs
index d271d22..f66a44f 100644
--- a/src/interface/peer_server.rs
+++ b/src/interface/peer_server.rs
@@ -82,7 +82,7 @@ impl PeerServer {
self.udp_tx.clone()
}
- fn handle_incoming_packet(&mut self, addr: SocketAddr, packet: Vec<u8>) {
+ fn handle_incoming_packet(&mut self, _addr: SocketAddr, packet: Vec<u8>) {
debug!("got a UDP packet of length {}, packet type {}", packet.len(), packet[0]);
let state = self.shared_state.borrow_mut();
match packet[0] {
@@ -168,7 +168,7 @@ impl PeerServer {
fn handle_timer(&mut self, message: TimerMessage) {
let mut state = self.shared_state.borrow_mut();
match message {
- TimerMessage::Rekey(peer_ref, our_index) => {
+ TimerMessage::Rekey(peer_ref, _our_index) => {
let mut peer = peer_ref.borrow_mut();
let noise = NoiseBuilder::new("Noise_IKpsk2_25519_ChaChaPoly_BLAKE2s".parse().unwrap())
.local_private_key(&state.interface_info.private_key.expect("no private key!"))
@@ -186,7 +186,7 @@ impl PeerServer {
self.handle.spawn(self.udp_tx.clone().send((endpoint, init_packet)).then(|_| Ok(())));
info!("sent rekey");
},
- TimerMessage::KeepAlive(peer_ref, our_index) => {
+ TimerMessage::KeepAlive(peer_ref, _our_index) => {
let mut peer = peer_ref.borrow_mut();
let mut packet = vec![0u8; 1500];
packet[0] = 4;
diff --git a/src/main.rs b/src/main.rs
index 8c327cf..5c16224 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -70,25 +70,25 @@ fn main() {
Interface::new(&opt.interface).start();
}
-fn daemonize() -> Result<()> {
- if !nix::unistd::getuid().is_root() {
- bail!("You are not the root user which can spawn the daemon.");
- }
-
- debug!("Starting daemon.");
-
- let pid_path = PathBuf::new(); // TODO temporary
-
-// let pid_path = WireGuard::get_run_path();
-
- let daemonize = Daemonize::new()
- .pid_file(pid_path.join("wireguard.pid"))
- .chown_pid_file(true)
- .working_directory(pid_path)
- .user("nobody")
- .group("daemon")
- .umask(0o077);
-
- daemonize.start()?;
- Ok(())
-}
+//fn daemonize() -> Result<()> {
+// if !nix::unistd::getuid().is_root() {
+// bail!("You are not the root user which can spawn the daemon.");
+// }
+//
+// debug!("Starting daemon.");
+//
+// let pid_path = PathBuf::new(); // TODO temporary
+//
+//// let pid_path = WireGuard::get_run_path();
+//
+// let daemonize = Daemonize::new()
+// .pid_file(pid_path.join("wireguard.pid"))
+// .chown_pid_file(true)
+// .working_directory(pid_path)
+// .user("nobody")
+// .group("daemon")
+// .umask(0o077);
+//
+// daemonize.start()?;
+// Ok(())
+//}