diff --git a/Cargo.lock b/Cargo.lock index c98fe08b..1cfb4ba9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -595,6 +595,25 @@ version = "0.21.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "bindgen" version = "0.59.2" @@ -602,7 +621,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2bd2a9a458e8f4304c52c43ebb0cfbd520289f8379a52e329a38afda99bf8eb8" dependencies = [ "bitflags 1.3.2", - "cexpr", + "cexpr 0.6.0", "clang-sys", "clap 2.34.0", "env_logger 0.9.3", @@ -614,7 +633,7 @@ dependencies = [ "quote", "regex", "rustc-hash", - "shlex", + "shlex 1.1.0", "which", ] @@ -718,9 +737,9 @@ dependencies = [ [[package]] name = "boringssl-src" -version = "0.5.2+6195bf8" +version = "0.3.0+688fc5c" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab565ccc5e276ea82a2013dd08bf2c999866b06daf1d4f30fee419c4aaec6d5" +checksum = "f901accdf830d2ea2f4e27f923a5e1125cd8b1a39ab578b9db1a42d578a6922b" dependencies = [ "cmake", ] @@ -837,6 +856,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "cexpr" version = "0.6.0" @@ -1914,6 +1942,12 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "fixedbitset" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce7134b9999ecaf8bcd65542e436736ef32ddca1b3e06094cb6ec5755203b80" + [[package]] name = "flate2" version = "1.0.25" @@ -2207,26 +2241,25 @@ dependencies = [ [[package]] name = "grpcio" -version = "0.12.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "609832ca501baeb662dc81932fda9ed83f5d058f4b899a807ba222ce696f430a" +checksum = "24d99e00eed7e0a04ee2705112e7cfdbe1a3cc771147f22f016a8cd2d002187b" dependencies = [ - "futures-executor", - "futures-util", + "futures", "grpcio-sys", "libc", "log", - "parking_lot 0.12.1", + "parking_lot 0.11.2", "protobuf", ] [[package]] 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" -checksum = "cf625d1803b6f44203f0428ddace847fb4994def5c803fc8a7a2f18fb3daec62" +checksum = "9447d1a926beeef466606cc45717f80897998b548e7dc622873d453e1ecb4be4" dependencies = [ - "bindgen", + "bindgen 0.57.0", "boringssl-src", "cc", "cmake", @@ -3146,6 +3179,12 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "multimap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5ce46fe64a9d73be07dcbe690a38ce1b293be448fd8ce1e6c1b8062c9f72c6a" + [[package]] name = "nanorand" version = "0.7.0" @@ -3337,6 +3376,16 @@ dependencies = [ "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]] name = "nom" version = "7.1.3" @@ -3524,32 +3573,22 @@ version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69d6c3d7288a106c0a363e4b0e8d308058d56902adefb16f4936f417ffef086e" dependencies = [ - "opentelemetry_api 0.18.0", - "opentelemetry_sdk 0.18.0", -] - -[[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", + "opentelemetry_api", + "opentelemetry_sdk", ] [[package]] name = "opentelemetry-otlp" -version = "0.12.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8af72d59a4484654ea8eb183fea5ae4eb6a41d7ac3e3bae5f4d2a282a3a7d3ca" +checksum = "d1c928609d087790fc936a1067bdc310ae702bdf3b090c3f281b713622c8bbde" dependencies = [ "async-trait", "futures", "futures-util", "grpcio", "http", - "opentelemetry 0.19.0", + "opentelemetry", "opentelemetry-proto", "prost", "protobuf", @@ -3560,26 +3599,27 @@ dependencies = [ [[package]] name = "opentelemetry-proto" -version = "0.2.0" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "045f8eea8c0fa19f7d48e7bc3128a39c2e5c533d5c61298c548dfefc1064474c" +checksum = "d61a2f56df5574508dd86aaca016c917489e589ece4141df1b5e349af8d66c28" dependencies = [ "futures", "futures-util", "grpcio", - "opentelemetry 0.19.0", + "opentelemetry", "prost", "protobuf", "tonic", + "tonic-build", ] [[package]] name = "opentelemetry-semantic-conventions" -version = "0.11.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24e33428e6bf08c6f7fcea4ddb8e358fab0fe48ab877a87c70c6ebe20f673ce5" +checksum = "9b02e0230abb0ab6636d18e2ba8fa02903ea63772281340ccac18e0af3ec9eeb" dependencies = [ - "opentelemetry 0.19.0", + "opentelemetry", ] [[package]] @@ -3598,47 +3638,11 @@ dependencies = [ "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]] name = "opentelemetry_sdk" version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" 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 = [ "async-std", "async-trait", @@ -3649,7 +3653,7 @@ dependencies = [ "futures-executor", "futures-util", "once_cell", - "opentelemetry_api 0.19.0", + "opentelemetry_api", "percent-encoding", "rand 0.8.5", "thiserror", @@ -3867,6 +3871,16 @@ dependencies = [ "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]] name = "pharos" version = "0.5.3" @@ -4002,6 +4016,16 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" 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]] name = "primitive-types" version = "0.12.1" @@ -4059,6 +4083,28 @@ dependencies = [ "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]] name = "prost-derive" version = "0.11.9" @@ -4864,6 +4910,12 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "shlex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7fdf1b9db47230893d76faad238fd6097fd6d6a9245cd7a4d90dbd639536bbd2" + [[package]] name = "shlex" version = "1.1.0" @@ -5505,6 +5557,19 @@ dependencies = [ "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]] name = "tower" version = "0.4.13" @@ -5631,7 +5696,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "21ebb87a95ea13271332df069020513ab70bdb5637ca42d6e492dc3bbbad48de" dependencies = [ "once_cell", - "opentelemetry 0.18.0", + "opentelemetry", "tracing", "tracing-core", "tracing-log", @@ -5644,7 +5709,7 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9bc58223383423483e4bc056c7e7b3f77bdee924a9d33834112c69ead06dc847" dependencies = [ - "bindgen", + "bindgen 0.59.2", "cc", "cfg-if 1.0.0", "fnv", @@ -5874,12 +5939,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "urlencoding" -version = "2.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" - [[package]] name = "utf-8" version = "0.7.6" @@ -6061,7 +6120,7 @@ dependencies = [ "hostname", "jni 0.21.1", "lazy_static", - "opentelemetry 0.19.0", + "opentelemetry", "opentelemetry-otlp", "opentelemetry-semantic-conventions", "parking_lot 0.12.1", @@ -6102,7 +6161,7 @@ dependencies = [ "json", "lazy_static", "nix 0.26.2", - "opentelemetry 0.19.0", + "opentelemetry", "opentelemetry-otlp", "opentelemetry-semantic-conventions", "parking_lot 0.12.1", diff --git a/veilid-cli/src/command_processor.rs b/veilid-cli/src/command_processor.rs index 2e32f584..5832fa21 100644 --- a/veilid-cli/src/command_processor.rs +++ b/veilid-cli/src/command_processor.rs @@ -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) { // check is message body is ascii printable let mut printable = true; - for c in &msg.message { + for c in msg.message() { if *c < 32 || *c > 126 { printable = false; } } let strmsg = if printable { - String::from_utf8_lossy(&msg.message).to_string() + String::from_utf8_lossy(msg.message()).to_string() } else { - hex::encode(&msg.message) + hex::encode(msg.message()) }; self.inner() .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) { // check is message body is ascii printable let mut printable = true; - for c in &call.message { + for c in call.message() { if *c < 32 || *c > 126 { printable = false; } } let strmsg = if printable { - String::from_utf8_lossy(&call.message).to_string() + String::from_utf8_lossy(call.message()).to_string() } else { - format!("#{}", hex::encode(&call.message)) + format!("#{}", hex::encode(call.message())) }; self.inner().ui.add_node_event(format!( "AppCall ({:?}) id = {:016x} : {}", - call.sender, - call.id.as_u64(), + call.sender(), + call.id().as_u64(), 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) { diff --git a/veilid-core/src/network_manager/tests/test_signed_node_info.rs b/veilid-core/src/network_manager/tests/test_signed_node_info.rs index bab0a6e1..c6a943d1 100644 --- a/veilid-core/src/network_manager/tests/test_signed_node_info.rs +++ b/veilid-core/src/network_manager/tests/test_signed_node_info.rs @@ -14,17 +14,17 @@ pub async fn test_signed_node_info() { let vcrypto = crypto.get(ck).unwrap(); // Test direct - let node_info = NodeInfo { - network_class: NetworkClass::InboundCapable, - outbound_protocols: ProtocolTypeSet::all(), - address_types: AddressTypeSet::all(), - envelope_support: VALID_ENVELOPE_VERSIONS.to_vec(), - crypto_support: VALID_CRYPTO_KINDS.to_vec(), - dial_info_detail_list: vec![DialInfoDetail { + let node_info = NodeInfo::new( + NetworkClass::InboundCapable, + ProtocolTypeSet::all(), + AddressTypeSet::all(), + VALID_ENVELOPE_VERSIONS.to_vec(), + VALID_CRYPTO_KINDS.to_vec(), + vec![DialInfoDetail { class: DialInfoClass::Mapped, dial_info: DialInfo::udp(SocketAddress::default()), }], - }; + ); // Test correct validation let keypair = vcrypto.generate_keypair(); @@ -48,7 +48,6 @@ pub async fn test_signed_node_info() { // Test incorrect validation let keypair1 = vcrypto.generate_keypair(); let tks1: TypedKeySet = TypedKey::new(ck, keypair1.key).into(); - let oldtks1len = tks1.len(); let sdni = SignedDirectNodeInfo::new( node_info.clone(), sni.timestamp(), @@ -69,17 +68,17 @@ pub async fn test_signed_node_info() { assert_eq!(sdnifake.signatures().len(), sigsfake.len()); // Test relayed - let node_info2 = NodeInfo { - network_class: NetworkClass::OutboundOnly, - outbound_protocols: ProtocolTypeSet::all(), - address_types: AddressTypeSet::all(), - envelope_support: VALID_ENVELOPE_VERSIONS.to_vec(), - crypto_support: VALID_CRYPTO_KINDS.to_vec(), - dial_info_detail_list: vec![DialInfoDetail { + let node_info2 = NodeInfo::new( + NetworkClass::OutboundOnly, + ProtocolTypeSet::all(), + AddressTypeSet::all(), + VALID_ENVELOPE_VERSIONS.to_vec(), + VALID_CRYPTO_KINDS.to_vec(), + vec![DialInfoDetail { class: DialInfoClass::Blocked, dial_info: DialInfo::udp(SocketAddress::default()), }], - }; + ); // Test correct validation let keypair2 = vcrypto.generate_keypair(); @@ -109,7 +108,6 @@ pub async fn test_signed_node_info() { // Test incorrect validation let keypair3 = vcrypto.generate_keypair(); let tks3: TypedKeySet = TypedKey::new(ck, keypair3.key).into(); - let oldtks3len = tks3.len(); let srni = SignedRelayedNodeInfo::new( node_info2.clone(), diff --git a/veilid-core/src/network_manager/types/low_level_protocol_type.rs b/veilid-core/src/network_manager/types/low_level_protocol_type.rs index 3ae2df7b..69dfeae7 100644 --- a/veilid-core/src/network_manager/types/low_level_protocol_type.rs +++ b/veilid-core/src/network_manager/types/low_level_protocol_type.rs @@ -27,5 +27,5 @@ impl LowLevelProtocolType { matches!(self, LowLevelProtocolType::TCP) } } -pub type LowLevelProtocolTypeSet = EnumSet; +// pub type LowLevelProtocolTypeSet = EnumSet; diff --git a/veilid-core/src/routing_table/bucket_entry.rs b/veilid-core/src/routing_table/bucket_entry.rs index 92a6dad5..0f1919d2 100644 --- a/veilid-core/src/routing_table/bucket_entry.rs +++ b/veilid-core/src/routing_table/bucket_entry.rs @@ -136,6 +136,7 @@ impl BucketEntryInner { /// 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 pub fn add_node_id(&mut self, node_id: TypedKey) -> EyreResult> { + 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) { &mut self.validated_node_ids } else { @@ -152,7 +153,7 @@ impl BucketEntryInner { return Ok(Some(old_node_id)); } // 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"); } node_ids.add(node_id); @@ -345,10 +346,10 @@ impl BucketEntryInner { }; // Peer info includes all node ids, even unvalidated ones 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, - signed_node_info: *s.clone(), - }) + *s.clone(), + )) } pub fn best_routing_domain( @@ -792,14 +793,14 @@ pub struct BucketEntry { impl BucketEntry { 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 { - validated_node_ids, - unsupported_node_ids, + validated_node_ids: TypedKeySet::from(first_node_id), + unsupported_node_ids: TypedKeySet::new(), envelope_support: Vec::new(), updated_since_last_network_change: false, last_connections: BTreeMap::new(), diff --git a/veilid-core/src/routing_table/tasks/bootstrap.rs b/veilid-core/src/routing_table/tasks/bootstrap.rs index f467c2ba..25a51416 100644 --- a/veilid-core/src/routing_table/tasks/bootstrap.rs +++ b/veilid-core/src/routing_table/tasks/bootstrap.rs @@ -329,14 +329,15 @@ impl RoutingTable { let crypto_support = bsrec.node_ids.kinds(); // Make unsigned SignedNodeInfo - let sni = SignedNodeInfo::Direct(SignedDirectNodeInfo::with_no_signature(NodeInfo { - network_class: NetworkClass::InboundCapable, // Bootstraps are always inbound capable - outbound_protocols: ProtocolTypeSet::only(ProtocolType::UDP), // Bootstraps do not participate in relaying and will not make outbound requests, but will have UDP enabled - address_types: AddressTypeSet::all(), // Bootstraps are always IPV4 and IPV6 capable - envelope_support: bsrec.envelope_support, // Envelope support is as specified in the bootstrap list - 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 - })); + let sni = + SignedNodeInfo::Direct(SignedDirectNodeInfo::with_no_signature(NodeInfo::new( + NetworkClass::InboundCapable, // Bootstraps are always inbound capable + ProtocolTypeSet::only(ProtocolType::UDP), // Bootstraps do not participate in relaying and will not make outbound requests, but will have UDP enabled + 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 + bsrec.dial_info_details, // Dial info is as specified in the bootstrap list + ))); let pi = PeerInfo::new(bsrec.node_ids, sni); diff --git a/veilid-core/src/rpc_processor/coders/mod.rs b/veilid-core/src/rpc_processor/coders/mod.rs index 6ad58903..34bc7913 100644 --- a/veilid-core/src/rpc_processor/coders/mod.rs +++ b/veilid-core/src/rpc_processor/coders/mod.rs @@ -56,11 +56,6 @@ pub use typed_signature::*; use super::*; -#[derive(Debug, Clone)] -pub struct DecodeContext { - config: VeilidConfig, -} - #[derive(Debug, Clone)] pub enum QuestionContext { GetValue(ValidateGetValueContext), @@ -69,7 +64,7 @@ pub enum QuestionContext { #[derive(Clone)] pub struct RPCValidateContext { - crypto: Crypto, - rpc_processor: RPCProcessor, - question_context: Option, + pub crypto: Crypto, + pub rpc_processor: RPCProcessor, + pub question_context: Option, } diff --git a/veilid-core/src/rpc_processor/coders/operations/operation.rs b/veilid-core/src/rpc_processor/coders/operations/operation.rs index af5df0b4..9118c2cb 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation.rs @@ -133,10 +133,7 @@ impl RPCOperation { ) } - pub fn decode( - context: &DecodeContext, - operation_reader: &veilid_capnp::operation::Reader, - ) -> Result { + pub fn decode(operation_reader: &veilid_capnp::operation::Reader) -> Result { let op_id = OperationId::new(operation_reader.get_op_id()); let sender_peer_info = if operation_reader.has_sender_peer_info() { diff --git a/veilid-core/src/rpc_processor/coders/operations/operation_get_value.rs b/veilid-core/src/rpc_processor/coders/operations/operation_get_value.rs index 5ff3edb5..f8f0a37f 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation_get_value.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation_get_value.rs @@ -5,9 +5,9 @@ const MAX_GET_VALUE_A_PEERS_LEN: usize = 20; #[derive(Clone)] pub struct ValidateGetValueContext { - last_descriptor: Option, - subkey: ValueSubkey, - vcrypto: CryptoSystemVersion, + pub last_descriptor: Option, + pub subkey: ValueSubkey, + pub vcrypto: CryptoSystemVersion, } impl fmt::Debug for ValidateGetValueContext { diff --git a/veilid-core/src/rpc_processor/coders/operations/operation_return_receipt.rs b/veilid-core/src/rpc_processor/coders/operations/operation_return_receipt.rs index 62e14182..6edcae84 100644 --- a/veilid-core/src/rpc_processor/coders/operations/operation_return_receipt.rs +++ b/veilid-core/src/rpc_processor/coders/operations/operation_return_receipt.rs @@ -6,7 +6,7 @@ pub struct RPCOperationReturnReceipt { } impl RPCOperationReturnReceipt { - pub fn new(receipt: &[u8]) -> Result { + pub fn new(receipt: Vec) -> Result { if receipt.len() < MIN_RECEIPT_SIZE { 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")); } - Ok(Self { - receipt: receipt.to_vec(), - }) + Ok(Self { receipt }) } pub fn validate(&mut self, _validate_context: &RPCValidateContext) -> Result<(), RPCError> { Ok(()) diff --git a/veilid-core/src/rpc_processor/coders/peer_info.rs b/veilid-core/src/rpc_processor/coders/peer_info.rs index b7081aab..7e5b5091 100644 --- a/veilid-core/src/rpc_processor/coders/peer_info.rs +++ b/veilid-core/src/rpc_processor/coders/peer_info.rs @@ -44,8 +44,5 @@ pub fn decode_peer_info(reader: &veilid_capnp::peer_info::Reader) -> Result) { - let inner = self.inner.lock(); + let mut inner = self.inner.lock(); inner.opt_storage_manager = opt_storage_manager } @@ -555,10 +555,7 @@ impl RPCProcessor { // Prepare route operation let sr_hop_count = compiled_route.safety_route.hop_count; - let route_operation = RPCOperationRoute { - safety_route: compiled_route.safety_route, - operation, - }; + let route_operation = RPCOperationRoute::new(compiled_route.safety_route, operation); let ssni_route = self.get_sender_peer_info(&Destination::direct(compiled_route.first_hop.clone())); let operation = RPCOperation::new_statement( @@ -1216,18 +1213,15 @@ impl RPCProcessor { .get_root::() .map_err(RPCError::protocol) .map_err(logthru_rpc!())?; - let decode_context = DecodeContext { - config: self.config.clone(), - }; - let operation = RPCOperation::decode(&decode_context, &op_reader)?; + let mut operation = RPCOperation::decode(&op_reader)?; // Validate the RPC message - self.validate_rpc_operation(&operation)?; + self.validate_rpc_operation(&mut 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 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() { @@ -1260,7 +1254,10 @@ impl RPCProcessor { let msg = match &encoded_msg.header.detail { RPCMessageHeaderDetail::Direct(detail) => { // 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 let routing_domain = detail.routing_domain; diff --git a/veilid-core/src/rpc_processor/operation_waiter.rs b/veilid-core/src/rpc_processor/operation_waiter.rs index 37ee0ce0..e2da9e9c 100644 --- a/veilid-core/src/rpc_processor/operation_waiter.rs +++ b/veilid-core/src/rpc_processor/operation_waiter.rs @@ -100,7 +100,7 @@ where /// Get operation context pub fn get_op_context(&self, op_id: OperationId) -> Result { - let mut inner = self.inner.lock(); + let inner = self.inner.lock(); let Some(waiting_op) = inner.waiting_op_table.get(&op_id) else { return Err(RPCError::internal("Missing operation id getting op context")); }; diff --git a/veilid-core/src/rpc_processor/rpc_app_call.rs b/veilid-core/src/rpc_processor/rpc_app_call.rs index 5ba05dfb..2ec9a24b 100644 --- a/veilid-core/src/rpc_processor/rpc_app_call.rs +++ b/veilid-core/src/rpc_processor/rpc_app_call.rs @@ -9,7 +9,7 @@ impl RPCProcessor { dest: Destination, message: Vec, ) -> Result>>, RPCError> { - let app_call_q = RPCOperationAppCallQ::new(&message)?; + let app_call_q = RPCOperationAppCallQ::new(message)?; let question = RPCQuestion::new( network_result_try!(self.get_destination_respond_to(&dest)?), RPCQuestionDetail::AppCallQ(app_call_q), @@ -91,7 +91,7 @@ impl RPCProcessor { }; // Return the appcall answer - let app_call_a = RPCOperationAppCallA::new(&message_a)?; + let app_call_a = RPCOperationAppCallA::new(message_a)?; // Send status answer self.answer(msg, RPCAnswer::new(RPCAnswerDetail::AppCallA(app_call_a))) diff --git a/veilid-core/src/rpc_processor/rpc_app_message.rs b/veilid-core/src/rpc_processor/rpc_app_message.rs index 3bfbbb5e..e8454f79 100644 --- a/veilid-core/src/rpc_processor/rpc_app_message.rs +++ b/veilid-core/src/rpc_processor/rpc_app_message.rs @@ -9,7 +9,7 @@ impl RPCProcessor { dest: Destination, message: Vec, ) -> Result, RPCError> { - let app_message = RPCOperationAppMessage { message }; + let app_message = RPCOperationAppMessage::new(message)?; let statement = RPCStatement::new(RPCStatementDetail::AppMessage(app_message)); // Send the app message request @@ -22,7 +22,7 @@ impl RPCProcessor { msg: RPCMessage, ) -> Result, RPCError> { // Get the statement - let (op_id, _, _, kind) = msg.operation.destructure(); + let (_, _, _, kind) = msg.operation.destructure(); let app_message = match kind { RPCOperationKind::Statement(s) => match s.destructure() { RPCStatementDetail::AppMessage(s) => s, diff --git a/veilid-core/src/rpc_processor/rpc_get_value.rs b/veilid-core/src/rpc_processor/rpc_get_value.rs index 5ba248f8..9fe2dcaa 100644 --- a/veilid-core/src/rpc_processor/rpc_get_value.rs +++ b/veilid-core/src/rpc_processor/rpc_get_value.rs @@ -1,8 +1,12 @@ use super::*; -use crate::storage_manager::SignedValueDescriptor; +use crate::storage_manager::{SignedValueData, SignedValueDescriptor}; -#[derive(Clone, Debug, PartialEq, PartialOrd, Ord, Eq, Hash)] -pub enum GetValueAnswer {} +#[derive(Clone, Debug)] +pub struct GetValueAnswer { + pub value: Option, + pub peers: Vec, + pub descriptor: Option, +} impl RPCProcessor { // Sends a get value request and wait for response @@ -44,17 +48,24 @@ impl RPCProcessor { // Get the right answer type let (_, _, _, kind) = msg.operation.destructure(); - let app_call_a = match kind { + let get_value_a = match kind { RPCOperationKind::Answer(a) => match a.destructure() { - RPCAnswerDetail::AppCallA(a) => a, - _ => return Err(RPCError::invalid_format("not an appcall answer")), + RPCAnswerDetail::GetValueA(a) => a, + _ => return Err(RPCError::invalid_format("not a getvalue 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)] diff --git a/veilid-core/src/rpc_processor/rpc_return_receipt.rs b/veilid-core/src/rpc_processor/rpc_return_receipt.rs index 9c2bed0d..383dcc6d 100644 --- a/veilid-core/src/rpc_processor/rpc_return_receipt.rs +++ b/veilid-core/src/rpc_processor/rpc_return_receipt.rs @@ -11,7 +11,7 @@ impl RPCProcessor { ) -> Result, RPCError> { 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)); // Send the return_receipt request @@ -27,9 +27,9 @@ impl RPCProcessor { ) -> Result, RPCError> { // Get the statement let (_, _, _, kind) = msg.operation.destructure(); - let RPCOperationReturnReceipt { receipt } = match kind { + let receipt = match kind { RPCOperationKind::Statement(s) => match s.destructure() { - RPCStatementDetail::ReturnReceipt(s) => s, + RPCStatementDetail::ReturnReceipt(s) => s.destructure(), _ => panic!("not a return receipt"), }, _ => panic!("not a statement"), diff --git a/veilid-core/src/rpc_processor/rpc_route.rs b/veilid-core/src/rpc_processor/rpc_route.rs index 01e251ca..64bc884e 100644 --- a/veilid-core/src/rpc_processor/rpc_route.rs +++ b/veilid-core/src/rpc_processor/rpc_route.rs @@ -34,17 +34,17 @@ impl RPCProcessor { }; // Apply sequencing preference - next_hop_nr.set_sequencing(routed_operation.sequencing); + next_hop_nr.set_sequencing(routed_operation.sequencing()); // Pass along the route - let next_hop_route = RPCOperationRoute { - safety_route: SafetyRoute { + let next_hop_route = RPCOperationRoute::new( + SafetyRoute { public_key: safety_route.public_key, hop_count: safety_route.hop_count - 1, 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)); // Send the next route statement @@ -76,17 +76,17 @@ impl RPCProcessor { }; // Apply sequencing preference - next_hop_nr.set_sequencing(routed_operation.sequencing); + next_hop_nr.set_sequencing(routed_operation.sequencing()); // Pass along the route - let next_hop_route = RPCOperationRoute { - safety_route: SafetyRoute { + let next_hop_route = RPCOperationRoute::new( + SafetyRoute { public_key: safety_route_public_key, hop_count: 0, hops: SafetyRouteHops::Private(next_private_route), }, - operation: routed_operation, - }; + routed_operation, + ); let next_hop_route_stmt = RPCStatement::new(RPCStatementDetail::Route(next_hop_route)); // Send the next route statement @@ -114,8 +114,8 @@ impl RPCProcessor { .cached_dh(&remote_sr_pubkey.value, &node_id_secret) .map_err(RPCError::protocol)?; let body = match vcrypto.decrypt_aead( - &routed_operation.data, - &routed_operation.nonce, + routed_operation.data(), + routed_operation.nonce(), &dh_secret, None, ) { @@ -132,7 +132,7 @@ impl RPCProcessor { self.enqueue_safety_routed_message( detail, remote_sr_pubkey.value, - routed_operation.sequencing, + routed_operation.sequencing(), body, ) .map_err(RPCError::internal)?; @@ -162,8 +162,8 @@ impl RPCProcessor { let Some((secret_key, safety_spec)) = rss .with_signature_validated_route( &pr_pubkey, - &routed_operation.signatures, - &routed_operation.data, + routed_operation.signatures(), + routed_operation.data(), sender_id.value, |rssd, rsd| { ( @@ -172,7 +172,7 @@ impl RPCProcessor { preferred_route, hop_count: rssd.hop_count(), stability: rssd.get_stability(), - sequencing: routed_operation.sequencing, + sequencing: routed_operation.sequencing(), }, ) } @@ -188,8 +188,8 @@ impl RPCProcessor { .map_err(RPCError::protocol)?; let body = vcrypto .decrypt_aead( - &routed_operation.data, - &routed_operation.nonce, + routed_operation.data(), + routed_operation.nonce(), &dh_secret, None, ) @@ -353,9 +353,9 @@ impl RPCProcessor { let node_id = self.routing_table.node_id(crypto_kind); let node_id_secret = self.routing_table.node_id_secret_key(crypto_kind); 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)?; - route_operation.signatures.push(sig); + route_operation.add_signature(sig); } Ok(NetworkResult::value(route_hop)) @@ -378,7 +378,7 @@ impl RPCProcessor { // Get the statement let (_,_,_,kind) = msg.operation.destructure(); - let mut route = match kind { + let route = match kind { RPCOperationKind::Statement(s) => match s.destructure() { RPCStatementDetail::Route(s) => s, _ => panic!("not a route statement"), @@ -387,7 +387,7 @@ impl RPCProcessor { }; // 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 { return Ok(NetworkResult::invalid_message( "routed operation crypto is not supported", @@ -395,13 +395,14 @@ impl RPCProcessor { }; // 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 SafetyRouteHops::Data(ref route_hop_data) => { // 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 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)?; let mut dec_blob_data = vcrypto .decrypt_aead( @@ -435,8 +436,8 @@ impl RPCProcessor { // Switching from full safety route to private route first hop network_result_try!( self.process_private_route_first_hop( - route.operation, - route.safety_route.public_key, + routed_operation, + safety_route.public_key, private_route, ) .await? @@ -456,9 +457,9 @@ impl RPCProcessor { // Continue the full safety route with another hop network_result_try!( self.process_route_safety_route_hop( - route.operation, + routed_operation, route_hop, - route.safety_route + safety_route ) .await? ); @@ -474,8 +475,8 @@ impl RPCProcessor { // Safety route was a stub, start with the beginning of the private route network_result_try!( self.process_private_route_first_hop( - route.operation, - route.safety_route.public_key, + routed_operation, + safety_route.public_key, private_route, ) .await? @@ -486,7 +487,7 @@ impl RPCProcessor { let route_hop = network_result_try!(self.decrypt_private_route_hop_data( &route_hop_data, &private_route.public_key, - &mut route.operation + &mut routed_operation )?); // Ensure hop count > 0 @@ -499,9 +500,9 @@ impl RPCProcessor { // Make next PrivateRoute and pass it on network_result_try!( self.process_route_private_route_hop( - route.operation, + routed_operation, route_hop.node, - route.safety_route.public_key, + safety_route.public_key, PrivateRoute { public_key: private_route.public_key, hop_count: private_route.hop_count - 1, @@ -521,7 +522,7 @@ impl RPCProcessor { "route should be at the end", )); } - if route.safety_route.hop_count != 0 { + if safety_route.hop_count != 0 { return Ok(NetworkResult::invalid_message( "Safety hop count should be zero if switched to private route", )); @@ -531,8 +532,8 @@ impl RPCProcessor { network_result_try!(self.process_routed_operation( detail, vcrypto, - route.operation, - route.safety_route.public_key, + routed_operation, + safety_route.public_key, private_route.public_key, )?); } diff --git a/veilid-core/src/rpc_processor/rpc_signal.rs b/veilid-core/src/rpc_processor/rpc_signal.rs index f2d1d19e..57f81513 100644 --- a/veilid-core/src/rpc_processor/rpc_signal.rs +++ b/veilid-core/src/rpc_processor/rpc_signal.rs @@ -22,7 +22,7 @@ impl RPCProcessor { )); } - let signal = RPCOperationSignal { signal_info }; + let signal = RPCOperationSignal::new(signal_info); let statement = RPCStatement::new(RPCStatementDetail::Signal(signal)); // Send the signal request diff --git a/veilid-core/src/rpc_processor/rpc_status.rs b/veilid-core/src/rpc_processor/rpc_status.rs index 29b13d61..cedccf5c 100644 --- a/veilid-core/src/rpc_processor/rpc_status.rs +++ b/veilid-core/src/rpc_processor/rpc_status.rs @@ -68,7 +68,7 @@ impl RPCProcessor { } }; - let status_q = RPCOperationStatusQ { node_status }; + let status_q = RPCOperationStatusQ::new(node_status); let question = RPCQuestion::new( network_result_try!(self.get_destination_respond_to(&dest)?), RPCQuestionDetail::StatusQ(status_q), @@ -88,8 +88,9 @@ impl RPCProcessor { }; // Get the right answer type - let status_a = match msg.operation.into_kind() { - RPCOperationKind::Answer(a) => match a.into_detail() { + let (_, _, _, kind) = msg.operation.destructure(); + let status_a = match kind { + RPCOperationKind::Answer(a) => match a.destructure() { RPCAnswerDetail::StatusA(a) => a, _ => 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 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 { RoutingDomain::PublicInternet => { if !matches!(node_status, NodeStatus::PublicInternet(_)) { @@ -117,7 +118,7 @@ impl RPCProcessor { } // 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, } => { 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 { 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 @@ -199,7 +200,7 @@ impl RPCProcessor { 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 - if let Some(node_status) = &status_q.node_status { + if let Some(node_status) = status_q.node_status() { match routing_domain { RoutingDomain::PublicInternet => { if !matches!(node_status, NodeStatus::PublicInternet(_)) { @@ -244,10 +245,7 @@ impl RPCProcessor { }; // Make status answer - let status_a = RPCOperationStatusA { - node_status, - sender_info, - }; + let status_a = RPCOperationStatusA::new(node_status, sender_info); // Send status answer self.answer(msg, RPCAnswer::new(RPCAnswerDetail::StatusA(status_a))) diff --git a/veilid-core/src/rpc_processor/rpc_validate_dial_info.rs b/veilid-core/src/rpc_processor/rpc_validate_dial_info.rs index d5d860b6..e1530359 100644 --- a/veilid-core/src/rpc_processor/rpc_validate_dial_info.rs +++ b/veilid-core/src/rpc_processor/rpc_validate_dial_info.rs @@ -17,11 +17,7 @@ impl RPCProcessor { .generate_single_shot_receipt(receipt_time, []) .map_err(RPCError::internal)?; - let validate_dial_info = RPCOperationValidateDialInfo { - dial_info, - receipt, - redirect, - }; + let validate_dial_info = RPCOperationValidateDialInfo::new(dial_info, receipt, redirect)?; let statement = RPCStatement::new(RPCStatementDetail::ValidateDialInfo(validate_dial_info)); // Send the validate_dial_info request @@ -134,11 +130,8 @@ impl RPCProcessor { } // Make a copy of the request, without the redirect flag - let validate_dial_info = RPCOperationValidateDialInfo { - dial_info: dial_info.clone(), - receipt: receipt.clone(), - redirect: false, - }; + let validate_dial_info = + RPCOperationValidateDialInfo::new(dial_info.clone(), receipt.clone(), false)?; let statement = RPCStatement::new(RPCStatementDetail::ValidateDialInfo(validate_dial_info)); diff --git a/veilid-core/src/storage_manager/record_store.rs b/veilid-core/src/storage_manager/record_store.rs index 6bbb125d..f96337f5 100644 --- a/veilid-core/src/storage_manager/record_store.rs +++ b/veilid-core/src/storage_manager/record_store.rs @@ -101,6 +101,7 @@ impl RecordStore { } 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 let mut dead_size = 0usize; 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(); } 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 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, { // Get record from index + let mut out = None; let rtk = RecordTableKey { key }; if let Some(record) = self.record_index.get_mut(&rtk) { + // Callback + out = Some(f(record)); + // Touch 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( diff --git a/veilid-core/src/veilid_api/types/app_message_call.rs b/veilid-core/src/veilid_api/types/app_message_call.rs index 42035271..95fa27f8 100644 --- a/veilid-core/src/veilid_api/types/app_message_call.rs +++ b/veilid-core/src/veilid_api/types/app_message_call.rs @@ -8,10 +8,10 @@ use super::*; pub struct VeilidAppMessage { /// Some(sender) if the message was sent directly, None if received via a private/safety route #[serde(with = "opt_json_as_string")] - pub sender: Option, + sender: Option, /// The content of the message to deliver to the application #[serde(with = "json_as_base64")] - pub message: Vec, + message: Vec, } impl VeilidAppMessage { diff --git a/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs b/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs index ad2fac30..24e18337 100644 --- a/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs +++ b/veilid-core/src/veilid_api/types/dht/dht_record_descriptor.rs @@ -25,11 +25,11 @@ impl DHTRecordDescriptor { Self { owner, schema } } - pub fn owner(&self) -> PublicKey { - self.owner + pub fn owner(&self) -> &PublicKey { + &self.owner } - pub fn schema(&self) -> DHTSchema { - self.schema + pub fn schema(&self) -> &DHTSchema { + &self.schema } } diff --git a/veilid-core/src/veilid_api/types/dht/schema/smpl.rs b/veilid-core/src/veilid_api/types/dht/schema/smpl.rs index 6ae08a26..1ac4a17b 100644 --- a/veilid-core/src/veilid_api/types/dht/schema/smpl.rs +++ b/veilid-core/src/veilid_api/types/dht/schema/smpl.rs @@ -58,7 +58,7 @@ impl DHTSchemaSMPL { // o_cnt out.extend_from_slice(&self.o_cnt.to_le_bytes()); // members - for m in self.members { + for m in &self.members { // m_key out.extend_from_slice(&m.m_key.bytes); // m_cnt diff --git a/veilid-flutter/rust/Cargo.toml b/veilid-flutter/rust/Cargo.toml index 8b8b0773..002db7da 100644 --- a/veilid-flutter/rust/Cargo.toml +++ b/veilid-flutter/rust/Cargo.toml @@ -27,10 +27,10 @@ data-encoding = { version = "^2" } # Dependencies for native builds only # Linux, Windows, Mac, iOS, Android [target.'cfg(not(target_arch = "wasm32"))'.dependencies] -tracing-opentelemetry = "^0" -opentelemetry = { version = "^0" } -opentelemetry-otlp = { version = "^0" } -opentelemetry-semantic-conventions = "^0" +tracing-opentelemetry = "0.18" +opentelemetry = { version = "0.18" } +opentelemetry-otlp = { version = "0.11" } +opentelemetry-semantic-conventions = "0.10" async-std = { version = "^1", features = ["unstable"], optional = true } tokio = { version = "^1", features = ["full"], optional = true } tokio-stream = { version = "^0", features = ["net"], optional = true } diff --git a/veilid-server/Cargo.toml b/veilid-server/Cargo.toml index 6222cb83..b4ed29c7 100644 --- a/veilid-server/Cargo.toml +++ b/veilid-server/Cargo.toml @@ -24,11 +24,11 @@ veilid-core = { path = "../veilid-core", default-features = false } tracing = { version = "^0", features = ["log", "attributes"] } tracing-subscriber = { version = "^0", features = ["env-filter"] } tracing-appender = "^0" -tracing-opentelemetry = "^0" +tracing-opentelemetry = "0.18" # Buggy: tracing-error = "^0" -opentelemetry = { version = "^0" } -opentelemetry-otlp = { version = "^0" } -opentelemetry-semantic-conventions = "^0" +opentelemetry = { version = "0.18" } +opentelemetry-otlp = { version = "0.11" } +opentelemetry-semantic-conventions = "0.10" async-std = { version = "^1", features = ["unstable"], optional = true } tokio = { version = "^1", features = ["full", "tracing"], optional = true } console-subscriber = { version = "^0", optional = true } diff --git a/veilid-server/src/settings.rs b/veilid-server/src/settings.rs index 4d25c912..c0dc796a 100644 --- a/veilid-server/src/settings.rs +++ b/veilid-server/src/settings.rs @@ -6,7 +6,7 @@ use serde_derive::*; use std::ffi::OsStr; use std::net::SocketAddr; use std::path::{Path, PathBuf}; -use sysinfo::{DiskExt, System, SystemExt}; +use sysinfo::{DiskExt, SystemExt}; use url::Url; use veilid_core::tools::*; use veilid_core::*; @@ -174,7 +174,7 @@ core: ) .replace( "%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() .add_source(config::File::from_str( @@ -638,7 +638,7 @@ impl Settings { } // Generate config - let inner: SettingsInner = cfg.try_deserialize()?; + let mut inner: SettingsInner = cfg.try_deserialize()?; // Fill in missing defaults 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 { - 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 } - pub fn get_default_remote_max_storage_space_mb(inner: &SettingsInner) -> usize { - let mut sys = System::new_with_specifics(sysinfo::RefreshKind::new().with_disks()); + pub fn get_default_remote_max_storage_space_mb(inner: &SettingsInner) -> u32 { + let mut sys = sysinfo::System::new_with_specifics(sysinfo::RefreshKind::new().with_disks()); 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 sys.sort_disks_by(|a, b| { b.mount_point() @@ -874,13 +873,13 @@ impl Settings { }); for disk in sys.disks() { 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 { // Default to 10GB if more than 40GB is available return 10_000; } // 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 diff --git a/veilid-server/src/unix.rs b/veilid-server/src/unix.rs index fe66e943..1d2aa389 100644 --- a/veilid-server/src/unix.rs +++ b/veilid-server/src/unix.rs @@ -7,7 +7,7 @@ use clap::ArgMatches; use futures_util::StreamExt; use signal_hook::consts::signal::*; use signal_hook_async_std::Signals; -use std::io::Read; +//use std::io::Read; use tracing::*; #[instrument(skip(signals))] @@ -34,23 +34,23 @@ pub fn run_daemon(settings: Settings, _matches: ArgMatches) -> EyreResult<()> { let s = settings.read(); if let Some(pid_file) = s.daemon.pid_file.clone() { daemon = daemon.pid_file(pid_file.clone()); //.chown_pid_file(true); - daemon = daemon.exit_action(move || { - // wait for pid file to exist before exiting parent - let pid_path = std::path::Path::new(&pid_file); - loop { - if let Ok(mut f) = std::fs::File::open(pid_path) { - let mut s = String::new(); - if f.read_to_string(&mut s).is_ok() - && !s.is_empty() - && s.parse::().is_ok() - { - println!("pidfile found"); - break; - } - } - std::thread::sleep(std::time::Duration::from_millis(100)); - } - }) + // daemon = daemon.exit_action(move || { + // // wait for pid file to exist before exiting parent + // let pid_path = std::path::Path::new(&pid_file); + // loop { + // if let Ok(mut f) = std::fs::File::open(pid_path) { + // let mut s = String::new(); + // if f.read_to_string(&mut s).is_ok() + // && !s.is_empty() + // && s.parse::().is_ok() + // { + // println!("pidfile found"); + // break; + // } + // } + // std::thread::sleep(std::time::Duration::from_millis(100)); + // } + // }) } if let Some(chroot) = &s.daemon.chroot { daemon = daemon.chroot(chroot);