Some fixes

This commit is contained in:
Dennis Schwerdel 2021-03-27 10:53:36 +00:00
parent 68f4cb7787
commit a3d0daa0f6
6 changed files with 32 additions and 42 deletions

View File

@ -3,4 +3,4 @@
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-1
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends asciidoctor
&& apt-get -y install --no-install-recommends asciidoctor valgrind

13
Cargo.lock generated
View File

@ -156,9 +156,9 @@ dependencies = [
[[package]]
name = "console"
version = "0.13.0"
version = "0.14.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a50aab2529019abfabfa93f1e6c41ef392f91fbf179b347a7e96abb524884a08"
checksum = "3993e6445baa160675931ec041a5e03ca84b9c6e32a056150d3aa2bdda0a1f45"
dependencies = [
"encode_unicode",
"lazy_static",
@ -167,7 +167,6 @@ dependencies = [
"terminal_size",
"unicode-width",
"winapi",
"winapi-util",
]
[[package]]
@ -299,9 +298,9 @@ dependencies = [
[[package]]
name = "dialoguer"
version = "0.7.1"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70f807b2943dc90f9747497d9d65d7e92472149be0b88bf4ce1201b4ac979c26"
checksum = "c9dd058f8b65922819fabb4a41e7d1964e56344042c26efbccd465202c23fa0c"
dependencies = [
"console",
"lazy_static",
@ -1624,6 +1623,6 @@ dependencies = [
[[package]]
name = "zeroize"
version = "0.9.3"
version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86"
checksum = "81a974bcdd357f0dca4d41677db03436324d45a4c9ed2d0b873a5a360ce41c36"

View File

@ -33,7 +33,7 @@ byteorder = "1.4"
thiserror = "1.0"
parking_lot = "*"
smallvec = "1.6"
dialoguer = { version = "0.7", optional = true }
dialoguer = { version = "0.8", optional = true }
tungstenite = { version = "0.13", optional = true, default-features = false }
url = { version = "2.2", optional = true }
igd = { version = "0.12", optional = true }

View File

@ -236,6 +236,7 @@ impl TunTapDevice {
Some(value) => value,
None => {
let default_device = get_default_device().await?;
info!("Deriving MTU from default device {}", default_device);
get_device_mtu(&default_device)? - self.get_overhead()
}
};
@ -480,6 +481,8 @@ async fn get_default_device() -> io::Result<String> {
let mut fd = BufReader::new(File::open("/proc/net/route").await?);
let mut best = None;
let mut line = String::with_capacity(80);
fd.read_line(&mut line).await?;
line.clear();
while let Ok(read) = fd.read_line(&mut line).await {
if read == 0 {
break;
@ -492,6 +495,7 @@ async fn get_default_device() -> io::Result<String> {
if parts[2] != "00000000" {
best = Some(parts[0].to_string())
}
line.clear();
}
if let Some(ifname) = best {
Ok(ifname)

View File

@ -3,23 +3,11 @@ use tokio;
use fnv::FnvHasher;
use crate::{
config::Config,
crypto::PeerCrypto,
device::Device,
engine::{
use crate::{config::Config, crypto::PeerCrypto, device::Device, engine::{
device_thread::DeviceThread,
shared::{SharedPeerCrypto, SharedTable, SharedTraffic},
socket_thread::SocketThread,
},
error::Error,
messages::AddrList,
net::Socket,
payload::Protocol,
port_forwarding::PortForwarding,
types::NodeId,
util::{CtrlC, Time, TimeSource},
};
socket_thread::{SocketThread, ReconnectEntry},
}, error::Error, messages::AddrList, net::Socket, payload::Protocol, port_forwarding::PortForwarding, types::NodeId, util::{CtrlC, Time, TimeSource, resolve}};
pub type Hash = BuildHasherDefault<FnvHasher>;
@ -36,16 +24,6 @@ pub struct PeerData {
pub crypto: PeerCrypto,
}
#[derive(Clone)]
pub struct ReconnectEntry {
address: Option<(String, Time)>,
resolved: AddrList,
tries: u16,
timeout: u16,
next: Time,
final_timeout: Option<Time>,
}
pub struct GenericCloud<D: Device, P: Protocol, S: Socket, TS: TimeSource> {
socket_thread: SocketThread<S, D, P, TS>,
device_thread: DeviceThread<S, D, P, TS>,
@ -82,7 +60,16 @@ impl<D: Device, P: Protocol, S: Socket, TS: TimeSource> GenericCloud<D, P, S, TS
}
pub fn add_peer(&mut self, addr: String) -> Result<(), Error> {
unimplemented!()
let resolved = resolve(addr.clone())?;
self.socket_thread.reconnect_peers.push(ReconnectEntry{
address: Some((addr, TS::now())),
resolved,
tries: 0,
timeout: 1,
next: TS::now(),
final_timeout: None
});
Ok(())
}
pub async fn run(self) {

View File

@ -42,12 +42,12 @@ pub const STATS_INTERVAL: Time = 60;
#[derive(Clone)]
pub struct ReconnectEntry {
address: Option<(String, Time)>,
resolved: AddrList,
tries: u16,
timeout: u16,
next: Time,
final_timeout: Option<Time>,
pub address: Option<(String, Time)>,
pub resolved: AddrList,
pub tries: u16,
pub timeout: u16,
pub next: Time,
pub final_timeout: Option<Time>,
}
pub struct SocketThread<S: Socket, D: Device, P: Protocol, TS: TimeSource> {
@ -75,7 +75,7 @@ pub struct SocketThread<S: Socket, D: Device, P: Protocol, TS: TimeSource> {
beacon_serializer: BeaconSerializer<TS>,
stats_file: Option<File>,
statsd_server: Option<String>,
reconnect_peers: SmallVec<[ReconnectEntry; 3]>,
pub reconnect_peers: SmallVec<[ReconnectEntry; 3]>,
buffer: MsgBuffer,
broadcast_buffer: MsgBuffer,
// Shared fields