mirror of https://github.com/dswd/vpncloud.git
Sending close message at the end
This commit is contained in:
parent
8e34acb5de
commit
b4cc4d402a
|
@ -10,6 +10,8 @@ docopt = "0.6"
|
|||
rustc-serialize = "0.3"
|
||||
log = "0.3"
|
||||
epoll = "0.2"
|
||||
signal = "0.1"
|
||||
nix = "*"
|
||||
libsodium-sys = {version = "0.0.9", optional = true}
|
||||
|
||||
[build-dependencies]
|
||||
|
|
|
@ -29,9 +29,7 @@ However there are some open issues:
|
|||
|
||||
* Encryption has not been thoroughly reviewed, use with care.
|
||||
* The protocol can still change.
|
||||
* Running on IPv6 is not supported.
|
||||
* The software is not very well tested.
|
||||
* The closing message is not sent to peers.
|
||||
* The coverage score includes all unused methods from *libsodium*
|
||||
|
||||
Please feel free to help and contribute code.
|
||||
|
|
11
src/cloud.rs
11
src/cloud.rs
|
@ -9,6 +9,8 @@ use std::marker::PhantomData;
|
|||
|
||||
use time::{Duration, SteadyTime, precise_time_ns};
|
||||
use epoll;
|
||||
use nix::sys::signal::{SIGTERM, SIGQUIT, SIGINT};
|
||||
use signal::trap::Trap;
|
||||
|
||||
use super::types::{Table, Protocol, Range, Error, NetworkId};
|
||||
use super::device::Device;
|
||||
|
@ -270,6 +272,7 @@ impl<P: Protocol> GenericCloud<P> {
|
|||
}
|
||||
|
||||
pub fn run(&mut self) {
|
||||
let trap = Trap::trap(&[SIGINT, SIGTERM, SIGQUIT]);
|
||||
let epoll_handle = try_fail!(epoll::create1(0), "Failed to create epoll handle: {}");
|
||||
let socket_fd = self.socket.as_raw_fd();
|
||||
let device_fd = self.device.as_raw_fd();
|
||||
|
@ -281,6 +284,10 @@ impl<P: Protocol> GenericCloud<P> {
|
|||
let mut buffer = [0; 64*1024];
|
||||
loop {
|
||||
let count = try_fail!(epoll::wait(epoll_handle, &mut events, 1000), "Epoll wait failed: {}");
|
||||
// Check for signals
|
||||
if trap.wait(SteadyTime::now()).is_some() {
|
||||
break;
|
||||
}
|
||||
// Process events
|
||||
for i in 0..count {
|
||||
match &events[i as usize].data {
|
||||
|
@ -310,5 +317,9 @@ impl<P: Protocol> GenericCloud<P> {
|
|||
self.next_housekeep = SteadyTime::now() + Duration::seconds(1)
|
||||
}
|
||||
}
|
||||
info!("Shutting down...");
|
||||
for p in &self.peers.as_vec() {
|
||||
let _ = self.send_msg(p, &Message::Close);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,8 @@ extern crate time;
|
|||
extern crate docopt;
|
||||
extern crate rustc_serialize;
|
||||
extern crate epoll;
|
||||
extern crate signal;
|
||||
extern crate nix;
|
||||
#[cfg(feature = "crypto")] extern crate libsodium_sys;
|
||||
|
||||
#[macro_use] mod util;
|
||||
|
@ -29,7 +31,6 @@ use cloud::GenericCloud;
|
|||
use udpmessage::VERSION;
|
||||
use crypto::Crypto;
|
||||
|
||||
//TODO: Call close
|
||||
|
||||
struct SimpleLogger;
|
||||
|
||||
|
|
Loading…
Reference in New Issue