mirror of https://github.com/dswd/vpncloud.git
Using FNV hash
This commit is contained in:
parent
dffdd4fd0a
commit
c11d5b4d6e
|
@ -14,6 +14,7 @@ This project follows [semantic versioning](http://semver.org).
|
|||
- [changed] New measurements
|
||||
- [changed] Only calling crypto_init once
|
||||
- [changed] Passing listen address as &str
|
||||
- [changed] Using FNV hash for better performance
|
||||
- [fixed] Fixed wrong hex address formatting
|
||||
- [fixed] Fixed peer exchange for more than 65000 peers
|
||||
- [fixed] Initializing crypto for benchmarks
|
||||
|
|
|
@ -5,11 +5,12 @@ dependencies = [
|
|||
"aligned_alloc 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"docopt 0.6.78 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"epoll 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fnv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"gcc 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nix 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"nix 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pkg-config 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"signal 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -30,8 +31,8 @@ version = "0.1.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -39,12 +40,17 @@ name = "bitflags"
|
|||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "docopt"
|
||||
version = "0.6.78"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"regex 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.1.59 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-serialize 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"strsim 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
@ -55,7 +61,7 @@ version = "0.2.5"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"errno 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -64,13 +70,18 @@ version = "0.1.6"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "fnv"
|
||||
version = "1.0.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "gcc"
|
||||
version = "0.3.24"
|
||||
version = "0.3.26"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -78,7 +89,7 @@ name = "kernel32-sys"
|
|||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
|
@ -89,7 +100,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.7"
|
||||
version = "0.2.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -97,7 +108,7 @@ name = "log"
|
|||
version = "0.3.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -105,9 +116,14 @@ name = "memchr"
|
|||
version = "0.1.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mempool"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.4.2"
|
||||
|
@ -117,9 +133,18 @@ dependencies = [
|
|||
"libc 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nix"
|
||||
version = "0.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"bitflags 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "pkg-config"
|
||||
version = "0.3.6"
|
||||
version = "0.3.8"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -127,23 +152,24 @@ name = "rand"
|
|||
version = "0.3.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "0.1.51"
|
||||
version = "0.1.59"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"aho-corasick 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"memchr 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mempool 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"utf8-ranges 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.2.3"
|
||||
version = "0.3.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
@ -172,8 +198,8 @@ version = "0.1.34"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"kernel32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"winapi 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -183,7 +209,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
|
||||
[[package]]
|
||||
name = "winapi"
|
||||
version = "0.2.5"
|
||||
version = "0.2.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -17,14 +17,15 @@ rustc-serialize = "0.3"
|
|||
log = "0.3"
|
||||
epoll = "0.2"
|
||||
signal = "0.1"
|
||||
nix = "0.4"
|
||||
nix = "0.5"
|
||||
libc = "0.2"
|
||||
aligned_alloc = "0.1.1"
|
||||
rand = "0.3"
|
||||
fnv = "1"
|
||||
|
||||
[build-dependencies]
|
||||
gcc = "0.3"
|
||||
pkg-config = "0.3.6"
|
||||
pkg-config = "0.3"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
|
|
@ -11,7 +11,9 @@ use std::io::Result as IoResult;
|
|||
use std::fmt;
|
||||
use std::os::unix::io::AsRawFd;
|
||||
use std::marker::PhantomData;
|
||||
use std::hash::BuildHasherDefault;
|
||||
|
||||
use fnv::FnvHasher;
|
||||
use epoll;
|
||||
use nix::sys::signal::{SIGTERM, SIGQUIT, SIGINT};
|
||||
use signal::trap::Trap;
|
||||
|
@ -24,14 +26,16 @@ use super::udpmessage::{encode, decode, Options, Message};
|
|||
use super::crypto::Crypto;
|
||||
use super::util::{now, Time, Duration};
|
||||
|
||||
type Hash = BuildHasherDefault<FnvHasher>;
|
||||
|
||||
struct PeerList {
|
||||
timeout: Duration,
|
||||
peers: HashMap<SocketAddr, Time>
|
||||
peers: HashMap<SocketAddr, Time, Hash>
|
||||
}
|
||||
|
||||
impl PeerList {
|
||||
fn new(timeout: Duration) -> PeerList {
|
||||
PeerList{peers: HashMap::new(), timeout: timeout}
|
||||
PeerList{peers: HashMap::default(), timeout: timeout}
|
||||
}
|
||||
|
||||
fn timeout(&mut self) -> Vec<SocketAddr> {
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
|
||||
use std::net::SocketAddr;
|
||||
use std::collections::HashMap;
|
||||
use std::hash::BuildHasherDefault;
|
||||
|
||||
use fnv::FnvHasher;
|
||||
|
||||
use super::types::{Error, Table, Protocol, Address};
|
||||
use super::util::{now, Time, Duration};
|
||||
|
@ -48,15 +51,17 @@ struct SwitchTableValue {
|
|||
timeout: Time
|
||||
}
|
||||
|
||||
type Hash = BuildHasherDefault<FnvHasher>;
|
||||
|
||||
pub struct SwitchTable {
|
||||
table: HashMap<Address, SwitchTableValue>,
|
||||
table: HashMap<Address, SwitchTableValue, Hash>,
|
||||
cache: Option<(Address, SocketAddr)>,
|
||||
timeout: Duration
|
||||
}
|
||||
|
||||
impl SwitchTable {
|
||||
pub fn new(timeout: Duration) -> Self {
|
||||
SwitchTable{table: HashMap::new(), cache: None, timeout: timeout}
|
||||
SwitchTable{table: HashMap::default(), cache: None, timeout: timeout}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
use std::net::SocketAddr;
|
||||
use std::collections::{hash_map, HashMap};
|
||||
use std::io::Read;
|
||||
use std::hash::BuildHasherDefault;
|
||||
|
||||
use fnv::FnvHasher;
|
||||
|
||||
use super::types::{Protocol, Error, Table, Address};
|
||||
|
||||
|
@ -47,11 +50,13 @@ struct RoutingEntry {
|
|||
prefix_len: u8
|
||||
}
|
||||
|
||||
pub struct RoutingTable(HashMap<Vec<u8>, Vec<RoutingEntry>>);
|
||||
type Hash = BuildHasherDefault<FnvHasher>;
|
||||
|
||||
pub struct RoutingTable(HashMap<Vec<u8>, Vec<RoutingEntry>, Hash>);
|
||||
|
||||
impl RoutingTable {
|
||||
pub fn new() -> Self {
|
||||
RoutingTable(HashMap::new())
|
||||
RoutingTable(HashMap::default())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ extern crate nix;
|
|||
extern crate libc;
|
||||
extern crate aligned_alloc;
|
||||
extern crate rand;
|
||||
extern crate fnv;
|
||||
#[cfg(feature = "bench")] extern crate test;
|
||||
|
||||
#[macro_use] mod util;
|
||||
|
|
Loading…
Reference in New Issue