Merge branch 'main' of gitlab.hackers.town:veilid/veilid into json-rpc

This commit is contained in:
John Smith 2023-06-16 13:13:51 -04:00
commit fe502a3645
18 changed files with 787 additions and 123 deletions

View File

@ -72,6 +72,7 @@ data-encoding = { version = "^2" }
weak-table = "0.3.2" weak-table = "0.3.2"
range-set-blaze = "0.1.5" range-set-blaze = "0.1.5"
argon2 = "0.5.0" argon2 = "0.5.0"
paste = "1.0.12"
schemars = "0.8.12" schemars = "0.8.12"
# Dependencies for native builds only # Dependencies for native builds only

View File

@ -1 +1 @@
pub mod test_serialize; pub mod test_serialize_routing_table;

View File

@ -1,5 +1,7 @@
use crate::*; 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":[]}}}"###;
fn fake_routing_table() -> routing_table::RoutingTable { fn fake_routing_table() -> routing_table::RoutingTable {
let veilid_config = VeilidConfig::new(); let veilid_config = VeilidConfig::new();
#[cfg(feature = "unstable-blockstore")] #[cfg(feature = "unstable-blockstore")]
@ -81,6 +83,15 @@ pub async fn test_routingtable_buckets_round_trip() {
copy.terminate().await; copy.terminate().await;
} }
pub async fn test_round_trip_peerinfo() {
let pi: routing_table::PeerInfo = deserialize_json(SERIALIZED_PEERINFO).unwrap();
let back = serialize_json(pi);
assert_eq!(SERIALIZED_PEERINFO, back);
}
pub async fn test_all() { pub async fn test_all() {
test_routingtable_buckets_round_trip().await; test_routingtable_buckets_round_trip().await;
test_round_trip_peerinfo().await;
} }

View File

@ -12,6 +12,6 @@ use super::*;
pub use common::*; pub use common::*;
pub use crypto::tests::*; pub use crypto::tests::*;
pub use network_manager::tests::*; pub use network_manager::tests::*;
pub use routing_table::tests::test_serialize as test_routing_table_serialize; pub use routing_table::tests::*;
pub use table_store::tests::*; pub use table_store::tests::*;
pub use veilid_api::tests::*; pub use veilid_api::tests::*;

View File

@ -33,10 +33,12 @@ pub async fn run_all_tests() {
test_crypto::test_all().await; test_crypto::test_all().await;
info!("TEST: test_envelope_receipt"); info!("TEST: test_envelope_receipt");
test_envelope_receipt::test_all().await; test_envelope_receipt::test_all().await;
info!("TEST: veilid_api::test_serialize"); info!("TEST: veilid_api::tests::test_serialize_json");
veilid_api::tests::test_serialize_json::test_all().await;
info!("TEST: veilid_api::tests::test_serialize_rkyv");
veilid_api::tests::test_serialize_rkyv::test_all().await; veilid_api::tests::test_serialize_rkyv::test_all().await;
info!("TEST: routing_table::test_serialize"); info!("TEST: routing_table::test_serialize_routing_table");
routing_table::tests::test_serialize::test_all().await; routing_table::tests::test_serialize_routing_table::test_all().await;
info!("Finished unit tests"); info!("Finished unit tests");
} }
@ -59,6 +61,39 @@ cfg_if! {
if #[cfg(test)] { if #[cfg(test)] {
use serial_test::serial; use serial_test::serial;
use std::sync::Once; use std::sync::Once;
use paste::paste;
macro_rules! run_test {
// Nearly all test runner code is cookie cutter, and copy-pasting makes it too easy to make a typo.
// Pass in a module and test module, and we'll run its `test_all`.
($parent_module:ident, $test_module:ident) => {
paste! {
#[test]
#[serial]
fn [<run_ $parent_module _ $test_module>]() {
setup();
block_on(async {
$parent_module::tests::$test_module::test_all().await;
})
}
}
};
// Pass in a test module name, and we'll run its `test_all`.
($test_module:ident) => {
paste! {
#[test]
#[serial]
fn [<run_ $test_module>]() {
setup();
block_on(async {
$test_module::test_all().await;
})
}
}
};
}
static SETUP_ONCE: Once = Once::new(); static SETUP_ONCE: Once = Once::new();
@ -81,112 +116,30 @@ cfg_if! {
}); });
} }
#[test] run_test!(test_host_interface);
#[serial]
fn run_test_host_interface() {
setup();
block_on(async {
test_host_interface::test_all().await;
});
}
#[test] run_test!(test_types);
#[serial]
fn run_test_dht_key() {
setup();
block_on(async {
test_types::test_all().await;
});
}
#[test] run_test!(test_veilid_core);
#[serial]
fn run_test_veilid_core() {
setup();
block_on(async {
test_veilid_core::test_all().await;
});
}
#[test] run_test!(test_veilid_config);
#[serial]
fn run_test_veilid_config() {
setup();
block_on(async {
test_veilid_config::test_all().await;
})
}
#[test] run_test!(test_connection_table);
#[serial]
fn run_test_connection_table() {
setup();
block_on(async {
test_connection_table::test_all().await;
})
}
#[test] run_test!(test_signed_node_info);
#[serial]
fn run_test_signed_node_info() {
setup();
block_on(async {
test_signed_node_info::test_all().await;
})
}
#[test] run_test!(test_table_store);
#[serial]
fn run_test_table_store() {
setup();
block_on(async {
test_table_store::test_all().await;
})
}
#[test] run_test!(test_protected_store);
#[serial]
fn run_test_protected_store() {
setup();
block_on(async {
test_protected_store::test_all().await;
})
}
#[test] run_test!(test_crypto);
#[serial]
fn run_test_crypto() {
setup();
block_on(async {
test_crypto::test_all().await;
})
}
#[test] run_test!(test_envelope_receipt);
#[serial]
fn run_test_envelope_receipt() {
setup();
block_on(async {
test_envelope_receipt::test_all().await;
})
}
#[test] run_test!(veilid_api, test_serialize_json);
#[serial]
fn run_test_serialize_rkyv() {
setup();
block_on(async {
veilid_api::tests::test_serialize_rkyv::test_all().await;
})
}
#[test] run_test!(veilid_api, test_serialize_rkyv);
#[serial]
fn run_test_routing_table_serialize() { run_test!(routing_table, test_serialize_routing_table);
setup();
block_on(async {
routing_table::tests::test_serialize::test_all().await;
})
}
} }
} }

View File

@ -0,0 +1,221 @@
use crate::*;
// Fixtures used by various tests
pub fn fix_latencystats() -> LatencyStats {
LatencyStats {
fastest: AlignedU64::from(1234),
average: AlignedU64::from(2345),
slowest: AlignedU64::from(3456),
}
}
pub fn fix_transferstats() -> TransferStats {
TransferStats {
total: AlignedU64::from(1_000_000),
maximum: AlignedU64::from(3456),
average: AlignedU64::from(2345),
minimum: AlignedU64::from(1234),
}
}
pub fn fix_transferstatsdownup() -> TransferStatsDownUp {
TransferStatsDownUp {
down: fix_transferstats(),
up: fix_transferstats(),
}
}
pub fn fix_rpcstats() -> RPCStats {
RPCStats {
messages_sent: 1_000_000,
messages_rcvd: 2_000_000,
questions_in_flight: 42,
last_question_ts: Some(AlignedU64::from(1685569084280)),
last_seen_ts: Some(AlignedU64::from(1685569101256)),
first_consecutive_seen_ts: Some(AlignedU64::from(1685569111851)),
recent_lost_answers: 5,
failed_to_send: 3,
}
}
pub fn fix_peerstats() -> PeerStats {
PeerStats {
time_added: AlignedU64::from(1685569176894),
rpc_stats: fix_rpcstats(),
latency: Some(fix_latencystats()),
transfer: fix_transferstatsdownup(),
}
}
pub fn fix_cryptokey() -> CryptoKey {
let mut fake_key = [0u8; CRYPTO_KEY_LENGTH];
random_bytes(&mut fake_key);
CryptoKey::new(fake_key)
}
pub fn fix_typedkey() -> TypedKey {
let mut fake_key = [0u8; CRYPTO_KEY_LENGTH];
random_bytes(&mut fake_key);
TypedKey {
kind: FourCC::from_str("FAKE").unwrap(),
value: fix_cryptokey(),
}
}
pub fn fix_peertabledata() -> PeerTableData {
PeerTableData {
node_ids: vec![fix_typedkey()],
peer_address: "123 Main St.".to_string(),
peer_stats: fix_peerstats(),
}
}
pub fn fix_veilidconfiginner() -> VeilidConfigInner {
VeilidConfigInner {
program_name: "Bob".to_string(),
namespace: "Internets".to_string(),
capabilities: VeilidConfigCapabilities {
protocol_udp: false,
protocol_connect_tcp: true,
protocol_accept_tcp: false,
protocol_connect_ws: true,
protocol_accept_ws: false,
protocol_connect_wss: true,
protocol_accept_wss: false,
},
protected_store: VeilidConfigProtectedStore {
allow_insecure_fallback: true,
always_use_insecure_storage: false,
directory: "/root".to_string(),
delete: true,
device_encryption_key_password: "1234".to_string(),
new_device_encryption_key_password: Some("5678".to_string()),
},
table_store: VeilidConfigTableStore {
directory: "Yellow Pages".to_string(),
delete: false,
},
block_store: VeilidConfigBlockStore {
directory: "C:\\Program Files".to_string(),
delete: true,
},
network: VeilidConfigNetwork {
connection_initial_timeout_ms: 1000,
connection_inactivity_timeout_ms: 2000,
max_connections_per_ip4: 3000,
max_connections_per_ip6_prefix: 4000,
max_connections_per_ip6_prefix_size: 5000,
max_connection_frequency_per_min: 6000,
client_whitelist_timeout_ms: 7000,
reverse_connection_receipt_time_ms: 8000,
hole_punch_receipt_time_ms: 9000,
routing_table: VeilidConfigRoutingTable {
node_id: TypedKeySet::new(),
node_id_secret: TypedSecretSet::new(),
bootstrap: vec!["boots".to_string()],
limit_over_attached: 1,
limit_fully_attached: 2,
limit_attached_strong: 3,
limit_attached_good: 4,
limit_attached_weak: 5,
},
rpc: VeilidConfigRPC {
concurrency: 5,
queue_size: 6,
max_timestamp_behind_ms: Some(1000),
max_timestamp_ahead_ms: Some(2000),
timeout_ms: 3000,
max_route_hop_count: 7,
default_route_hop_count: 8,
},
dht: VeilidConfigDHT {
max_find_node_count: 1,
resolve_node_timeout_ms: 2,
resolve_node_count: 3,
resolve_node_fanout: 4,
get_value_timeout_ms: 5,
get_value_count: 6,
get_value_fanout: 7,
set_value_timeout_ms: 8,
set_value_count: 9,
set_value_fanout: 10,
min_peer_count: 11,
min_peer_refresh_time_ms: 12,
validate_dial_info_receipt_time_ms: 13,
local_subkey_cache_size: 14,
local_max_subkey_cache_memory_mb: 15,
remote_subkey_cache_size: 16,
remote_max_records: 17,
remote_max_subkey_cache_memory_mb: 18,
remote_max_storage_space_mb: 19,
},
upnp: true,
detect_address_changes: false,
restricted_nat_retries: 10000,
tls: VeilidConfigTLS {
certificate_path: "/etc/ssl/certs/cert.pem".to_string(),
private_key_path: "/etc/ssl/keys/key.pem".to_string(),
connection_initial_timeout_ms: 1000,
},
application: VeilidConfigApplication {
https: VeilidConfigHTTPS {
enabled: true,
listen_address: "10.0.0.3".to_string(),
path: "/https_path/".to_string(),
url: Some("https://veilid.com/".to_string()),
},
http: VeilidConfigHTTP {
enabled: true,
listen_address: "10.0.0.4".to_string(),
path: "/http_path/".to_string(),
url: Some("http://veilid.com/".to_string()),
},
},
protocol: VeilidConfigProtocol {
udp: VeilidConfigUDP {
enabled: false,
socket_pool_size: 30,
listen_address: "10.0.0.2".to_string(),
public_address: Some("2.3.4.5".to_string()),
},
tcp: VeilidConfigTCP {
connect: true,
listen: false,
max_connections: 8,
listen_address: "10.0.0.1".to_string(),
public_address: Some("1.2.3.4".to_string()),
},
ws: VeilidConfigWS {
connect: false,
listen: true,
max_connections: 9,
listen_address: "127.0.0.1".to_string(),
path: "Straight".to_string(),
url: Some("https://veilid.com/ws".to_string()),
},
wss: VeilidConfigWSS {
connect: true,
listen: false,
max_connections: 10,
listen_address: "::1".to_string(),
path: "Curved".to_string(),
url: Some("https://veilid.com/wss".to_string()),
},
},
},
}
}
pub fn fix_veilidvaluechange() -> 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(),
},
}
}

View File

@ -1 +1,6 @@
mod fixtures;
pub mod test_serialize_json;
pub mod test_serialize_rkyv; pub mod test_serialize_rkyv;
mod test_types;
mod test_types_dht;
mod test_types_dht_schema;

View File

@ -0,0 +1,45 @@
use super::test_types::*;
use super::test_types_dht::*;
use super::test_types_dht_schema::*;
pub async fn test_all() {
// test_types
test_alignedu64().await;
test_veilidappmessage().await;
test_veilidappcall().await;
test_fourcc().await;
test_sequencing().await;
test_stability().await;
test_safetyselection().await;
test_safetyspec().await;
test_latencystats().await;
test_transferstats().await;
test_transferstatsdownup().await;
test_rpcstats().await;
test_peerstats().await;
test_tunnelmode().await;
test_tunnelerror().await;
test_tunnelendpoint().await;
test_fulltunnel().await;
test_partialtunnel().await;
test_veilidloglevel().await;
test_veilidlog().await;
test_attachmentstate().await;
test_veilidstateattachment().await;
test_peertabledata().await;
test_veilidstatenetwork().await;
test_veilidroutechange().await;
test_veilidstateconfig().await;
test_veilidvaluechange().await;
test_veilidupdate().await;
test_veilidstate().await;
// test_types_dht
test_dhtrecorddescriptor().await;
test_valuedata().await;
test_valuesubkeyrangeset().await;
// test_types_dht_schema
test_dhtschemadflt().await;
test_dhtschema().await;
test_dhtschemasmplmember().await;
test_dhtschemasmpl().await;
}

View File

@ -0,0 +1,286 @@
use super::fixtures::*;
use crate::*;
// aligned_u64
pub async fn test_alignedu64() {
let orig = AlignedU64::new(0x0123456789abcdef);
let copy = deserialize_json(&serialize_json(orig)).unwrap();
assert_eq!(orig, copy);
}
// app_messsage_call
pub async fn test_veilidappmessage() {
let orig = VeilidAppMessage {
sender: Some(fix_typedkey()),
message: 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(),
id: AlignedU64::from(123),
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
// fourcc
pub async fn test_fourcc() {
let orig = FourCC::from_str("D34D").unwrap();
let copy = deserialize_json(&serialize_json(orig)).unwrap();
assert_eq!(orig, copy);
}
// safety
pub async fn test_sequencing() {
let orig = Sequencing::PreferOrdered;
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_stability() {
let orig = Stability::Reliable;
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_safetyselection() {
let orig = SafetySelection::Unsafe(Sequencing::EnsureOrdered);
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_safetyspec() {
let orig = SafetySpec {
preferred_route: Some(fix_cryptokey()),
hop_count: 23,
stability: Stability::default(),
sequencing: Sequencing::default(),
};
let copy = deserialize_json(&serialize_json(orig)).unwrap();
assert_eq!(orig, copy);
}
// stats
pub async fn test_latencystats() {
let orig = fix_latencystats();
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_transferstats() {
let orig = fix_transferstats();
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_transferstatsdownup() {
let orig = fix_transferstatsdownup();
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_rpcstats() {
let orig = fix_rpcstats();
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_peerstats() {
let orig = fix_peerstats();
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
// tunnel
pub async fn test_tunnelmode() {
let orig = TunnelMode::Raw;
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_tunnelerror() {
let orig = TunnelError::NoCapacity;
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_tunnelendpoint() {
let orig = TunnelEndpoint {
mode: TunnelMode::Raw,
description: "Here there be tygers.".to_string(),
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_fulltunnel() {
let orig = FullTunnel {
id: AlignedU64::from(42),
timeout: AlignedU64::from(3_000_000),
local: TunnelEndpoint {
mode: TunnelMode::Turn,
description: "Left end.".to_string(),
},
remote: TunnelEndpoint {
mode: TunnelMode::Turn,
description: "Right end.".to_string(),
},
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_partialtunnel() {
let orig = PartialTunnel {
id: AlignedU64::from(42),
timeout: AlignedU64::from(3_000_000),
local: TunnelEndpoint {
mode: TunnelMode::Turn,
description: "I'm so lonely.".to_string(),
},
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
// veilid_log
pub async fn test_veilidloglevel() {
let orig = VeilidLogLevel::Info;
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidlog() {
let orig = VeilidLog {
log_level: VeilidLogLevel::Debug,
message: "A log! A log!".to_string(),
backtrace: Some("Func1 -> Func2 -> Func3".to_string()),
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
// veilid_state
pub async fn test_attachmentstate() {
let orig = AttachmentState::FullyAttached;
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidstateattachment() {
let orig = VeilidStateAttachment {
state: AttachmentState::OverAttached,
public_internet_ready: true,
local_network_ready: false,
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_peertabledata() {
let orig = fix_peertabledata();
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidstatenetwork() {
let orig = VeilidStateNetwork {
started: true,
bps_down: AlignedU64::from(14_400),
bps_up: AlignedU64::from(1200),
peers: vec![fix_peertabledata()],
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidroutechange() {
let orig = VeilidRouteChange {
dead_routes: vec![fix_cryptokey()],
dead_remote_routes: vec![fix_cryptokey()],
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidstateconfig() {
let orig = VeilidStateConfig {
config: fix_veilidconfiginner(),
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidvaluechange() {
let orig = fix_veilidvaluechange();
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidupdate() {
let orig = VeilidUpdate::ValueChange(fix_veilidvaluechange());
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_veilidstate() {
let orig = VeilidState {
attachment: VeilidStateAttachment {
state: AttachmentState::OverAttached,
public_internet_ready: true,
local_network_ready: false,
},
network: VeilidStateNetwork {
started: true,
bps_down: AlignedU64::from(14_400),
bps_up: AlignedU64::from(1200),
peers: vec![fix_peertabledata()],
},
config: VeilidStateConfig {
config: fix_veilidconfiginner(),
},
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}

View File

@ -0,0 +1,41 @@
use super::fixtures::*;
use crate::*;
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 copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
// value_data
pub async fn test_valuedata() {
let orig = ValueData {
seq: 42,
data: b"Brent Spiner".to_vec(),
writer: fix_cryptokey(),
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
// value_subkey_range_set
pub async fn test_valuesubkeyrangeset() {
let orig = ValueSubkeyRangeSet {
data: RangeSetBlaze::from_iter([20..=30]),
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}

View File

@ -0,0 +1,64 @@
use super::fixtures::*;
use crate::*;
use range_set_blaze::*;
// dlft
pub async fn test_dhtschemadflt() {
let orig = DHTSchemaDFLT { o_cnt: 9 };
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
// mod
pub async fn test_dhtschema() {
let orig = DHTSchema::SMPL(DHTSchemaSMPL {
o_cnt: 91,
members: vec![
DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_cnt: 5,
},
DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_cnt: 6,
},
],
});
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
// smpl
pub async fn test_dhtschemasmplmember() {
let orig = DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_cnt: 7,
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}
pub async fn test_dhtschemasmpl() {
let orig = DHTSchemaSMPL {
o_cnt: 91,
members: vec![
DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_cnt: 8,
},
DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_cnt: 9,
},
],
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);
}

View File

@ -18,12 +18,12 @@ 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")]
#[schemars(with = "Option<String>")] #[schemars(with = "Option<String>")]
sender: Option<TypedKey>, pub sender: Option<TypedKey>,
/// 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")]
#[schemars(with = "String")] #[schemars(with = "String")]
message: Vec<u8>, pub message: Vec<u8>,
} }
impl VeilidAppMessage { impl VeilidAppMessage {
@ -57,17 +57,17 @@ pub struct VeilidAppCall {
/// Some(sender) if the request was sent directly, None if received via a private/safety route /// Some(sender) if the request was sent directly, None if received via a private/safety route
#[serde(with = "opt_json_as_string")] #[serde(with = "opt_json_as_string")]
#[schemars(with = "Option<String>")] #[schemars(with = "Option<String>")]
sender: Option<TypedKey>, pub sender: Option<TypedKey>,
/// The content of the request to deliver to the application /// The content of the request to deliver to the application
#[serde(with = "json_as_base64")] #[serde(with = "json_as_base64")]
#[schemars(with = "String")] #[schemars(with = "String")]
message: Vec<u8>, pub message: Vec<u8>,
/// The id to reply to /// The id to reply to
#[serde(with = "json_as_string")] #[serde(with = "json_as_string")]
#[schemars(with = "String")] #[schemars(with = "String")]
call_id: OperationId, pub call_id: OperationId,
} }
impl VeilidAppCall { impl VeilidAppCall {

View File

@ -19,16 +19,16 @@ use super::*;
pub struct DHTRecordDescriptor { pub struct DHTRecordDescriptor {
/// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ] /// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
#[schemars(with = "String")] #[schemars(with = "String")]
key: TypedKey, pub key: TypedKey,
/// The public key of the owner /// The public key of the owner
#[schemars(with = "String")] #[schemars(with = "String")]
owner: PublicKey, pub owner: PublicKey,
/// If this key is being created: Some(the secret key of the owner) /// If this key is being created: Some(the secret key of the owner)
/// If this key is just being opened: None /// If this key is just being opened: None
#[schemars(with = "Option<String>")] #[schemars(with = "Option<String>")]
owner_secret: Option<SecretKey>, pub owner_secret: Option<SecretKey>,
/// The schema in use associated with the key /// The schema in use associated with the key
schema: DHTSchema, pub schema: DHTSchema,
} }
impl DHTRecordDescriptor { impl DHTRecordDescriptor {

View File

@ -18,16 +18,16 @@ use super::*;
#[archive_attr(repr(C), derive(CheckBytes))] #[archive_attr(repr(C), derive(CheckBytes))]
pub struct ValueData { pub struct ValueData {
/// An increasing sequence number to time-order the DHT record changes /// An increasing sequence number to time-order the DHT record changes
seq: ValueSeqNum, pub seq: ValueSeqNum,
/// The contents of a DHT Record /// The contents of a DHT Record
#[serde(with = "json_as_base64")] #[serde(with = "json_as_base64")]
#[schemars(with = "String")] #[schemars(with = "String")]
data: Vec<u8>, pub data: Vec<u8>,
/// The public identity key of the writer of the data /// The public identity key of the writer of the data
#[schemars(with = "String")] #[schemars(with = "String")]
writer: PublicKey, pub writer: PublicKey,
} }
impl ValueData { impl ValueData {
pub const MAX_LEN: usize = 32768; pub const MAX_LEN: usize = 32768;

View File

@ -23,7 +23,7 @@ pub struct ValueSubkeyRangeSet {
#[with(RkyvRangeSetBlaze)] #[with(RkyvRangeSetBlaze)]
#[serde(with = "serialize_range_set_blaze")] #[serde(with = "serialize_range_set_blaze")]
#[schemars(with = "Vec<(u32,u32)>")] #[schemars(with = "Vec<(u32,u32)>")]
data: RangeSetBlaze<ValueSubkey>, pub data: RangeSetBlaze<ValueSubkey>,
} }
impl ValueSubkeyRangeSet { impl ValueSubkeyRangeSet {

View File

@ -53,7 +53,16 @@ pub enum TunnelError {
#[cfg(feature = "unstable-tunnels")] #[cfg(feature = "unstable-tunnels")]
#[derive( #[derive(
Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, JsonSchema, Clone,
Debug,
PartialEq,
Eq,
Serialize,
Deserialize,
RkyvArchive,
RkyvSerialize,
RkyvDeserialize,
JsonSchema,
)] )]
#[archive_attr(repr(C), derive(CheckBytes))] #[archive_attr(repr(C), derive(CheckBytes))]
pub struct TunnelEndpoint { pub struct TunnelEndpoint {
@ -76,6 +85,8 @@ impl Default for TunnelEndpoint {
Clone, Clone,
Debug, Debug,
Default, Default,
PartialEq,
Eq,
Serialize, Serialize,
Deserialize, Deserialize,
RkyvArchive, RkyvArchive,
@ -96,6 +107,8 @@ pub struct FullTunnel {
Clone, Clone,
Debug, Debug,
Default, Default,
PartialEq,
Eq,
Serialize, Serialize,
Deserialize, Deserialize,
RkyvArchive, RkyvArchive,

View File

@ -171,14 +171,23 @@ pub struct VeilidStateConfig {
#[archive_attr(repr(C), derive(CheckBytes))] #[archive_attr(repr(C), derive(CheckBytes))]
pub struct VeilidValueChange { pub struct VeilidValueChange {
#[schemars(with = "String")] #[schemars(with = "String")]
key: TypedKey, pub key: TypedKey,
subkeys: Vec<ValueSubkey>, pub subkeys: Vec<ValueSubkey>,
count: u32, pub count: u32,
value: ValueData, pub value: ValueData,
} }
#[derive( #[derive(
Debug, Clone, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, JsonSchema, Debug,
Clone,
PartialEq,
Eq,
Serialize,
Deserialize,
RkyvArchive,
RkyvSerialize,
RkyvDeserialize,
JsonSchema,
)] )]
#[archive_attr(repr(u8), derive(CheckBytes))] #[archive_attr(repr(u8), derive(CheckBytes))]
#[serde(tag = "kind")] #[serde(tag = "kind")]
@ -195,7 +204,16 @@ pub enum VeilidUpdate {
} }
#[derive( #[derive(
Debug, Clone, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize, JsonSchema, Debug,
Clone,
PartialEq,
Eq,
Serialize,
Deserialize,
RkyvArchive,
RkyvSerialize,
RkyvDeserialize,
JsonSchema,
)] )]
#[archive_attr(repr(C), derive(CheckBytes))] #[archive_attr(repr(C), derive(CheckBytes))]
pub struct VeilidState { pub struct VeilidState {

View File

@ -90,6 +90,12 @@ async fn wasm_test_envelope_receipt() {
test_envelope_receipt::test_all().await; test_envelope_receipt::test_all().await;
} }
#[wasm_bindgen_test]
async fn wasm_test_serialize_json() {
setup();
test_serialize_json::test_all().await;
}
#[wasm_bindgen_test] #[wasm_bindgen_test]
async fn wasm_test_serialize_rkyv() { async fn wasm_test_serialize_rkyv() {
setup(); setup();
@ -97,7 +103,7 @@ async fn wasm_test_serialize_rkyv() {
} }
#[wasm_bindgen_test] #[wasm_bindgen_test]
async fn wasm_test_routing_table_serialize() { async fn wasm_test_serialize_routing_table() {
setup(); setup();
test_routing_table_serialize::test_all().await; test_serialize_routing_table::test_all().await;
} }