This commit is contained in:
John Smith 2023-04-22 20:48:24 -04:00
parent 438553a1ca
commit cb4abaefd7
29 changed files with 334 additions and 284 deletions

219
Cargo.lock generated
View File

@ -595,6 +595,25 @@ version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a"
[[package]]
name = "bindgen"
version = "0.57.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd4865004a46a0aafb2a0a5eb19d3c9fc46ee5f063a6cfc605c69ac9ecf5263d"
dependencies = [
"bitflags 1.3.2",
"cexpr 0.4.0",
"clang-sys",
"lazy_static",
"lazycell",
"peeking_take_while",
"proc-macro2",
"quote",
"regex",
"rustc-hash",
"shlex 0.1.1",
]
[[package]] [[package]]
name = "bindgen" name = "bindgen"
version = "0.59.2" version = "0.59.2"
@ -602,7 +621,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"cexpr", "cexpr 0.6.0",
"clang-sys", "clang-sys",
"clap 2.34.0", "clap 2.34.0",
"env_logger 0.9.3", "env_logger 0.9.3",
@ -614,7 +633,7 @@ dependencies = [
"quote", "quote",
"regex", "regex",
"rustc-hash", "rustc-hash",
"shlex", "shlex 1.1.0",
"which", "which",
] ]
@ -718,9 +737,9 @@ dependencies = [
[[package]] [[package]]
name = "boringssl-src" name = "boringssl-src"
version = "0.5.2+6195bf8" version = "0.3.0+688fc5c"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ab565ccc5e276ea82a2013dd08bf2c999866b06daf1d4f30fee419c4aaec6d5" checksum = "f901accdf830d2ea2f4e27f923a5e1125cd8b1a39ab578b9db1a42d578a6922b"
dependencies = [ dependencies = [
"cmake", "cmake",
] ]
@ -837,6 +856,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c"
[[package]]
name = "cexpr"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f4aedb84272dbe89af497cf81375129abda4fc0a9e7c5d317498c15cc30c0d27"
dependencies = [
"nom 5.1.2",
]
[[package]] [[package]]
name = "cexpr" name = "cexpr"
version = "0.6.0" version = "0.6.0"
@ -1914,6 +1942,12 @@ dependencies = [
"static_assertions", "static_assertions",
] ]
[[package]]
name = "fixedbitset"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80"
[[package]] [[package]]
name = "flate2" name = "flate2"
version = "1.0.25" version = "1.0.25"
@ -2207,26 +2241,25 @@ dependencies = [
[[package]] [[package]]
name = "grpcio" name = "grpcio"
version = "0.12.1" version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "609832ca501baeb662dc81932fda9ed83f5d058f4b899a807ba222ce696f430a" checksum = "24d99e00eed7e0a04ee2705112e7cfdbe1a3cc771147f22f016a8cd2d002187b"
dependencies = [ dependencies = [
"futures-executor", "futures",
"futures-util",
"grpcio-sys", "grpcio-sys",
"libc", "libc",
"log", "log",
"parking_lot 0.12.1", "parking_lot 0.11.2",
"protobuf", "protobuf",
] ]
[[package]] [[package]]
name = "grpcio-sys" name = "grpcio-sys"
version = "0.12.1+1.46.5-patched" version = "0.9.1+1.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf625d1803b6f44203f0428ddace847fb4994def5c803fc8a7a2f18fb3daec62" checksum = "9447d1a926beeef466606cc45717f80897998b548e7dc622873d453e1ecb4be4"
dependencies = [ dependencies = [
"bindgen", "bindgen 0.57.0",
"boringssl-src", "boringssl-src",
"cc", "cc",
"cmake", "cmake",
@ -3146,6 +3179,12 @@ dependencies = [
"winapi 0.3.9", "winapi 0.3.9",
] ]
[[package]]
name = "multimap"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a"
[[package]] [[package]]
name = "nanorand" name = "nanorand"
version = "0.7.0" version = "0.7.0"
@ -3337,6 +3376,16 @@ dependencies = [
"version_check 0.1.5", "version_check 0.1.5",
] ]
[[package]]
name = "nom"
version = "5.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
dependencies = [
"memchr",
"version_check 0.9.4",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.3" version = "7.1.3"
@ -3524,32 +3573,22 @@ version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e" checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e"
dependencies = [ dependencies = [
"opentelemetry_api 0.18.0", "opentelemetry_api",
"opentelemetry_sdk 0.18.0", "opentelemetry_sdk",
]
[[package]]
name = "opentelemetry"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f4b8347cc26099d3aeee044065ecc3ae11469796b4d65d065a23a584ed92a6f"
dependencies = [
"opentelemetry_api 0.19.0",
"opentelemetry_sdk 0.19.0",
] ]
[[package]] [[package]]
name = "opentelemetry-otlp" name = "opentelemetry-otlp"
version = "0.12.0" version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8af72d59a4484654ea8eb183fea5ae4eb6a41d7ac3e3bae5f4d2a282a3a7d3ca" checksum = "d1c928609d087790fc936a1067bdc310ae702bdf3b090c3f281b713622c8bbde"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"futures", "futures",
"futures-util", "futures-util",
"grpcio", "grpcio",
"http", "http",
"opentelemetry 0.19.0", "opentelemetry",
"opentelemetry-proto", "opentelemetry-proto",
"prost", "prost",
"protobuf", "protobuf",
@ -3560,26 +3599,27 @@ dependencies = [
[[package]] [[package]]
name = "opentelemetry-proto" name = "opentelemetry-proto"
version = "0.2.0" version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "045f8eea8c0fa19f7d48e7bc3128a39c2e5c533d5c61298c548dfefc1064474c" checksum = "d61a2f56df5574508dd86aaca016c917489e589ece4141df1b5e349af8d66c28"
dependencies = [ dependencies = [
"futures", "futures",
"futures-util", "futures-util",
"grpcio", "grpcio",
"opentelemetry 0.19.0", "opentelemetry",
"prost", "prost",
"protobuf", "protobuf",
"tonic", "tonic",
"tonic-build",
] ]
[[package]] [[package]]
name = "opentelemetry-semantic-conventions" name = "opentelemetry-semantic-conventions"
version = "0.11.0" version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "24e33428e6bf08c6f7fcea4ddb8e358fab0fe48ab877a87c70c6ebe20f673ce5" checksum = "9b02e0230abb0ab6636d18e2ba8fa02903ea63772281340ccac18e0af3ec9eeb"
dependencies = [ dependencies = [
"opentelemetry 0.19.0", "opentelemetry",
] ]
[[package]] [[package]]
@ -3598,47 +3638,11 @@ dependencies = [
"thiserror", "thiserror",
] ]
[[package]]
name = "opentelemetry_api"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed41783a5bf567688eb38372f2b7a8530f5a607a4b49d38dd7573236c23ca7e2"
dependencies = [
"fnv",
"futures-channel",
"futures-util",
"indexmap",
"once_cell",
"pin-project-lite 0.2.9",
"thiserror",
"urlencoding",
]
[[package]] [[package]]
name = "opentelemetry_sdk" name = "opentelemetry_sdk"
version = "0.18.0" version = "0.18.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ca41c4933371b61c2a2f214bf16931499af4ec90543604ec828f7a625c09113" checksum = "1ca41c4933371b61c2a2f214bf16931499af4ec90543604ec828f7a625c09113"
dependencies = [
"async-trait",
"crossbeam-channel",
"dashmap",
"fnv",
"futures-channel",
"futures-executor",
"futures-util",
"once_cell",
"opentelemetry_api 0.18.0",
"percent-encoding",
"rand 0.8.5",
"thiserror",
]
[[package]]
name = "opentelemetry_sdk"
version = "0.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b3a2a91fdbfdd4d212c0dcc2ab540de2c2bcbbd90be17de7a7daf8822d010c1"
dependencies = [ dependencies = [
"async-std", "async-std",
"async-trait", "async-trait",
@ -3649,7 +3653,7 @@ dependencies = [
"futures-executor", "futures-executor",
"futures-util", "futures-util",
"once_cell", "once_cell",
"opentelemetry_api 0.19.0", "opentelemetry_api",
"percent-encoding", "percent-encoding",
"rand 0.8.5", "rand 0.8.5",
"thiserror", "thiserror",
@ -3867,6 +3871,16 @@ dependencies = [
"sha2 0.10.6", "sha2 0.10.6",
] ]
[[package]]
name = "petgraph"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4dd7d28ee937e54fe3080c91faa1c3a46c06de6252988a7f4592ba2310ef22a4"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]] [[package]]
name = "pharos" name = "pharos"
version = "0.5.3" version = "0.5.3"
@ -4002,6 +4016,16 @@ version = "0.2.17"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
[[package]]
name = "prettyplease"
version = "0.1.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8646e95016a7a6c4adea95bafa8a16baab64b583356217f2c85db4a39d9a86"
dependencies = [
"proc-macro2",
"syn 1.0.109",
]
[[package]] [[package]]
name = "primitive-types" name = "primitive-types"
version = "0.12.1" version = "0.12.1"
@ -4059,6 +4083,28 @@ dependencies = [
"prost-derive", "prost-derive",
] ]
[[package]]
name = "prost-build"
version = "0.11.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "119533552c9a7ffacc21e099c24a0ac8bb19c2a2a3f363de84cd9b844feab270"
dependencies = [
"bytes 1.4.0",
"heck",
"itertools",
"lazy_static",
"log",
"multimap",
"petgraph",
"prettyplease",
"prost",
"prost-types",
"regex",
"syn 1.0.109",
"tempfile",
"which",
]
[[package]] [[package]]
name = "prost-derive" name = "prost-derive"
version = "0.11.9" version = "0.11.9"
@ -4864,6 +4910,12 @@ dependencies = [
"lazy_static", "lazy_static",
] ]
[[package]]
name = "shlex"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2"
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.1.0" version = "1.1.0"
@ -5505,6 +5557,19 @@ dependencies = [
"tracing-futures", "tracing-futures",
] ]
[[package]]
name = "tonic-build"
version = "0.8.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bf5e9b9c0f7e0a7c027dcfaba7b2c60816c7049171f679d99ee2ff65d0de8c4"
dependencies = [
"prettyplease",
"proc-macro2",
"prost-build",
"quote",
"syn 1.0.109",
]
[[package]] [[package]]
name = "tower" name = "tower"
version = "0.4.13" version = "0.4.13"
@ -5631,7 +5696,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21ebb87a95ea13271332df069020513ab70bdb5637ca42d6e492dc3bbbad48de" checksum = "21ebb87a95ea13271332df069020513ab70bdb5637ca42d6e492dc3bbbad48de"
dependencies = [ dependencies = [
"once_cell", "once_cell",
"opentelemetry 0.18.0", "opentelemetry",
"tracing", "tracing",
"tracing-core", "tracing-core",
"tracing-log", "tracing-log",
@ -5644,7 +5709,7 @@ version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9bc58223383423483e4bc056c7e7b3f77bdee924a9d33834112c69ead06dc847" checksum = "9bc58223383423483e4bc056c7e7b3f77bdee924a9d33834112c69ead06dc847"
dependencies = [ dependencies = [
"bindgen", "bindgen 0.59.2",
"cc", "cc",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"fnv", "fnv",
@ -5874,12 +5939,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "urlencoding"
version = "2.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9"
[[package]] [[package]]
name = "utf-8" name = "utf-8"
version = "0.7.6" version = "0.7.6"
@ -6061,7 +6120,7 @@ dependencies = [
"hostname", "hostname",
"jni 0.21.1", "jni 0.21.1",
"lazy_static", "lazy_static",
"opentelemetry 0.19.0", "opentelemetry",
"opentelemetry-otlp", "opentelemetry-otlp",
"opentelemetry-semantic-conventions", "opentelemetry-semantic-conventions",
"parking_lot 0.12.1", "parking_lot 0.12.1",
@ -6102,7 +6161,7 @@ dependencies = [
"json", "json",
"lazy_static", "lazy_static",
"nix 0.26.2", "nix 0.26.2",
"opentelemetry 0.19.0", "opentelemetry",
"opentelemetry-otlp", "opentelemetry-otlp",
"opentelemetry-semantic-conventions", "opentelemetry-semantic-conventions",
"parking_lot 0.12.1", "parking_lot 0.12.1",

View File

@ -445,46 +445,46 @@ reply - reply to an AppCall not handled directly by the server
pub fn update_app_message(&mut self, msg: veilid_core::VeilidAppMessage) { pub fn update_app_message(&mut self, msg: veilid_core::VeilidAppMessage) {
// check is message body is ascii printable // check is message body is ascii printable
let mut printable = true; let mut printable = true;
for c in &msg.message { for c in msg.message() {
if *c < 32 || *c > 126 { if *c < 32 || *c > 126 {
printable = false; printable = false;
} }
} }
let strmsg = if printable { let strmsg = if printable {
String::from_utf8_lossy(&msg.message).to_string() String::from_utf8_lossy(msg.message()).to_string()
} else { } else {
hex::encode(&msg.message) hex::encode(msg.message())
}; };
self.inner() self.inner()
.ui .ui
.add_node_event(format!("AppMessage ({:?}): {}", msg.sender, strmsg)); .add_node_event(format!("AppMessage ({:?}): {}", msg.sender(), strmsg));
} }
pub fn update_app_call(&mut self, call: veilid_core::VeilidAppCall) { pub fn update_app_call(&mut self, call: veilid_core::VeilidAppCall) {
// check is message body is ascii printable // check is message body is ascii printable
let mut printable = true; let mut printable = true;
for c in &call.message { for c in call.message() {
if *c < 32 || *c > 126 { if *c < 32 || *c > 126 {
printable = false; printable = false;
} }
} }
let strmsg = if printable { let strmsg = if printable {
String::from_utf8_lossy(&call.message).to_string() String::from_utf8_lossy(call.message()).to_string()
} else { } else {
format!("#{}", hex::encode(&call.message)) format!("#{}", hex::encode(call.message()))
}; };
self.inner().ui.add_node_event(format!( self.inner().ui.add_node_event(format!(
"AppCall ({:?}) id = {:016x} : {}", "AppCall ({:?}) id = {:016x} : {}",
call.sender, call.sender(),
call.id.as_u64(), call.id().as_u64(),
strmsg strmsg
)); ));
self.inner_mut().last_call_id = Some(call.id); self.inner_mut().last_call_id = Some(call.id());
} }
pub fn update_shutdown(&mut self) { pub fn update_shutdown(&mut self) {

View File

@ -14,17 +14,17 @@ pub async fn test_signed_node_info() {
let vcrypto = crypto.get(ck).unwrap(); let vcrypto = crypto.get(ck).unwrap();
// Test direct // Test direct
let node_info = NodeInfo { let node_info = NodeInfo::new(
network_class: NetworkClass::InboundCapable, NetworkClass::InboundCapable,
outbound_protocols: ProtocolTypeSet::all(), ProtocolTypeSet::all(),
address_types: AddressTypeSet::all(), AddressTypeSet::all(),
envelope_support: VALID_ENVELOPE_VERSIONS.to_vec(), VALID_ENVELOPE_VERSIONS.to_vec(),
crypto_support: VALID_CRYPTO_KINDS.to_vec(), VALID_CRYPTO_KINDS.to_vec(),
dial_info_detail_list: vec![DialInfoDetail { vec![DialInfoDetail {
class: DialInfoClass::Mapped, class: DialInfoClass::Mapped,
dial_info: DialInfo::udp(SocketAddress::default()), dial_info: DialInfo::udp(SocketAddress::default()),
}], }],
}; );
// Test correct validation // Test correct validation
let keypair = vcrypto.generate_keypair(); let keypair = vcrypto.generate_keypair();
@ -48,7 +48,6 @@ pub async fn test_signed_node_info() {
// Test incorrect validation // Test incorrect validation
let keypair1 = vcrypto.generate_keypair(); let keypair1 = vcrypto.generate_keypair();
let tks1: TypedKeySet = TypedKey::new(ck, keypair1.key).into(); let tks1: TypedKeySet = TypedKey::new(ck, keypair1.key).into();
let oldtks1len = tks1.len();
let sdni = SignedDirectNodeInfo::new( let sdni = SignedDirectNodeInfo::new(
node_info.clone(), node_info.clone(),
sni.timestamp(), sni.timestamp(),
@ -69,17 +68,17 @@ pub async fn test_signed_node_info() {
assert_eq!(sdnifake.signatures().len(), sigsfake.len()); assert_eq!(sdnifake.signatures().len(), sigsfake.len());
// Test relayed // Test relayed
let node_info2 = NodeInfo { let node_info2 = NodeInfo::new(
network_class: NetworkClass::OutboundOnly, NetworkClass::OutboundOnly,
outbound_protocols: ProtocolTypeSet::all(), ProtocolTypeSet::all(),
address_types: AddressTypeSet::all(), AddressTypeSet::all(),
envelope_support: VALID_ENVELOPE_VERSIONS.to_vec(), VALID_ENVELOPE_VERSIONS.to_vec(),
crypto_support: VALID_CRYPTO_KINDS.to_vec(), VALID_CRYPTO_KINDS.to_vec(),
dial_info_detail_list: vec![DialInfoDetail { vec![DialInfoDetail {
class: DialInfoClass::Blocked, class: DialInfoClass::Blocked,
dial_info: DialInfo::udp(SocketAddress::default()), dial_info: DialInfo::udp(SocketAddress::default()),
}], }],
}; );
// Test correct validation // Test correct validation
let keypair2 = vcrypto.generate_keypair(); let keypair2 = vcrypto.generate_keypair();
@ -109,7 +108,6 @@ pub async fn test_signed_node_info() {
// Test incorrect validation // Test incorrect validation
let keypair3 = vcrypto.generate_keypair(); let keypair3 = vcrypto.generate_keypair();
let tks3: TypedKeySet = TypedKey::new(ck, keypair3.key).into(); let tks3: TypedKeySet = TypedKey::new(ck, keypair3.key).into();
let oldtks3len = tks3.len();
let srni = SignedRelayedNodeInfo::new( let srni = SignedRelayedNodeInfo::new(
node_info2.clone(), node_info2.clone(),

View File

@ -27,5 +27,5 @@ impl LowLevelProtocolType {
matches!(self, LowLevelProtocolType::TCP) matches!(self, LowLevelProtocolType::TCP)
} }
} }
pub type LowLevelProtocolTypeSet = EnumSet<LowLevelProtocolType>;
// pub type LowLevelProtocolTypeSet = EnumSet<LowLevelProtocolType>;

View File

@ -136,6 +136,7 @@ impl BucketEntryInner {
/// Returns Ok(None) if no previous existing node id was associated with that crypto kind /// Returns Ok(None) if no previous existing node id was associated with that crypto kind
/// Results Err() if this operation would add more crypto kinds than we support /// Results Err() if this operation would add more crypto kinds than we support
pub fn add_node_id(&mut self, node_id: TypedKey) -> EyreResult<Option<TypedKey>> { pub fn add_node_id(&mut self, node_id: TypedKey) -> EyreResult<Option<TypedKey>> {
let total_node_id_count = self.validated_node_ids.len() + self.unsupported_node_ids.len();
let node_ids = if VALID_CRYPTO_KINDS.contains(&node_id.kind) { let node_ids = if VALID_CRYPTO_KINDS.contains(&node_id.kind) {
&mut self.validated_node_ids &mut self.validated_node_ids
} else { } else {
@ -152,7 +153,7 @@ impl BucketEntryInner {
return Ok(Some(old_node_id)); return Ok(Some(old_node_id));
} }
// Check to ensure we aren't adding more crypto kinds than we support // Check to ensure we aren't adding more crypto kinds than we support
if self.validated_node_ids.len() + self.unsupported_node_ids.len() == MAX_CRYPTO_KINDS { if total_node_id_count == MAX_CRYPTO_KINDS {
bail!("too many crypto kinds for this node"); bail!("too many crypto kinds for this node");
} }
node_ids.add(node_id); node_ids.add(node_id);
@ -345,10 +346,10 @@ impl BucketEntryInner {
}; };
// Peer info includes all node ids, even unvalidated ones // Peer info includes all node ids, even unvalidated ones
let node_ids = self.node_ids(); let node_ids = self.node_ids();
opt_current_sni.as_ref().map(|s| PeerInfo { opt_current_sni.as_ref().map(|s| PeerInfo::new(
node_ids, node_ids,
signed_node_info: *s.clone(), *s.clone(),
}) ))
} }
pub fn best_routing_domain( pub fn best_routing_domain(
@ -792,14 +793,14 @@ pub struct BucketEntry {
impl BucketEntry { impl BucketEntry {
pub(super) fn new(first_node_id: TypedKey) -> Self { pub(super) fn new(first_node_id: TypedKey) -> Self {
let now = get_aligned_timestamp();
let mut validated_node_ids = TypedKeySet::new();
let mut unsupported_node_ids = TypedKeySet::new();
validated_node_ids.add(first_node_id);
// First node id should always be one we support since TypedKeySets are sorted and we must have at least one supported key
assert!(VALID_CRYPTO_KINDS.contains(&first_node_id.kind));
let now = get_aligned_timestamp();
let inner = BucketEntryInner { let inner = BucketEntryInner {
validated_node_ids, validated_node_ids: TypedKeySet::from(first_node_id),
unsupported_node_ids, unsupported_node_ids: TypedKeySet::new(),
envelope_support: Vec::new(), envelope_support: Vec::new(),
updated_since_last_network_change: false, updated_since_last_network_change: false,
last_connections: BTreeMap::new(), last_connections: BTreeMap::new(),

View File

@ -329,14 +329,15 @@ impl RoutingTable {
let crypto_support = bsrec.node_ids.kinds(); let crypto_support = bsrec.node_ids.kinds();
// Make unsigned SignedNodeInfo // Make unsigned SignedNodeInfo
let sni = SignedNodeInfo::Direct(SignedDirectNodeInfo::with_no_signature(NodeInfo { let sni =
network_class: NetworkClass::InboundCapable, // Bootstraps are always inbound capable SignedNodeInfo::Direct(SignedDirectNodeInfo::with_no_signature(NodeInfo::new(
outbound_protocols: ProtocolTypeSet::only(ProtocolType::UDP), // Bootstraps do not participate in relaying and will not make outbound requests, but will have UDP enabled NetworkClass::InboundCapable, // Bootstraps are always inbound capable
address_types: AddressTypeSet::all(), // Bootstraps are always IPV4 and IPV6 capable ProtocolTypeSet::only(ProtocolType::UDP), // Bootstraps do not participate in relaying and will not make outbound requests, but will have UDP enabled
envelope_support: bsrec.envelope_support, // Envelope support is as specified in the bootstrap list AddressTypeSet::all(), // Bootstraps are always IPV4 and IPV6 capable
bsrec.envelope_support, // Envelope support is as specified in the bootstrap list
crypto_support, // Crypto support is derived from list of node ids crypto_support, // Crypto support is derived from list of node ids
dial_info_detail_list: bsrec.dial_info_details, // Dial info is as specified in the bootstrap list bsrec.dial_info_details, // Dial info is as specified in the bootstrap list
})); )));
let pi = PeerInfo::new(bsrec.node_ids, sni); let pi = PeerInfo::new(bsrec.node_ids, sni);

View File

@ -56,11 +56,6 @@ pub use typed_signature::*;
use super::*; use super::*;
#[derive(Debug, Clone)]
pub struct DecodeContext {
config: VeilidConfig,
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub enum QuestionContext { pub enum QuestionContext {
GetValue(ValidateGetValueContext), GetValue(ValidateGetValueContext),
@ -69,7 +64,7 @@ pub enum QuestionContext {
#[derive(Clone)] #[derive(Clone)]
pub struct RPCValidateContext { pub struct RPCValidateContext {
crypto: Crypto, pub crypto: Crypto,
rpc_processor: RPCProcessor, pub rpc_processor: RPCProcessor,
question_context: Option<QuestionContext>, pub question_context: Option<QuestionContext>,
} }

View File

@ -133,10 +133,7 @@ impl RPCOperation {
) )
} }
pub fn decode( pub fn decode(operation_reader: &veilid_capnp::operation::Reader) -> Result<Self, RPCError> {
context: &DecodeContext,
operation_reader: &veilid_capnp::operation::Reader,
) -> Result<Self, RPCError> {
let op_id = OperationId::new(operation_reader.get_op_id()); let op_id = OperationId::new(operation_reader.get_op_id());
let sender_peer_info = if operation_reader.has_sender_peer_info() { let sender_peer_info = if operation_reader.has_sender_peer_info() {

View File

@ -5,9 +5,9 @@ const MAX_GET_VALUE_A_PEERS_LEN: usize = 20;
#[derive(Clone)] #[derive(Clone)]
pub struct ValidateGetValueContext { pub struct ValidateGetValueContext {
last_descriptor: Option<SignedValueDescriptor>, pub last_descriptor: Option<SignedValueDescriptor>,
subkey: ValueSubkey, pub subkey: ValueSubkey,
vcrypto: CryptoSystemVersion, pub vcrypto: CryptoSystemVersion,
} }
impl fmt::Debug for ValidateGetValueContext { impl fmt::Debug for ValidateGetValueContext {

View File

@ -6,7 +6,7 @@ pub struct RPCOperationReturnReceipt {
} }
impl RPCOperationReturnReceipt { impl RPCOperationReturnReceipt {
pub fn new(receipt: &[u8]) -> Result<Self, RPCError> { pub fn new(receipt: Vec<u8>) -> Result<Self, RPCError> {
if receipt.len() < MIN_RECEIPT_SIZE { if receipt.len() < MIN_RECEIPT_SIZE {
return Err(RPCError::protocol("ReturnReceipt receipt too short to set")); return Err(RPCError::protocol("ReturnReceipt receipt too short to set"));
} }
@ -14,9 +14,7 @@ impl RPCOperationReturnReceipt {
return Err(RPCError::protocol("ReturnReceipt receipt too long to set")); return Err(RPCError::protocol("ReturnReceipt receipt too long to set"));
} }
Ok(Self { Ok(Self { receipt })
receipt: receipt.to_vec(),
})
} }
pub fn validate(&mut self, _validate_context: &RPCValidateContext) -> Result<(), RPCError> { pub fn validate(&mut self, _validate_context: &RPCValidateContext) -> Result<(), RPCError> {
Ok(()) Ok(())

View File

@ -44,8 +44,5 @@ pub fn decode_peer_info(reader: &veilid_capnp::peer_info::Reader) -> Result<Peer
if node_ids.len() == 0 { if node_ids.len() == 0 {
return Err(RPCError::protocol("no verified node ids")); return Err(RPCError::protocol("no verified node ids"));
} }
Ok(PeerInfo { Ok(PeerInfo::new(node_ids, signed_node_info))
node_ids,
signed_node_info,
})
} }

View File

@ -312,7 +312,7 @@ impl RPCProcessor {
} }
pub fn set_storage_manager(&self, opt_storage_manager: Option<StorageManager>) { pub fn set_storage_manager(&self, opt_storage_manager: Option<StorageManager>) {
let inner = self.inner.lock(); let mut inner = self.inner.lock();
inner.opt_storage_manager = opt_storage_manager inner.opt_storage_manager = opt_storage_manager
} }
@ -555,10 +555,7 @@ impl RPCProcessor {
// Prepare route operation // Prepare route operation
let sr_hop_count = compiled_route.safety_route.hop_count; let sr_hop_count = compiled_route.safety_route.hop_count;
let route_operation = RPCOperationRoute { let route_operation = RPCOperationRoute::new(compiled_route.safety_route, operation);
safety_route: compiled_route.safety_route,
operation,
};
let ssni_route = let ssni_route =
self.get_sender_peer_info(&Destination::direct(compiled_route.first_hop.clone())); self.get_sender_peer_info(&Destination::direct(compiled_route.first_hop.clone()));
let operation = RPCOperation::new_statement( let operation = RPCOperation::new_statement(
@ -1216,18 +1213,15 @@ impl RPCProcessor {
.get_root::<veilid_capnp::operation::Reader>() .get_root::<veilid_capnp::operation::Reader>()
.map_err(RPCError::protocol) .map_err(RPCError::protocol)
.map_err(logthru_rpc!())?; .map_err(logthru_rpc!())?;
let decode_context = DecodeContext { let mut operation = RPCOperation::decode(&op_reader)?;
config: self.config.clone(),
};
let operation = RPCOperation::decode(&decode_context, &op_reader)?;
// Validate the RPC message // Validate the RPC message
self.validate_rpc_operation(&operation)?; self.validate_rpc_operation(&mut operation)?;
Ok(operation) Ok(operation)
} }
fn validate_rpc_operation(&self, operation: &RPCOperation) -> Result<(), RPCError> { fn validate_rpc_operation(&self, operation: &mut RPCOperation) -> Result<(), RPCError> {
// If this is an answer, get the question context for this answer // If this is an answer, get the question context for this answer
// If we received an answer for a question we did not ask, this will return an error // If we received an answer for a question we did not ask, this will return an error
let question_context = if let RPCOperationKind::Answer(_) = operation.kind() { let question_context = if let RPCOperationKind::Answer(_) = operation.kind() {
@ -1260,7 +1254,10 @@ impl RPCProcessor {
let msg = match &encoded_msg.header.detail { let msg = match &encoded_msg.header.detail {
RPCMessageHeaderDetail::Direct(detail) => { RPCMessageHeaderDetail::Direct(detail) => {
// Decode and validate the RPC operation // Decode and validate the RPC operation
let operation = self.decode_rpc_operation(&encoded_msg)?; let operation = match self.decode_rpc_operation(&encoded_msg) {
Ok(v) => v,
Err(e) => return Ok(NetworkResult::invalid_message(e)),
};
// Get the routing domain this message came over // Get the routing domain this message came over
let routing_domain = detail.routing_domain; let routing_domain = detail.routing_domain;

View File

@ -100,7 +100,7 @@ where
/// Get operation context /// Get operation context
pub fn get_op_context(&self, op_id: OperationId) -> Result<C, RPCError> { pub fn get_op_context(&self, op_id: OperationId) -> Result<C, RPCError> {
let mut inner = self.inner.lock(); let inner = self.inner.lock();
let Some(waiting_op) = inner.waiting_op_table.get(&op_id) else { let Some(waiting_op) = inner.waiting_op_table.get(&op_id) else {
return Err(RPCError::internal("Missing operation id getting op context")); return Err(RPCError::internal("Missing operation id getting op context"));
}; };

View File

@ -9,7 +9,7 @@ impl RPCProcessor {
dest: Destination, dest: Destination,
message: Vec<u8>, message: Vec<u8>,
) -> Result<NetworkResult<Answer<Vec<u8>>>, RPCError> { ) -> Result<NetworkResult<Answer<Vec<u8>>>, RPCError> {
let app_call_q = RPCOperationAppCallQ::new(&message)?; let app_call_q = RPCOperationAppCallQ::new(message)?;
let question = RPCQuestion::new( let question = RPCQuestion::new(
network_result_try!(self.get_destination_respond_to(&dest)?), network_result_try!(self.get_destination_respond_to(&dest)?),
RPCQuestionDetail::AppCallQ(app_call_q), RPCQuestionDetail::AppCallQ(app_call_q),
@ -91,7 +91,7 @@ impl RPCProcessor {
}; };
// Return the appcall answer // Return the appcall answer
let app_call_a = RPCOperationAppCallA::new(&message_a)?; let app_call_a = RPCOperationAppCallA::new(message_a)?;
// Send status answer // Send status answer
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::AppCallA(app_call_a))) self.answer(msg, RPCAnswer::new(RPCAnswerDetail::AppCallA(app_call_a)))

View File

@ -9,7 +9,7 @@ impl RPCProcessor {
dest: Destination, dest: Destination,
message: Vec<u8>, message: Vec<u8>,
) -> Result<NetworkResult<()>, RPCError> { ) -> Result<NetworkResult<()>, RPCError> {
let app_message = RPCOperationAppMessage { message }; let app_message = RPCOperationAppMessage::new(message)?;
let statement = RPCStatement::new(RPCStatementDetail::AppMessage(app_message)); let statement = RPCStatement::new(RPCStatementDetail::AppMessage(app_message));
// Send the app message request // Send the app message request
@ -22,7 +22,7 @@ impl RPCProcessor {
msg: RPCMessage, msg: RPCMessage,
) -> Result<NetworkResult<()>, RPCError> { ) -> Result<NetworkResult<()>, RPCError> {
// Get the statement // Get the statement
let (op_id, _, _, kind) = msg.operation.destructure(); let (_, _, _, kind) = msg.operation.destructure();
let app_message = match kind { let app_message = match kind {
RPCOperationKind::Statement(s) => match s.destructure() { RPCOperationKind::Statement(s) => match s.destructure() {
RPCStatementDetail::AppMessage(s) => s, RPCStatementDetail::AppMessage(s) => s,

View File

@ -1,8 +1,12 @@
use super::*; use super::*;
use crate::storage_manager::SignedValueDescriptor; use crate::storage_manager::{SignedValueData, SignedValueDescriptor};
#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)] #[derive(Clone, Debug)]
pub enum GetValueAnswer {} pub struct GetValueAnswer {
pub value: Option<SignedValueData>,
pub peers: Vec<PeerInfo>,
pub descriptor: Option<SignedValueDescriptor>,
}
impl RPCProcessor { impl RPCProcessor {
// Sends a get value request and wait for response // Sends a get value request and wait for response
@ -44,17 +48,24 @@ impl RPCProcessor {
// Get the right answer type // Get the right answer type
let (_, _, _, kind) = msg.operation.destructure(); let (_, _, _, kind) = msg.operation.destructure();
let app_call_a = match kind { let get_value_a = match kind {
RPCOperationKind::Answer(a) => match a.destructure() { RPCOperationKind::Answer(a) => match a.destructure() {
RPCAnswerDetail::AppCallA(a) => a, RPCAnswerDetail::GetValueA(a) => a,
_ => return Err(RPCError::invalid_format("not an appcall answer")), _ => return Err(RPCError::invalid_format("not a getvalue answer")),
}, },
_ => return Err(RPCError::invalid_format("not an answer")), _ => return Err(RPCError::invalid_format("not an answer")),
}; };
let a_message = app_call_a.destructure(); let (value, peers, descriptor) = get_value_a.destructure();
Ok(NetworkResult::value(Answer::new(latency, a_message))) Ok(NetworkResult::value(Answer::new(
latency,
GetValueAnswer {
value,
peers,
descriptor,
},
)))
} }
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)] #[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), ret, err)]

View File

@ -11,7 +11,7 @@ impl RPCProcessor {
) -> Result<NetworkResult<()>, RPCError> { ) -> Result<NetworkResult<()>, RPCError> {
let receipt = receipt.as_ref().to_vec(); let receipt = receipt.as_ref().to_vec();
let return_receipt = RPCOperationReturnReceipt { receipt }; let return_receipt = RPCOperationReturnReceipt::new(receipt)?;
let statement = RPCStatement::new(RPCStatementDetail::ReturnReceipt(return_receipt)); let statement = RPCStatement::new(RPCStatementDetail::ReturnReceipt(return_receipt));
// Send the return_receipt request // Send the return_receipt request
@ -27,9 +27,9 @@ impl RPCProcessor {
) -> Result<NetworkResult<()>, RPCError> { ) -> Result<NetworkResult<()>, RPCError> {
// Get the statement // Get the statement
let (_, _, _, kind) = msg.operation.destructure(); let (_, _, _, kind) = msg.operation.destructure();
let RPCOperationReturnReceipt { receipt } = match kind { let receipt = match kind {
RPCOperationKind::Statement(s) => match s.destructure() { RPCOperationKind::Statement(s) => match s.destructure() {
RPCStatementDetail::ReturnReceipt(s) => s, RPCStatementDetail::ReturnReceipt(s) => s.destructure(),
_ => panic!("not a return receipt"), _ => panic!("not a return receipt"),
}, },
_ => panic!("not a statement"), _ => panic!("not a statement"),

View File

@ -34,17 +34,17 @@ impl RPCProcessor {
}; };
// Apply sequencing preference // Apply sequencing preference
next_hop_nr.set_sequencing(routed_operation.sequencing); next_hop_nr.set_sequencing(routed_operation.sequencing());
// Pass along the route // Pass along the route
let next_hop_route = RPCOperationRoute { let next_hop_route = RPCOperationRoute::new(
safety_route: SafetyRoute { SafetyRoute {
public_key: safety_route.public_key, public_key: safety_route.public_key,
hop_count: safety_route.hop_count - 1, hop_count: safety_route.hop_count - 1,
hops: SafetyRouteHops::Data(route_hop.next_hop.unwrap()), hops: SafetyRouteHops::Data(route_hop.next_hop.unwrap()),
}, },
operation: routed_operation, routed_operation,
}; );
let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route)); let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route));
// Send the next route statement // Send the next route statement
@ -76,17 +76,17 @@ impl RPCProcessor {
}; };
// Apply sequencing preference // Apply sequencing preference
next_hop_nr.set_sequencing(routed_operation.sequencing); next_hop_nr.set_sequencing(routed_operation.sequencing());
// Pass along the route // Pass along the route
let next_hop_route = RPCOperationRoute { let next_hop_route = RPCOperationRoute::new(
safety_route: SafetyRoute { SafetyRoute {
public_key: safety_route_public_key, public_key: safety_route_public_key,
hop_count: 0, hop_count: 0,
hops: SafetyRouteHops::Private(next_private_route), hops: SafetyRouteHops::Private(next_private_route),
}, },
operation: routed_operation, routed_operation,
}; );
let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route)); let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route));
// Send the next route statement // Send the next route statement
@ -114,8 +114,8 @@ impl RPCProcessor {
.cached_dh(&remote_sr_pubkey.value, &node_id_secret) .cached_dh(&remote_sr_pubkey.value, &node_id_secret)
.map_err(RPCError::protocol)?; .map_err(RPCError::protocol)?;
let body = match vcrypto.decrypt_aead( let body = match vcrypto.decrypt_aead(
&routed_operation.data, routed_operation.data(),
&routed_operation.nonce, routed_operation.nonce(),
&dh_secret, &dh_secret,
None, None,
) { ) {
@ -132,7 +132,7 @@ impl RPCProcessor {
self.enqueue_safety_routed_message( self.enqueue_safety_routed_message(
detail, detail,
remote_sr_pubkey.value, remote_sr_pubkey.value,
routed_operation.sequencing, routed_operation.sequencing(),
body, body,
) )
.map_err(RPCError::internal)?; .map_err(RPCError::internal)?;
@ -162,8 +162,8 @@ impl RPCProcessor {
let Some((secret_key, safety_spec)) = rss let Some((secret_key, safety_spec)) = rss
.with_signature_validated_route( .with_signature_validated_route(
&pr_pubkey, &pr_pubkey,
&routed_operation.signatures, routed_operation.signatures(),
&routed_operation.data, routed_operation.data(),
sender_id.value, sender_id.value,
|rssd, rsd| { |rssd, rsd| {
( (
@ -172,7 +172,7 @@ impl RPCProcessor {
preferred_route, preferred_route,
hop_count: rssd.hop_count(), hop_count: rssd.hop_count(),
stability: rssd.get_stability(), stability: rssd.get_stability(),
sequencing: routed_operation.sequencing, sequencing: routed_operation.sequencing(),
}, },
) )
} }
@ -188,8 +188,8 @@ impl RPCProcessor {
.map_err(RPCError::protocol)?; .map_err(RPCError::protocol)?;
let body = vcrypto let body = vcrypto
.decrypt_aead( .decrypt_aead(
&routed_operation.data, routed_operation.data(),
&routed_operation.nonce, routed_operation.nonce(),
&dh_secret, &dh_secret,
None, None,
) )
@ -353,9 +353,9 @@ impl RPCProcessor {
let node_id = self.routing_table.node_id(crypto_kind); let node_id = self.routing_table.node_id(crypto_kind);
let node_id_secret = self.routing_table.node_id_secret_key(crypto_kind); let node_id_secret = self.routing_table.node_id_secret_key(crypto_kind);
let sig = vcrypto let sig = vcrypto
.sign(&node_id.value, &node_id_secret, &route_operation.data) .sign(&node_id.value, &node_id_secret, route_operation.data())
.map_err(RPCError::internal)?; .map_err(RPCError::internal)?;
route_operation.signatures.push(sig); route_operation.add_signature(sig);
} }
Ok(NetworkResult::value(route_hop)) Ok(NetworkResult::value(route_hop))
@ -378,7 +378,7 @@ impl RPCProcessor {
// Get the statement // Get the statement
let (_,_,_,kind) = msg.operation.destructure(); let (_,_,_,kind) = msg.operation.destructure();
let mut route = match kind { let route = match kind {
RPCOperationKind::Statement(s) => match s.destructure() { RPCOperationKind::Statement(s) => match s.destructure() {
RPCStatementDetail::Route(s) => s, RPCStatementDetail::Route(s) => s,
_ => panic!("not a route statement"), _ => panic!("not a route statement"),
@ -387,7 +387,7 @@ impl RPCProcessor {
}; };
// Get crypto kind // Get crypto kind
let crypto_kind = route.safety_route.crypto_kind(); let crypto_kind = route.safety_route().crypto_kind();
let Some(vcrypto) = self.crypto.get(crypto_kind) else { let Some(vcrypto) = self.crypto.get(crypto_kind) else {
return Ok(NetworkResult::invalid_message( return Ok(NetworkResult::invalid_message(
"routed operation crypto is not supported", "routed operation crypto is not supported",
@ -395,13 +395,14 @@ impl RPCProcessor {
}; };
// See what kind of safety route we have going on here // See what kind of safety route we have going on here
match route.safety_route.hops { let (safety_route, mut routed_operation) = route.destructure();
match safety_route.hops {
// There is a safety route hop // There is a safety route hop
SafetyRouteHops::Data(ref route_hop_data) => { SafetyRouteHops::Data(ref route_hop_data) => {
// Decrypt the blob with DEC(nonce, DH(the SR's public key, this hop's secret) // Decrypt the blob with DEC(nonce, DH(the SR's public key, this hop's secret)
let node_id_secret = self.routing_table.node_id_secret_key(crypto_kind); let node_id_secret = self.routing_table.node_id_secret_key(crypto_kind);
let dh_secret = vcrypto let dh_secret = vcrypto
.cached_dh(&route.safety_route.public_key.value, &node_id_secret) .cached_dh(&safety_route.public_key.value, &node_id_secret)
.map_err(RPCError::protocol)?; .map_err(RPCError::protocol)?;
let mut dec_blob_data = vcrypto let mut dec_blob_data = vcrypto
.decrypt_aead( .decrypt_aead(
@ -435,8 +436,8 @@ impl RPCProcessor {
// Switching from full safety route to private route first hop // Switching from full safety route to private route first hop
network_result_try!( network_result_try!(
self.process_private_route_first_hop( self.process_private_route_first_hop(
route.operation, routed_operation,
route.safety_route.public_key, safety_route.public_key,
private_route, private_route,
) )
.await? .await?
@ -456,9 +457,9 @@ impl RPCProcessor {
// Continue the full safety route with another hop // Continue the full safety route with another hop
network_result_try!( network_result_try!(
self.process_route_safety_route_hop( self.process_route_safety_route_hop(
route.operation, routed_operation,
route_hop, route_hop,
route.safety_route safety_route
) )
.await? .await?
); );
@ -474,8 +475,8 @@ impl RPCProcessor {
// Safety route was a stub, start with the beginning of the private route // Safety route was a stub, start with the beginning of the private route
network_result_try!( network_result_try!(
self.process_private_route_first_hop( self.process_private_route_first_hop(
route.operation, routed_operation,
route.safety_route.public_key, safety_route.public_key,
private_route, private_route,
) )
.await? .await?
@ -486,7 +487,7 @@ impl RPCProcessor {
let route_hop = network_result_try!(self.decrypt_private_route_hop_data( let route_hop = network_result_try!(self.decrypt_private_route_hop_data(
&route_hop_data, &route_hop_data,
&private_route.public_key, &private_route.public_key,
&mut route.operation &mut routed_operation
)?); )?);
// Ensure hop count > 0 // Ensure hop count > 0
@ -499,9 +500,9 @@ impl RPCProcessor {
// Make next PrivateRoute and pass it on // Make next PrivateRoute and pass it on
network_result_try!( network_result_try!(
self.process_route_private_route_hop( self.process_route_private_route_hop(
route.operation, routed_operation,
route_hop.node, route_hop.node,
route.safety_route.public_key, safety_route.public_key,
PrivateRoute { PrivateRoute {
public_key: private_route.public_key, public_key: private_route.public_key,
hop_count: private_route.hop_count - 1, hop_count: private_route.hop_count - 1,
@ -521,7 +522,7 @@ impl RPCProcessor {
"route should be at the end", "route should be at the end",
)); ));
} }
if route.safety_route.hop_count != 0 { if safety_route.hop_count != 0 {
return Ok(NetworkResult::invalid_message( return Ok(NetworkResult::invalid_message(
"Safety hop count should be zero if switched to private route", "Safety hop count should be zero if switched to private route",
)); ));
@ -531,8 +532,8 @@ impl RPCProcessor {
network_result_try!(self.process_routed_operation( network_result_try!(self.process_routed_operation(
detail, detail,
vcrypto, vcrypto,
route.operation, routed_operation,
route.safety_route.public_key, safety_route.public_key,
private_route.public_key, private_route.public_key,
)?); )?);
} }

View File

@ -22,7 +22,7 @@ impl RPCProcessor {
)); ));
} }
let signal = RPCOperationSignal { signal_info }; let signal = RPCOperationSignal::new(signal_info);
let statement = RPCStatement::new(RPCStatementDetail::Signal(signal)); let statement = RPCStatement::new(RPCStatementDetail::Signal(signal));
// Send the signal request // Send the signal request

View File

@ -68,7 +68,7 @@ impl RPCProcessor {
} }
}; };
let status_q = RPCOperationStatusQ { node_status }; let status_q = RPCOperationStatusQ::new(node_status);
let question = RPCQuestion::new( let question = RPCQuestion::new(
network_result_try!(self.get_destination_respond_to(&dest)?), network_result_try!(self.get_destination_respond_to(&dest)?),
RPCQuestionDetail::StatusQ(status_q), RPCQuestionDetail::StatusQ(status_q),
@ -88,8 +88,9 @@ impl RPCProcessor {
}; };
// Get the right answer type // Get the right answer type
let status_a = match msg.operation.into_kind() { let (_, _, _, kind) = msg.operation.destructure();
RPCOperationKind::Answer(a) => match a.into_detail() { let status_a = match kind {
RPCOperationKind::Answer(a) => match a.destructure() {
RPCAnswerDetail::StatusA(a) => a, RPCAnswerDetail::StatusA(a) => a,
_ => return Err(RPCError::invalid_format("not a status answer")), _ => return Err(RPCError::invalid_format("not a status answer")),
}, },
@ -98,7 +99,7 @@ impl RPCProcessor {
// Ensure the returned node status is the kind for the routing domain we asked for // Ensure the returned node status is the kind for the routing domain we asked for
if let Some(target_nr) = opt_target_nr { if let Some(target_nr) = opt_target_nr {
if let Some(node_status) = status_a.node_status { if let Some(node_status) = status_a.node_status() {
match routing_domain { match routing_domain {
RoutingDomain::PublicInternet => { RoutingDomain::PublicInternet => {
if !matches!(node_status, NodeStatus::PublicInternet(_)) { if !matches!(node_status, NodeStatus::PublicInternet(_)) {
@ -117,7 +118,7 @@ impl RPCProcessor {
} }
// Update latest node status in routing table // Update latest node status in routing table
target_nr.update_node_status(node_status); target_nr.update_node_status(node_status.clone());
} }
} }
@ -131,7 +132,7 @@ impl RPCProcessor {
safety_selection, safety_selection,
} => { } => {
if matches!(safety_selection, SafetySelection::Unsafe(_)) { if matches!(safety_selection, SafetySelection::Unsafe(_)) {
if let Some(sender_info) = status_a.sender_info { if let Some(sender_info) = status_a.sender_info() {
match send_data_kind { match send_data_kind {
SendDataKind::Direct(connection_descriptor) => { SendDataKind::Direct(connection_descriptor) => {
// Directly requested status that actually gets sent directly and not over a relay will tell us what our IP address appears as // Directly requested status that actually gets sent directly and not over a relay will tell us what our IP address appears as
@ -199,7 +200,7 @@ impl RPCProcessor {
let routing_domain = detail.routing_domain; let routing_domain = detail.routing_domain;
// Ensure the node status from the question is the kind for the routing domain we received the request in // Ensure the node status from the question is the kind for the routing domain we received the request in
if let Some(node_status) = &status_q.node_status { if let Some(node_status) = status_q.node_status() {
match routing_domain { match routing_domain {
RoutingDomain::PublicInternet => { RoutingDomain::PublicInternet => {
if !matches!(node_status, NodeStatus::PublicInternet(_)) { if !matches!(node_status, NodeStatus::PublicInternet(_)) {
@ -244,10 +245,7 @@ impl RPCProcessor {
}; };
// Make status answer // Make status answer
let status_a = RPCOperationStatusA { let status_a = RPCOperationStatusA::new(node_status, sender_info);
node_status,
sender_info,
};
// Send status answer // Send status answer
self.answer(msg, RPCAnswer::new(RPCAnswerDetail::StatusA(status_a))) self.answer(msg, RPCAnswer::new(RPCAnswerDetail::StatusA(status_a)))

View File

@ -17,11 +17,7 @@ impl RPCProcessor {
.generate_single_shot_receipt(receipt_time, []) .generate_single_shot_receipt(receipt_time, [])
.map_err(RPCError::internal)?; .map_err(RPCError::internal)?;
let validate_dial_info = RPCOperationValidateDialInfo { let validate_dial_info = RPCOperationValidateDialInfo::new(dial_info, receipt, redirect)?;
dial_info,
receipt,
redirect,
};
let statement = RPCStatement::new(RPCStatementDetail::ValidateDialInfo(validate_dial_info)); let statement = RPCStatement::new(RPCStatementDetail::ValidateDialInfo(validate_dial_info));
// Send the validate_dial_info request // Send the validate_dial_info request
@ -134,11 +130,8 @@ impl RPCProcessor {
} }
// Make a copy of the request, without the redirect flag // Make a copy of the request, without the redirect flag
let validate_dial_info = RPCOperationValidateDialInfo { let validate_dial_info =
dial_info: dial_info.clone(), RPCOperationValidateDialInfo::new(dial_info.clone(), receipt.clone(), false)?;
receipt: receipt.clone(),
redirect: false,
};
let statement = let statement =
RPCStatement::new(RPCStatementDetail::ValidateDialInfo(validate_dial_info)); RPCStatement::new(RPCStatementDetail::ValidateDialInfo(validate_dial_info));

View File

@ -101,6 +101,7 @@ impl RecordStore {
} }
fn add_to_subkey_cache(&mut self, key: SubkeyTableKey, record_data: RecordData) { fn add_to_subkey_cache(&mut self, key: SubkeyTableKey, record_data: RecordData) {
let record_data_total_size = record_data.total_size();
// Write to subkey cache // Write to subkey cache
let mut dead_size = 0usize; let mut dead_size = 0usize;
if let Some(old_record_data) = self.subkey_cache.insert(key, record_data, |_, v| { if let Some(old_record_data) = self.subkey_cache.insert(key, record_data, |_, v| {
@ -111,7 +112,7 @@ impl RecordStore {
dead_size += old_record_data.total_size(); dead_size += old_record_data.total_size();
} }
self.subkey_cache_total_size -= dead_size; self.subkey_cache_total_size -= dead_size;
self.subkey_cache_total_size += record_data.total_size(); self.subkey_cache_total_size += record_data_total_size;
// Purge over size limit // Purge over size limit
if let Some(max_subkey_cache_memory_mb) = self.limits.max_subkey_cache_memory_mb { if let Some(max_subkey_cache_memory_mb) = self.limits.max_subkey_cache_memory_mb {
@ -270,16 +271,20 @@ impl RecordStore {
F: FnOnce(&Record) -> R, F: FnOnce(&Record) -> R,
{ {
// Get record from index // Get record from index
let mut out = None;
let rtk = RecordTableKey { key }; let rtk = RecordTableKey { key };
if let Some(record) = self.record_index.get_mut(&rtk) { if let Some(record) = self.record_index.get_mut(&rtk) {
// Callback
out = Some(f(record));
// Touch // Touch
record.touch(get_aligned_timestamp()); record.touch(get_aligned_timestamp());
self.mark_record_changed(rtk);
// Callback
return Some(f(record));
} }
None if out.is_some() {
self.mark_record_changed(rtk);
}
out
} }
pub async fn get_subkey<R, F>( pub async fn get_subkey<R, F>(

View File

@ -8,10 +8,10 @@ use super::*;
pub struct VeilidAppMessage { pub struct VeilidAppMessage {
/// Some(sender) if the message was sent directly, None if received via a private/safety route /// Some(sender) if the message was sent directly, None if received via a private/safety route
#[serde(with = "opt_json_as_string")] #[serde(with = "opt_json_as_string")]
pub sender: Option<PublicKey>, sender: Option<PublicKey>,
/// The content of the message to deliver to the application /// The content of the message to deliver to the application
#[serde(with = "json_as_base64")] #[serde(with = "json_as_base64")]
pub message: Vec<u8>, message: Vec<u8>,
} }
impl VeilidAppMessage { impl VeilidAppMessage {

View File

@ -25,11 +25,11 @@ impl DHTRecordDescriptor {
Self { owner, schema } Self { owner, schema }
} }
pub fn owner(&self) -> PublicKey { pub fn owner(&self) -> &PublicKey {
self.owner &self.owner
} }
pub fn schema(&self) -> DHTSchema { pub fn schema(&self) -> &DHTSchema {
self.schema &self.schema
} }
} }

View File

@ -58,7 +58,7 @@ impl DHTSchemaSMPL {
// o_cnt // o_cnt
out.extend_from_slice(&self.o_cnt.to_le_bytes()); out.extend_from_slice(&self.o_cnt.to_le_bytes());
// members // members
for m in self.members { for m in &self.members {
// m_key // m_key
out.extend_from_slice(&m.m_key.bytes); out.extend_from_slice(&m.m_key.bytes);
// m_cnt // m_cnt

View File

@ -27,10 +27,10 @@ data-encoding = { version = "^2" }
# Dependencies for native builds only # Dependencies for native builds only
# Linux, Windows, Mac, iOS, Android # Linux, Windows, Mac, iOS, Android
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]
tracing-opentelemetry = "^0" tracing-opentelemetry = "0.18"
opentelemetry = { version = "^0" } opentelemetry = { version = "0.18" }
opentelemetry-otlp = { version = "^0" } opentelemetry-otlp = { version = "0.11" }
opentelemetry-semantic-conventions = "^0" opentelemetry-semantic-conventions = "0.10"
async-std = { version = "^1", features = ["unstable"], optional = true } async-std = { version = "^1", features = ["unstable"], optional = true }
tokio = { version = "^1", features = ["full"], optional = true } tokio = { version = "^1", features = ["full"], optional = true }
tokio-stream = { version = "^0", features = ["net"], optional = true } tokio-stream = { version = "^0", features = ["net"], optional = true }

View File

@ -24,11 +24,11 @@ veilid-core = { path = "../veilid-core", default-features = false }
tracing = { version = "^0", features = ["log", "attributes"] } tracing = { version = "^0", features = ["log", "attributes"] }
tracing-subscriber = { version = "^0", features = ["env-filter"] } tracing-subscriber = { version = "^0", features = ["env-filter"] }
tracing-appender = "^0" tracing-appender = "^0"
tracing-opentelemetry = "^0" tracing-opentelemetry = "0.18"
# Buggy: tracing-error = "^0" # Buggy: tracing-error = "^0"
opentelemetry = { version = "^0" } opentelemetry = { version = "0.18" }
opentelemetry-otlp = { version = "^0" } opentelemetry-otlp = { version = "0.11" }
opentelemetry-semantic-conventions = "^0" opentelemetry-semantic-conventions = "0.10"
async-std = { version = "^1", features = ["unstable"], optional = true } async-std = { version = "^1", features = ["unstable"], optional = true }
tokio = { version = "^1", features = ["full", "tracing"], optional = true } tokio = { version = "^1", features = ["full", "tracing"], optional = true }
console-subscriber = { version = "^0", optional = true } console-subscriber = { version = "^0", optional = true }

View File

@ -6,7 +6,7 @@ use serde_derive::*;
use std::ffi::OsStr; use std::ffi::OsStr;
use std::net::SocketAddr; use std::net::SocketAddr;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use sysinfo::{DiskExt, System, SystemExt}; use sysinfo::{DiskExt, SystemExt};
use url::Url; use url::Url;
use veilid_core::tools::*; use veilid_core::tools::*;
use veilid_core::*; use veilid_core::*;
@ -174,7 +174,7 @@ core:
) )
.replace( .replace(
"%REMOTE_MAX_SUBKEY_CACHE_MEMORY_MB%", "%REMOTE_MAX_SUBKEY_CACHE_MEMORY_MB%",
&Settings::get_default_remote_max_subkey_cache_memory_mb().to_string_lossy(), &Settings::get_default_remote_max_subkey_cache_memory_mb().to_string(),
); );
config::Config::builder() config::Config::builder()
.add_source(config::File::from_str( .add_source(config::File::from_str(
@ -638,7 +638,7 @@ impl Settings {
} }
// Generate config // Generate config
let inner: SettingsInner = cfg.try_deserialize()?; let mut inner: SettingsInner = cfg.try_deserialize()?;
// Fill in missing defaults // Fill in missing defaults
if inner.core.network.dht.remote_max_storage_space_mb == 0 { if inner.core.network.dht.remote_max_storage_space_mb == 0 {
@ -857,14 +857,13 @@ impl Settings {
} }
pub fn get_default_remote_max_subkey_cache_memory_mb() -> usize { pub fn get_default_remote_max_subkey_cache_memory_mb() -> usize {
let mut sys = System::new_with_specifics(sysinfo::RefreshKind::new().with_memory()); let sys = sysinfo::System::new_with_specifics(sysinfo::RefreshKind::new().with_memory());
sys.free_memory() as usize / 8 sys.free_memory() as usize / 8
} }
pub fn get_default_remote_max_storage_space_mb(inner: &SettingsInner) -> usize { pub fn get_default_remote_max_storage_space_mb(inner: &SettingsInner) -> u32 {
let mut sys = System::new_with_specifics(sysinfo::RefreshKind::new().with_disks()); let mut sys = sysinfo::System::new_with_specifics(sysinfo::RefreshKind::new().with_disks());
let dht_storage_path = inner.core.table_store.directory.clone(); let dht_storage_path = inner.core.table_store.directory.clone();
let mut available_mb = 0usize;
// Sort longer mount point paths first since we want the mount point closest to our table store directory // Sort longer mount point paths first since we want the mount point closest to our table store directory
sys.sort_disks_by(|a, b| { sys.sort_disks_by(|a, b| {
b.mount_point() b.mount_point()
@ -874,13 +873,13 @@ impl Settings {
}); });
for disk in sys.disks() { for disk in sys.disks() {
if dht_storage_path.starts_with(disk.mount_point()) { if dht_storage_path.starts_with(disk.mount_point()) {
let available_mb = disk.available_space() / 1_000_000usize; let available_mb = disk.available_space() / 1_000_000u64;
if available_mb > 40_000 { if available_mb > 40_000 {
// Default to 10GB if more than 40GB is available // Default to 10GB if more than 40GB is available
return 10_000; return 10_000;
} }
// Default to 1/4 of the available space, if less than 40GB is available // Default to 1/4 of the available space, if less than 40GB is available
return available_mb; return available_mb as u32;
} }
} }
// If we can't figure out our storage path go with 1GB of space and pray // If we can't figure out our storage path go with 1GB of space and pray

View File

@ -7,7 +7,7 @@ use clap::ArgMatches;
use futures_util::StreamExt; use futures_util::StreamExt;
use signal_hook::consts::signal::*; use signal_hook::consts::signal::*;
use signal_hook_async_std::Signals; use signal_hook_async_std::Signals;
use std::io::Read; //use std::io::Read;
use tracing::*; use tracing::*;
#[instrument(skip(signals))] #[instrument(skip(signals))]
@ -34,23 +34,23 @@ pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> EyreResult<()> {
let s = settings.read(); let s = settings.read();
if let Some(pid_file) = s.daemon.pid_file.clone() { if let Some(pid_file) = s.daemon.pid_file.clone() {
daemon = daemon.pid_file(pid_file.clone()); //.chown_pid_file(true); daemon = daemon.pid_file(pid_file.clone()); //.chown_pid_file(true);
daemon = daemon.exit_action(move || { // daemon = daemon.exit_action(move || {
// wait for pid file to exist before exiting parent // // wait for pid file to exist before exiting parent
let pid_path = std::path::Path::new(&pid_file); // let pid_path = std::path::Path::new(&pid_file);
loop { // loop {
if let Ok(mut f) = std::fs::File::open(pid_path) { // if let Ok(mut f) = std::fs::File::open(pid_path) {
let mut s = String::new(); // let mut s = String::new();
if f.read_to_string(&mut s).is_ok() // if f.read_to_string(&mut s).is_ok()
&& !s.is_empty() // && !s.is_empty()
&& s.parse::<u32>().is_ok() // && s.parse::<u32>().is_ok()
{ // {
println!("pidfile found"); // println!("pidfile found");
break; // break;
} // }
} // }
std::thread::sleep(std::time::Duration::from_millis(100)); // std::thread::sleep(std::time::Duration::from_millis(100));
} // }
}) // })
} }
if let Some(chroot) = &s.daemon.chroot { if let Some(chroot) = &s.daemon.chroot {
daemon = daemon.chroot(chroot); daemon = daemon.chroot(chroot);