diff --git a/Cargo.toml b/Cargo.toml
index 444767b0a..f7bb47033 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,10 +1,10 @@
[workspace]
members = [
- "zerotier-core-crypto",
- "zerotier-network-hypervisor",
- "zerotier-network-controller",
- "zerotier-system-service",
+ "core-crypto",
+ "network-hypervisor",
+ "controller",
+ "system-service",
]
[profile.release]
diff --git a/zerotier-network-controller/src/rules.rs b/attic/rules.rs
similarity index 100%
rename from zerotier-network-controller/src/rules.rs
rename to attic/rules.rs
diff --git a/controller/Cargo.toml b/controller/Cargo.toml
new file mode 100644
index 000000000..b6fb7171e
--- /dev/null
+++ b/controller/Cargo.toml
@@ -0,0 +1,12 @@
+[package]
+name = "zerotier-network-controller"
+version = "0.1.0"
+edition = "2021"
+
+[[bin]]
+name = "zerotier-controller"
+path = "src/main.rs"
+
+[dependencies]
+zerotier-core-crypto = { path = "../core-crypto" }
+zerotier-network-hypervisor = { path = "../network-hypervisor" }
diff --git a/controller/src/main.rs b/controller/src/main.rs
new file mode 100644
index 000000000..8b1378917
--- /dev/null
+++ b/controller/src/main.rs
@@ -0,0 +1 @@
+
diff --git a/zerotier-core-crypto/Cargo.toml b/core-crypto/Cargo.toml
similarity index 100%
rename from zerotier-core-crypto/Cargo.toml
rename to core-crypto/Cargo.toml
diff --git a/zerotier-core-crypto/README.md b/core-crypto/README.md
similarity index 100%
rename from zerotier-core-crypto/README.md
rename to core-crypto/README.md
diff --git a/zerotier-core-crypto/rustfmt.toml b/core-crypto/rustfmt.toml
similarity index 100%
rename from zerotier-core-crypto/rustfmt.toml
rename to core-crypto/rustfmt.toml
diff --git a/zerotier-core-crypto/src/aes.rs b/core-crypto/src/aes.rs
similarity index 100%
rename from zerotier-core-crypto/src/aes.rs
rename to core-crypto/src/aes.rs
diff --git a/zerotier-core-crypto/src/aes_gmac_siv/AES-GMAC-SIV.png b/core-crypto/src/aes_gmac_siv/AES-GMAC-SIV.png
similarity index 100%
rename from zerotier-core-crypto/src/aes_gmac_siv/AES-GMAC-SIV.png
rename to core-crypto/src/aes_gmac_siv/AES-GMAC-SIV.png
diff --git a/zerotier-core-crypto/src/aes_gmac_siv/README.md b/core-crypto/src/aes_gmac_siv/README.md
similarity index 100%
rename from zerotier-core-crypto/src/aes_gmac_siv/README.md
rename to core-crypto/src/aes_gmac_siv/README.md
diff --git a/zerotier-core-crypto/src/aes_gmac_siv/impl_macos.rs b/core-crypto/src/aes_gmac_siv/impl_macos.rs
similarity index 100%
rename from zerotier-core-crypto/src/aes_gmac_siv/impl_macos.rs
rename to core-crypto/src/aes_gmac_siv/impl_macos.rs
diff --git a/zerotier-core-crypto/src/aes_gmac_siv/impl_openssl.rs b/core-crypto/src/aes_gmac_siv/impl_openssl.rs
similarity index 100%
rename from zerotier-core-crypto/src/aes_gmac_siv/impl_openssl.rs
rename to core-crypto/src/aes_gmac_siv/impl_openssl.rs
diff --git a/zerotier-core-crypto/src/aes_gmac_siv/mod.rs b/core-crypto/src/aes_gmac_siv/mod.rs
similarity index 100%
rename from zerotier-core-crypto/src/aes_gmac_siv/mod.rs
rename to core-crypto/src/aes_gmac_siv/mod.rs
diff --git a/zerotier-core-crypto/src/hash.rs b/core-crypto/src/hash.rs
similarity index 100%
rename from zerotier-core-crypto/src/hash.rs
rename to core-crypto/src/hash.rs
diff --git a/zerotier-core-crypto/src/hex.rs b/core-crypto/src/hex.rs
similarity index 100%
rename from zerotier-core-crypto/src/hex.rs
rename to core-crypto/src/hex.rs
diff --git a/zerotier-core-crypto/src/kbkdf.rs b/core-crypto/src/kbkdf.rs
similarity index 100%
rename from zerotier-core-crypto/src/kbkdf.rs
rename to core-crypto/src/kbkdf.rs
diff --git a/zerotier-core-crypto/src/lib.rs b/core-crypto/src/lib.rs
similarity index 94%
rename from zerotier-core-crypto/src/lib.rs
rename to core-crypto/src/lib.rs
index 19000753d..2567fd7c4 100644
--- a/zerotier-core-crypto/src/lib.rs
+++ b/core-crypto/src/lib.rs
@@ -14,6 +14,4 @@ pub mod secret;
pub mod varint;
pub mod x25519;
-pub use pqc_kyber;
-
pub const ZEROES: [u8; 16] = [0_u8; 16];
diff --git a/zerotier-core-crypto/src/noise.rs b/core-crypto/src/noise.rs
similarity index 99%
rename from zerotier-core-crypto/src/noise.rs
rename to core-crypto/src/noise.rs
index 8ef8a889d..4bce88a96 100644
--- a/zerotier-core-crypto/src/noise.rs
+++ b/core-crypto/src/noise.rs
@@ -398,8 +398,8 @@ pub fn receive<
key.return_receive_cipher(c);
if tag.eq(&incoming_packet[data_len..]) {
- // If this is the "next" key, a valid packet using it indicates that it should become the current key.
if ki == 1 {
+ // Promote next key to current key on success.
unlikely_branch();
drop(state);
let mut state = session.state.write();
@@ -409,7 +409,6 @@ pub fn receive<
if packet_type == PACKET_TYPE_DATA {
return Ok(ReceiveResult::OkData(&buffer[HEADER_SIZE..data_len], u32::from_le_bytes(nonce[..4].try_into().unwrap())));
} else {
- unlikely_branch();
return Ok(ReceiveResult::Ok);
}
}
diff --git a/zerotier-core-crypto/src/p384.rs b/core-crypto/src/p384.rs
similarity index 100%
rename from zerotier-core-crypto/src/p384.rs
rename to core-crypto/src/p384.rs
diff --git a/zerotier-core-crypto/src/poly1305.rs b/core-crypto/src/poly1305.rs
similarity index 100%
rename from zerotier-core-crypto/src/poly1305.rs
rename to core-crypto/src/poly1305.rs
diff --git a/zerotier-core-crypto/src/random.rs b/core-crypto/src/random.rs
similarity index 100%
rename from zerotier-core-crypto/src/random.rs
rename to core-crypto/src/random.rs
diff --git a/zerotier-core-crypto/src/salsa.rs b/core-crypto/src/salsa.rs
similarity index 100%
rename from zerotier-core-crypto/src/salsa.rs
rename to core-crypto/src/salsa.rs
diff --git a/zerotier-core-crypto/src/secret.rs b/core-crypto/src/secret.rs
similarity index 100%
rename from zerotier-core-crypto/src/secret.rs
rename to core-crypto/src/secret.rs
diff --git a/zerotier-core-crypto/src/varint.rs b/core-crypto/src/varint.rs
similarity index 100%
rename from zerotier-core-crypto/src/varint.rs
rename to core-crypto/src/varint.rs
diff --git a/zerotier-core-crypto/src/x25519.rs b/core-crypto/src/x25519.rs
similarity index 100%
rename from zerotier-core-crypto/src/x25519.rs
rename to core-crypto/src/x25519.rs
diff --git a/zerotier-network-hypervisor/Cargo.toml b/network-hypervisor/Cargo.toml
similarity index 93%
rename from zerotier-network-hypervisor/Cargo.toml
rename to network-hypervisor/Cargo.toml
index 51e1642c8..e0548cba2 100644
--- a/zerotier-network-hypervisor/Cargo.toml
+++ b/network-hypervisor/Cargo.toml
@@ -10,7 +10,7 @@ default = ["debug_events"]
debug_events = []
[dependencies]
-zerotier-core-crypto = { path = "../zerotier-core-crypto" }
+zerotier-core-crypto = { path = "../core-crypto" }
async-trait = "^0"
base64 = "^0"
lz4_flex = { version = "^0", features = ["safe-encode", "safe-decode", "checked-decode"] }
diff --git a/zerotier-network-hypervisor/benches/benchmark_identity.rs b/network-hypervisor/benches/benchmark_identity.rs
similarity index 100%
rename from zerotier-network-hypervisor/benches/benchmark_identity.rs
rename to network-hypervisor/benches/benchmark_identity.rs
diff --git a/zerotier-network-hypervisor/default-rootset/make-root-set.sh b/network-hypervisor/default-rootset/make-root-set.sh
similarity index 100%
rename from zerotier-network-hypervisor/default-rootset/make-root-set.sh
rename to network-hypervisor/default-rootset/make-root-set.sh
diff --git a/zerotier-network-hypervisor/default-rootset/root.zerotier.com.bin b/network-hypervisor/default-rootset/root.zerotier.com.bin
similarity index 100%
rename from zerotier-network-hypervisor/default-rootset/root.zerotier.com.bin
rename to network-hypervisor/default-rootset/root.zerotier.com.bin
diff --git a/zerotier-network-hypervisor/default-rootset/root.zerotier.com.json b/network-hypervisor/default-rootset/root.zerotier.com.json
similarity index 100%
rename from zerotier-network-hypervisor/default-rootset/root.zerotier.com.json
rename to network-hypervisor/default-rootset/root.zerotier.com.json
diff --git a/zerotier-network-hypervisor/default-rootset/test-root.bin b/network-hypervisor/default-rootset/test-root.bin
similarity index 100%
rename from zerotier-network-hypervisor/default-rootset/test-root.bin
rename to network-hypervisor/default-rootset/test-root.bin
diff --git a/zerotier-network-hypervisor/default-rootset/test-root.json b/network-hypervisor/default-rootset/test-root.json
similarity index 100%
rename from zerotier-network-hypervisor/default-rootset/test-root.json
rename to network-hypervisor/default-rootset/test-root.json
diff --git a/zerotier-network-hypervisor/rustfmt.toml b/network-hypervisor/rustfmt.toml
similarity index 100%
rename from zerotier-network-hypervisor/rustfmt.toml
rename to network-hypervisor/rustfmt.toml
diff --git a/zerotier-network-hypervisor/src/error.rs b/network-hypervisor/src/error.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/error.rs
rename to network-hypervisor/src/error.rs
diff --git a/zerotier-network-hypervisor/src/event.rs b/network-hypervisor/src/event.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/event.rs
rename to network-hypervisor/src/event.rs
diff --git a/zerotier-network-hypervisor/src/lib.rs b/network-hypervisor/src/lib.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/lib.rs
rename to network-hypervisor/src/lib.rs
diff --git a/zerotier-network-hypervisor/src/networkhypervisor.rs b/network-hypervisor/src/networkhypervisor.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/networkhypervisor.rs
rename to network-hypervisor/src/networkhypervisor.rs
diff --git a/zerotier-network-hypervisor/src/util/buffer.rs b/network-hypervisor/src/util/buffer.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/util/buffer.rs
rename to network-hypervisor/src/util/buffer.rs
diff --git a/zerotier-network-hypervisor/src/util/canonicalobject.rs b/network-hypervisor/src/util/canonicalobject.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/util/canonicalobject.rs
rename to network-hypervisor/src/util/canonicalobject.rs
diff --git a/zerotier-network-hypervisor/src/util/gate.rs b/network-hypervisor/src/util/gate.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/util/gate.rs
rename to network-hypervisor/src/util/gate.rs
diff --git a/zerotier-network-hypervisor/src/util/marshalable.rs b/network-hypervisor/src/util/marshalable.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/util/marshalable.rs
rename to network-hypervisor/src/util/marshalable.rs
diff --git a/zerotier-network-hypervisor/src/util/mod.rs b/network-hypervisor/src/util/mod.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/util/mod.rs
rename to network-hypervisor/src/util/mod.rs
diff --git a/zerotier-network-hypervisor/src/util/pool.rs b/network-hypervisor/src/util/pool.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/util/pool.rs
rename to network-hypervisor/src/util/pool.rs
diff --git a/zerotier-network-hypervisor/src/util/testutil.rs b/network-hypervisor/src/util/testutil.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/util/testutil.rs
rename to network-hypervisor/src/util/testutil.rs
diff --git a/zerotier-network-hypervisor/src/vl1/address.rs b/network-hypervisor/src/vl1/address.rs
similarity index 92%
rename from zerotier-network-hypervisor/src/vl1/address.rs
rename to network-hypervisor/src/vl1/address.rs
index c36cea23f..d28f00328 100644
--- a/zerotier-network-hypervisor/src/vl1/address.rs
+++ b/network-hypervisor/src/vl1/address.rs
@@ -19,13 +19,19 @@ pub struct Address(NonZeroU64);
impl Address {
/// Get an address from a 64-bit integer or return None if it is zero or reserved.
- #[inline]
+ #[inline(always)]
pub fn from_u64(mut i: u64) -> Option
{
i &= 0xffffffffff;
- NonZeroU64::new(i).and_then(|ii| if (i >> 32) != ADDRESS_RESERVED_PREFIX as u64 { Some(Address(ii)) } else { None })
+ NonZeroU64::new(i).and_then(|ii| {
+ if (i >> 32) != ADDRESS_RESERVED_PREFIX as u64 {
+ Some(Address(ii))
+ } else {
+ None
+ }
+ })
}
- #[inline]
+ #[inline(always)]
pub fn from_bytes(b: &[u8]) -> Option {
if b.len() >= ADDRESS_SIZE {
Self::from_u64((b[0] as u64) << 32 | (b[1] as u64) << 24 | (b[2] as u64) << 16 | (b[3] as u64) << 8 | b[4] as u64)
@@ -34,32 +40,41 @@ impl Address {
}
}
- #[inline]
+ #[inline(always)]
pub fn from_bytes_fixed(b: &[u8; ADDRESS_SIZE]) -> Option {
Self::from_u64((b[0] as u64) << 32 | (b[1] as u64) << 24 | (b[2] as u64) << 16 | (b[3] as u64) << 8 | b[4] as u64)
}
- #[inline]
+ #[inline(always)]
pub fn to_bytes(&self) -> [u8; ADDRESS_SIZE] {
let i = self.0.get();
[(i >> 32) as u8, (i >> 24) as u8, (i >> 16) as u8, (i >> 8) as u8, i as u8]
}
+}
+impl From for u64 {
#[inline(always)]
- pub fn to_u64(&self) -> u64 {
- self.0.get()
+ fn from(a: Address) -> Self {
+ a.0.get()
+ }
+}
+
+impl From<&Address> for u64 {
+ #[inline(always)]
+ fn from(a: &Address) -> Self {
+ a.0.get()
}
}
impl Marshalable for Address {
const MAX_MARSHAL_SIZE: usize = ADDRESS_SIZE;
- #[inline]
+ #[inline(always)]
fn marshal(&self, buf: &mut Buffer) -> std::io::Result<()> {
buf.append_bytes(&self.0.get().to_be_bytes()[8 - ADDRESS_SIZE..])
}
- #[inline]
+ #[inline(always)]
fn unmarshal(buf: &Buffer, cursor: &mut usize) -> std::io::Result {
Self::from_bytes_fixed(buf.read_bytes_fixed(cursor)?).map_or_else(|| Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "cannot be zero")), |a| Ok(a))
}
@@ -168,7 +183,8 @@ mod tests {
let mut rawaddr: u64 = rand::random();
let addr = super::Address::from_u64(rawaddr);
assert!(addr.is_some());
- assert_eq!(addr.unwrap().to_u64(), rawaddr & 0xffffffffff);
+ let addr: u64 = addr.unwrap().into();
+ assert_eq!(addr, rawaddr & 0xffffffffff);
rawaddr = 0;
assert!(super::Address::from_u64(rawaddr).is_none());
diff --git a/zerotier-network-hypervisor/src/vl1/careof.rs b/network-hypervisor/src/vl1/careof.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/careof.rs
rename to network-hypervisor/src/vl1/careof.rs
diff --git a/zerotier-network-hypervisor/src/vl1/dictionary.rs b/network-hypervisor/src/vl1/dictionary.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/dictionary.rs
rename to network-hypervisor/src/vl1/dictionary.rs
diff --git a/zerotier-network-hypervisor/src/vl1/endpoint.rs b/network-hypervisor/src/vl1/endpoint.rs
similarity index 99%
rename from zerotier-network-hypervisor/src/vl1/endpoint.rs
rename to network-hypervisor/src/vl1/endpoint.rs
index 8abf7e8ae..fd9fb5b98 100644
--- a/zerotier-network-hypervisor/src/vl1/endpoint.rs
+++ b/network-hypervisor/src/vl1/endpoint.rs
@@ -230,19 +230,19 @@ impl Hash for Endpoint {
}
Endpoint::ZeroTier(a, _) => {
state.write_u8(TYPE_ZEROTIER);
- state.write_u64(a.to_u64())
+ state.write_u64(a.into())
}
Endpoint::Ethernet(m) => {
state.write_u8(TYPE_ETHERNET);
- state.write_u64(m.to_u64())
+ state.write_u64(m.into())
}
Endpoint::WifiDirect(m) => {
state.write_u8(TYPE_WIFIDIRECT);
- state.write_u64(m.to_u64())
+ state.write_u64(m.into())
}
Endpoint::Bluetooth(m) => {
state.write_u8(TYPE_BLUETOOTH);
- state.write_u64(m.to_u64())
+ state.write_u64(m.into())
}
Endpoint::Ip(ip) => {
state.write_u8(TYPE_IP);
@@ -266,7 +266,7 @@ impl Hash for Endpoint {
}
Endpoint::ZeroTierEncap(a, _) => {
state.write_u8(TYPE_ZEROTIER_ENCAP);
- state.write_u64(a.to_u64())
+ state.write_u64(a.into())
}
}
}
diff --git a/zerotier-network-hypervisor/src/vl1/fragmentedpacket.rs b/network-hypervisor/src/vl1/fragmentedpacket.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/fragmentedpacket.rs
rename to network-hypervisor/src/vl1/fragmentedpacket.rs
diff --git a/zerotier-network-hypervisor/src/vl1/identity.rs b/network-hypervisor/src/vl1/identity.rs
similarity index 98%
rename from zerotier-network-hypervisor/src/vl1/identity.rs
rename to network-hypervisor/src/vl1/identity.rs
index 465b47d58..bc1ecc74c 100644
--- a/zerotier-network-hypervisor/src/vl1/identity.rs
+++ b/network-hypervisor/src/vl1/identity.rs
@@ -208,8 +208,7 @@ impl Identity {
let p384_ecdh = P384KeyPair::generate();
let p384_ecdsa = P384KeyPair::generate();
- let mut self_sign_buf: Vec =
- Vec::with_capacity(ADDRESS_SIZE + C25519_PUBLIC_KEY_SIZE + ED25519_PUBLIC_KEY_SIZE + P384_PUBLIC_KEY_SIZE + P384_PUBLIC_KEY_SIZE + P384_ECDSA_SIGNATURE_SIZE + 4);
+ let mut self_sign_buf: Vec = Vec::with_capacity(ADDRESS_SIZE + C25519_PUBLIC_KEY_SIZE + ED25519_PUBLIC_KEY_SIZE + P384_PUBLIC_KEY_SIZE + P384_PUBLIC_KEY_SIZE + P384_ECDSA_SIGNATURE_SIZE + 4);
let _ = self_sign_buf.write_all(&self.address.to_bytes());
let _ = self_sign_buf.write_all(&self.x25519);
let _ = self_sign_buf.write_all(&self.ed25519);
@@ -614,15 +613,13 @@ impl Identity {
s.push(':');
}
s.push_str(":2:"); // 2 == IDENTITY_ALGORITHM_EC_NIST_P384
- let p384_joined: [u8; P384_PUBLIC_KEY_SIZE + P384_PUBLIC_KEY_SIZE + P384_ECDSA_SIGNATURE_SIZE + ED25519_SIGNATURE_SIZE] =
- concat_arrays_4(p384.ecdh.as_bytes(), p384.ecdsa.as_bytes(), &p384.ecdsa_self_signature, &p384.ed25519_self_signature);
+ let p384_joined: [u8; P384_PUBLIC_KEY_SIZE + P384_PUBLIC_KEY_SIZE + P384_ECDSA_SIGNATURE_SIZE + ED25519_SIGNATURE_SIZE] = concat_arrays_4(p384.ecdh.as_bytes(), p384.ecdsa.as_bytes(), &p384.ecdsa_self_signature, &p384.ed25519_self_signature);
s.push_str(base64::encode_config(p384_joined, base64::URL_SAFE_NO_PAD).as_str());
if self.secret.is_some() && include_private {
let secret = self.secret.as_ref().unwrap();
if secret.p384.is_some() {
let p384_secret = secret.p384.as_ref().unwrap();
- let p384_secret_joined: [u8; P384_SECRET_KEY_SIZE + P384_SECRET_KEY_SIZE] =
- concat_arrays_2(p384_secret.ecdh.secret_key_bytes().as_bytes(), p384_secret.ecdsa.secret_key_bytes().as_bytes());
+ let p384_secret_joined: [u8; P384_SECRET_KEY_SIZE + P384_SECRET_KEY_SIZE] = concat_arrays_2(p384_secret.ecdh.secret_key_bytes().as_bytes(), p384_secret.ecdsa.secret_key_bytes().as_bytes());
s.push(':');
s.push_str(base64::encode_config(p384_secret_joined, base64::URL_SAFE_NO_PAD).as_str());
}
@@ -809,7 +806,7 @@ impl PartialOrd for Identity {
impl Hash for Identity {
#[inline(always)]
fn hash(&self, state: &mut H) {
- state.write_u64(self.address.to_u64())
+ state.write_u64(self.address.into())
}
}
diff --git a/zerotier-network-hypervisor/src/vl1/inetaddress.rs b/network-hypervisor/src/vl1/inetaddress.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/inetaddress.rs
rename to network-hypervisor/src/vl1/inetaddress.rs
diff --git a/zerotier-network-hypervisor/src/vl1/mac.rs b/network-hypervisor/src/vl1/mac.rs
similarity index 92%
rename from zerotier-network-hypervisor/src/vl1/mac.rs
rename to network-hypervisor/src/vl1/mac.rs
index bdc463c6f..3ff4c6d2b 100644
--- a/zerotier-network-hypervisor/src/vl1/mac.rs
+++ b/network-hypervisor/src/vl1/mac.rs
@@ -23,12 +23,12 @@ impl Debug for MAC {
}
impl MAC {
- #[inline]
+ #[inline(always)]
pub fn from_u64(i: u64) -> Option {
NonZeroU64::new(i & 0xffffffffffff).map(|i| MAC(i))
}
- #[inline]
+ #[inline(always)]
pub fn from_bytes(b: &[u8]) -> Option {
if b.len() >= 6 {
NonZeroU64::new((b[0] as u64) << 40 | (b[1] as u64) << 32 | (b[2] as u64) << 24 | (b[3] as u64) << 16 as u64 | (b[4] as u64) << 8 | b[5] as u64).map(|i| MAC(i))
@@ -37,32 +37,41 @@ impl MAC {
}
}
- #[inline]
+ #[inline(always)]
pub fn from_bytes_fixed(b: &[u8; 6]) -> Option {
NonZeroU64::new((b[0] as u64) << 40 | (b[1] as u64) << 32 | (b[2] as u64) << 24 | (b[3] as u64) << 16 as u64 | (b[4] as u64) << 8 | b[5] as u64).map(|i| MAC(i))
}
- #[inline]
+ #[inline(always)]
pub fn to_bytes(&self) -> [u8; 6] {
let i = self.0.get();
[(i >> 40) as u8, (i >> 32) as u8, (i >> 24) as u8, (i >> 16) as u8, (i >> 8) as u8, i as u8]
}
+}
+impl From for u64 {
#[inline(always)]
- pub fn to_u64(&self) -> u64 {
- self.0.get()
+ fn from(m: MAC) -> Self {
+ m.0.get()
+ }
+}
+
+impl From<&MAC> for u64 {
+ #[inline(always)]
+ fn from(m: &MAC) -> Self {
+ m.0.get()
}
}
impl Marshalable for MAC {
const MAX_MARSHAL_SIZE: usize = 6;
- #[inline]
+ #[inline(always)]
fn marshal(&self, buf: &mut Buffer) -> std::io::Result<()> {
buf.append_bytes(&self.0.get().to_be_bytes()[2..])
}
- #[inline]
+ #[inline(always)]
fn unmarshal(buf: &Buffer, cursor: &mut usize) -> std::io::Result {
Self::from_bytes_fixed(buf.read_bytes_fixed(cursor)?).map_or_else(|| Err(std::io::Error::new(std::io::ErrorKind::InvalidData, "cannot be zero")), |a| Ok(a))
}
diff --git a/zerotier-network-hypervisor/src/vl1/mod.rs b/network-hypervisor/src/vl1/mod.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/mod.rs
rename to network-hypervisor/src/vl1/mod.rs
diff --git a/zerotier-network-hypervisor/src/vl1/node.rs b/network-hypervisor/src/vl1/node.rs
similarity index 95%
rename from zerotier-network-hypervisor/src/vl1/node.rs
rename to network-hypervisor/src/vl1/node.rs
index b97143999..6baed36bf 100644
--- a/zerotier-network-hypervisor/src/vl1/node.rs
+++ b/network-hypervisor/src/vl1/node.rs
@@ -97,16 +97,7 @@ pub trait InnerProtocolInterface: Sync + Send + 'static {
async fn handle_packet(&self, source: &Peer, source_path: &Path, verb: u8, payload: &PacketBuffer) -> bool;
/// Handle errors, returning true if the error was recognized.
- async fn handle_error(
- &self,
- source: &Peer,
- source_path: &Path,
- in_re_verb: u8,
- in_re_message_id: u64,
- error_code: u8,
- payload: &PacketBuffer,
- cursor: &mut usize,
- ) -> bool;
+ async fn handle_error(&self, source: &Peer, source_path: &Path, in_re_verb: u8, in_re_message_id: u64, error_code: u8, payload: &PacketBuffer, cursor: &mut usize) -> bool;
/// Handle an OK, returing true if the OK was recognized.
async fn handle_ok(&self, source: &Peer, source_path: &Path, in_re_verb: u8, in_re_message_id: u64, payload: &PacketBuffer, cursor: &mut usize) -> bool;
@@ -350,12 +341,36 @@ impl Node {
debug_event!(
si,
"[vl1] do_background_tasks:{}{}{}{}{}{} ----",
- if root_sync { " root_sync" } else { "" },
- if root_hello { " root_hello" } else { "" },
- if root_spam_hello { " root_spam_hello" } else { "" },
- if peer_service { " peer_service" } else { "" },
- if path_service { " path_service" } else { "" },
- if whois_service { " whois_service" } else { "" },
+ if root_sync {
+ " root_sync"
+ } else {
+ ""
+ },
+ if root_hello {
+ " root_hello"
+ } else {
+ ""
+ },
+ if root_spam_hello {
+ " root_spam_hello"
+ } else {
+ ""
+ },
+ if peer_service {
+ " peer_service"
+ } else {
+ ""
+ },
+ if path_service {
+ " path_service"
+ } else {
+ ""
+ },
+ if whois_service {
+ " whois_service"
+ } else {
+ ""
+ },
);
if root_sync {
@@ -388,9 +403,7 @@ impl Node {
for m in rs.members.iter() {
if m.identity.eq(&self.identity) {
let _ = my_root_sets.get_or_insert_with(|| Vec::new()).write_all(rs.to_bytes().as_slice());
- } else if self.peers.read().get(&m.identity.address).map_or(false, |p| !p.identity.eq(&m.identity))
- || address_collision_check.insert(m.identity.address, &m.identity).map_or(false, |old_id| !old_id.eq(&m.identity))
- {
+ } else if self.peers.read().get(&m.identity.address).map_or(false, |p| !p.identity.eq(&m.identity)) || address_collision_check.insert(m.identity.address, &m.identity).map_or(false, |old_id| !old_id.eq(&m.identity)) {
address_collisions.push(m.identity.address);
}
}
@@ -428,7 +441,10 @@ impl Node {
)));
}
for i in bad_identities.iter() {
- si.event(Event::SecurityWarning(format!("bad identity detected for address {} in at least one root set, ignoring (error creating peer object)", i.address.to_string())));
+ si.event(Event::SecurityWarning(format!(
+ "bad identity detected for address {} in at least one root set, ignoring (error creating peer object)",
+ i.address.to_string()
+ )));
}
let mut new_root_identities: Vec = new_roots.iter().map(|(p, _)| p.identity.clone()).collect();
@@ -529,15 +545,7 @@ impl Node {
Duration::from_millis(1000)
}
- pub async fn handle_incoming_physical_packet(
- &self,
- si: &SI,
- ph: &PH,
- source_endpoint: &Endpoint,
- source_local_socket: &SI::LocalSocket,
- source_local_interface: &SI::LocalInterface,
- mut data: PooledPacketBuffer,
- ) {
+ pub async fn handle_incoming_physical_packet(&self, si: &SI, ph: &PH, source_endpoint: &Endpoint, source_local_socket: &SI::LocalSocket, source_local_interface: &SI::LocalInterface, mut data: PooledPacketBuffer) {
debug_event!(
si,
"[vl1] {} -> #{} {}->{} length {} (on socket {}@{})",
diff --git a/zerotier-network-hypervisor/src/vl1/path.rs b/network-hypervisor/src/vl1/path.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/path.rs
rename to network-hypervisor/src/vl1/path.rs
diff --git a/zerotier-network-hypervisor/src/vl1/peer.rs b/network-hypervisor/src/vl1/peer.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/peer.rs
rename to network-hypervisor/src/vl1/peer.rs
diff --git a/zerotier-network-hypervisor/src/vl1/protocol.rs b/network-hypervisor/src/vl1/protocol.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/protocol.rs
rename to network-hypervisor/src/vl1/protocol.rs
diff --git a/zerotier-network-hypervisor/src/vl1/rootset.rs b/network-hypervisor/src/vl1/rootset.rs
similarity index 98%
rename from zerotier-network-hypervisor/src/vl1/rootset.rs
rename to network-hypervisor/src/vl1/rootset.rs
index 262b552b6..29ce0cad2 100644
--- a/zerotier-network-hypervisor/src/vl1/rootset.rs
+++ b/network-hypervisor/src/vl1/rootset.rs
@@ -183,7 +183,13 @@ impl RootSet {
/// method will return true when signing is complete.
pub fn sign(&mut self, member_identity: &Identity) -> bool {
let signature = member_identity.sign(self.marshal_for_signing().as_bytes(), false);
- let unsigned_entry = self.members.iter().find_map(|m| if m.identity.eq(member_identity) { Some(m.clone()) } else { None });
+ let unsigned_entry = self.members.iter().find_map(|m| {
+ if m.identity.eq(member_identity) {
+ Some(m.clone())
+ } else {
+ None
+ }
+ });
if unsigned_entry.is_some() && signature.is_some() {
let unsigned_entry = unsigned_entry.unwrap();
self.members.retain(|m| !m.identity.eq(member_identity));
diff --git a/zerotier-network-hypervisor/src/vl1/symmetricsecret.rs b/network-hypervisor/src/vl1/symmetricsecret.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/symmetricsecret.rs
rename to network-hypervisor/src/vl1/symmetricsecret.rs
diff --git a/zerotier-network-hypervisor/src/vl1/whoisqueue.rs b/network-hypervisor/src/vl1/whoisqueue.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl1/whoisqueue.rs
rename to network-hypervisor/src/vl1/whoisqueue.rs
diff --git a/zerotier-network-hypervisor/src/vl2/mod.rs b/network-hypervisor/src/vl2/mod.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl2/mod.rs
rename to network-hypervisor/src/vl2/mod.rs
diff --git a/zerotier-network-hypervisor/src/vl2/multicastgroup.rs b/network-hypervisor/src/vl2/multicastgroup.rs
similarity index 96%
rename from zerotier-network-hypervisor/src/vl2/multicastgroup.rs
rename to network-hypervisor/src/vl2/multicastgroup.rs
index 113acf3dc..b80b7a1bf 100644
--- a/zerotier-network-hypervisor/src/vl2/multicastgroup.rs
+++ b/network-hypervisor/src/vl2/multicastgroup.rs
@@ -45,7 +45,7 @@ impl PartialOrd for MulticastGroup {
impl Hash for MulticastGroup {
#[inline(always)]
fn hash(&self, state: &mut H) {
- state.write_u64(self.mac.to_u64());
+ state.write_u64(self.mac.into());
state.write_u32(self.adi);
}
}
diff --git a/zerotier-network-hypervisor/src/vl2/networkid.rs b/network-hypervisor/src/vl2/networkid.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl2/networkid.rs
rename to network-hypervisor/src/vl2/networkid.rs
diff --git a/zerotier-network-hypervisor/src/vl2/switch.rs b/network-hypervisor/src/vl2/switch.rs
similarity index 100%
rename from zerotier-network-hypervisor/src/vl2/switch.rs
rename to network-hypervisor/src/vl2/switch.rs
diff --git a/zerotier-system-service/Cargo.toml b/system-service/Cargo.toml
similarity index 88%
rename from zerotier-system-service/Cargo.toml
rename to system-service/Cargo.toml
index 117e5eb8f..19e24802c 100644
--- a/zerotier-system-service/Cargo.toml
+++ b/system-service/Cargo.toml
@@ -10,8 +10,8 @@ name = "zerotier"
path = "src/main.rs"
[dependencies]
-zerotier-network-hypervisor = { path = "../zerotier-network-hypervisor" }
-zerotier-core-crypto = { path = "../zerotier-core-crypto" }
+zerotier-network-hypervisor = { path = "../network-hypervisor" }
+zerotier-core-crypto = { path = "../core-crypto" }
async-trait = "^0"
num-traits = "^0"
tokio = { version = "^1", features = ["fs", "io-util", "io-std", "net", "parking_lot", "process", "rt", "rt-multi-thread", "signal", "sync", "time"], default-features = false }
diff --git a/zerotier-system-service/rustfmt.toml b/system-service/rustfmt.toml
similarity index 100%
rename from zerotier-system-service/rustfmt.toml
rename to system-service/rustfmt.toml
diff --git a/zerotier-system-service/src/cli/mod.rs b/system-service/src/cli/mod.rs
similarity index 100%
rename from zerotier-system-service/src/cli/mod.rs
rename to system-service/src/cli/mod.rs
diff --git a/zerotier-system-service/src/cli/rootset.rs b/system-service/src/cli/rootset.rs
similarity index 100%
rename from zerotier-system-service/src/cli/rootset.rs
rename to system-service/src/cli/rootset.rs
diff --git a/zerotier-system-service/src/cmdline_help.rs b/system-service/src/cmdline_help.rs
similarity index 100%
rename from zerotier-system-service/src/cmdline_help.rs
rename to system-service/src/cmdline_help.rs
diff --git a/zerotier-system-service/src/datadir.rs b/system-service/src/datadir.rs
similarity index 100%
rename from zerotier-system-service/src/datadir.rs
rename to system-service/src/datadir.rs
diff --git a/zerotier-system-service/src/exitcode.rs b/system-service/src/exitcode.rs
similarity index 100%
rename from zerotier-system-service/src/exitcode.rs
rename to system-service/src/exitcode.rs
diff --git a/zerotier-system-service/src/getifaddrs.rs b/system-service/src/getifaddrs.rs
similarity index 100%
rename from zerotier-system-service/src/getifaddrs.rs
rename to system-service/src/getifaddrs.rs
diff --git a/zerotier-system-service/src/ipv6.rs b/system-service/src/ipv6.rs
similarity index 100%
rename from zerotier-system-service/src/ipv6.rs
rename to system-service/src/ipv6.rs
diff --git a/zerotier-system-service/src/jsonformatter.rs b/system-service/src/jsonformatter.rs
similarity index 100%
rename from zerotier-system-service/src/jsonformatter.rs
rename to system-service/src/jsonformatter.rs
diff --git a/zerotier-system-service/src/localconfig.rs b/system-service/src/localconfig.rs
similarity index 100%
rename from zerotier-system-service/src/localconfig.rs
rename to system-service/src/localconfig.rs
diff --git a/zerotier-system-service/src/localinterface.rs b/system-service/src/localinterface.rs
similarity index 100%
rename from zerotier-system-service/src/localinterface.rs
rename to system-service/src/localinterface.rs
diff --git a/zerotier-system-service/src/localsocket.rs b/system-service/src/localsocket.rs
similarity index 100%
rename from zerotier-system-service/src/localsocket.rs
rename to system-service/src/localsocket.rs
diff --git a/zerotier-system-service/src/main.rs b/system-service/src/main.rs
similarity index 100%
rename from zerotier-system-service/src/main.rs
rename to system-service/src/main.rs
diff --git a/zerotier-system-service/src/service.rs b/system-service/src/service.rs
similarity index 100%
rename from zerotier-system-service/src/service.rs
rename to system-service/src/service.rs
diff --git a/zerotier-system-service/src/udp.rs b/system-service/src/udp.rs
similarity index 100%
rename from zerotier-system-service/src/udp.rs
rename to system-service/src/udp.rs
diff --git a/zerotier-system-service/src/utils.rs b/system-service/src/utils.rs
similarity index 100%
rename from zerotier-system-service/src/utils.rs
rename to system-service/src/utils.rs
diff --git a/zerotier-system-service/src/vnic/common.rs b/system-service/src/vnic/common.rs
similarity index 100%
rename from zerotier-system-service/src/vnic/common.rs
rename to system-service/src/vnic/common.rs
diff --git a/zerotier-system-service/src/vnic/mac_feth_tap.rs b/system-service/src/vnic/mac_feth_tap.rs
similarity index 100%
rename from zerotier-system-service/src/vnic/mac_feth_tap.rs
rename to system-service/src/vnic/mac_feth_tap.rs
diff --git a/zerotier-system-service/src/vnic/mod.rs b/system-service/src/vnic/mod.rs
similarity index 100%
rename from zerotier-system-service/src/vnic/mod.rs
rename to system-service/src/vnic/mod.rs
diff --git a/zerotier-system-service/src/vnic/vnic.rs b/system-service/src/vnic/vnic.rs
similarity index 100%
rename from zerotier-system-service/src/vnic/vnic.rs
rename to system-service/src/vnic/vnic.rs
diff --git a/zerotier-network-controller/Cargo.toml b/zerotier-network-controller/Cargo.toml
deleted file mode 100644
index 31b0c6f4c..000000000
--- a/zerotier-network-controller/Cargo.toml
+++ /dev/null
@@ -1,10 +0,0 @@
-[package]
-name = "zerotier-network-controller"
-version = "0.1.0"
-edition = "2021"
-
-# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
-
-[dependencies]
-serde = "*"
-serde_json = "*"
diff --git a/zerotier-network-controller/src/main.rs b/zerotier-network-controller/src/main.rs
deleted file mode 100644
index 3590dc634..000000000
--- a/zerotier-network-controller/src/main.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-mod rules;
-
-fn main() {
- println!("Hello, world!");
-}