diff --git a/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs b/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs index c2a7b530..5bf624aa 100644 --- a/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs +++ b/veilid-core/src/routing_table/tests/test_serialize_routing_table.rs @@ -1,6 +1,5 @@ use crate::*; - -const SERIALIZED_PEERINFO: &str = r###"{"node_ids":["FAKE:eFOfgm_FNZBsTRi7KAESNwYFAUGgX2uDrTRWAL8ucjM"],"signed_node_info":{"Direct":{"node_info":{"network_class":"InboundCapable","outbound_protocols":1,"address_types":3,"envelope_support":[0],"crypto_support":[[86,76,68,48]],"dial_info_detail_list":[{"class":"Direct","dial_info":{"kind":"UDP","socket_address":{"address":{"IPV4":"1.2.3.4"},"port":5150}}},{"class":"Direct","dial_info":{"kind":"UDP","socket_address":{"address":{"IPV6":"bad:cafe::1"},"port":5150}}},{"class":"Direct","dial_info":{"kind":"TCP","socket_address":{"address":{"IPV4":"5.6.7.8"},"port":5150}}},{"class":"Direct","dial_info":{"kind":"TCP","socket_address":{"address":{"IPV6":"bad:cafe::1"},"port":5150}}},{"class":"Direct","dial_info":{"kind":"WS","socket_address":{"address":{"IPV4":"9.10.11.12"},"port":5150},"request":"bootstrap-1.dev.veilid.net:5150/ws"}},{"class":"Direct","dial_info":{"kind":"WS","socket_address":{"address":{"IPV6":"bad:cafe::1"},"port":5150},"request":"bootstrap-1.dev.veilid.net:5150/ws"}}]},"timestamp":1685058646770389,"signatures":[]}}}"###; +use routing_table::*; fn fake_routing_table() -> routing_table::RoutingTable { let veilid_config = VeilidConfig::new(); @@ -25,7 +24,7 @@ fn fake_routing_table() -> routing_table::RoutingTable { block_store.clone(), crypto.clone(), ); - routing_table::RoutingTable::new(network_manager) + RoutingTable::new(network_manager) } pub async fn test_routingtable_buckets_round_trip() { @@ -84,11 +83,27 @@ pub async fn test_routingtable_buckets_round_trip() { } pub async fn test_round_trip_peerinfo() { - let pi: routing_table::PeerInfo = deserialize_json(SERIALIZED_PEERINFO).unwrap(); + let pi: PeerInfo = PeerInfo::new( + TypedKeySet::new(), + SignedNodeInfo::Direct(SignedDirectNodeInfo::new( + NodeInfo::new( + NetworkClass::OutboundOnly, + ProtocolTypeSet::new(), + AddressTypeSet::new(), + vec![0], + vec![CRYPTO_KIND_VLD0], + vec![], + ), + Timestamp::new(0), + Vec::new(), + )), + ); + let s = serialize_json(&pi); + let pi2 = deserialize_json(&s).expect("Should deserialize"); + let s2 = serialize_json(&pi2); - let back = serialize_json(pi); - - assert_eq!(SERIALIZED_PEERINFO, back); + assert_eq!(pi, pi2); + assert_eq!(s, s2); } pub async fn test_all() { diff --git a/veilid-core/src/routing_table/types/node_info.rs b/veilid-core/src/routing_table/types/node_info.rs index ca5cbde8..e67f4711 100644 --- a/veilid-core/src/routing_table/types/node_info.rs +++ b/veilid-core/src/routing_table/types/node_info.rs @@ -1,7 +1,16 @@ use super::*; #[derive( - Clone, Default, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, + Clone, + Default, + PartialEq, + Eq, + Debug, + Serialize, + Deserialize, + RkyvArchive, + RkyvSerialize, + RkyvDeserialize, )] #[archive_attr(repr(C), derive(CheckBytes))] pub struct NodeInfo { diff --git a/veilid-core/src/routing_table/types/peer_info.rs b/veilid-core/src/routing_table/types/peer_info.rs index b7037646..e3037459 100644 --- a/veilid-core/src/routing_table/types/peer_info.rs +++ b/veilid-core/src/routing_table/types/peer_info.rs @@ -1,6 +1,8 @@ use super::*; -#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)] +#[derive( + Clone, Debug, Serialize, Deserialize, PartialEq, Eq, RkyvArchive, RkyvSerialize, RkyvDeserialize, +)] #[archive_attr(repr(C), derive(CheckBytes))] pub struct PeerInfo { node_ids: TypedKeySet, diff --git a/veilid-core/src/routing_table/types/signed_direct_node_info.rs b/veilid-core/src/routing_table/types/signed_direct_node_info.rs index e6fee40d..32efb8de 100644 --- a/veilid-core/src/routing_table/types/signed_direct_node_info.rs +++ b/veilid-core/src/routing_table/types/signed_direct_node_info.rs @@ -1,7 +1,9 @@ use super::*; /// Signed NodeInfo that can be passed around amongst peers and verifiable -#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, +)] #[archive_attr(repr(C), derive(CheckBytes))] pub struct SignedDirectNodeInfo { node_info: NodeInfo, diff --git a/veilid-core/src/routing_table/types/signed_node_info.rs b/veilid-core/src/routing_table/types/signed_node_info.rs index 5557a76a..60e99c89 100644 --- a/veilid-core/src/routing_table/types/signed_node_info.rs +++ b/veilid-core/src/routing_table/types/signed_node_info.rs @@ -1,6 +1,8 @@ use super::*; -#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, +)] #[archive_attr(repr(u8), derive(CheckBytes))] pub enum SignedNodeInfo { Direct(SignedDirectNodeInfo), diff --git a/veilid-core/src/routing_table/types/signed_relayed_node_info.rs b/veilid-core/src/routing_table/types/signed_relayed_node_info.rs index 8a429e4c..cdfda702 100644 --- a/veilid-core/src/routing_table/types/signed_relayed_node_info.rs +++ b/veilid-core/src/routing_table/types/signed_relayed_node_info.rs @@ -1,7 +1,9 @@ use super::*; /// Signed NodeInfo with a relay that can be passed around amongst peers and verifiable -#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)] +#[derive( + Clone, Debug, PartialEq, Eq, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, +)] #[archive_attr(repr(C), derive(CheckBytes))] pub struct SignedRelayedNodeInfo { node_info: NodeInfo, diff --git a/veilid-core/src/veilid_api/tests/fixtures.rs b/veilid-core/src/veilid_api/tests/fixtures.rs index 7f86ac22..bb503260 100644 --- a/veilid-core/src/veilid_api/tests/fixtures.rs +++ b/veilid-core/src/veilid_api/tests/fixtures.rs @@ -212,10 +212,6 @@ pub fn fix_veilidvaluechange() -> VeilidValueChange { key: fix_typedkey(), subkeys: vec![1, 2, 3, 4], count: 5, - value: ValueData { - seq: 23, - data: b"ValueData".to_vec(), - writer: fix_cryptokey(), - }, + value: ValueData::new_with_seq(23, b"ValueData".to_vec(), fix_cryptokey()), } } diff --git a/veilid-core/src/veilid_api/tests/test_types.rs b/veilid-core/src/veilid_api/tests/test_types.rs index 524f9f7a..7cbe27bb 100644 --- a/veilid-core/src/veilid_api/tests/test_types.rs +++ b/veilid-core/src/veilid_api/tests/test_types.rs @@ -13,21 +13,18 @@ pub async fn test_alignedu64() { // app_messsage_call pub async fn test_veilidappmessage() { - let orig = VeilidAppMessage { - sender: Some(fix_typedkey()), - message: b"Hi there!".to_vec(), - }; + let orig = VeilidAppMessage::new(Some(fix_typedkey()), b"Hi there!".to_vec()); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); } pub async fn test_veilidappcall() { - let orig = VeilidAppCall { - sender: Some(fix_typedkey()), - message: b"Well, hello!".to_vec(), - call_id: AlignedU64::from(123), - }; + let orig = VeilidAppCall::new( + Some(fix_typedkey()), + b"Well, hello!".to_vec(), + AlignedU64::from(123), + ); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); diff --git a/veilid-core/src/veilid_api/tests/test_types_dht.rs b/veilid-core/src/veilid_api/tests/test_types_dht.rs index f098e06b..73f32eda 100644 --- a/veilid-core/src/veilid_api/tests/test_types_dht.rs +++ b/veilid-core/src/veilid_api/tests/test_types_dht.rs @@ -5,12 +5,12 @@ use range_set_blaze::*; // dht_record_descriptors pub async fn test_dhtrecorddescriptor() { - let orig = DHTRecordDescriptor { - key: fix_typedkey(), - owner: fix_cryptokey(), - owner_secret: Some(fix_cryptokey()), - schema: DHTSchema::DFLT(DHTSchemaDFLT { o_cnt: 4321 }), - }; + let orig = DHTRecordDescriptor::new( + fix_typedkey(), + fix_cryptokey(), + Some(fix_cryptokey()), + DHTSchema::DFLT(DHTSchemaDFLT { o_cnt: 4321 }), + ); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); @@ -19,11 +19,7 @@ pub async fn test_dhtrecorddescriptor() { // value_data pub async fn test_valuedata() { - let orig = ValueData { - seq: 42, - data: b"Brent Spiner".to_vec(), - writer: fix_cryptokey(), - }; + let orig = ValueData::new_with_seq(42, b"Brent Spiner".to_vec(), fix_cryptokey()); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); @@ -32,9 +28,7 @@ pub async fn test_valuedata() { // value_subkey_range_set pub async fn test_valuesubkeyrangeset() { - let orig = ValueSubkeyRangeSet { - data: RangeSetBlaze::from_iter([20..=30]), - }; + let orig = ValueSubkeyRangeSet::new_with_data(RangeSetBlaze::from_iter([20..=30])); let copy = deserialize_json(&serialize_json(&orig)).unwrap(); assert_eq!(orig, copy); 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 3d6a096e..36fa47e1 100644 --- a/veilid-core/src/veilid_api/types/app_message_call.rs +++ b/veilid-core/src/veilid_api/types/app_message_call.rs @@ -57,17 +57,17 @@ pub struct VeilidAppCall { /// Some(sender) if the request was sent directly, None if received via a private/safety route #[serde(with = "opt_json_as_string")] #[schemars(with = "Option")] - pub sender: Option, + sender: Option, /// The content of the request to deliver to the application #[serde(with = "json_as_base64")] #[schemars(with = "String")] - pub message: Vec, + message: Vec, /// The id to reply to #[serde(with = "json_as_string")] #[schemars(with = "String")] - pub call_id: OperationId, + call_id: OperationId, } impl VeilidAppCall { 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 03857c1a..6162fd9f 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 @@ -19,16 +19,16 @@ use super::*; pub struct DHTRecordDescriptor { /// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ] #[schemars(with = "String")] - pub key: TypedKey, + key: TypedKey, /// The public key of the owner #[schemars(with = "String")] - pub owner: PublicKey, + owner: PublicKey, /// If this key is being created: Some(the secret key of the owner) /// If this key is just being opened: None #[schemars(with = "Option")] - pub owner_secret: Option, + owner_secret: Option, /// The schema in use associated with the key - pub schema: DHTSchema, + schema: DHTSchema, } impl DHTRecordDescriptor { diff --git a/veilid-core/src/veilid_api/types/dht/value_data.rs b/veilid-core/src/veilid_api/types/dht/value_data.rs index 737d4a7d..c57fc2e5 100644 --- a/veilid-core/src/veilid_api/types/dht/value_data.rs +++ b/veilid-core/src/veilid_api/types/dht/value_data.rs @@ -18,16 +18,16 @@ use super::*; #[archive_attr(repr(C), derive(CheckBytes))] pub struct ValueData { /// An increasing sequence number to time-order the DHT record changes - pub seq: ValueSeqNum, + seq: ValueSeqNum, /// The contents of a DHT Record #[serde(with = "json_as_base64")] #[schemars(with = "String")] - pub data: Vec, + data: Vec, /// The public identity key of the writer of the data #[schemars(with = "String")] - pub writer: PublicKey, + writer: PublicKey, } impl ValueData { pub const MAX_LEN: usize = 32768; diff --git a/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs b/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs index 8a7196ab..466346d3 100644 --- a/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs +++ b/veilid-core/src/veilid_api/types/dht/value_subkey_range_set.rs @@ -23,7 +23,7 @@ pub struct ValueSubkeyRangeSet { #[with(RkyvRangeSetBlaze)] #[serde(with = "serialize_range_set_blaze")] #[schemars(with = "Vec<(u32,u32)>")] - pub data: RangeSetBlaze, + data: RangeSetBlaze, } impl ValueSubkeyRangeSet { @@ -32,6 +32,9 @@ impl ValueSubkeyRangeSet { data: Default::default(), } } + pub fn new_with_data(data: RangeSetBlaze) -> Self { + Self { data } + } pub fn single(value: ValueSubkey) -> Self { let mut data = RangeSetBlaze::new(); data.insert(value);