// VpnCloud - Peer-to-Peer VPN // Copyright (C) 2015-2021 Dennis Schwerdel // This software is licensed under GPL-3 or newer (see LICENSE.md) use std::{ cmp::{max, min}, collections::HashMap, fmt, fs::{self, File}, hash::BuildHasherDefault, io::{self, Cursor, Seek, SeekFrom, Write}, marker::PhantomData, net::{SocketAddr, ToSocketAddrs}, path::Path, str::FromStr, }; use fnv::FnvHasher; use rand::{random, seq::SliceRandom, thread_rng}; use smallvec::{smallvec, SmallVec}; use crate::{ beacon::BeaconSerializer, config::{Config, DEFAULT_PEER_TIMEOUT, DEFAULT_PORT}, crypto::{is_init_message, Crypto, MessageResult, PeerCrypto}, device::{Device, Type}, error::Error, messages::{ AddrList, NodeInfo, PeerInfo, MESSAGE_TYPE_CLOSE, MESSAGE_TYPE_DATA, MESSAGE_TYPE_KEEPALIVE, MESSAGE_TYPE_NODE_INFO, }, net::{mapped_addr, parse_listen, Socket}, payload::Protocol, poll::{WaitImpl, WaitResult}, port_forwarding::PortForwarding, table::ClaimTable, traffic::TrafficStats, types::{Address, Mode, NodeId, Range, RangeList}, util::{addr_nice, bytes_to_hex, resolve, CtrlC, Duration, MsgBuffer, StatsdMsg, Time, TimeSource}, }; pub type Hash = BuildHasherDefault; const MAX_RECONNECT_INTERVAL: u16 = 3600; const RESOLVE_INTERVAL: Time = 300; pub const STATS_INTERVAL: Time = 60; const OWN_ADDRESS_RESET_INTERVAL: Time = 300; const SPACE_BEFORE: usize = 100; struct PeerData { addrs: AddrList, #[allow(dead_code)] //TODO: export in status last_seen: Time, timeout: Time, peer_timeout: u16, node_id: NodeId, crypto: PeerCrypto, } #[derive(Clone)] pub struct ReconnectEntry { address: Option<(String, Time)>, resolved: AddrList, tries: u16, timeout: u16, next: Time, final_timeout: Option