mirror of https://github.com/dswd/vpncloud.git
small changes
This commit is contained in:
parent
8f747e3448
commit
b66e86bddf
|
@ -142,7 +142,8 @@ pub struct EthCloudInner {
|
||||||
tapdev: Mutex<TapDevice>,
|
tapdev: Mutex<TapDevice>,
|
||||||
token: Token,
|
token: Token,
|
||||||
next_peerlist: Mutex<SteadyTime>,
|
next_peerlist: Mutex<SteadyTime>,
|
||||||
update_freq: Duration
|
update_freq: Duration,
|
||||||
|
running: Mutex<bool>
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -175,7 +176,8 @@ impl EthCloud {
|
||||||
tapdev: Mutex::new(tapdev),
|
tapdev: Mutex::new(tapdev),
|
||||||
token: token,
|
token: token,
|
||||||
next_peerlist: Mutex::new(SteadyTime::now()),
|
next_peerlist: Mutex::new(SteadyTime::now()),
|
||||||
update_freq: peer_timeout/2
|
update_freq: peer_timeout/2,
|
||||||
|
running: Mutex::new(true)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -312,7 +314,7 @@ impl EthCloud {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
clone.run_tapdev()
|
clone.run_tapdev()
|
||||||
});
|
});
|
||||||
loop {
|
while *self.running.lock().expect("Lock poisoned") {
|
||||||
match self.housekeep() {
|
match self.housekeep() {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(e) => error!("Error: {:?}", e)
|
Err(e) => error!("Error: {:?}", e)
|
||||||
|
@ -320,4 +322,15 @@ impl EthCloud {
|
||||||
thread::sleep(StdDuration::new(1, 0));
|
thread::sleep(StdDuration::new(1, 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn close(&self) {
|
||||||
|
info!("Shutting down...");
|
||||||
|
for p in self.peers.lock().expect("Lock poisoned").as_vec() {
|
||||||
|
match self.send_msg(p, &udpmessage::Message::Close) {
|
||||||
|
Ok(()) => (),
|
||||||
|
Err(e) => error!("Failed to send close message to {}: {:?}", p, e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*self.running.lock().expect("Lock poisoned") = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,8 @@ use ethcloud::{Error, Token, EthCloud};
|
||||||
//FIXME: Send peer list in several packets when too large. The current behaviour panics at about
|
//FIXME: Send peer list in several packets when too large. The current behaviour panics at about
|
||||||
// 10000 peers.
|
// 10000 peers.
|
||||||
//TODO: Implement IPv6
|
//TODO: Implement IPv6
|
||||||
|
//TODO: Encryption
|
||||||
|
//TODO: Call close
|
||||||
|
|
||||||
|
|
||||||
struct SimpleLogger;
|
struct SimpleLogger;
|
||||||
|
@ -86,5 +88,5 @@ fn main() {
|
||||||
for addr in args.flag_connect {
|
for addr in args.flag_connect {
|
||||||
tapcloud.connect(&addr as &str).expect("Failed to send");
|
tapcloud.connect(&addr as &str).expect("Failed to send");
|
||||||
}
|
}
|
||||||
tapcloud.run();
|
tapcloud.run()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ use std::{mem, ptr, fmt};
|
||||||
use std::net::{SocketAddr, SocketAddrV4, Ipv4Addr};
|
use std::net::{SocketAddr, SocketAddrV4, Ipv4Addr};
|
||||||
use std::u16;
|
use std::u16;
|
||||||
|
|
||||||
use super::ethcloud::{Mac, Error, Token};
|
use super::ethcloud::{Error, Token};
|
||||||
use super::ethernet;
|
use super::ethernet;
|
||||||
use super::util::as_obj;
|
use super::util::as_obj;
|
||||||
|
|
||||||
|
@ -134,6 +134,7 @@ pub fn encode(token: Token, msg: &Message, buf: &mut [u8]) -> usize {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn encode_message_packet() {
|
fn encode_message_packet() {
|
||||||
|
use super::ethcloud::Mac;
|
||||||
let token = 134;
|
let token = 134;
|
||||||
let src = Mac([1,2,3,4,5,6]);
|
let src = Mac([1,2,3,4,5,6]);
|
||||||
let dst = Mac([7,8,9,10,11,12]);
|
let dst = Mac([7,8,9,10,11,12]);
|
||||||
|
|
Loading…
Reference in New Issue