small changes

This commit is contained in:
Dennis Schwerdel 2015-11-19 20:51:53 +01:00
parent 8f747e3448
commit b66e86bddf
3 changed files with 21 additions and 5 deletions

View File

@ -142,7 +142,8 @@ pub struct EthCloudInner {
tapdev: Mutex<TapDevice>,
token: Token,
next_peerlist: Mutex<SteadyTime>,
update_freq: Duration
update_freq: Duration,
running: Mutex<bool>
}
#[derive(Clone)]
@ -175,7 +176,8 @@ impl EthCloud {
tapdev: Mutex::new(tapdev),
token: token,
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 || {
clone.run_tapdev()
});
loop {
while *self.running.lock().expect("Lock poisoned") {
match self.housekeep() {
Ok(_) => (),
Err(e) => error!("Error: {:?}", e)
@ -320,4 +322,15 @@ impl EthCloud {
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;
}
}

View File

@ -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
// 10000 peers.
//TODO: Implement IPv6
//TODO: Encryption
//TODO: Call close
struct SimpleLogger;
@ -86,5 +88,5 @@ fn main() {
for addr in args.flag_connect {
tapcloud.connect(&addr as &str).expect("Failed to send");
}
tapcloud.run();
tapcloud.run()
}

View File

@ -2,7 +2,7 @@ use std::{mem, ptr, fmt};
use std::net::{SocketAddr, SocketAddrV4, Ipv4Addr};
use std::u16;
use super::ethcloud::{Mac, Error, Token};
use super::ethcloud::{Error, Token};
use super::ethernet;
use super::util::as_obj;
@ -134,6 +134,7 @@ pub fn encode(token: Token, msg: &Message, buf: &mut [u8]) -> usize {
#[test]
fn encode_message_packet() {
use super::ethcloud::Mac;
let token = 134;
let src = Mac([1,2,3,4,5,6]);
let dst = Mac([7,8,9,10,11,12]);