Use newtypes for crypto structs

This commit is contained in:
Brandon Vandegrift 2025-05-23 19:33:01 +00:00
parent aab80eaa8e
commit 95d272dec9
105 changed files with 925 additions and 717 deletions

View file

@ -26,11 +26,13 @@ pub trait CryptoSystem {
domain: &[u8],
) -> VeilidAPIResult<SharedSecret> {
let dh = self.compute_dh(key, secret)?;
Ok(self.generate_hash(&[&dh.bytes, domain, VEILID_DOMAIN_API].concat()))
Ok(SharedSecret::from(self.generate_hash(
&[&dh.bytes, domain, VEILID_DOMAIN_API].concat(),
)))
}
fn generate_keypair(&self) -> KeyPair;
fn generate_hash(&self, data: &[u8]) -> HashDigest;
fn generate_hash_reader(&self, reader: &mut dyn std::io::Read) -> VeilidAPIResult<HashDigest>;
fn generate_hash_reader(&self, reader: &mut dyn std::io::Read) -> VeilidAPIResult<PublicKey>;
// Validation
fn validate_keypair(&self, key: &PublicKey, secret: &SecretKey) -> bool;
@ -42,7 +44,7 @@ pub trait CryptoSystem {
) -> VeilidAPIResult<bool>;
// Distance Metric
fn distance(&self, key1: &CryptoKey, key2: &CryptoKey) -> CryptoKeyDistance;
fn distance(&self, hash1: &HashDigest, hash2: &HashDigest) -> HashDistance;
// Authentication
fn sign(&self, key: &PublicKey, secret: &SecretKey, data: &[u8]) -> VeilidAPIResult<Signature>;
@ -80,29 +82,24 @@ pub trait CryptoSystem {
) -> VeilidAPIResult<Vec<u8>>;
// NoAuth Encrypt/Decrypt
fn crypt_in_place_no_auth(
&self,
body: &mut [u8],
nonce: &[u8; NONCE_LENGTH],
shared_secret: &SharedSecret,
);
fn crypt_in_place_no_auth(&self, body: &mut [u8], nonce: &Nonce, shared_secret: &SharedSecret);
fn crypt_b2b_no_auth(
&self,
in_buf: &[u8],
out_buf: &mut [u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
);
fn crypt_no_auth_aligned_8(
&self,
body: &[u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) -> Vec<u8>;
fn crypt_no_auth_unaligned(
&self,
body: &[u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) -> Vec<u8>;
}

View file

@ -211,11 +211,8 @@ impl Envelope {
}
}
// Decrypt message without authentication
let body = vcrypto.crypt_no_auth_aligned_8(
&data[0x6A..data.len() - 64],
&self.nonce.bytes,
&dh_secret,
);
let body =
vcrypto.crypt_no_auth_aligned_8(&data[0x6A..data.len() - 64], &self.nonce, &dh_secret);
// Decompress body
let body = decompress_size_prepended(&body, Some(MAX_ENVELOPE_SIZE))?;
@ -294,7 +291,7 @@ impl Envelope {
}
// Encrypt message
let encrypted_body = vcrypto.crypt_no_auth_unaligned(&body, &self.nonce.bytes, &dh_secret);
let encrypted_body = vcrypto.crypt_no_auth_unaligned(&body, &self.nonce, &dh_secret);
// Write body
if !encrypted_body.is_empty() {
@ -335,15 +332,15 @@ impl Envelope {
self.sender_id
}
pub fn get_sender_typed_id(&self) -> TypedKey {
TypedKey::new(self.crypto_kind, self.sender_id)
pub fn get_sender_typed_id(&self) -> TypedPublicKey {
TypedPublicKey::new(self.crypto_kind, self.sender_id)
}
pub fn get_recipient_id(&self) -> PublicKey {
self.recipient_id
}
pub fn get_recipient_typed_id(&self) -> TypedKey {
TypedKey::new(self.crypto_kind, self.recipient_id)
pub fn get_recipient_typed_id(&self) -> TypedPublicKey {
TypedPublicKey::new(self.crypto_kind, self.recipient_id)
}
}

View file

@ -103,9 +103,10 @@ impl AsyncCryptoSystemGuard<'_> {
domain: &[u8],
) -> VeilidAPIResult<SharedSecret> {
let dh = self.compute_dh(key, secret).await?;
Ok(self
.generate_hash(&[&dh.bytes, domain, VEILID_DOMAIN_API].concat())
.await)
Ok(SharedSecret::from(
self.generate_hash(&[&dh.bytes, domain, VEILID_DOMAIN_API].concat())
.await,
))
}
pub async fn generate_keypair(&self) -> KeyPair {
@ -119,7 +120,7 @@ impl AsyncCryptoSystemGuard<'_> {
pub async fn generate_hash_reader(
&self,
reader: &mut dyn std::io::Read,
) -> VeilidAPIResult<HashDigest> {
) -> VeilidAPIResult<PublicKey> {
yielding(|| self.guard.generate_hash_reader(reader)).await
}
@ -141,7 +142,7 @@ impl AsyncCryptoSystemGuard<'_> {
}
// Distance Metric
pub async fn distance(&self, key1: &CryptoKey, key2: &CryptoKey) -> CryptoKeyDistance {
pub async fn distance(&self, key1: &HashDigest, key2: &HashDigest) -> HashDistance {
yielding(|| self.guard.distance(key1, key2)).await
}
@ -229,7 +230,7 @@ impl AsyncCryptoSystemGuard<'_> {
pub async fn crypt_in_place_no_auth(
&self,
body: &mut [u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) {
yielding(|| {
@ -243,7 +244,7 @@ impl AsyncCryptoSystemGuard<'_> {
&self,
in_buf: &[u8],
out_buf: &mut [u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) {
yielding(|| {
@ -256,7 +257,7 @@ impl AsyncCryptoSystemGuard<'_> {
pub async fn crypt_no_auth_aligned_8(
&self,
body: &[u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) -> Vec<u8> {
yielding(|| {
@ -269,7 +270,7 @@ impl AsyncCryptoSystemGuard<'_> {
pub async fn crypt_no_auth_unaligned(
&self,
body: &[u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) -> Vec<u8> {
yielding(|| {

View file

@ -259,11 +259,11 @@ impl Crypto {
/// Returns None if any cryptokinds are supported and do not validate
pub fn verify_signatures(
&self,
public_keys: &[TypedKey],
public_keys: &[TypedPublicKey],
data: &[u8],
typed_signatures: &[TypedSignature],
) -> VeilidAPIResult<Option<TypedKeyGroup>> {
let mut out = TypedKeyGroup::with_capacity(public_keys.len());
) -> VeilidAPIResult<Option<TypedPublicKeyGroup>> {
let mut out = TypedPublicKeyGroup::with_capacity(public_keys.len());
for sig in typed_signatures {
for nid in public_keys {
if nid.kind == sig.kind {
@ -352,7 +352,7 @@ impl Crypto {
&self,
vcrypto: AsyncCryptoSystemGuard<'_>,
table_store: &TableStore,
) -> VeilidAPIResult<(TypedKey, TypedSecret)> {
) -> VeilidAPIResult<(TypedPublicKey, TypedSecretKey)> {
let config = self.config();
let ck = vcrypto.kind();
let (mut node_id, mut node_id_secret) = config.with(|c| {
@ -371,7 +371,7 @@ impl Crypto {
if node_id.is_none() {
veilid_log!(self debug "pulling {} from storage", table_key_node_id);
if let Ok(Some(stored_node_id)) = config_table
.load_json::<TypedKey>(0, table_key_node_id.as_bytes())
.load_json::<TypedPublicKey>(0, table_key_node_id.as_bytes())
.await
{
veilid_log!(self debug "{} found in storage", table_key_node_id);
@ -385,7 +385,7 @@ impl Crypto {
if node_id_secret.is_none() {
veilid_log!(self debug "pulling {} from storage", table_key_node_id_secret);
if let Ok(Some(stored_node_id_secret)) = config_table
.load_json::<TypedSecret>(0, table_key_node_id_secret.as_bytes())
.load_json::<TypedSecretKey>(0, table_key_node_id_secret.as_bytes())
.await
{
veilid_log!(self debug "{} found in storage", table_key_node_id_secret);
@ -413,7 +413,10 @@ impl Crypto {
// If we still don't have a valid node id, generate one
veilid_log!(self debug "generating new node_id_{}", ck);
let kp = vcrypto.generate_keypair().await;
(TypedKey::new(ck, kp.key), TypedSecret::new(ck, kp.secret))
(
TypedPublicKey::new(ck, kp.key),
TypedSecretKey::new(ck, kp.secret),
)
};
veilid_log!(self info "Node Id: {}", node_id);
@ -432,8 +435,8 @@ impl Crypto {
/// Must be done -after- protected store is initialized, during table store init
#[cfg_attr(test, allow(unused_variables))]
async fn setup_node_ids(&self, table_store: &TableStore) -> VeilidAPIResult<()> {
let mut out_node_id = TypedKeyGroup::new();
let mut out_node_id_secret = TypedSecretGroup::new();
let mut out_node_id = TypedPublicKeyGroup::new();
let mut out_node_id_secret = TypedSecretKeyGroup::new();
for ck in VALID_CRYPTO_KINDS {
let vcrypto = self
@ -443,7 +446,10 @@ impl Crypto {
#[cfg(test)]
let (node_id, node_id_secret) = {
let kp = vcrypto.generate_keypair().await;
(TypedKey::new(ck, kp.key), TypedSecret::new(ck, kp.secret))
(
TypedPublicKey::new(ck, kp.key),
TypedSecretKey::new(ck, kp.secret),
)
};
#[cfg(not(test))]
let (node_id, node_id_secret) = self.setup_node_id(vcrypto, table_store).await?;

View file

@ -165,14 +165,14 @@ impl CryptoSystem for CryptoSystemNONE {
Ok(bytes == dht_key.bytes)
}
// Distance Metric
fn distance(&self, key1: &PublicKey, key2: &PublicKey) -> CryptoKeyDistance {
fn distance(&self, key1: &PublicKey, key2: &PublicKey) -> HashDistance {
let mut bytes = [0u8; PUBLIC_KEY_LENGTH];
for (n, byte) in bytes.iter_mut().enumerate() {
*byte = key1.bytes[n] ^ key2.bytes[n];
}
CryptoKeyDistance::new(bytes)
HashDistance::new(bytes)
}
// Authentication

View file

@ -212,8 +212,8 @@ impl Receipt {
self.sender_id
}
pub fn get_sender_typed_id(&self) -> TypedKey {
TypedKey::new(self.crypto_kind, self.sender_id)
pub fn get_sender_typed_id(&self) -> TypedPublicKey {
TypedPublicKey::new(self.crypto_kind, self.sender_id)
}
#[must_use]

View file

@ -258,7 +258,7 @@ pub fn test_typed_convert(vcrypto: &AsyncCryptoSystemGuard<'_>) {
"{}:7lxDEabK_qgjbe38RtBa3IZLrud84P6NhGP-pRTZzdQ",
vcrypto.kind()
);
let tk1 = TypedKey::from_str(&tks1).expect("failed");
let tk1 = TypedPublicKey::from_str(&tks1).expect("failed");
let tks1x = tk1.to_string();
assert_eq!(tks1, tks1x);
@ -266,27 +266,27 @@ pub fn test_typed_convert(vcrypto: &AsyncCryptoSystemGuard<'_>) {
"{}:7lxDEabK_qgjbe38RtBa3IZLrud84P6NhGP-pRTZzd",
vcrypto.kind()
);
let _tk2 = TypedKey::from_str(&tks2).expect_err("succeeded when it shouldnt have");
let _tk2 = TypedPublicKey::from_str(&tks2).expect_err("succeeded when it shouldnt have");
let tks3 = "XXXX:7lxDEabK_qgjbe38RtBa3IZLrud84P6NhGP-pRTZzdQ".to_string();
let tk3 = TypedKey::from_str(&tks3).expect("failed");
let tk3 = TypedPublicKey::from_str(&tks3).expect("failed");
let tks3x = tk3.to_string();
assert_eq!(tks3, tks3x);
let tks4 = "XXXX:7lxDEabK_qgjbe38RtBa3IZLrud84P6NhGP-pRTZzd".to_string();
let _tk4 = TypedKey::from_str(&tks4).expect_err("succeeded when it shouldnt have");
let _tk4 = TypedPublicKey::from_str(&tks4).expect_err("succeeded when it shouldnt have");
let tks5 = "XXX:7lxDEabK_qgjbe38RtBa3IZLrud84P6NhGP-pRTZzdQ".to_string();
let _tk5 = TypedKey::from_str(&tks5).expect_err("succeeded when it shouldnt have");
let _tk5 = TypedPublicKey::from_str(&tks5).expect_err("succeeded when it shouldnt have");
let tks6 = "7lxDEabK_qgjbe38RtBa3IZLrud84P6NhGP-pRTZzdQ".to_string();
let tk6 = TypedKey::from_str(&tks6).expect("failed");
let tk6 = TypedPublicKey::from_str(&tks6).expect("failed");
let tks6x = tk6.to_string();
assert!(tks6x.ends_with(&tks6));
}
async fn test_hash(vcrypto: &AsyncCryptoSystemGuard<'_>) {
let mut s = BTreeSet::<PublicKey>::new();
let mut s = BTreeSet::<HashDigest>::new();
let k1 = vcrypto.generate_hash("abc".as_bytes()).await;
let k2 = vcrypto.generate_hash("abcd".as_bytes()).await;
@ -381,24 +381,24 @@ async fn test_operations(vcrypto: &AsyncCryptoSystemGuard<'_>) {
assert_eq!(d4.first_nonzero_bit(), Some(0));
}
pub fn test_crypto_key_ordering() {
let k1 = CryptoKey::new([
pub fn test_public_key_ordering() {
let k1 = PublicKey::new([
128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
]);
let k2 = CryptoKey::new([
let k2 = PublicKey::new([
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
]);
let k3 = CryptoKey::new([
let k3 = PublicKey::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 128,
]);
let k4 = CryptoKey::new([
let k4 = PublicKey::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1,
]);
let k5 = CryptoKey::new([
let k5 = PublicKey::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0,
]);
@ -413,7 +413,7 @@ pub async fn test_all() {
let api = crypto_tests_startup().await;
let crypto = api.crypto().unwrap();
test_crypto_key_ordering();
test_public_key_ordering();
// Test versions
for v in VALID_CRYPTO_KINDS {

View file

@ -39,24 +39,24 @@ pub const NONCE_LENGTH: usize = 24;
/// Length of a nonce in bytes after encoding to base64url
#[allow(dead_code)]
pub const NONCE_LENGTH_ENCODED: usize = 32;
/// Length of a shared secret in bytes
#[allow(dead_code)]
pub const SHARED_SECRET_LENGTH: usize = CRYPTO_KEY_LENGTH;
/// Length of a shared secret in bytes after encoding to base64url
#[allow(dead_code)]
pub const SHARED_SECRET_LENGTH_ENCODED: usize = CRYPTO_KEY_LENGTH_ENCODED;
/// Length of a route id in bytes
#[allow(dead_code)]
pub const ROUTE_ID_LENGTH: usize = CRYPTO_KEY_LENGTH;
/// Length of a route id in bytes after encoding to base64url
#[allow(dead_code)]
pub const ROUTE_ID_LENGTH_ENCODED: usize = CRYPTO_KEY_LENGTH_ENCODED;
/// Length of a hash digest in bytes
#[allow(dead_code)]
pub const HASH_DIGEST_LENGTH: usize = CRYPTO_KEY_LENGTH;
/// Length of a hash digest in bytes after encoding to base64url
#[allow(dead_code)]
pub const HASH_DIGEST_LENGTH_ENCODED: usize = CRYPTO_KEY_LENGTH_ENCODED;
/// Length of a shared secret in bytes
#[allow(dead_code)]
pub const SHARED_SECRET_LENGTH: usize = HASH_DIGEST_LENGTH;
/// Length of a shared secret in bytes after encoding to base64url
#[allow(dead_code)]
pub const SHARED_SECRET_LENGTH_ENCODED: usize = HASH_DIGEST_LENGTH_ENCODED;
/// Length of a route id in bytes
#[allow(dead_code)]
pub const ROUTE_ID_LENGTH: usize = HASH_DIGEST_LENGTH;
/// Length of a route id in bytes after encoding to base64url
#[allow(dead_code)]
pub const ROUTE_ID_LENGTH_ENCODED: usize = HASH_DIGEST_LENGTH_ENCODED;
//////////////////////////////////////////////////////////////////////
@ -292,20 +292,84 @@ macro_rules! byte_array_type {
/////////////////////////////////////////
byte_array_type!(CryptoKey, CRYPTO_KEY_LENGTH, CRYPTO_KEY_LENGTH_ENCODED);
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type PublicKey = CryptoKey;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type SecretKey = CryptoKey;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type HashDigest = CryptoKey;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type SharedSecret = CryptoKey;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type RouteId = CryptoKey;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type CryptoKeyDistance = CryptoKey;
byte_array_type!(PublicKey, PUBLIC_KEY_LENGTH, PUBLIC_KEY_LENGTH_ENCODED);
byte_array_type!(SecretKey, SECRET_KEY_LENGTH, SECRET_KEY_LENGTH_ENCODED);
byte_array_type!(Signature, SIGNATURE_LENGTH, SIGNATURE_LENGTH_ENCODED);
byte_array_type!(Nonce, NONCE_LENGTH, NONCE_LENGTH_ENCODED);
/*
Notes:
- These are actually HashDigest types, but not interchangable:
- RouteId (eventually will be a RecordKey type with DHT Routes)
- RecordKey
- SharedSecret
*/
// HashDigest sub-types
byte_array_type!(HashDigest, HASH_DIGEST_LENGTH, HASH_DIGEST_LENGTH_ENCODED);
byte_array_type!(
SharedSecret,
SHARED_SECRET_LENGTH,
SHARED_SECRET_LENGTH_ENCODED
);
byte_array_type!(RouteId, ROUTE_ID_LENGTH, ROUTE_ID_LENGTH_ENCODED);
byte_array_type!(RecordKey, HASH_DIGEST_LENGTH, HASH_DIGEST_LENGTH_ENCODED);
byte_array_type!(HashDistance, HASH_DIGEST_LENGTH, HASH_DIGEST_LENGTH_ENCODED);
// NodeId is currently the same as PublicKey, but will eventually be a sub-type of HashDigest.
byte_array_type!(NodeId, PUBLIC_KEY_LENGTH, PUBLIC_KEY_LENGTH_ENCODED);
// Temporary adapters for converting to/from HashDigest types
// Removing these will show where there's still issues.
impl From<HashDigest> for SharedSecret {
fn from(value: HashDigest) -> Self {
Self::new(value.bytes)
}
}
impl From<HashDigest> for RecordKey {
fn from(value: HashDigest) -> Self {
Self::new(value.bytes)
}
}
impl From<RecordKey> for HashDigest {
fn from(value: RecordKey) -> Self {
Self::new(value.bytes)
}
}
impl From<NodeId> for HashDigest {
fn from(value: NodeId) -> Self {
Self::new(value.bytes)
}
}
// Removing this will show where PublicKey might need to be converted to NodeId or RecordKey.
impl From<PublicKey> for HashDigest {
fn from(value: PublicKey) -> Self {
Self::new(value.bytes)
}
}
impl From<HashDigest> for PublicKey {
fn from(value: HashDigest) -> Self {
Self::new(value.bytes)
}
}
/*
- NodeId currently equals PublicKey, but should be distinct from PublicKey.
- NodeId eventually should be a HashDigest type that's constructable from a PublicKey
*/
impl From<PublicKey> for NodeId {
fn from(value: PublicKey) -> Self {
Self::new(value.bytes)
}
}
impl From<NodeId> for PublicKey {
fn from(value: NodeId) -> Self {
Self::new(value.bytes)
}
}

View file

@ -55,23 +55,50 @@ pub use crypto_typed_group::*;
pub use keypair::*;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedKey = CryptoTyped<PublicKey>;
pub type TypedPublicKey = CryptoTyped<PublicKey>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSecret = CryptoTyped<SecretKey>;
pub type TypedSecretKey = CryptoTyped<SecretKey>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedKeyPair = CryptoTyped<KeyPair>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSignature = CryptoTyped<Signature>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSharedSecret = CryptoTyped<SharedSecret>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedRouteId = CryptoTyped<RouteId>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedRecordKey = CryptoTyped<RecordKey>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedNodeId = CryptoTyped<NodeId>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedHashDigest = CryptoTyped<HashDigest>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedKeyGroup = CryptoTypedGroup<PublicKey>;
pub type TypedPublicKeyGroup = CryptoTypedGroup<PublicKey>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSecretGroup = CryptoTypedGroup<SecretKey>;
pub type TypedSecretKeyGroup = CryptoTypedGroup<SecretKey>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedKeyPairGroup = CryptoTypedGroup<KeyPair>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSignatureGroup = CryptoTypedGroup<Signature>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedSharedSecretGroup = CryptoTypedGroup<SharedSecret>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedRouteIdGroup = CryptoTypedGroup<RouteId>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedRecordKeyGroup = CryptoTypedGroup<RecordKey>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedNodeIdGroup = CryptoTypedGroup<NodeId>;
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), declare)]
pub type TypedHashDigestGroup = CryptoTypedGroup<HashDigest>;
impl From<TypedPublicKey> for TypedHashDigest {
fn from(value: TypedPublicKey) -> Self {
TypedHashDigest::new(value.kind, value.value.into())
}
}
impl From<TypedRecordKey> for TypedHashDigest {
fn from(value: TypedRecordKey) -> Self {
TypedHashDigest::new(value.kind, value.value.into())
}
}

View file

@ -40,10 +40,10 @@ pub fn vld0_generate_keypair() -> KeyPair {
let mut csprng = VeilidRng {};
let signing_key = ed::SigningKey::generate(&mut csprng);
let verifying_key = signing_key.verifying_key();
let dht_key = PublicKey::new(verifying_key.to_bytes());
let dht_key_secret = SecretKey::new(signing_key.to_bytes());
let public_key = PublicKey::new(verifying_key.to_bytes());
let secret_key = SecretKey::new(signing_key.to_bytes());
KeyPair::new(dht_key, dht_key_secret)
KeyPair::new(public_key, secret_key)
}
/// V0 CryptoSystem
@ -163,8 +163,8 @@ impl CryptoSystem for CryptoSystemVLD0 {
}
#[instrument(level = "trace", target = "crypto", skip_all)]
fn generate_hash(&self, data: &[u8]) -> PublicKey {
PublicKey::new(*blake3::hash(data).as_bytes())
fn generate_hash(&self, data: &[u8]) -> HashDigest {
HashDigest::new(*blake3::hash(data).as_bytes())
}
#[instrument(level = "trace", target = "crypto", skip_all)]
@ -176,61 +176,61 @@ impl CryptoSystem for CryptoSystemVLD0 {
// Validation
#[instrument(level = "trace", target = "crypto", skip_all)]
fn validate_keypair(&self, dht_key: &PublicKey, dht_key_secret: &SecretKey) -> bool {
fn validate_keypair(&self, public_key: &PublicKey, secret_key: &SecretKey) -> bool {
let data = vec![0u8; 512];
let Ok(sig) = self.sign(dht_key, dht_key_secret, &data) else {
let Ok(sig) = self.sign(public_key, secret_key, &data) else {
return false;
};
let Ok(v) = self.verify(dht_key, &data, &sig) else {
let Ok(v) = self.verify(public_key, &data, &sig) else {
return false;
};
v
}
#[instrument(level = "trace", target = "crypto", skip_all)]
fn validate_hash(&self, data: &[u8], dht_key: &PublicKey) -> bool {
fn validate_hash(&self, data: &[u8], hash_digest: &HashDigest) -> bool {
let bytes = *blake3::hash(data).as_bytes();
bytes == dht_key.bytes
bytes == hash_digest.bytes
}
#[instrument(level = "trace", target = "crypto", skip_all)]
fn validate_hash_reader(
&self,
reader: &mut dyn std::io::Read,
dht_key: &PublicKey,
hash_digest: &HashDigest,
) -> VeilidAPIResult<bool> {
let mut hasher = blake3::Hasher::new();
std::io::copy(reader, &mut hasher).map_err(VeilidAPIError::generic)?;
let bytes = *hasher.finalize().as_bytes();
Ok(bytes == dht_key.bytes)
Ok(bytes == hash_digest.bytes)
}
// Distance Metric
#[instrument(level = "trace", target = "crypto", skip_all)]
fn distance(&self, key1: &PublicKey, key2: &PublicKey) -> CryptoKeyDistance {
fn distance(&self, hash1: &HashDigest, hash2: &HashDigest) -> HashDistance {
let mut bytes = [0u8; CRYPTO_KEY_LENGTH];
(0..CRYPTO_KEY_LENGTH).for_each(|n| {
bytes[n] = key1.bytes[n] ^ key2.bytes[n];
bytes[n] = hash1.bytes[n] ^ hash2.bytes[n];
});
CryptoKeyDistance::new(bytes)
HashDistance::new(bytes)
}
// Authentication
#[instrument(level = "trace", target = "crypto", skip_all)]
fn sign(
&self,
dht_key: &PublicKey,
dht_key_secret: &SecretKey,
public_key: &PublicKey,
secret_key: &SecretKey,
data: &[u8],
) -> VeilidAPIResult<Signature> {
let mut kpb: [u8; SECRET_KEY_LENGTH + PUBLIC_KEY_LENGTH] =
[0u8; SECRET_KEY_LENGTH + PUBLIC_KEY_LENGTH];
kpb[..SECRET_KEY_LENGTH].copy_from_slice(&dht_key_secret.bytes);
kpb[SECRET_KEY_LENGTH..].copy_from_slice(&dht_key.bytes);
kpb[..SECRET_KEY_LENGTH].copy_from_slice(&secret_key.bytes);
kpb[SECRET_KEY_LENGTH..].copy_from_slice(&public_key.bytes);
let keypair = ed::SigningKey::from_keypair_bytes(&kpb)
.map_err(|e| VeilidAPIError::parse_error("Keypair is invalid", e))?;
@ -243,7 +243,7 @@ impl CryptoSystem for CryptoSystemVLD0 {
let sig = Signature::new(sig_bytes.to_bytes());
if !self.verify(dht_key, data, &sig)? {
if !self.verify(public_key, data, &sig)? {
apibail_internal!("newly created signature does not verify");
}
@ -252,11 +252,11 @@ impl CryptoSystem for CryptoSystemVLD0 {
#[instrument(level = "trace", target = "crypto", skip_all)]
fn verify(
&self,
dht_key: &PublicKey,
public_key: &PublicKey,
data: &[u8],
signature: &Signature,
) -> VeilidAPIResult<bool> {
let pk = ed::VerifyingKey::from_bytes(&dht_key.bytes)
let pk = ed::VerifyingKey::from_bytes(&public_key.bytes)
.map_err(|e| VeilidAPIError::parse_error("Public key is invalid", e))?;
let sig = ed::Signature::from_bytes(&signature.bytes);
@ -342,13 +342,9 @@ impl CryptoSystem for CryptoSystemVLD0 {
// NoAuth Encrypt/Decrypt
#[instrument(level = "trace", target = "crypto", skip_all)]
fn crypt_in_place_no_auth(
&self,
body: &mut [u8],
nonce: &[u8; NONCE_LENGTH],
shared_secret: &SharedSecret,
) {
let mut cipher = <XChaCha20 as KeyIvInit>::new(&shared_secret.bytes.into(), nonce.into());
fn crypt_in_place_no_auth(&self, body: &mut [u8], nonce: &Nonce, shared_secret: &SharedSecret) {
let mut cipher =
<XChaCha20 as KeyIvInit>::new(&shared_secret.bytes.into(), &nonce.bytes.into());
cipher.apply_keystream(body);
}
@ -357,10 +353,11 @@ impl CryptoSystem for CryptoSystemVLD0 {
&self,
in_buf: &[u8],
out_buf: &mut [u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) {
let mut cipher = <XChaCha20 as KeyIvInit>::new(&shared_secret.bytes.into(), nonce.into());
let mut cipher =
<XChaCha20 as KeyIvInit>::new(&shared_secret.bytes.into(), &nonce.bytes.into());
cipher.apply_keystream_b2b(in_buf, out_buf).unwrap();
}
@ -368,7 +365,7 @@ impl CryptoSystem for CryptoSystemVLD0 {
fn crypt_no_auth_aligned_8(
&self,
in_buf: &[u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) -> Vec<u8> {
let mut out_buf = unsafe { aligned_8_u8_vec_uninit(in_buf.len()) };
@ -380,7 +377,7 @@ impl CryptoSystem for CryptoSystemVLD0 {
fn crypt_no_auth_unaligned(
&self,
in_buf: &[u8],
nonce: &[u8; NONCE_LENGTH],
nonce: &Nonce,
shared_secret: &SharedSecret,
) -> Vec<u8> {
let mut out_buf = unsafe { unaligned_u8_vec_uninit(in_buf.len()) };

View file

@ -30,7 +30,7 @@ struct AddressFilterInner {
conn_timestamps_by_ip6_prefix: BTreeMap<Ipv6Addr, Vec<Timestamp>>,
punishments_by_ip4: BTreeMap<Ipv4Addr, Punishment>,
punishments_by_ip6_prefix: BTreeMap<Ipv6Addr, Punishment>,
punishments_by_node_id: BTreeMap<TypedKey, Punishment>,
punishments_by_node_id: BTreeMap<TypedPublicKey, Punishment>,
dial_info_failures: BTreeMap<DialInfo, Timestamp>,
}
@ -178,7 +178,7 @@ impl AddressFilter {
}
// node id
{
let mut dead_keys = Vec::<TypedKey>::new();
let mut dead_keys = Vec::<TypedPublicKey>::new();
for (key, value) in &mut inner.punishments_by_node_id {
// Drop punishments older than the punishment duration
if cur_ts.as_u64().saturating_sub(value.timestamp.as_u64())
@ -297,19 +297,23 @@ impl AddressFilter {
};
}
fn is_node_id_punished_inner(&self, inner: &AddressFilterInner, node_id: TypedKey) -> bool {
fn is_node_id_punished_inner(
&self,
inner: &AddressFilterInner,
node_id: TypedPublicKey,
) -> bool {
if inner.punishments_by_node_id.contains_key(&node_id) {
return true;
}
false
}
pub fn is_node_id_punished(&self, node_id: TypedKey) -> bool {
pub fn is_node_id_punished(&self, node_id: TypedPublicKey) -> bool {
let inner = self.inner.lock();
self.is_node_id_punished_inner(&inner, node_id)
}
pub fn punish_node_id(&self, node_id: TypedKey, reason: PunishmentReason) {
pub fn punish_node_id(&self, node_id: TypedPublicKey, reason: PunishmentReason) {
if let Ok(Some(nr)) = self.routing_table().lookup_node_ref(node_id) {
// make the entry dead if it's punished
nr.operate_mut(|_rti, e| e.set_punished(Some(reason)));

View file

@ -4,7 +4,7 @@ impl_veilid_log_facility!("net");
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BootstrapRecord {
node_ids: TypedKeyGroup,
node_ids: TypedPublicKeyGroup,
envelope_support: Vec<u8>,
dial_info_details: Vec<DialInfoDetail>,
timestamp_secs: Option<u64>,
@ -13,7 +13,7 @@ pub struct BootstrapRecord {
impl BootstrapRecord {
pub fn new(
node_ids: TypedKeyGroup,
node_ids: TypedPublicKeyGroup,
mut envelope_support: Vec<u8>,
mut dial_info_details: Vec<DialInfoDetail>,
timestamp_secs: Option<u64>,
@ -31,7 +31,7 @@ impl BootstrapRecord {
}
}
pub fn node_ids(&self) -> &TypedKeyGroup {
pub fn node_ids(&self) -> &TypedPublicKeyGroup {
&self.node_ids
}
pub fn envelope_support(&self) -> &[u8] {
@ -226,7 +226,7 @@ impl BootstrapRecord {
network_manager: &NetworkManager,
dial_info_converter: &dyn DialInfoConverter,
record_str: &str,
signing_keys: &[TypedKey],
signing_keys: &[TypedPublicKey],
) -> EyreResult<Option<BootstrapRecord>> {
// All formats split on '|' character
let fields: Vec<String> = record_str
@ -309,10 +309,10 @@ impl BootstrapRecord {
envelope_support.dedup();
// Node Id
let mut node_ids = TypedKeyGroup::new();
let mut node_ids = TypedPublicKeyGroup::new();
for node_id_str in fields[2].split(',') {
let node_id_str = node_id_str.trim();
let node_id = match TypedKey::from_str(node_id_str) {
let node_id = match TypedPublicKey::from_str(node_id_str) {
Ok(v) => v,
Err(e) => {
bail!(
@ -376,7 +376,7 @@ impl BootstrapRecord {
dial_info_converter: &dyn DialInfoConverter,
record_str: &str,
fields: &[String],
signing_keys: &[TypedKey],
signing_keys: &[TypedPublicKey],
) -> EyreResult<Option<BootstrapRecord>> {
if fields.len() < 7 {
bail!("invalid number of fields in bootstrap v1 txt record");
@ -432,10 +432,10 @@ impl BootstrapRecord {
envelope_support.dedup();
// Node Id
let mut node_ids = TypedKeyGroup::new();
let mut node_ids = TypedPublicKeyGroup::new();
for node_id_str in fields[2].split(',') {
let node_id_str = node_id_str.trim();
let node_id = match TypedKey::from_str(node_id_str) {
let node_id = match TypedPublicKey::from_str(node_id_str) {
Ok(v) => v,
Err(e) => {
bail!(

View file

@ -193,7 +193,7 @@ impl Default for NetworkManagerStartupContext {
#[derive(Debug)]
struct NetworkManagerInner {
stats: NetworkManagerStats,
client_allowlist: LruCache<TypedKey, ClientAllowlistEntry>,
client_allowlist: LruCache<TypedPublicKey, ClientAllowlistEntry>,
node_contact_method_cache: NodeContactMethodCache,
address_check: Option<AddressCheck>,
peer_info_change_subscription: Option<EventBusSubscription>,
@ -531,7 +531,7 @@ impl NetworkManager {
}
#[expect(dead_code)]
pub fn update_client_allowlist(&self, client: TypedKey) {
pub fn update_client_allowlist(&self, client: TypedPublicKey) {
let mut inner = self.inner.lock();
match inner.client_allowlist.entry(client) {
hashlink::lru_cache::Entry::Occupied(mut entry) => {
@ -546,7 +546,7 @@ impl NetworkManager {
}
#[instrument(level = "trace", skip(self), ret)]
pub fn check_client_allowlist(&self, client: TypedKey) -> bool {
pub fn check_client_allowlist(&self, client: TypedPublicKey) -> bool {
let mut inner = self.inner.lock();
match inner.client_allowlist.entry(client) {
@ -874,7 +874,7 @@ impl NetworkManager {
#[instrument(level = "trace", target = "net", skip_all)]
fn build_envelope<B: AsRef<[u8]>>(
&self,
dest_node_id: TypedKey,
dest_node_id: TypedPublicKey,
version: u8,
body: B,
) -> EyreResult<Vec<u8>> {

View file

@ -4,7 +4,7 @@ pub const NODE_CONTACT_METHOD_CACHE_SIZE: usize = 1024;
#[derive(Clone, Debug, PartialEq, Eq, Ord, PartialOrd, Hash)]
pub struct NodeContactMethodCacheKey {
pub node_ids: TypedKeyGroup,
pub node_ids: TypedPublicKeyGroup,
pub own_node_info_ts: Timestamp,
pub target_node_info_ts: Timestamp,
pub target_node_ref_filter: NodeRefFilter,

View file

@ -4,7 +4,7 @@ use crate::tests::mock_registry;
fn make_mock_bootstrap_record(include_timestamp: bool) -> BootstrapRecord {
let mut node_ids = CryptoTypedGroup::new();
node_ids.add(
TypedKey::from_str("VLD0:f8G4Ckr1UR8YXnmAllwfvBEvXGgfYicZllb7jEpJeSU")
TypedPublicKey::from_str("VLD0:f8G4Ckr1UR8YXnmAllwfvBEvXGgfYicZllb7jEpJeSU")
.expect("should parse key"),
);
let envelope_support = VALID_ENVELOPE_VERSIONS.to_vec();
@ -68,7 +68,7 @@ pub async fn test_bootstrap_v1() {
TypedKeyPair::from_str("VLD0:v6XPfyOoCP_ZP-CWFNrf_pF_dpxsq74p2LW_Q5Q4yPQ:n-DhHtOU7KWQkdp5to8cpBa_u0RFt2IDZzXPqMTq4O0").expect("should parse keypair")];
let signing_keys = signing_key_pairs
.iter()
.map(|skp| TypedKey::new(skp.kind, skp.value.key))
.map(|skp| TypedPublicKey::new(skp.kind, skp.value.key))
.collect::<Vec<_>>();
let v1str = bsrec
.to_v1_string(&network_manager, &dial_info_converter, signing_key_pairs[0])

View file

@ -35,7 +35,7 @@ pub async fn test_signed_node_info() {
node_info.clone(),
)
.unwrap();
let tks: TypedKeyGroup = TypedKey::new(ck, keypair.key).into();
let tks: TypedPublicKeyGroup = TypedPublicKey::new(ck, keypair.key).into();
let oldtkslen = tks.len();
let sdni = SignedDirectNodeInfo::new(
node_info.clone(),
@ -48,7 +48,7 @@ pub async fn test_signed_node_info() {
// Test incorrect validation
let keypair1 = vcrypto.generate_keypair();
let tks1: TypedKeyGroup = TypedKey::new(ck, keypair1.key).into();
let tks1: TypedPublicKeyGroup = TypedPublicKey::new(ck, keypair1.key).into();
let sdni = SignedDirectNodeInfo::new(
node_info.clone(),
sni.timestamp(),
@ -58,11 +58,11 @@ pub async fn test_signed_node_info() {
// Test unsupported cryptosystem validation
let fake_crypto_kind: CryptoKind = FourCC::from([0, 1, 2, 3]);
let mut tksfake: TypedKeyGroup =
TypedKey::new(fake_crypto_kind, PublicKey::default()).into();
let mut tksfake: TypedPublicKeyGroup =
TypedPublicKey::new(fake_crypto_kind, PublicKey::default()).into();
let mut sigsfake = sni.signatures().to_vec();
sigsfake.push(TypedSignature::new(fake_crypto_kind, Signature::default()));
tksfake.add(TypedKey::new(ck, keypair.key));
tksfake.add(TypedPublicKey::new(ck, keypair.key));
let sdnifake =
SignedDirectNodeInfo::new(node_info.clone(), sni.timestamp(), sigsfake.clone());
let tksfake_validated = sdnifake.validate(&tksfake, &crypto).unwrap();
@ -85,7 +85,7 @@ pub async fn test_signed_node_info() {
// Test correct validation
let keypair2 = vcrypto.generate_keypair();
let tks2: TypedKeyGroup = TypedKey::new(ck, keypair2.key).into();
let tks2: TypedPublicKeyGroup = TypedPublicKey::new(ck, keypair2.key).into();
let oldtks2len = tks2.len();
let sni2 = SignedRelayedNodeInfo::make_signatures(
@ -110,7 +110,7 @@ pub async fn test_signed_node_info() {
// Test incorrect validation
let keypair3 = vcrypto.generate_keypair();
let tks3: TypedKeyGroup = TypedKey::new(ck, keypair3.key).into();
let tks3: TypedPublicKeyGroup = TypedPublicKey::new(ck, keypair3.key).into();
let srni = SignedRelayedNodeInfo::new(
node_info2.clone(),
@ -123,11 +123,11 @@ pub async fn test_signed_node_info() {
// Test unsupported cryptosystem validation
let fake_crypto_kind: CryptoKind = FourCC::from([0, 1, 2, 3]);
let mut tksfake3: TypedKeyGroup =
TypedKey::new(fake_crypto_kind, PublicKey::default()).into();
let mut tksfake3: TypedPublicKeyGroup =
TypedPublicKey::new(fake_crypto_kind, PublicKey::default()).into();
let mut sigsfake3 = sni2.signatures().to_vec();
sigsfake3.push(TypedSignature::new(fake_crypto_kind, Signature::default()));
tksfake3.add(TypedKey::new(ck, keypair2.key));
tksfake3.add(TypedPublicKey::new(ck, keypair2.key));
let srnifake = SignedRelayedNodeInfo::new(
node_info2.clone(),
tks.clone(),

View file

@ -83,7 +83,10 @@ impl Bucket {
veilid_log!(self trace "Node added: {}:{}", self.kind, node_id_key);
// Add new entry
let entry = Arc::new(BucketEntry::new(TypedKey::new(self.kind, node_id_key)));
let entry = Arc::new(BucketEntry::new(TypedPublicKey::new(
self.kind,
node_id_key,
)));
self.entries.insert(node_id_key, entry.clone());
// Return the new entry

View file

@ -163,9 +163,9 @@ impl fmt::Display for BucketEntryLocalNetwork {
#[derive(Debug, Serialize, Deserialize)]
pub(crate) struct BucketEntryInner {
/// The node ids matching this bucket entry, with the cryptography versions supported by this node as the 'kind' field
validated_node_ids: TypedKeyGroup,
validated_node_ids: TypedPublicKeyGroup,
/// The node ids claimed by the remote node that use cryptography versions we do not support
unsupported_node_ids: TypedKeyGroup,
unsupported_node_ids: TypedPublicKeyGroup,
/// The set of envelope versions supported by the node inclusive of the requirements of any relay the node may be using
envelope_support: Vec<u8>,
/// If this node has updated it's SignedNodeInfo since our network
@ -283,7 +283,7 @@ impl BucketEntryInner {
}
/// Get all node ids
pub fn node_ids(&self) -> TypedKeyGroup {
pub fn node_ids(&self) -> TypedPublicKeyGroup {
let mut node_ids = self.validated_node_ids.clone();
node_ids.add_all(&self.unsupported_node_ids);
node_ids
@ -293,7 +293,7 @@ impl BucketEntryInner {
/// Returns Ok(Some(node)) any previous existing node id associated with that crypto kind
/// Returns Ok(None) if no previous existing node id was associated with that crypto kind, or one existed but nothing changed.
/// 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: TypedPublicKey) -> EyreResult<Option<TypedPublicKey>> {
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
@ -331,7 +331,7 @@ impl BucketEntryInner {
/// Remove a node id for a particular crypto kind.
/// Returns Some(node) any previous existing node id associated with that crypto kind
/// Returns None if no previous existing node id was associated with that crypto kind
pub fn remove_node_id(&mut self, crypto_kind: CryptoKind) -> Option<TypedKey> {
pub fn remove_node_id(&mut self, crypto_kind: CryptoKind) -> Option<TypedPublicKey> {
let node_ids = if VALID_CRYPTO_KINDS.contains(&crypto_kind) {
&mut self.validated_node_ids
} else {
@ -348,7 +348,7 @@ impl BucketEntryInner {
opt_dead_id
}
pub fn best_node_id(&self) -> TypedKey {
pub fn best_node_id(&self) -> TypedPublicKey {
self.validated_node_ids.best().unwrap()
}
@ -1217,14 +1217,14 @@ pub(crate) struct BucketEntry {
}
impl BucketEntry {
pub(super) fn new(first_node_id: TypedKey) -> Self {
pub(super) fn new(first_node_id: TypedPublicKey) -> Self {
// 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 = Timestamp::now();
let inner = BucketEntryInner {
validated_node_ids: TypedKeyGroup::from(first_node_id),
unsupported_node_ids: TypedKeyGroup::new(),
validated_node_ids: TypedPublicKeyGroup::from(first_node_id),
unsupported_node_ids: TypedPublicKeyGroup::new(),
envelope_support: Vec::new(),
updated_since_last_network_change: false,
last_flows: BTreeMap::new(),

View file

@ -87,7 +87,7 @@ impl RoutingTable {
fn format_entry(
cur_ts: Timestamp,
node: TypedKey,
node: TypedPublicKey,
e: &BucketEntryInner,
relay_tag: &str,
) -> String {
@ -245,7 +245,12 @@ impl RoutingTable {
out += " ";
out += &e.1.with(inner, |_rti, e| {
Self::format_entry(cur_ts, TypedKey::new(*ck, node), e, &relay_tag)
Self::format_entry(
cur_ts,
TypedPublicKey::new(*ck, node),
e,
&relay_tag,
)
});
out += "\n";
}

View file

@ -8,7 +8,7 @@ impl RoutingTable {
pub fn find_preferred_closest_peers(
&self,
routing_domain: RoutingDomain,
key: TypedKey,
key: TypedPublicKey,
capabilities: &[Capability],
) -> NetworkResult<Vec<Arc<PeerInfo>>> {
if Crypto::validate_crypto_kind(key.kind).is_err() {
@ -48,7 +48,7 @@ impl RoutingTable {
let closest_nodes = match self.find_preferred_closest_nodes(
node_count,
key,
key.into(),
filters,
// transform
|rti, entry| {
@ -72,7 +72,7 @@ impl RoutingTable {
pub fn find_preferred_peers_closer_to_key(
&self,
routing_domain: RoutingDomain,
key: TypedKey,
key: TypedRecordKey,
required_capabilities: Vec<Capability>,
) -> NetworkResult<Vec<Arc<PeerInfo>>> {
// add node information for the requesting node to our routing table
@ -87,7 +87,10 @@ impl RoutingTable {
};
let vcrypto = &vcrypto;
let own_distance = vcrypto.distance(&own_node_id.value, &key.value);
let own_distance = vcrypto.distance(
&HashDigest::from(own_node_id.value),
&HashDigest::from(key.value),
);
let filter = Box::new(
move |rti: &RoutingTableInner, opt_entry: Option<Arc<BucketEntry>>| {
@ -112,7 +115,10 @@ impl RoutingTable {
let Some(entry_node_id) = e.node_ids().get(crypto_kind) else {
return false;
};
let entry_distance = vcrypto.distance(&entry_node_id.value, &key.value);
let entry_distance = vcrypto.distance(
&HashDigest::from(entry_node_id.value),
&HashDigest::from(key.value),
);
if entry_distance >= own_distance {
return false;
}
@ -129,7 +135,7 @@ impl RoutingTable {
//
let closest_nodes = match self.find_preferred_closest_nodes(
node_count,
key,
key.into(),
filters,
// transform
|rti, entry| {
@ -147,7 +153,12 @@ impl RoutingTable {
// Validate peers returned are, in fact, closer to the key than the node we sent this to
// This same test is used on the other side so we vet things here
let valid = match Self::verify_peers_closer(vcrypto, own_node_id, key, &closest_nodes) {
let valid = match Self::verify_peers_closer(
vcrypto,
own_node_id.into(),
key.into(),
&closest_nodes,
) {
Ok(v) => v,
Err(e) => {
panic!("missing cryptosystem in peers node ids: {}", e);
@ -167,8 +178,8 @@ impl RoutingTable {
#[instrument(level = "trace", target = "rtab", skip_all, err)]
pub fn verify_peers_closer(
vcrypto: &crypto::CryptoSystemGuard<'_>,
key_far: TypedKey,
key_near: TypedKey,
key_far: TypedHashDigest,
key_near: TypedHashDigest,
peers: &[Arc<PeerInfo>],
) -> EyreResult<bool> {
let kind = vcrypto.kind();
@ -183,7 +194,7 @@ impl RoutingTable {
let Some(key_peer) = peer.node_ids().get(kind) else {
bail!("peers need to have a key with the same cryptosystem");
};
let d_near = vcrypto.distance(&key_near.value, &key_peer.value);
let d_near = vcrypto.distance(&key_near.value, &key_peer.value.into());
if d_far < d_near {
let warning = format!(
r#"peer: {}

View file

@ -304,7 +304,7 @@ impl RoutingTable {
///////////////////////////////////////////////////////////////////
pub fn node_id(&self, kind: CryptoKind) -> TypedKey {
pub fn node_id(&self, kind: CryptoKind) -> TypedPublicKey {
self.config()
.with(|c| c.network.routing_table.node_id.get(kind).unwrap())
}
@ -315,7 +315,7 @@ impl RoutingTable {
.value
}
pub fn node_ids(&self) -> TypedKeyGroup {
pub fn node_ids(&self) -> TypedPublicKeyGroup {
self.config()
.with(|c| c.network.routing_table.node_id.clone())
}
@ -331,7 +331,7 @@ impl RoutingTable {
tkps
}
pub fn matches_own_node_id(&self, node_ids: &[TypedKey]) -> bool {
pub fn matches_own_node_id(&self, node_ids: &[TypedPublicKey]) -> bool {
for ni in node_ids {
if let Some(v) = self.node_ids().get(ni.kind) {
if v.value == ni.value {
@ -351,14 +351,17 @@ impl RoutingTable {
false
}
pub fn calculate_bucket_index(&self, node_id: &TypedKey) -> BucketIndex {
pub fn calculate_bucket_index(&self, node_id: &TypedPublicKey) -> BucketIndex {
let crypto = self.crypto();
let self_node_id_key = self.node_id(node_id.kind).value;
let vcrypto = crypto.get(node_id.kind).unwrap();
(
node_id.kind,
vcrypto
.distance(&node_id.value, &self_node_id_key)
.distance(
&HashDigest::from(node_id.value),
&HashDigest::from(self_node_id_key),
)
.first_nonzero_bit()
.unwrap(),
)
@ -659,7 +662,7 @@ impl RoutingTable {
.get_nodes_needing_ping(routing_domain, cur_ts)
}
fn queue_bucket_kicks(&self, node_ids: TypedKeyGroup) {
fn queue_bucket_kicks(&self, node_ids: TypedPublicKeyGroup) {
for node_id in node_ids.iter() {
// Skip node ids we didn't add to buckets
if !VALID_CRYPTO_KINDS.contains(&node_id.kind) {
@ -678,7 +681,7 @@ impl RoutingTable {
}
/// Resolve an existing routing table entry and return a reference to it
pub fn lookup_node_ref(&self, node_id: TypedKey) -> EyreResult<Option<NodeRef>> {
pub fn lookup_node_ref(&self, node_id: TypedPublicKey) -> EyreResult<Option<NodeRef>> {
self.inner.read().lookup_node_ref(node_id)
}
@ -686,7 +689,7 @@ impl RoutingTable {
#[instrument(level = "trace", skip_all)]
pub fn lookup_and_filter_noderef(
&self,
node_id: TypedKey,
node_id: TypedPublicKey,
routing_domain_set: RoutingDomainSet,
dial_info_filter: DialInfoFilter,
) -> EyreResult<Option<FilteredNodeRef>> {
@ -716,7 +719,7 @@ impl RoutingTable {
pub fn register_node_with_id(
&self,
routing_domain: RoutingDomain,
node_id: TypedKey,
node_id: TypedPublicKey,
timestamp: Timestamp,
) -> EyreResult<FilteredNodeRef> {
self.inner
@ -736,7 +739,7 @@ impl RoutingTable {
}
#[instrument(level = "trace", skip_all)]
pub fn get_recent_peers(&self) -> Vec<(TypedKey, RecentPeersEntry)> {
pub fn get_recent_peers(&self) -> Vec<(TypedPublicKey, RecentPeersEntry)> {
let mut recent_peers = Vec::new();
let mut dead_peers = Vec::new();
let mut out = Vec::new();
@ -908,7 +911,7 @@ impl RoutingTable {
pub fn find_preferred_closest_nodes<'a, T, O>(
&self,
node_count: usize,
node_id: TypedKey,
node_id: TypedHashDigest,
filters: VecDeque<RoutingTableEntryFilter>,
transform: T,
) -> VeilidAPIResult<Vec<O>>
@ -922,7 +925,7 @@ impl RoutingTable {
pub fn sort_and_clean_closest_noderefs(
&self,
node_id: TypedKey,
node_id: TypedHashDigest,
closest_nodes: &[NodeRef],
) -> Vec<NodeRef> {
self.inner
@ -960,7 +963,7 @@ impl RoutingTable {
pub async fn find_nodes_close_to_node_id(
&self,
node_ref: FilteredNodeRef,
node_id: TypedKey,
node_id: TypedPublicKey,
capabilities: Vec<Capability>,
) -> EyreResult<NetworkResult<Vec<NodeRef>>> {
let rpc_processor = self.rpc_processor();
@ -1077,7 +1080,7 @@ impl RoutingTable {
#[instrument(level = "trace", skip(self, filter, metric), ret)]
pub fn get_node_speed_percentile(
&self,
node_id: TypedKey,
node_id: TypedPublicKey,
cur_ts: Timestamp,
filter: impl Fn(&BucketEntryInner) -> bool,
metric: impl Fn(&LatencyStats) -> TimestampDuration,

View file

@ -39,10 +39,10 @@ pub(crate) trait NodeRefCommonTrait: NodeRefAccessorsTrait + NodeRefOperateTrait
Arc::ptr_eq(&self.entry(), entry)
}
fn node_ids(&self) -> TypedKeyGroup {
fn node_ids(&self) -> TypedPublicKeyGroup {
self.operate(|_rti, e| e.node_ids())
}
fn best_node_id(&self) -> TypedKey {
fn best_node_id(&self) -> TypedPublicKey {
self.operate(|_rti, e| e.best_node_id())
}

View file

@ -47,7 +47,7 @@ impl RouteNode {
match self {
RouteNode::NodeId(id) => {
//
match routing_table.lookup_node_ref(TypedKey::new(crypto_kind, *id)) {
match routing_table.lookup_node_ref(TypedPublicKey::new(crypto_kind, *id)) {
Ok(nr) => nr,
Err(e) => {
veilid_log!(routing_table debug "failed to look up route node: {}", e);
@ -71,7 +71,7 @@ impl RouteNode {
pub fn describe(&self, crypto_kind: CryptoKind) -> String {
match self {
RouteNode::NodeId(id) => {
format!("{}", TypedKey::new(crypto_kind, *id))
format!("{}", TypedPublicKey::new(crypto_kind, *id))
}
RouteNode::PeerInfo(pi) => match pi.node_ids().get(crypto_kind) {
Some(id) => format!("{}", id),
@ -121,14 +121,14 @@ impl PrivateRouteHops {
#[derive(Clone, Debug)]
pub(crate) struct PrivateRoute {
/// The public key used for the entire route
pub public_key: TypedKey,
pub public_key: TypedPublicKey,
pub hop_count: u8,
pub hops: PrivateRouteHops,
}
impl PrivateRoute {
/// Stub route is the form used when no privacy is required, but you need to specify the destination for a safety route
pub fn new_stub(public_key: TypedKey, node: RouteNode) -> Self {
pub fn new_stub(public_key: TypedPublicKey, node: RouteNode) -> Self {
Self {
public_key,
hop_count: 1,
@ -182,14 +182,14 @@ impl PrivateRoute {
}
}
pub fn first_hop_node_id(&self) -> Option<TypedKey> {
pub fn first_hop_node_id(&self) -> Option<TypedPublicKey> {
let PrivateRouteHops::FirstHop(pr_first_hop) = &self.hops else {
return None;
};
// Get the safety route to use from the spec
Some(match &pr_first_hop.node {
RouteNode::NodeId(n) => TypedKey::new(self.public_key.kind, *n),
RouteNode::NodeId(n) => TypedPublicKey::new(self.public_key.kind, *n),
RouteNode::PeerInfo(p) => p.node_ids().get(self.public_key.kind).unwrap(),
})
}
@ -232,14 +232,14 @@ pub(crate) enum SafetyRouteHops {
#[derive(Clone, Debug)]
pub(crate) struct SafetyRoute {
pub public_key: TypedKey,
pub public_key: TypedPublicKey,
pub hop_count: u8,
pub hops: SafetyRouteHops,
}
impl SafetyRoute {
/// Stub route is the form used when no privacy is required, but you need to directly contact a private route
pub fn new_stub(public_key: TypedKey, private_route: PrivateRoute) -> Self {
pub fn new_stub(public_key: TypedPublicKey, private_route: PrivateRoute) -> Self {
// First hop should have already been popped off for stubbed safety routes since
// we are sending directly to the first hop
assert!(matches!(private_route.hops, PrivateRouteHops::Data(_)));

View file

@ -166,7 +166,7 @@ impl RouteSpecStore {
crypto_kinds: &[CryptoKind],
safety_spec: &SafetySpec,
directions: DirectionSet,
avoid_nodes: &[TypedKey],
avoid_nodes: &[TypedPublicKey],
automatic: bool,
) -> VeilidAPIResult<RouteId> {
let inner = &mut *self.inner.lock();
@ -193,7 +193,7 @@ impl RouteSpecStore {
crypto_kinds: &[CryptoKind],
safety_spec: &SafetySpec,
directions: DirectionSet,
avoid_nodes: &[TypedKey],
avoid_nodes: &[TypedPublicKey],
automatic: bool,
) -> VeilidAPIResult<RouteId> {
use core::cmp::Ordering;
@ -517,7 +517,7 @@ impl RouteSpecStore {
}
// Ensure the route doesn't contain both a node and its relay
let mut seen_nodes: HashSet<TypedKey> = HashSet::new();
let mut seen_nodes: HashSet<TypedPublicKey> = HashSet::new();
for n in permutation {
let node = nodes.get(*n).unwrap();
if !seen_nodes.insert(node.locked(rti).best_node_id()) {
@ -698,7 +698,7 @@ impl RouteSpecStore {
#[instrument(level = "trace", target = "route", skip(self, data, callback), ret)]
pub fn with_signature_validated_route<F, R>(
&self,
public_key: &TypedKey,
public_key: &TypedPublicKey,
signatures: &[Signature],
data: &[u8],
last_hop_id: PublicKey,
@ -948,7 +948,7 @@ impl RouteSpecStore {
stability: Stability,
sequencing: Sequencing,
directions: DirectionSet,
avoid_nodes: &[TypedKey],
avoid_nodes: &[TypedPublicKey],
) -> Option<RouteId> {
let cur_ts = Timestamp::now();
@ -1105,7 +1105,7 @@ impl RouteSpecStore {
let opt_first_hop = match pr_first_hop_node {
RouteNode::NodeId(id) => rti
.lookup_node_ref(TypedKey::new(crypto_kind, id))
.lookup_node_ref(TypedPublicKey::new(crypto_kind, id))
.map_err(VeilidAPIError::internal)?,
RouteNode::PeerInfo(pi) => Some(
rti.register_node_with_peer_info(pi, false)
@ -1252,7 +1252,8 @@ impl RouteSpecStore {
RouteNode::NodeId(safety_rsd.hops[h])
} else {
// Full peer info, required until we are sure the route has been fully established
let node_id = TypedKey::new(safety_rsd.crypto_kind, safety_rsd.hops[h]);
let node_id =
TypedPublicKey::new(safety_rsd.crypto_kind, safety_rsd.hops[h]);
let pi = rti
.with_node_entry(node_id, |entry| {
entry.with(rti, |_rti, e| {
@ -1301,7 +1302,7 @@ impl RouteSpecStore {
// Build safety route
let safety_route = SafetyRoute {
public_key: TypedKey::new(crypto_kind, sr_pubkey),
public_key: TypedPublicKey::new(crypto_kind, sr_pubkey),
hop_count: safety_spec.hop_count as u8,
hops,
};
@ -1334,7 +1335,7 @@ impl RouteSpecStore {
crypto_kind: CryptoKind,
safety_spec: &SafetySpec,
direction: DirectionSet,
avoid_nodes: &[TypedKey],
avoid_nodes: &[TypedPublicKey],
) -> VeilidAPIResult<PublicKey> {
// Ensure the total hop count isn't too long for our config
let max_route_hop_count = self.max_route_hop_count;
@ -1410,7 +1411,7 @@ impl RouteSpecStore {
&self,
crypto_kind: CryptoKind,
safety_spec: &SafetySpec,
avoid_nodes: &[TypedKey],
avoid_nodes: &[TypedPublicKey],
) -> VeilidAPIResult<PublicKey> {
let inner = &mut *self.inner.lock();
let routing_table = self.routing_table();
@ -1496,7 +1497,7 @@ impl RouteSpecStore {
RouteNode::NodeId(rsd.hops[h])
} else {
// Full peer info, required until we are sure the route has been fully established
let node_id = TypedKey::new(rsd.crypto_kind, rsd.hops[h]);
let node_id = TypedPublicKey::new(rsd.crypto_kind, rsd.hops[h]);
let pi = rti
.with_node_entry(node_id, |entry| {
entry.with(rti, |_rti, e| {
@ -1514,7 +1515,7 @@ impl RouteSpecStore {
}
let private_route = PrivateRoute {
public_key: TypedKey::new(rsd.crypto_kind, *key),
public_key: TypedPublicKey::new(rsd.crypto_kind, *key),
// add hop for 'FirstHop'
hop_count: (hop_count + 1).try_into().unwrap(),
hops: PrivateRouteHops::FirstHop(Box::new(route_hop)),

View file

@ -57,10 +57,10 @@ impl RouteSetSpecDetail {
pub fn get_route_by_key(&self, key: &PublicKey) -> Option<&RouteSpecDetail> {
self.route_set.get(key)
}
pub fn get_route_set_keys(&self) -> TypedKeyGroup {
let mut tks = TypedKeyGroup::new();
pub fn get_route_set_keys(&self) -> TypedPublicKeyGroup {
let mut tks = TypedPublicKeyGroup::new();
for (k, v) in &self.route_set {
tks.add(TypedKey::new(v.crypto_kind, *k));
tks.add(TypedPublicKey::new(v.crypto_kind, *k));
}
tks
}
@ -109,7 +109,7 @@ impl RouteSetSpecDetail {
Sequencing::EnsureOrdered => self.can_do_sequenced,
}
}
pub fn contains_nodes(&self, nodes: &[TypedKey]) -> bool {
pub fn contains_nodes(&self, nodes: &[TypedPublicKey]) -> bool {
for tk in nodes {
for rsd in self.route_set.values() {
if rsd.crypto_kind == tk.kind && rsd.hops.contains(&tk.value) {

View file

@ -139,14 +139,14 @@ impl RouteSpecStoreCache {
}
/// calculate how many times a node with a particular node id set has been used anywhere in the path of our allocated routes
pub fn get_used_node_count(&self, node_ids: &TypedKeyGroup) -> usize {
pub fn get_used_node_count(&self, node_ids: &TypedPublicKeyGroup) -> usize {
node_ids.iter().fold(0usize, |acc, k| {
acc + self.used_nodes.get(&k.value).cloned().unwrap_or_default()
})
}
/// calculate how many times a node with a particular node id set has been used at the end of the path of our allocated routes
pub fn get_used_end_node_count(&self, node_ids: &TypedKeyGroup) -> usize {
pub fn get_used_end_node_count(&self, node_ids: &TypedPublicKeyGroup) -> usize {
node_ids.iter().fold(0usize, |acc, k| {
acc + self
.used_end_nodes

View file

@ -35,7 +35,7 @@ impl RouteSpecStoreContent {
let mut hop_node_refs = Vec::with_capacity(rsd.hops.len());
for h in &rsd.hops {
let Ok(Some(nr)) =
routing_table.lookup_node_ref(TypedKey::new(rsd.crypto_kind, *h))
routing_table.lookup_node_ref(TypedPublicKey::new(rsd.crypto_kind, *h))
else {
dead_ids.push(*rsid);
break;

View file

@ -55,7 +55,7 @@ pub struct RoutingTableInner {
/// Statistics about the total bandwidth to/from this node
pub(super) self_transfer_stats: TransferStatsDownUp,
/// Peers we have recently communicated with
pub(super) recent_peers: LruCache<TypedKey, RecentPeersEntry>,
pub(super) recent_peers: LruCache<TypedPublicKey, RecentPeersEntry>,
/// Async tagged critical sections table
/// Tag: "tick" -> in ticker
pub(super) critical_sections: AsyncTagLockTable<&'static str>,
@ -655,7 +655,7 @@ impl RoutingTableInner {
fn update_bucket_entry_node_ids(
&mut self,
entry: Arc<BucketEntry>,
node_ids: &[TypedKey],
node_ids: &[TypedPublicKey],
) -> EyreResult<()> {
let routing_table = self.routing_table();
@ -745,7 +745,7 @@ impl RoutingTableInner {
#[instrument(level = "trace", skip_all, err)]
fn create_node_ref<F>(
&mut self,
node_ids: &TypedKeyGroup,
node_ids: &TypedPublicKeyGroup,
update_func: F,
) -> EyreResult<NodeRef>
where
@ -827,7 +827,7 @@ impl RoutingTableInner {
#[instrument(level = "trace", skip_all, err)]
pub fn lookup_any_node_ref(&self, node_id_key: PublicKey) -> EyreResult<Option<NodeRef>> {
for ck in VALID_CRYPTO_KINDS {
if let Some(nr) = self.lookup_node_ref(TypedKey::new(ck, node_id_key))? {
if let Some(nr) = self.lookup_node_ref(TypedPublicKey::new(ck, node_id_key))? {
return Ok(Some(nr));
}
}
@ -836,7 +836,7 @@ impl RoutingTableInner {
/// Resolve an existing routing table entry and return a reference to it
#[instrument(level = "trace", skip_all, err)]
pub fn lookup_node_ref(&self, node_id: TypedKey) -> EyreResult<Option<NodeRef>> {
pub fn lookup_node_ref(&self, node_id: TypedPublicKey) -> EyreResult<Option<NodeRef>> {
if self.routing_table().matches_own_node_id(&[node_id]) {
bail!("can't look up own node id in routing table");
}
@ -855,7 +855,7 @@ impl RoutingTableInner {
#[instrument(level = "trace", skip_all, err)]
pub fn lookup_and_filter_noderef(
&self,
node_id: TypedKey,
node_id: TypedPublicKey,
routing_domain_set: RoutingDomainSet,
dial_info_filter: DialInfoFilter,
) -> EyreResult<Option<FilteredNodeRef>> {
@ -870,7 +870,7 @@ impl RoutingTableInner {
}
/// Resolve an existing routing table entry and call a function on its entry without using a noderef
pub fn with_node_entry<F, R>(&self, node_id: TypedKey, f: F) -> Option<R>
pub fn with_node_entry<F, R>(&self, node_id: TypedPublicKey, f: F) -> Option<R>
where
F: FnOnce(Arc<BucketEntry>) -> R,
{
@ -970,10 +970,10 @@ impl RoutingTableInner {
pub fn register_node_with_id(
&mut self,
routing_domain: RoutingDomain,
node_id: TypedKey,
node_id: TypedPublicKey,
timestamp: Timestamp,
) -> EyreResult<FilteredNodeRef> {
let nr = self.create_node_ref(&TypedKeyGroup::from(node_id), |_rti, e| {
let nr = self.create_node_ref(&TypedPublicKeyGroup::from(node_id), |_rti, e| {
//e.make_not_dead(timestamp);
e.touch_last_seen(timestamp);
})?;
@ -1091,7 +1091,7 @@ impl RoutingTableInner {
}
}
pub fn touch_recent_peer(&mut self, node_id: TypedKey, last_connection: Flow) {
pub fn touch_recent_peer(&mut self, node_id: TypedPublicKey, last_connection: Flow) {
self.recent_peers
.insert(node_id, RecentPeersEntry { last_connection });
}
@ -1319,7 +1319,7 @@ impl RoutingTableInner {
pub fn find_preferred_closest_nodes<T, O>(
&self,
node_count: usize,
node_id: TypedKey,
node_id: TypedHashDigest,
mut filters: VecDeque<RoutingTableEntryFilter>,
transform: T,
) -> VeilidAPIResult<Vec<O>>
@ -1393,8 +1393,8 @@ impl RoutingTableInner {
};
// distance is the next metric, closer nodes first
let da = vcrypto.distance(&a_key.value, &node_id.value);
let db = vcrypto.distance(&b_key.value, &node_id.value);
let da = vcrypto.distance(&HashDigest::from(a_key.value), &node_id.value);
let db = vcrypto.distance(&HashDigest::from(b_key.value), &node_id.value);
da.cmp(&db)
};
@ -1407,7 +1407,7 @@ impl RoutingTableInner {
#[instrument(level = "trace", skip_all)]
pub fn sort_and_clean_closest_noderefs(
&self,
node_id: TypedKey,
node_id: TypedHashDigest,
closest_nodes: &[NodeRef],
) -> Vec<NodeRef> {
// Lock all noderefs
@ -1525,7 +1525,7 @@ impl RoutingTableInner {
#[instrument(level = "trace", skip(self, filter, metric), ret)]
pub fn get_node_relative_performance(
&self,
node_id: TypedKey,
node_id: TypedPublicKey,
cur_ts: Timestamp,
filter: impl Fn(&BucketEntryInner) -> bool,
metric: impl Fn(&LatencyStats) -> TimestampDuration,
@ -1584,7 +1584,7 @@ impl RoutingTableInner {
#[instrument(level = "trace", skip_all)]
pub fn make_closest_noderef_sort<'a>(
crypto: &'a Crypto,
node_id: TypedKey,
node_id: TypedHashDigest,
) -> impl Fn(&LockedNodeRef, &LockedNodeRef) -> core::cmp::Ordering + 'a {
let kind = node_id.kind;
// Get cryptoversion to check distance with
@ -1603,8 +1603,8 @@ pub fn make_closest_noderef_sort<'a>(
let b_key = b_entry.node_ids().get(kind).unwrap();
// distance is the next metric, closer nodes first
let da = vcrypto.distance(&a_key.value, &node_id.value);
let db = vcrypto.distance(&b_key.value, &node_id.value);
let da = vcrypto.distance(&HashDigest::from(a_key.value), &node_id.value);
let db = vcrypto.distance(&HashDigest::from(b_key.value), &node_id.value);
da.cmp(&db)
})
})
@ -1613,16 +1613,16 @@ pub fn make_closest_noderef_sort<'a>(
pub fn make_closest_node_id_sort(
crypto: &Crypto,
node_id: TypedKey,
) -> impl Fn(&CryptoKey, &CryptoKey) -> core::cmp::Ordering + '_ {
node_id: TypedPublicKey,
) -> impl Fn(&PublicKey, &PublicKey) -> core::cmp::Ordering + '_ {
let kind = node_id.kind;
// Get cryptoversion to check distance with
let vcrypto = crypto.get(kind).unwrap();
move |a: &CryptoKey, b: &CryptoKey| -> core::cmp::Ordering {
move |a: &PublicKey, b: &PublicKey| -> core::cmp::Ordering {
// distance is the next metric, closer nodes first
let da = vcrypto.distance(a, &node_id.value);
let db = vcrypto.distance(b, &node_id.value);
let da = vcrypto.distance(&HashDigest::from(*a), &HashDigest::from(node_id.value));
let db = vcrypto.distance(&HashDigest::from(*b), &HashDigest::from(node_id.value));
da.cmp(&db)
}
}

View file

@ -62,7 +62,7 @@ impl RoutingTable {
}));
}
let mut bootstrapped_peer_id_set = HashSet::<TypedKey>::new();
let mut bootstrapped_peer_id_set = HashSet::<TypedPublicKey>::new();
let mut bootstrapped_peers = vec![];
loop {
match unord.next().timeout_at(stop_token.clone()).await {

View file

@ -55,7 +55,7 @@ impl RoutingTable {
let noderefs = self
.find_preferred_closest_nodes(
CLOSEST_PEERS_REQUEST_COUNT,
self_node_id,
self_node_id.into(),
filters,
|_rti, entry: Option<Arc<BucketEntry>>| {
NodeRef::new(self.registry(), entry.unwrap().clone())

View file

@ -32,7 +32,7 @@ impl RoutingTable {
};
let sort = make_closest_node_id_sort(&crypto, our_node_id);
let mut closest_peers = BTreeSet::<CryptoKey>::new();
let mut closest_peers = BTreeSet::<PublicKey>::new();
let mut closest_unreliable_count = 0usize;
let mut closest_reliable_count = 0usize;

View file

@ -58,10 +58,10 @@ pub async fn test_routingtable_buckets_round_trip() {
}
pub fn test_round_trip_peerinfo() {
let mut tks = TypedKeyGroup::new();
tks.add(TypedKey::new(
let mut tks = TypedPublicKeyGroup::new();
tks.add(TypedPublicKey::new(
CRYPTO_KIND_VLD0,
CryptoKey::new([
PublicKey::new([
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0,
]),

View file

@ -10,11 +10,11 @@ pub enum ContactMethod {
/// Contact the node directly
Direct(DialInfo),
/// Request via signal the node connect back directly (relay, target)
SignalReverse(TypedKey, TypedKey),
SignalReverse(TypedPublicKey, TypedPublicKey),
/// Request via signal the node negotiate a hole punch (relay, target)
SignalHolePunch(TypedKey, TypedKey),
SignalHolePunch(TypedPublicKey, TypedPublicKey),
/// Must use an inbound relay to reach the node
InboundRelay(TypedKey),
InboundRelay(TypedPublicKey),
/// Must use outbound relay to reach the node
OutboundRelay(TypedKey),
OutboundRelay(TypedPublicKey),
}

View file

@ -7,7 +7,7 @@ pub struct PeerInfo {
skip_serializing_if = "is_default_routing_domain"
)]
routing_domain: RoutingDomain,
node_ids: TypedKeyGroup,
node_ids: TypedPublicKeyGroup,
signed_node_info: SignedNodeInfo,
}
@ -32,7 +32,7 @@ impl fmt::Display for PeerInfo {
impl PeerInfo {
pub fn new(
routing_domain: RoutingDomain,
node_ids: TypedKeyGroup,
node_ids: TypedPublicKeyGroup,
signed_node_info: SignedNodeInfo,
) -> Self {
assert!(!node_ids.is_empty() && node_ids.len() <= MAX_CRYPTO_KINDS);
@ -55,13 +55,13 @@ impl PeerInfo {
pub fn routing_domain(&self) -> RoutingDomain {
self.routing_domain
}
pub fn node_ids(&self) -> &TypedKeyGroup {
pub fn node_ids(&self) -> &TypedPublicKeyGroup {
&self.node_ids
}
pub fn signed_node_info(&self) -> &SignedNodeInfo {
&self.signed_node_info
}
pub fn destructure(self) -> (RoutingDomain, TypedKeyGroup, SignedNodeInfo) {
pub fn destructure(self) -> (RoutingDomain, TypedPublicKeyGroup, SignedNodeInfo) {
(self.routing_domain, self.node_ids, self.signed_node_info)
}

View file

@ -35,9 +35,9 @@ impl SignedDirectNodeInfo {
pub fn validate(
&self,
node_ids: &TypedKeyGroup,
node_ids: &TypedPublicKeyGroup,
crypto: &Crypto,
) -> VeilidAPIResult<TypedKeyGroup> {
) -> VeilidAPIResult<TypedPublicKeyGroup> {
let node_info_bytes = Self::make_signature_bytes(&self.node_info, self.timestamp)?;
// Verify the signatures that we can

View file

@ -26,9 +26,9 @@ impl fmt::Display for SignedNodeInfo {
impl SignedNodeInfo {
pub fn validate(
&self,
node_ids: &TypedKeyGroup,
node_ids: &TypedPublicKeyGroup,
crypto: &Crypto,
) -> VeilidAPIResult<TypedKeyGroup> {
) -> VeilidAPIResult<TypedPublicKeyGroup> {
match self {
SignedNodeInfo::Direct(d) => d.validate(node_ids, crypto),
SignedNodeInfo::Relayed(r) => r.validate(node_ids, crypto),
@ -54,9 +54,9 @@ impl SignedNodeInfo {
SignedNodeInfo::Relayed(r) => r.node_info(),
}
}
pub fn relay_ids(&self) -> TypedKeyGroup {
pub fn relay_ids(&self) -> TypedPublicKeyGroup {
match self {
SignedNodeInfo::Direct(_) => TypedKeyGroup::new(),
SignedNodeInfo::Direct(_) => TypedPublicKeyGroup::new(),
SignedNodeInfo::Relayed(r) => r.relay_ids().clone(),
}
}

View file

@ -4,7 +4,7 @@ use super::*;
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct SignedRelayedNodeInfo {
node_info: NodeInfo,
relay_ids: TypedKeyGroup,
relay_ids: TypedPublicKeyGroup,
relay_info: SignedDirectNodeInfo,
timestamp: Timestamp,
signatures: Vec<TypedSignature>,
@ -32,7 +32,7 @@ impl SignedRelayedNodeInfo {
/// All signatures are stored however, as this can be passed to other nodes that may be able to validate those signatures.
pub fn new(
node_info: NodeInfo,
relay_ids: TypedKeyGroup,
relay_ids: TypedPublicKeyGroup,
relay_info: SignedDirectNodeInfo,
timestamp: Timestamp,
signatures: Vec<TypedSignature>,
@ -48,9 +48,9 @@ impl SignedRelayedNodeInfo {
pub fn validate(
&self,
node_ids: &TypedKeyGroup,
node_ids: &TypedPublicKeyGroup,
crypto: &Crypto,
) -> VeilidAPIResult<TypedKeyGroup> {
) -> VeilidAPIResult<TypedPublicKeyGroup> {
// Ensure the relay info for the node has a superset of the crypto kinds of the node it is relaying
if common_crypto_kinds(
self.node_info.crypto_support(),
@ -84,7 +84,7 @@ impl SignedRelayedNodeInfo {
crypto: &Crypto,
typed_key_pairs: Vec<TypedKeyPair>,
node_info: NodeInfo,
relay_ids: TypedKeyGroup,
relay_ids: TypedPublicKeyGroup,
relay_info: SignedDirectNodeInfo,
) -> VeilidAPIResult<Self> {
let timestamp = Timestamp::now();
@ -105,7 +105,7 @@ impl SignedRelayedNodeInfo {
fn make_signature_bytes(
node_info: &NodeInfo,
relay_ids: &[TypedKey],
relay_ids: &[TypedPublicKey],
relay_info: &SignedDirectNodeInfo,
timestamp: Timestamp,
) -> VeilidAPIResult<Vec<u8>> {
@ -148,7 +148,7 @@ impl SignedRelayedNodeInfo {
pub fn timestamp(&self) -> Timestamp {
self.timestamp
}
pub fn relay_ids(&self) -> &TypedKeyGroup {
pub fn relay_ids(&self) -> &TypedPublicKeyGroup {
&self.relay_ids
}
pub fn relay_info(&self) -> &SignedDirectNodeInfo {

View file

@ -6,22 +6,22 @@ const MAX_FIND_BLOCK_A_PEERS_LEN: usize = 10;
#[derive(Debug, Clone)]
pub(in crate::rpc_processor) struct RPCOperationFindBlockQ {
block_id: TypedKey,
block_id: TypedPublicKey,
}
impl RPCOperationFindBlockQ {
pub fn new(block_id: TypedKey) -> Self {
pub fn new(block_id: TypedPublicKey) -> Self {
Self { block_id }
}
pub fn validate(&mut self, _validate_context: &RPCValidateContext) -> Result<(), RPCError> {
Ok(())
}
pub fn block_id(&self) -> TypedKey {
pub fn block_id(&self) -> TypedPublicKey {
self.block_id
}
pub fn destructure(self) -> TypedKey {
pub fn destructure(self) -> TypedPublicKey {
self.block_id
}

View file

@ -4,12 +4,12 @@ const MAX_FIND_NODE_A_PEERS_LEN: usize = 20;
#[derive(Debug, Clone)]
pub(in crate::rpc_processor) struct RPCOperationFindNodeQ {
node_id: TypedKey,
node_id: TypedPublicKey,
capabilities: Vec<Capability>,
}
impl RPCOperationFindNodeQ {
pub fn new(node_id: TypedKey, capabilities: Vec<Capability>) -> Self {
pub fn new(node_id: TypedPublicKey, capabilities: Vec<Capability>) -> Self {
Self {
node_id,
capabilities,
@ -26,7 +26,7 @@ impl RPCOperationFindNodeQ {
// &self.capabilities
// }
pub fn destructure(self) -> (TypedKey, Vec<Capability>) {
pub fn destructure(self) -> (TypedPublicKey, Vec<Capability>) {
(self.node_id, self.capabilities)
}

View file

@ -22,13 +22,13 @@ impl fmt::Debug for ValidateGetValueContext {
#[derive(Debug, Clone)]
pub(in crate::rpc_processor) struct RPCOperationGetValueQ {
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
want_descriptor: bool,
}
impl RPCOperationGetValueQ {
pub fn new(key: TypedKey, subkey: ValueSubkey, want_descriptor: bool) -> Self {
pub fn new(key: TypedRecordKey, subkey: ValueSubkey, want_descriptor: bool) -> Self {
Self {
key,
subkey,
@ -48,7 +48,7 @@ impl RPCOperationGetValueQ {
// pub fn want_descriptor(&self) -> bool {
// self.want_descriptor
// }
pub fn destructure(self) -> (TypedKey, ValueSubkey, bool) {
pub fn destructure(self) -> (TypedRecordKey, ValueSubkey, bool) {
(self.key, self.subkey, self.want_descriptor)
}
@ -57,7 +57,7 @@ impl RPCOperationGetValueQ {
reader: &veilid_capnp::operation_get_value_q::Reader,
) -> Result<Self, RPCError> {
let k_reader = reader.reborrow().get_key().map_err(RPCError::protocol)?;
let key = decode_typed_key(&k_reader)?;
let key = decode_typed_record_key(&k_reader)?;
let subkey = reader.reborrow().get_subkey();
let want_descriptor = reader.reborrow().get_want_descriptor();
Ok(Self {
@ -71,7 +71,7 @@ impl RPCOperationGetValueQ {
builder: &mut veilid_capnp::operation_get_value_q::Builder,
) -> Result<(), RPCError> {
let mut k_builder = builder.reborrow().init_key();
encode_typed_key(&self.key, &mut k_builder);
encode_typed_record_key(&self.key, &mut k_builder);
builder.set_subkey(self.subkey);
builder.set_want_descriptor(self.want_descriptor);
Ok(())

View file

@ -14,14 +14,14 @@ pub(in crate::rpc_processor) struct ValidateInspectValueContext {
#[derive(Debug, Clone)]
pub(in crate::rpc_processor) struct RPCOperationInspectValueQ {
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
want_descriptor: bool,
}
impl RPCOperationInspectValueQ {
pub fn new(
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
want_descriptor: bool,
) -> Result<Self, RPCError> {
@ -44,7 +44,7 @@ impl RPCOperationInspectValueQ {
// pub fn want_descriptor(&self) -> bool {
// self.want_descriptor
// }
pub fn destructure(self) -> (TypedKey, ValueSubkeyRangeSet, bool) {
pub fn destructure(self) -> (TypedRecordKey, ValueSubkeyRangeSet, bool) {
(self.key, self.subkeys, self.want_descriptor)
}
@ -53,7 +53,7 @@ impl RPCOperationInspectValueQ {
reader: &veilid_capnp::operation_inspect_value_q::Reader,
) -> Result<Self, RPCError> {
let k_reader = reader.reborrow().get_key().map_err(RPCError::protocol)?;
let key = decode_typed_key(&k_reader)?;
let key = decode_typed_record_key(&k_reader)?;
let sk_reader = reader.get_subkeys().map_err(RPCError::protocol)?;
// Maximum number of ranges that can hold the maximum number of subkeys is one subkey per range
if sk_reader.len() as usize > MAX_INSPECT_VALUE_Q_SUBKEY_RANGES_LEN {
@ -87,7 +87,7 @@ impl RPCOperationInspectValueQ {
builder: &mut veilid_capnp::operation_inspect_value_q::Builder,
) -> Result<(), RPCError> {
let mut k_builder = builder.reborrow().init_key();
encode_typed_key(&self.key, &mut k_builder);
encode_typed_record_key(&self.key, &mut k_builder);
let mut sk_builder = builder.reborrow().init_subkeys(
self.subkeys

View file

@ -22,7 +22,7 @@ impl fmt::Debug for ValidateSetValueContext {
#[derive(Debug, Clone)]
pub(in crate::rpc_processor) struct RPCOperationSetValueQ {
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
value: SignedValueData,
descriptor: Option<SignedValueDescriptor>,
@ -30,7 +30,7 @@ pub(in crate::rpc_processor) struct RPCOperationSetValueQ {
impl RPCOperationSetValueQ {
pub fn new(
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
value: SignedValueData,
descriptor: Option<SignedValueDescriptor>,
@ -64,7 +64,7 @@ impl RPCOperationSetValueQ {
pub fn destructure(
self,
) -> (
TypedKey,
TypedRecordKey,
ValueSubkey,
SignedValueData,
Option<SignedValueDescriptor>,
@ -77,7 +77,7 @@ impl RPCOperationSetValueQ {
reader: &veilid_capnp::operation_set_value_q::Reader,
) -> Result<Self, RPCError> {
let k_reader = reader.get_key().map_err(RPCError::protocol)?;
let key = decode_typed_key(&k_reader)?;
let key = decode_typed_record_key(&k_reader)?;
let subkey = reader.get_subkey();
let v_reader = reader.get_value().map_err(RPCError::protocol)?;
let value = decode_signed_value_data(&v_reader)?;
@ -100,7 +100,7 @@ impl RPCOperationSetValueQ {
builder: &mut veilid_capnp::operation_set_value_q::Builder,
) -> Result<(), RPCError> {
let mut k_builder = builder.reborrow().init_key();
encode_typed_key(&self.key, &mut k_builder);
encode_typed_record_key(&self.key, &mut k_builder);
builder.set_subkey(self.subkey);
let mut v_builder = builder.reborrow().init_value();
encode_signed_value_data(&self.value, &mut v_builder)?;

View file

@ -4,22 +4,22 @@ const MAX_SUPPLY_BLOCK_A_PEERS_LEN: usize = 20;
#[derive(Debug, Clone)]
pub(in crate::rpc_processor) struct RPCOperationSupplyBlockQ {
block_id: TypedKey,
block_id: TypedPublicKey,
}
impl RPCOperationSupplyBlockQ {
pub fn new(block_id: TypedKey) -> Self {
pub fn new(block_id: TypedPublicKey) -> Self {
Self { block_id }
}
pub fn validate(&mut self, _validate_context: &RPCValidateContext) -> Result<(), RPCError> {
Ok(())
}
pub fn block_id(&self) -> &TypedKey {
pub fn block_id(&self) -> &TypedPublicKey {
&self.block_id
}
pub fn destructure(self) -> TypedKey {
pub fn destructure(self) -> TypedPublicKey {
self.block_id
}

View file

@ -5,7 +5,7 @@ const MAX_VALUE_CHANGED_SUBKEY_RANGES_LEN: usize = 512;
#[derive(Debug, Clone)]
pub(in crate::rpc_processor) struct RPCOperationValueChanged {
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
count: u32,
watch_id: u64,
@ -14,7 +14,7 @@ pub(in crate::rpc_processor) struct RPCOperationValueChanged {
impl RPCOperationValueChanged {
pub fn new(
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
count: u32,
watch_id: u64,
@ -58,7 +58,7 @@ impl RPCOperationValueChanged {
}
#[expect(dead_code)]
pub fn key(&self) -> &TypedKey {
pub fn key(&self) -> &TypedRecordKey {
&self.key
}
@ -85,7 +85,7 @@ impl RPCOperationValueChanged {
pub fn destructure(
self,
) -> (
TypedKey,
TypedRecordKey,
ValueSubkeyRangeSet,
u32,
u64,
@ -105,7 +105,7 @@ impl RPCOperationValueChanged {
reader: &veilid_capnp::operation_value_changed::Reader,
) -> Result<Self, RPCError> {
let k_reader = reader.get_key().map_err(RPCError::protocol)?;
let key = decode_typed_key(&k_reader)?;
let key = decode_typed_record_key(&k_reader)?;
let sk_reader = reader.get_subkeys().map_err(RPCError::protocol)?;
if sk_reader.len() as usize > MAX_VALUE_CHANGED_SUBKEY_RANGES_LEN {
@ -151,7 +151,7 @@ impl RPCOperationValueChanged {
builder: &mut veilid_capnp::operation_value_changed::Builder,
) -> Result<(), RPCError> {
let mut k_builder = builder.reborrow().init_key();
encode_typed_key(&self.key, &mut k_builder);
encode_typed_record_key(&self.key, &mut k_builder);
let mut sk_builder = builder.reborrow().init_subkeys(
self.subkeys

View file

@ -5,7 +5,7 @@ const MAX_WATCH_VALUE_A_PEERS_LEN: usize = 20;
#[derive(Debug, Clone)]
pub(in crate::rpc_processor) struct RPCOperationWatchValueQ {
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
expiration: u64,
count: u32,
@ -16,7 +16,7 @@ pub(in crate::rpc_processor) struct RPCOperationWatchValueQ {
impl RPCOperationWatchValueQ {
pub fn new(
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
expiration: u64,
count: u32,
@ -51,7 +51,7 @@ impl RPCOperationWatchValueQ {
// signature covers: key, subkeys, expiration, count, using watcher key
fn make_signature_data(
key: &TypedKey,
key: &TypedRecordKey,
subkeys: &ValueSubkeyRangeSet,
expiration: u64,
count: u32,
@ -104,7 +104,7 @@ impl RPCOperationWatchValueQ {
}
#[expect(dead_code)]
pub fn key(&self) -> &TypedKey {
pub fn key(&self) -> &TypedRecordKey {
&self.key
}
@ -139,7 +139,7 @@ impl RPCOperationWatchValueQ {
pub fn destructure(
self,
) -> (
TypedKey,
TypedRecordKey,
ValueSubkeyRangeSet,
u64,
u32,
@ -163,7 +163,7 @@ impl RPCOperationWatchValueQ {
reader: &veilid_capnp::operation_watch_value_q::Reader,
) -> Result<Self, RPCError> {
let k_reader = reader.get_key().map_err(RPCError::protocol)?;
let key = decode_typed_key(&k_reader)?;
let key = decode_typed_record_key(&k_reader)?;
let sk_reader = reader.get_subkeys().map_err(RPCError::protocol)?;
if sk_reader.len() as usize > MAX_WATCH_VALUE_Q_SUBKEY_RANGES_LEN {
@ -215,7 +215,7 @@ impl RPCOperationWatchValueQ {
builder: &mut veilid_capnp::operation_watch_value_q::Builder,
) -> Result<(), RPCError> {
let mut k_builder = builder.reborrow().init_key();
encode_typed_key(&self.key, &mut k_builder);
encode_typed_record_key(&self.key, &mut k_builder);
let mut sk_builder = builder.reborrow().init_subkeys(
self.subkeys

View file

@ -39,7 +39,7 @@ pub fn decode_peer_info(
.reborrow()
.get_signed_node_info()
.map_err(RPCError::protocol)?;
let mut node_ids = TypedKeyGroup::with_capacity(nids_reader.len() as usize);
let mut node_ids = TypedPublicKeyGroup::with_capacity(nids_reader.len() as usize);
for nid_reader in nids_reader.iter() {
node_ids.add(decode_typed_key(&nid_reader)?);
}

View file

@ -69,7 +69,7 @@ pub fn decode_signed_relayed_node_info(
if rid_count > MAX_CRYPTO_KINDS {
return Err(RPCError::protocol("too many relay ids"));
}
let mut relay_ids = TypedKeyGroup::with_capacity(rid_count);
let mut relay_ids = TypedPublicKeyGroup::with_capacity(rid_count);
for rid_reader in rids_reader {
let relay_id = decode_typed_key(&rid_reader)?;
relay_ids.add(relay_id);

View file

@ -1,19 +1,47 @@
use super::*;
pub fn decode_typed_key(typed_key: &veilid_capnp::typed_key::Reader) -> Result<TypedKey, RPCError> {
pub fn decode_typed_key(
typed_key: &veilid_capnp::typed_key::Reader,
) -> Result<TypedPublicKey, RPCError> {
let key_reader = typed_key
.get_key()
.map_err(RPCError::map_invalid_format("invalid typed key"))?;
let kind = typed_key.get_kind();
Ok(TypedKey::new(
Ok(TypedPublicKey::new(
CryptoKind::from(kind.to_be_bytes()),
decode_key256(&key_reader),
))
}
pub fn encode_typed_key(typed_key: &TypedKey, builder: &mut veilid_capnp::typed_key::Builder) {
pub fn encode_typed_key(
typed_key: &TypedPublicKey,
builder: &mut veilid_capnp::typed_key::Builder,
) {
builder.set_kind(u32::from_be_bytes(typed_key.kind.0));
let mut key_builder = builder.reborrow().init_key();
encode_key256(&typed_key.value, &mut key_builder);
}
pub fn decode_typed_record_key(
typed_key: &veilid_capnp::typed_key::Reader,
) -> Result<TypedRecordKey, RPCError> {
let key_reader = typed_key
.get_key()
.map_err(RPCError::map_invalid_format("invalid typed key"))?;
let kind = typed_key.get_kind();
Ok(TypedRecordKey::new(
CryptoKind::from(kind.to_be_bytes()),
RecordKey::new(decode_key256(&key_reader).bytes),
))
}
pub fn encode_typed_record_key(
typed_key: &TypedRecordKey,
builder: &mut veilid_capnp::typed_key::Builder,
) {
builder.set_kind(u32::from_be_bytes(typed_key.kind.0));
let mut key_builder = builder.reborrow().init_key();
encode_key256(&PublicKey::new(typed_key.value.bytes), &mut key_builder);
}

View file

@ -107,7 +107,7 @@ impl Destination {
}
}
pub fn get_target_node_ids(&self) -> Option<TypedKeyGroup> {
pub fn get_target_node_ids(&self) -> Option<TypedPublicKeyGroup> {
match self {
Destination::Direct {
node,

View file

@ -112,7 +112,7 @@ pub enum FanoutCallDisposition {
}
pub type FanoutCallResult = Result<FanoutCallOutput, RPCError>;
pub type FanoutNodeInfoFilter = Arc<dyn (Fn(&[TypedKey], &NodeInfo) -> bool) + Send + Sync>;
pub type FanoutNodeInfoFilter = Arc<dyn (Fn(&[TypedPublicKey], &NodeInfo) -> bool) + Send + Sync>;
pub type FanoutCheckDone = Arc<dyn (Fn(&FanoutResult) -> bool) + Send + Sync>;
pub type FanoutCallRoutine =
Arc<dyn (Fn(NodeRef) -> PinBoxFutureStatic<FanoutCallResult>) + Send + Sync>;
@ -146,7 +146,7 @@ pub fn capability_fanout_node_info_filter(caps: Vec<Capability>) -> FanoutNodeIn
/// in the given time
pub(crate) struct FanoutCall<'a> {
routing_table: &'a RoutingTable,
node_id: TypedKey,
hash_coordinate: TypedHashDigest,
node_count: usize,
fanout_tasks: usize,
consensus_count: usize,
@ -166,7 +166,7 @@ impl<'a> FanoutCall<'a> {
#[allow(clippy::too_many_arguments)]
pub fn new(
routing_table: &'a RoutingTable,
node_id: TypedKey,
hash_coordinate: TypedHashDigest,
node_count: usize,
fanout_tasks: usize,
consensus_count: usize,
@ -177,7 +177,7 @@ impl<'a> FanoutCall<'a> {
) -> Self {
Self {
routing_table,
node_id,
hash_coordinate,
node_count,
fanout_tasks,
consensus_count,
@ -398,7 +398,12 @@ impl<'a> FanoutCall<'a> {
};
self.routing_table
.find_preferred_closest_nodes(self.node_count, self.node_id, filters, transform)
.find_preferred_closest_nodes(
self.node_count,
self.hash_coordinate,
filters,
transform,
)
.map_err(RPCError::invalid_format)?
};
context.fanout_queue.add(&closest_nodes);
@ -410,24 +415,26 @@ impl<'a> FanoutCall<'a> {
pub async fn run(&self, init_fanout_queue: Vec<NodeRef>) -> Result<FanoutResult, RPCError> {
// Create context for this run
let crypto = self.routing_table.crypto();
let Some(vcrypto) = crypto.get(self.node_id.kind) else {
let Some(vcrypto) = crypto.get(self.hash_coordinate.kind) else {
return Err(RPCError::internal(
"should not try this on crypto we don't support",
));
};
let node_sort = Box::new(
|a_key: &CryptoTyped<CryptoKey>,
b_key: &CryptoTyped<CryptoKey>|
|a_key: &CryptoTyped<PublicKey>,
b_key: &CryptoTyped<PublicKey>|
-> core::cmp::Ordering {
let da = vcrypto.distance(&a_key.value, &self.node_id.value);
let db = vcrypto.distance(&b_key.value, &self.node_id.value);
let da =
vcrypto.distance(&HashDigest::from(a_key.value), &self.hash_coordinate.value);
let db =
vcrypto.distance(&HashDigest::from(b_key.value), &self.hash_coordinate.value);
da.cmp(&db)
},
);
let context = Arc::new(Mutex::new(FanoutContext {
fanout_queue: FanoutQueue::new(
self.routing_table.registry(),
self.node_id.kind,
self.hash_coordinate.kind,
node_sort,
self.consensus_count,
),

View file

@ -32,7 +32,8 @@ pub struct FanoutNode {
pub status: FanoutNodeStatus,
}
pub type FanoutQueueSort<'a> = Box<dyn Fn(&TypedKey, &TypedKey) -> core::cmp::Ordering + Send + 'a>;
pub type FanoutQueueSort<'a> =
Box<dyn Fn(&TypedPublicKey, &TypedPublicKey) -> core::cmp::Ordering + Send + 'a>;
pub struct FanoutQueue<'a> {
/// Link back to veilid component registry for logging
@ -40,9 +41,9 @@ pub struct FanoutQueue<'a> {
/// Crypto kind in use for this queue
crypto_kind: CryptoKind,
/// The status of all the nodes we have added so far
nodes: HashMap<TypedKey, FanoutNode>,
nodes: HashMap<TypedPublicKey, FanoutNode>,
/// Closer nodes to the record key are at the front of the list
sorted_nodes: Vec<TypedKey>,
sorted_nodes: Vec<TypedPublicKey>,
/// The sort function to use for the nodes
node_sort: FanoutQueueSort<'a>,
/// The channel to receive work requests to process
@ -264,7 +265,10 @@ impl<'a> FanoutQueue<'a> {
}
/// Review the nodes in the queue
pub fn with_nodes<R, F: FnOnce(&HashMap<TypedKey, FanoutNode>, &[TypedKey]) -> R>(
pub fn with_nodes<
R,
F: FnOnce(&HashMap<TypedPublicKey, FanoutNode>, &[TypedPublicKey]) -> R,
>(
&self,
func: F,
) -> R {

View file

@ -72,7 +72,7 @@ impl MessageHeader {
RPCMessageHeaderDetail::PrivateRouted(p) => p.direct.routing_domain,
}
}
pub fn direct_sender_node_id(&self) -> TypedKey {
pub fn direct_sender_node_id(&self) -> TypedPublicKey {
match &self.detail {
RPCMessageHeaderDetail::Direct(d) => d.envelope.get_sender_typed_id(),
RPCMessageHeaderDetail::SafetyRouted(s) => s.direct.envelope.get_sender_typed_id(),

View file

@ -303,7 +303,7 @@ impl RPCProcessor {
fn process_sender_peer_info(
&self,
routing_domain: RoutingDomain,
sender_node_id: TypedKey,
sender_node_id: TypedPublicKey,
sender_peer_info: &SenderPeerInfo,
) -> RPCNetworkResult<Option<NodeRef>> {
let Some(peer_info) = sender_peer_info.opt_peer_info.clone() else {
@ -364,7 +364,7 @@ impl RPCProcessor {
#[instrument(level = "trace", target = "rpc", skip_all)]
async fn public_internet_peer_search(
&self,
node_id: TypedKey,
node_id: TypedPublicKey,
count: usize,
fanout: usize,
timeout_us: TimestampDuration,
@ -436,7 +436,7 @@ impl RPCProcessor {
let routing_table = self.routing_table();
let fanout_call = FanoutCall::new(
&routing_table,
node_id,
node_id.into(),
count,
fanout,
0,
@ -464,7 +464,7 @@ impl RPCProcessor {
#[instrument(level = "trace", target = "rpc", skip_all)]
pub fn resolve_node(
&self,
node_id: TypedKey,
node_id: TypedPublicKey,
safety_selection: SafetySelection,
) -> PinBoxFuture<Result<Option<NodeRef>, RPCError>> {
let registry = self.registry();

View file

@ -13,7 +13,7 @@ impl RPCProcessor {
pub async fn rpc_call_find_node(
&self,
dest: Destination,
node_id: TypedKey,
node_id: TypedPublicKey,
capabilities: Vec<Capability>,
) -> RPCNetworkResult<Answer<Vec<Arc<PeerInfo>>>> {
let _guard = self

View file

@ -28,7 +28,7 @@ impl RPCProcessor {
pub async fn rpc_call_get_value(
&self,
dest: Destination,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
last_descriptor: Option<SignedValueDescriptor>,
) -> RPCNetworkResult<Answer<GetValueAnswer>> {
@ -140,7 +140,12 @@ impl RPCProcessor {
}
// Validate peers returned are, in fact, closer to the key than the node we sent this to
let valid = match RoutingTable::verify_peers_closer(&vcrypto, target_node_id, key, &peers) {
let valid = match RoutingTable::verify_peers_closer(
&vcrypto,
target_node_id.into(),
key.into(),
&peers,
) {
Ok(v) => v,
Err(e) => {
return Ok(NetworkResult::invalid_message(format!(

View file

@ -30,7 +30,7 @@ impl RPCProcessor {
pub async fn rpc_call_inspect_value(
&self,
dest: Destination,
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
last_descriptor: Option<SignedValueDescriptor>,
) -> RPCNetworkResult<Answer<InspectValueAnswer>> {
@ -135,7 +135,12 @@ impl RPCProcessor {
}
// Validate peers returned are, in fact, closer to the key than the node we sent this to
let valid = match RoutingTable::verify_peers_closer(&vcrypto, target_node_id, key, &peers) {
let valid = match RoutingTable::verify_peers_closer(
&vcrypto,
target_node_id.into(),
key.into(),
&peers,
) {
Ok(v) => v,
Err(e) => {
return Ok(NetworkResult::invalid_message(format!(

View file

@ -64,7 +64,7 @@ impl RPCProcessor {
&self,
routed_operation: RoutedOperation,
next_route_node: RouteNode,
safety_route_public_key: TypedKey,
safety_route_public_key: TypedPublicKey,
next_private_route: PrivateRoute,
) -> RPCNetworkResult<()> {
// Make sure hop count makes sense
@ -116,7 +116,7 @@ impl RPCProcessor {
detail: RPCMessageHeaderDetailDirect,
vcrypto: &CryptoSystemGuard<'_>,
routed_operation: RoutedOperation,
remote_sr_pubkey: TypedKey,
remote_sr_pubkey: TypedPublicKey,
) -> RPCNetworkResult<()> {
// Now that things are valid, decrypt the routed operation with DEC(nonce, DH(the SR's public key, the PR's (or node's) secret)
// xxx: punish nodes that send messages that fail to decrypt eventually? How to do this for safety routes?
@ -162,8 +162,8 @@ impl RPCProcessor {
detail: RPCMessageHeaderDetailDirect,
vcrypto: &CryptoSystemGuard<'_>,
routed_operation: RoutedOperation,
remote_sr_pubkey: TypedKey,
pr_pubkey: TypedKey,
remote_sr_pubkey: TypedPublicKey,
pr_pubkey: TypedPublicKey,
) -> RPCNetworkResult<()> {
// Get sender id of the peer with the crypto kind of the route
let Some(sender_id) = detail.sender_noderef.node_ids().get(pr_pubkey.kind) else {
@ -237,8 +237,8 @@ impl RPCProcessor {
detail: RPCMessageHeaderDetailDirect,
vcrypto: &CryptoSystemGuard<'_>,
routed_operation: RoutedOperation,
remote_sr_pubkey: TypedKey,
pr_pubkey: TypedKey,
remote_sr_pubkey: TypedPublicKey,
pr_pubkey: TypedPublicKey,
) -> RPCNetworkResult<()> {
// If the private route public key is our node id, then this was sent via safety route to our node directly
// so there will be no signatures to validate
@ -266,7 +266,7 @@ impl RPCProcessor {
async fn process_private_route_first_hop(
&self,
mut routed_operation: RoutedOperation,
sr_pubkey: TypedKey,
sr_pubkey: TypedPublicKey,
mut private_route: PrivateRoute,
) -> RPCNetworkResult<()> {
let Some(pr_first_hop) = private_route.pop_first_hop() else {
@ -331,7 +331,7 @@ impl RPCProcessor {
fn decrypt_private_route_hop_data(
&self,
route_hop_data: &RouteHopData,
pr_pubkey: &TypedKey,
pr_pubkey: &TypedPublicKey,
routed_operation: &mut RoutedOperation,
) -> RPCNetworkResult<RouteHop> {
// Get crypto kind

View file

@ -30,7 +30,7 @@ impl RPCProcessor {
pub async fn rpc_call_set_value(
&self,
dest: Destination,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
value: SignedValueData,
descriptor: SignedValueDescriptor,
@ -154,7 +154,12 @@ impl RPCProcessor {
}
// Validate peers returned are, in fact, closer to the key than the node we sent this to
let valid = match RoutingTable::verify_peers_closer(&vcrypto, target_node_id, key, &peers) {
let valid = match RoutingTable::verify_peers_closer(
&vcrypto,
target_node_id.into(),
key.into(),
&peers,
) {
Ok(v) => v,
Err(e) => {
return Ok(NetworkResult::invalid_message(format!(

View file

@ -9,7 +9,7 @@ impl RPCProcessor {
pub async fn rpc_call_value_changed(
&self,
dest: Destination,
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
count: u32,
watch_id: u64,
@ -63,7 +63,7 @@ impl RPCProcessor {
));
}
RPCMessageHeaderDetail::PrivateRouted(p) => {
TypedKey::new(p.direct.envelope.get_crypto_kind(), p.remote_safety_route)
TypedPublicKey::new(p.direct.envelope.get_crypto_kind(), p.remote_safety_route)
}
};

View file

@ -27,7 +27,7 @@ impl RPCProcessor {
pub async fn rpc_call_watch_value(
&self,
dest: Destination,
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
expiration: Timestamp,
count: u32,
@ -153,7 +153,12 @@ impl RPCProcessor {
}
// Validate peers returned are, in fact, closer to the key than the node we sent this to
let valid = match RoutingTable::verify_peers_closer(&vcrypto, target_node_id, key, &peers) {
let valid = match RoutingTable::verify_peers_closer(
&vcrypto,
target_node_id.into(),
key.into(),
&peers,
) {
Ok(v) => v,
Err(e) => {
return Ok(NetworkResult::invalid_message(format!(

View file

@ -79,7 +79,7 @@ impl StorageManager {
pub async fn debug_local_record_subkey_info(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
) -> String {
let inner = self.inner.lock().await;
@ -92,7 +92,7 @@ impl StorageManager {
}
pub async fn debug_remote_record_subkey_info(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
) -> String {
let inner = self.inner.lock().await;
@ -103,7 +103,7 @@ impl StorageManager {
.debug_record_subkey_info(record_key, subkey)
.await
}
pub async fn debug_local_record_info(&self, record_key: TypedKey) -> String {
pub async fn debug_local_record_info(&self, record_key: TypedRecordKey) -> String {
let inner = self.inner.lock().await;
let Some(local_record_store) = &inner.local_record_store else {
return "not initialized".to_owned();
@ -119,7 +119,7 @@ impl StorageManager {
format!("{}\n{}", local_debug, opened_debug)
}
pub async fn debug_remote_record_info(&self, record_key: TypedKey) -> String {
pub async fn debug_remote_record_info(&self, record_key: TypedRecordKey) -> String {
let inner = self.inner.lock().await;
let Some(remote_record_store) = &inner.remote_record_store else {
return "not initialized".to_owned();

View file

@ -28,7 +28,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "dht", skip_all, err)]
pub(super) async fn outbound_get_value(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
safety_selection: SafetySelection,
last_get_result: GetResult,
@ -255,7 +255,7 @@ impl StorageManager {
let routing_table = registry.routing_table();
let fanout_call = FanoutCall::new(
&routing_table,
record_key,
record_key.into(),
key_count,
fanout,
consensus_count,
@ -306,7 +306,7 @@ impl StorageManager {
pub(super) fn process_deferred_outbound_get_value_result(
&self,
res_rx: flume::Receiver<Result<get_value::OutboundGetValueResult, VeilidAPIError>>,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
last_seq: ValueSeqNum,
) {
@ -358,7 +358,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "dht", skip_all)]
pub(super) async fn process_outbound_get_value_result(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
opt_last_seq: Option<u32>,
result: get_value::OutboundGetValueResult,
@ -406,7 +406,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "dht", skip_all)]
pub async fn inbound_get_value(
&self,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
want_descriptor: bool,
) -> VeilidAPIResult<NetworkResult<GetResult>> {

View file

@ -57,7 +57,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "dht", skip_all, err)]
pub(super) async fn outbound_inspect_value(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
safety_selection: SafetySelection,
local_inspect_result: InspectResult,
@ -290,7 +290,7 @@ impl StorageManager {
let routing_table = self.routing_table();
let fanout_call = FanoutCall::new(
&routing_table,
record_key,
record_key.into(),
key_count,
fanout,
consensus_count,
@ -358,7 +358,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "dht", skip_all)]
pub async fn inbound_inspect_value(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
want_descriptor: bool,
) -> VeilidAPIResult<NetworkResult<InspectResult>> {

View file

@ -65,7 +65,7 @@ const REHYDRATION_REQUESTS: &[u8] = b"rehydration_requests";
/// A single 'value changed' message to send
struct ValueChangedInfo {
target: Target,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
count: u32,
watch_id: u64,
@ -76,18 +76,18 @@ struct ValueChangedInfo {
#[derive(Default)]
struct StorageManagerInner {
/// Records that have been 'opened' and are not yet closed
pub opened_records: HashMap<TypedKey, OpenedRecord>,
pub opened_records: HashMap<TypedRecordKey, OpenedRecord>,
/// Records that have ever been 'created' or 'opened' by this node, things we care about that we must republish to keep alive
pub local_record_store: Option<RecordStore<LocalRecordDetail>>,
/// Records that have been pushed to this node for distribution by other nodes, that we make an effort to republish
pub remote_record_store: Option<RecordStore<RemoteRecordDetail>>,
/// Record subkeys that have not been pushed to the network because they were written to offline
pub offline_subkey_writes:
LinkedHashMap<TypedKey, tasks::offline_subkey_writes::OfflineSubkeyWrite>,
LinkedHashMap<TypedRecordKey, tasks::offline_subkey_writes::OfflineSubkeyWrite>,
/// Record subkeys that are currently being written to in the foreground
pub active_subkey_writes: HashMap<TypedKey, ValueSubkeyRangeSet>,
pub active_subkey_writes: HashMap<TypedRecordKey, ValueSubkeyRangeSet>,
/// Records that have rehydration requests
pub rehydration_requests: HashMap<TypedKey, RehydrationRequest>,
pub rehydration_requests: HashMap<TypedRecordKey, RehydrationRequest>,
/// State management for outbound watches
pub outbound_watch_manager: OutboundWatchManager,
/// Storage manager metadata that is persistent, including copy of offline subkey writes
@ -137,7 +137,7 @@ pub(crate) struct StorageManager {
// Outbound watch operation lock
// Keeps changes to watches to one-at-a-time per record
outbound_watch_lock_table: AsyncTagLockTable<TypedKey>,
outbound_watch_lock_table: AsyncTagLockTable<TypedRecordKey>,
// Background operation processor
// for offline subkey writes, watch changes, and any other
@ -492,7 +492,7 @@ impl StorageManager {
kind: CryptoKind,
schema: DHTSchema,
owner_key: &PublicKey,
) -> VeilidAPIResult<TypedKey> {
) -> VeilidAPIResult<TypedRecordKey> {
// Get cryptosystem
let crypto = self.crypto();
let Some(vcrypto) = crypto.get(kind) else {
@ -536,7 +536,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn open_record(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
writer: Option<KeyPair>,
safety_selection: SafetySelection,
) -> VeilidAPIResult<DHTRecordDescriptor> {
@ -615,7 +615,7 @@ impl StorageManager {
/// Close an opened local record
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn close_record(&self, record_key: TypedKey) -> VeilidAPIResult<()> {
pub async fn close_record(&self, record_key: TypedRecordKey) -> VeilidAPIResult<()> {
// Attempt to close the record, returning the opened record if it wasn't already closed
let mut inner = self.inner.lock().await;
Self::close_record_inner(&mut inner, record_key)?;
@ -637,7 +637,7 @@ impl StorageManager {
/// Delete a local record
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn delete_record(&self, record_key: TypedKey) -> VeilidAPIResult<()> {
pub async fn delete_record(&self, record_key: TypedRecordKey) -> VeilidAPIResult<()> {
// Ensure the record is closed
let mut inner = self.inner.lock().await;
Self::close_record_inner(&mut inner, record_key)?;
@ -655,7 +655,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn get_value(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
force_refresh: bool,
) -> VeilidAPIResult<Option<ValueData>> {
@ -731,7 +731,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn set_value(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
data: Vec<u8>,
writer: Option<KeyPair>,
@ -934,7 +934,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn watch_values(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
expiration: Timestamp,
count: u32,
@ -950,7 +950,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
async fn watch_values_inner(
&self,
watch_lock: AsyncTagLockGuard<TypedKey>,
watch_lock: AsyncTagLockGuard<TypedRecordKey>,
subkeys: ValueSubkeyRangeSet,
expiration: Timestamp,
count: u32,
@ -1034,7 +1034,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn cancel_watch_values(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
) -> VeilidAPIResult<bool> {
// Obtain the watch change lock
@ -1102,7 +1102,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn inspect_record(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
scope: DHTReportScope,
) -> VeilidAPIResult<DHTRecordReport> {
@ -1263,7 +1263,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip(self, value))]
fn update_callback_value_change(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
count: u32,
value: Option<ValueData>,
@ -1280,7 +1280,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
fn check_fanout_set_offline(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
fanout_result: &FanoutResult,
) -> bool {
@ -1333,7 +1333,7 @@ impl StorageManager {
schema: DHTSchema,
owner: Option<KeyPair>,
safety_selection: SafetySelection,
) -> VeilidAPIResult<(TypedKey, KeyPair)> {
) -> VeilidAPIResult<(TypedRecordKey, KeyPair)> {
// Get cryptosystem
let crypto = self.crypto();
let Some(vcrypto) = crypto.get(kind) else {
@ -1392,7 +1392,7 @@ impl StorageManager {
async fn move_remote_record_to_local_inner(
&self,
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
safety_selection: SafetySelection,
) -> VeilidAPIResult<Option<(PublicKey, DHTSchema)>> {
// Get local record store
@ -1467,7 +1467,7 @@ impl StorageManager {
pub async fn open_existing_record_inner(
&self,
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
writer: Option<KeyPair>,
safety_selection: SafetySelection,
) -> VeilidAPIResult<Option<DHTRecordDescriptor>> {
@ -1534,7 +1534,7 @@ impl StorageManager {
pub async fn open_new_record_inner(
&self,
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
writer: Option<KeyPair>,
inspect_result: InspectResult,
safety_selection: SafetySelection,
@ -1591,7 +1591,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn get_value_nodes(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
) -> VeilidAPIResult<Option<Vec<NodeRef>>> {
let inner = self.inner.lock().await;
// Get local record store
@ -1609,7 +1609,7 @@ impl StorageManager {
.copied()
.filter_map(|x| {
routing_table
.lookup_node_ref(TypedKey::new(record_key.kind, x))
.lookup_node_ref(TypedPublicKey::new(record_key.kind, x))
.ok()
.flatten()
})
@ -1625,7 +1625,7 @@ impl StorageManager {
>(
inner: &mut StorageManagerInner,
vcrypto: &CryptoSystemGuard<'_>,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey_results_iter: I,
is_set: bool,
consensus_count: usize,
@ -1665,8 +1665,10 @@ impl StorageManager {
return res;
}
// Distance is the next metric, closer nodes first
let da = vcrypto.distance(&a.0, &record_key.value);
let db = vcrypto.distance(&b.0, &record_key.value);
let da =
vcrypto.distance(&HashDigest::from(a.0), &HashDigest::from(record_key.value));
let db =
vcrypto.distance(&HashDigest::from(b.0), &HashDigest::from(record_key.value));
da.cmp(&db)
});
@ -1678,7 +1680,7 @@ impl StorageManager {
fn close_record_inner(
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
) -> VeilidAPIResult<()> {
let Some(local_record_store) = inner.local_record_store.as_mut() else {
apibail_not_initialized!();
@ -1701,7 +1703,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all, err)]
async fn handle_get_local_value_inner(
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
want_descriptor: bool,
) -> VeilidAPIResult<GetResult> {
@ -1725,7 +1727,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub(super) async fn handle_set_local_value_inner(
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
signed_value_data: Arc<SignedValueData>,
watch_update_mode: InboundWatchUpdateMode,
@ -1747,7 +1749,7 @@ impl StorageManager {
pub(super) async fn handle_inspect_local_value_inner(
&self,
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
want_descriptor: bool,
) -> VeilidAPIResult<InspectResult> {
@ -1775,7 +1777,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub(super) async fn handle_get_remote_value_inner(
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
want_descriptor: bool,
) -> VeilidAPIResult<GetResult> {
@ -1799,7 +1801,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub(super) async fn handle_set_remote_value_inner(
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
signed_value_data: Arc<SignedValueData>,
signed_value_descriptor: Arc<SignedValueDescriptor>,
@ -1838,7 +1840,7 @@ impl StorageManager {
pub(super) async fn handle_inspect_remote_value_inner(
&self,
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
want_descriptor: bool,
) -> VeilidAPIResult<InspectResult> {
@ -1867,19 +1869,19 @@ impl StorageManager {
vcrypto: &CryptoSystemGuard<'_>,
owner_key: &PublicKey,
schema_data: &[u8],
) -> TypedKey {
) -> TypedRecordKey {
let mut hash_data = Vec::<u8>::with_capacity(PUBLIC_KEY_LENGTH + 4 + schema_data.len());
hash_data.extend_from_slice(&vcrypto.kind().0);
hash_data.extend_from_slice(&owner_key.bytes);
hash_data.extend_from_slice(schema_data);
let hash = vcrypto.generate_hash(&hash_data);
TypedKey::new(vcrypto.kind(), hash)
TypedRecordKey::new(vcrypto.kind(), RecordKey::from(hash))
}
#[instrument(level = "trace", target = "stor", skip_all)]
pub(super) fn add_offline_subkey_write_inner(
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
safety_selection: SafetySelection,
) {

View file

@ -19,13 +19,13 @@ impl_veilid_log_facility!("stor");
pub(in crate::storage_manager) struct OutboundWatchManager {
/// Each watch per record key
#[serde(skip)]
pub outbound_watches: HashMap<TypedKey, OutboundWatch>,
pub outbound_watches: HashMap<TypedRecordKey, OutboundWatch>,
/// Last known active watch per node+record
#[serde_as(as = "Vec<(_, _)>")]
pub per_node_states: HashMap<PerNodeKey, PerNodeState>,
/// Value changed updates that need inpection to determine if they should be reported
#[serde(skip)]
pub needs_change_inspection: HashMap<TypedKey, ValueSubkeyRangeSet>,
pub needs_change_inspection: HashMap<TypedRecordKey, ValueSubkeyRangeSet>,
}
impl fmt::Display for OutboundWatchManager {
@ -116,7 +116,7 @@ impl OutboundWatchManager {
pub fn set_desired_watch(
&mut self,
record_key: TypedKey,
record_key: TypedRecordKey,
desired_watch: Option<OutboundWatchParameters>,
) {
match self.outbound_watches.get_mut(&record_key) {
@ -139,7 +139,7 @@ impl OutboundWatchManager {
}
}
pub fn set_next_reconcile_ts(&mut self, record_key: TypedKey, next_ts: Timestamp) {
pub fn set_next_reconcile_ts(&mut self, record_key: TypedRecordKey, next_ts: Timestamp) {
if let Some(outbound_watch) = self.outbound_watches.get_mut(&record_key) {
if let Some(state) = outbound_watch.state_mut() {
state.edit(&self.per_node_states, |editor| {
@ -204,7 +204,11 @@ impl OutboundWatchManager {
}
/// Set a record up to be inspected for changed subkeys
pub fn enqueue_change_inspect(&mut self, record_key: TypedKey, subkeys: ValueSubkeyRangeSet) {
pub fn enqueue_change_inspect(
&mut self,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
) {
self.needs_change_inspection
.entry(record_key)
.and_modify(|x| *x = x.union(&subkeys))

View file

@ -5,7 +5,7 @@ impl_veilid_log_facility!("stor");
#[derive(Clone, Debug, Serialize, Deserialize)]
pub(in crate::storage_manager) struct OutboundWatch {
/// Record key being watched
record_key: TypedKey,
record_key: TypedRecordKey,
/// Current state
/// None means inactive/cancelled
@ -37,7 +37,7 @@ impl fmt::Display for OutboundWatch {
impl OutboundWatch {
/// Create new outbound watch with desired parameters
pub fn new(record_key: TypedKey, desired: OutboundWatchParameters) -> Self {
pub fn new(record_key: TypedRecordKey, desired: OutboundWatchParameters) -> Self {
Self {
record_key,
state: None,

View file

@ -5,9 +5,9 @@ impl_veilid_log_facility!("stor");
#[derive(Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
pub(in crate::storage_manager) struct PerNodeKey {
/// Watched record key
pub record_key: TypedKey,
pub record_key: TypedRecordKey,
/// Watching node id
pub node_id: TypedKey,
pub node_id: TypedPublicKey,
}
impl fmt::Display for PerNodeKey {
@ -23,8 +23,8 @@ impl FromStr for PerNodeKey {
.split_once('@')
.ok_or_else(|| VeilidAPIError::parse_error("invalid per-node key", s))?;
Ok(PerNodeKey {
record_key: TypedKey::from_str(rkey)?,
node_id: TypedKey::from_str(nid)?,
record_key: TypedRecordKey::from_str(rkey)?,
node_id: TypedPublicKey::from_str(nid)?,
})
}
}

View file

@ -22,7 +22,7 @@ impl InspectCacheL2 {
#[derive(Debug)]
pub struct InspectCache {
cache: LruCache<TypedKey, InspectCacheL2>,
cache: LruCache<TypedRecordKey, InspectCacheL2>,
}
impl InspectCache {
@ -34,7 +34,7 @@ impl InspectCache {
pub fn get(
&mut self,
key: &TypedKey,
key: &TypedRecordKey,
subkeys: &ValueSubkeyRangeSet,
) -> Option<InspectCacheL2Value> {
if let Some(l2c) = self.cache.get_mut(key) {
@ -45,7 +45,12 @@ impl InspectCache {
None
}
pub fn put(&mut self, key: TypedKey, subkeys: ValueSubkeyRangeSet, value: InspectCacheL2Value) {
pub fn put(
&mut self,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
value: InspectCacheL2Value,
) {
self.cache
.entry(key)
.or_insert_with(|| InspectCacheL2::new(L2_CACHE_DEPTH))
@ -53,11 +58,16 @@ impl InspectCache {
.insert(subkeys, value);
}
pub fn invalidate(&mut self, key: &TypedKey) {
pub fn invalidate(&mut self, key: &TypedRecordKey) {
self.cache.remove(key);
}
pub fn replace_subkey_seq(&mut self, key: &TypedKey, subkey: ValueSubkey, seq: ValueSeqNum) {
pub fn replace_subkey_seq(
&mut self,
key: &TypedRecordKey,
subkey: ValueSubkey,
seq: ValueSeqNum,
) {
let Some(l2) = self.cache.get_mut(key) else {
return;
};

View file

@ -2,13 +2,13 @@ use super::*;
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct RecordTableKey {
pub key: TypedKey,
pub key: TypedRecordKey,
}
impl RecordTableKey {
pub fn bytes(&self) -> [u8; PUBLIC_KEY_LENGTH + 4] {
let mut bytes = [0u8; PUBLIC_KEY_LENGTH + 4];
pub fn bytes(&self) -> [u8; HASH_DIGEST_LENGTH + 4] {
let mut bytes = [0u8; HASH_DIGEST_LENGTH + 4];
bytes[0..4].copy_from_slice(&self.key.kind.0);
bytes[4..PUBLIC_KEY_LENGTH + 4].copy_from_slice(&self.key.value.bytes);
bytes[4..HASH_DIGEST_LENGTH + 4].copy_from_slice(&self.key.value.bytes);
bytes
}
}
@ -16,28 +16,28 @@ impl RecordTableKey {
impl TryFrom<&[u8]> for RecordTableKey {
type Error = EyreReport;
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
if bytes.len() != PUBLIC_KEY_LENGTH + 4 {
if bytes.len() != HASH_DIGEST_LENGTH + 4 {
bail!("invalid bytes length");
}
let kind = FourCC::try_from(&bytes[0..4]).wrap_err("invalid kind")?;
let value =
PublicKey::try_from(&bytes[4..PUBLIC_KEY_LENGTH + 4]).wrap_err("invalid value")?;
let key = TypedKey::new(kind, value);
RecordKey::try_from(&bytes[4..HASH_DIGEST_LENGTH + 4]).wrap_err("invalid value")?;
let key = TypedRecordKey::new(kind, value);
Ok(RecordTableKey { key })
}
}
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub struct SubkeyTableKey {
pub key: TypedKey,
pub key: TypedRecordKey,
pub subkey: ValueSubkey,
}
impl SubkeyTableKey {
pub fn bytes(&self) -> [u8; PUBLIC_KEY_LENGTH + 4 + 4] {
let mut bytes = [0u8; PUBLIC_KEY_LENGTH + 4 + 4];
pub fn bytes(&self) -> [u8; HASH_DIGEST_LENGTH + 4 + 4] {
let mut bytes = [0u8; HASH_DIGEST_LENGTH + 4 + 4];
bytes[0..4].copy_from_slice(&self.key.kind.0);
bytes[4..PUBLIC_KEY_LENGTH + 4].copy_from_slice(&self.key.value.bytes);
bytes[PUBLIC_KEY_LENGTH + 4..PUBLIC_KEY_LENGTH + 4 + 4]
bytes[4..HASH_DIGEST_LENGTH + 4].copy_from_slice(&self.key.value.bytes);
bytes[HASH_DIGEST_LENGTH + 4..HASH_DIGEST_LENGTH + 4 + 4]
.copy_from_slice(&self.subkey.to_le_bytes());
bytes
}
@ -45,19 +45,19 @@ impl SubkeyTableKey {
impl TryFrom<&[u8]> for SubkeyTableKey {
type Error = EyreReport;
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error> {
if bytes.len() != PUBLIC_KEY_LENGTH + 4 {
if bytes.len() != HASH_DIGEST_LENGTH + 4 {
bail!("invalid bytes length");
}
let kind = FourCC::try_from(&bytes[0..4]).wrap_err("invalid kind")?;
let value =
PublicKey::try_from(&bytes[4..PUBLIC_KEY_LENGTH + 4]).wrap_err("invalid value")?;
RecordKey::try_from(&bytes[4..HASH_DIGEST_LENGTH + 4]).wrap_err("invalid value")?;
let subkey = ValueSubkey::from_le_bytes(
bytes[PUBLIC_KEY_LENGTH + 4..PUBLIC_KEY_LENGTH + 4 + 4]
bytes[HASH_DIGEST_LENGTH + 4..HASH_DIGEST_LENGTH + 4 + 4]
.try_into()
.wrap_err("invalid subkey")?,
);
let key = TypedKey::new(kind, value);
let key = TypedRecordKey::new(kind, value);
Ok(SubkeyTableKey { key, subkey })
}
}

View file

@ -469,7 +469,11 @@ where
}
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn new_record(&mut self, key: TypedKey, record: Record<D>) -> VeilidAPIResult<()> {
pub async fn new_record(
&mut self,
key: TypedRecordKey,
record: Record<D>,
) -> VeilidAPIResult<()> {
let rtk = RecordTableKey { key };
if self.record_index.contains_key(&rtk) {
apibail_internal!("record already exists");
@ -510,7 +514,7 @@ where
}
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn delete_record(&mut self, key: TypedKey) -> VeilidAPIResult<()> {
pub async fn delete_record(&mut self, key: TypedRecordKey) -> VeilidAPIResult<()> {
// Get the record table key
let rtk = RecordTableKey { key };
@ -536,13 +540,13 @@ where
}
#[instrument(level = "trace", target = "stor", skip_all)]
pub(super) fn contains_record(&mut self, key: TypedKey) -> bool {
pub(super) fn contains_record(&mut self, key: TypedRecordKey) -> bool {
let rtk = RecordTableKey { key };
self.record_index.contains_key(&rtk)
}
#[instrument(level = "trace", target = "stor", skip_all)]
pub(super) fn with_record<R, F>(&mut self, key: TypedKey, f: F) -> Option<R>
pub(super) fn with_record<R, F>(&mut self, key: TypedRecordKey, f: F) -> Option<R>
where
F: FnOnce(&Record<D>) -> R,
{
@ -566,7 +570,7 @@ where
}
#[instrument(level = "trace", target = "stor", skip_all)]
pub(super) fn peek_record<R, F>(&self, key: TypedKey, f: F) -> Option<R>
pub(super) fn peek_record<R, F>(&self, key: TypedRecordKey, f: F) -> Option<R>
where
F: FnOnce(&Record<D>) -> R,
{
@ -581,7 +585,7 @@ where
}
#[instrument(level = "trace", target = "stor", skip_all)]
pub(super) fn with_record_mut<R, F>(&mut self, key: TypedKey, f: F) -> Option<R>
pub(super) fn with_record_mut<R, F>(&mut self, key: TypedRecordKey, f: F) -> Option<R>
where
F: FnOnce(&mut Record<D>) -> R,
{
@ -607,7 +611,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn get_subkey(
&mut self,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
want_descriptor: bool,
) -> VeilidAPIResult<Option<GetResult>> {
@ -675,7 +679,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn peek_subkey(
&self,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
want_descriptor: bool,
) -> VeilidAPIResult<Option<GetResult>> {
@ -740,7 +744,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all)]
async fn update_watched_value(
&mut self,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
watch_update_mode: InboundWatchUpdateMode,
) {
@ -779,7 +783,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn set_subkey(
&mut self,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
signed_value_data: Arc<SignedValueData>,
watch_update_mode: InboundWatchUpdateMode,
@ -883,7 +887,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn inspect_record(
&mut self,
key: TypedKey,
key: TypedRecordKey,
subkeys: &ValueSubkeyRangeSet,
want_descriptor: bool,
) -> VeilidAPIResult<Option<InspectResult>> {
@ -967,7 +971,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn _change_existing_watch(
&mut self,
key: TypedKey,
key: TypedRecordKey,
params: InboundWatchParameters,
watch_id: u64,
) -> VeilidAPIResult<InboundWatchResult> {
@ -1004,7 +1008,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn _create_new_watch(
&mut self,
key: TypedKey,
key: TypedRecordKey,
params: InboundWatchParameters,
member_check: Box<dyn Fn(PublicKey) -> bool + Send>,
) -> VeilidAPIResult<InboundWatchResult> {
@ -1095,7 +1099,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub async fn watch_record(
&mut self,
key: TypedKey,
key: TypedRecordKey,
mut params: InboundWatchParameters,
opt_watch_id: Option<u64>,
) -> VeilidAPIResult<InboundWatchResult> {
@ -1153,7 +1157,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all, err)]
async fn cancel_watch(
&mut self,
key: TypedKey,
key: TypedRecordKey,
watch_id: u64,
watcher: PublicKey,
) -> VeilidAPIResult<bool> {
@ -1193,7 +1197,7 @@ where
#[instrument(level = "trace", target = "stor", skip_all)]
pub fn move_watches(
&mut self,
key: TypedKey,
key: TypedRecordKey,
in_watch: Option<(InboundWatchList, bool)>,
) -> Option<(InboundWatchList, bool)> {
let rtk = RecordTableKey { key };
@ -1231,7 +1235,7 @@ where
// ValueChangedInfo but without the subkey data that requires a double mutable borrow to get
struct EarlyValueChangedInfo {
target: Target,
key: TypedKey,
key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
count: u32,
watch_id: u64,
@ -1369,7 +1373,7 @@ where
out
}
pub fn debug_record_info(&self, key: TypedKey) -> String {
pub fn debug_record_info(&self, key: TypedRecordKey) -> String {
let record_info = self
.peek_record(key, |r| format!("{:#?}", r))
.unwrap_or("Not found".to_owned());
@ -1382,7 +1386,11 @@ where
format!("{}\n{}\n", record_info, watched_record)
}
pub async fn debug_record_subkey_info(&self, key: TypedKey, subkey: ValueSubkey) -> String {
pub async fn debug_record_subkey_info(
&self,
key: TypedRecordKey,
subkey: ValueSubkey,
) -> String {
match self.peek_subkey(key, subkey, true).await {
Ok(Some(v)) => {
format!("{:#?}", v)

View file

@ -4,7 +4,7 @@ use super::{inspect_value::OutboundInspectValueResult, *};
#[derive(Debug, Clone)]
pub struct RehydrateReport {
/// The record key rehydrated
record_key: TypedKey,
record_key: TypedRecordKey,
/// The requested range of subkeys to rehydrate if necessary
subkeys: ValueSubkeyRangeSet,
/// The requested consensus count,
@ -24,7 +24,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all)]
pub async fn add_rehydration_request(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
consensus_count: usize,
) {
@ -55,7 +55,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip(self), ret, err)]
pub(super) async fn rehydrate_record(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
consensus_count: usize,
) -> VeilidAPIResult<RehydrateReport> {
@ -143,7 +143,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip(self), ret, err)]
pub(super) async fn rehydrate_all_subkeys(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
consensus_count: usize,
safety_selection: SafetySelection,
@ -185,7 +185,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip(self), ret, err)]
pub(super) async fn rehydrate_required_subkeys(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
consensus_count: usize,
safety_selection: SafetySelection,

View file

@ -28,7 +28,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "dht", skip_all, err)]
pub(super) async fn outbound_set_value(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
safety_selection: SafetySelection,
value: Arc<SignedValueData>,
@ -228,7 +228,7 @@ impl StorageManager {
let routing_table = registry.routing_table();
let fanout_call = FanoutCall::new(
&routing_table,
record_key,
record_key.into(),
key_count,
fanout,
consensus_count,
@ -277,7 +277,7 @@ impl StorageManager {
pub(super) fn process_deferred_outbound_set_value_result(
&self,
res_rx: flume::Receiver<Result<set_value::OutboundSetValueResult, VeilidAPIError>>,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
last_value_data: ValueData,
safety_selection: SafetySelection,
@ -343,7 +343,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "stor", skip_all, err)]
pub(super) async fn process_outbound_set_value_result(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkey: ValueSubkey,
last_value_data: ValueData,
safety_selection: SafetySelection,
@ -402,7 +402,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "dht", skip_all)]
pub async fn inbound_set_value(
&self,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
value: Arc<SignedValueData>,
descriptor: Option<Arc<SignedValueDescriptor>>,

View file

@ -21,7 +21,7 @@ enum OfflineSubkeyWriteResult {
#[derive(Debug)]
struct WorkItem {
record_key: TypedKey,
record_key: TypedRecordKey,
safety_selection: SafetySelection,
subkeys: ValueSubkeyRangeSet,
}
@ -39,7 +39,7 @@ impl StorageManager {
async fn write_single_offline_subkey(
&self,
stop_token: StopToken,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
safety_selection: SafetySelection,
) -> EyreResult<OfflineSubkeyWriteResult> {

View file

@ -47,7 +47,7 @@ impl StorageManager {
#[instrument(target = "watch", level = "debug", skip_all, err)]
pub(super) async fn outbound_watch_value_cancel(
&self,
watch_lock: AsyncTagLockGuard<TypedKey>,
watch_lock: AsyncTagLockGuard<TypedRecordKey>,
opt_watcher: Option<KeyPair>,
safety_selection: SafetySelection,
watch_node: NodeRef,
@ -95,7 +95,7 @@ impl StorageManager {
#[instrument(target = "watch", level = "debug", skip_all, err)]
pub(super) async fn outbound_watch_value_change(
&self,
watch_lock: AsyncTagLockGuard<TypedKey>,
watch_lock: AsyncTagLockGuard<TypedRecordKey>,
params: OutboundWatchParameters,
watch_node: NodeRef,
watch_id: u64,
@ -165,7 +165,7 @@ impl StorageManager {
#[instrument(target = "watch", level = "debug", skip_all, err)]
pub(super) async fn outbound_watch_value(
&self,
watch_lock: AsyncTagLockGuard<TypedKey>,
watch_lock: AsyncTagLockGuard<TypedRecordKey>,
params: OutboundWatchParameters,
per_node_state: HashMap<PerNodeKey, PerNodeState>,
) -> VeilidAPIResult<OutboundWatchValueResult> {
@ -332,7 +332,7 @@ impl StorageManager {
let routing_table = self.routing_table();
let fanout_call = FanoutCall::new(
&routing_table,
record_key,
record_key.into(),
key_count,
fanout,
consensus_count,
@ -374,7 +374,7 @@ impl StorageManager {
/// Remove dead watches from the table
pub(super) async fn process_outbound_watch_dead(
&self,
watch_lock: AsyncTagLockGuard<TypedKey>,
watch_lock: AsyncTagLockGuard<TypedRecordKey>,
) {
let record_key = watch_lock.tag();
@ -404,7 +404,7 @@ impl StorageManager {
/// and call their nodes to cancel the watch
pub(super) async fn process_outbound_watch_cancel(
&self,
watch_lock: AsyncTagLockGuard<TypedKey>,
watch_lock: AsyncTagLockGuard<TypedRecordKey>,
) {
let record_key = watch_lock.tag();
@ -520,7 +520,7 @@ impl StorageManager {
/// and drop the ones that can't be or are dead
pub(super) async fn process_outbound_watch_renew(
&self,
watch_lock: AsyncTagLockGuard<TypedKey>,
watch_lock: AsyncTagLockGuard<TypedRecordKey>,
) {
let record_key = watch_lock.tag();
@ -619,7 +619,7 @@ impl StorageManager {
/// Perform fanout to add or update per-node watches to an outbound watch
pub(super) async fn process_outbound_watch_reconcile(
&self,
watch_lock: AsyncTagLockGuard<TypedKey>,
watch_lock: AsyncTagLockGuard<TypedRecordKey>,
) {
let record_key = watch_lock.tag();
@ -734,7 +734,7 @@ impl StorageManager {
fn process_outbound_watch_value_result_inner(
&self,
inner: &mut StorageManagerInner,
record_key: TypedKey,
record_key: TypedRecordKey,
owvresult: OutboundWatchValueResult,
) {
let Some(outbound_watch) = inner
@ -842,8 +842,8 @@ impl StorageManager {
/// Can be processed in the foreground, or by the background operation queue
pub(super) fn get_next_outbound_watch_operation(
&self,
key: TypedKey,
opt_watch_lock: Option<AsyncTagLockGuard<TypedKey>>,
key: TypedRecordKey,
opt_watch_lock: Option<AsyncTagLockGuard<TypedRecordKey>>,
cur_ts: Timestamp,
outbound_watch: &mut OutboundWatch,
) -> Option<PinBoxFutureStatic<()>> {
@ -918,7 +918,7 @@ impl StorageManager {
/// Can be processed in the foreground, or by the background operation queue
pub(super) fn get_change_inspection_operation(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
subkeys: ValueSubkeyRangeSet,
) -> PinBoxFutureStatic<()> {
let fut = {
@ -1014,7 +1014,7 @@ impl StorageManager {
#[instrument(level = "trace", target = "dht", skip_all)]
pub async fn inbound_watch_value(
&self,
key: TypedKey,
key: TypedRecordKey,
params: InboundWatchParameters,
watch_id: Option<u64>,
) -> VeilidAPIResult<NetworkResult<InboundWatchResult>> {
@ -1055,11 +1055,11 @@ impl StorageManager {
#[instrument(level = "debug", target = "watch", skip_all)]
pub async fn inbound_value_changed(
&self,
record_key: TypedKey,
record_key: TypedRecordKey,
mut subkeys: ValueSubkeyRangeSet,
count: u32,
value: Option<Arc<SignedValueData>>,
inbound_node_id: TypedKey,
inbound_node_id: TypedPublicKey,
watch_id: u64,
) -> VeilidAPIResult<NetworkResult<()>> {
// Operate on the watch for this record

View file

@ -150,7 +150,7 @@ impl TableDB {
vcrypto.crypt_b2b_no_auth(
&data,
encout,
(nonce as &[u8]).try_into().unwrap(),
&Nonce::try_from(&nonce[0..NONCE_LENGTH]).unwrap(),
&ei.typed_key.value,
);
out
@ -175,7 +175,7 @@ impl TableDB {
vcrypto.crypt_b2b_no_auth(
&data[NONCE_LENGTH..],
&mut out,
(&data[0..NONCE_LENGTH]).try_into().unwrap(),
&Nonce::try_from(&data[0..NONCE_LENGTH]).unwrap(),
&di.typed_key.value,
);
decompress_size_prepended(&out, None)

View file

@ -196,7 +196,7 @@ pub async fn test_json(vcrypto: &AsyncCryptoSystemGuard<'_>, ts: &TableStore) {
);
assert!(
db.load_json::<TypedKey>(1, b"foo").await.is_err(),
db.load_json::<TypedPublicKey>(1, b"foo").await.is_err(),
"should fail to unfreeze"
);
}

View file

@ -4,9 +4,9 @@ use crate::*;
use lazy_static::*;
lazy_static! {
static ref BOGUS_KEY: TypedKey = TypedKey::from(CryptoTyped::new(
static ref BOGUS_KEY: TypedRecordKey = TypedRecordKey::from(CryptoTyped::new(
CRYPTO_KIND_VLD0,
CryptoKey::new([0u8; 32])
RecordKey::new([0u8; 32])
));
}

View file

@ -204,8 +204,8 @@ pub fn config_callback(key: String) -> ConfigCallbackReturn {
"network.reverse_connection_receipt_time_ms" => Ok(Box::new(5_000u32)),
"network.hole_punch_receipt_time_ms" => Ok(Box::new(5_000u32)),
"network.network_key_password" => Ok(Box::new(Option::<String>::None)),
"network.routing_table.node_id" => Ok(Box::new(TypedKeyGroup::new())),
"network.routing_table.node_id_secret" => Ok(Box::new(TypedSecretGroup::new())),
"network.routing_table.node_id" => Ok(Box::new(TypedPublicKeyGroup::new())),
"network.routing_table.node_id_secret" => Ok(Box::new(TypedSecretKeyGroup::new())),
// "network.routing_table.bootstrap" => Ok(Box::new(Vec::<String>::new())),
#[cfg(not(all(target_arch = "wasm32", target_os = "unknown")))]
"network.routing_table.bootstrap" => {
@ -216,9 +216,9 @@ pub fn config_callback(key: String) -> ConfigCallbackReturn {
"ws://bootstrap-v1.veilid.net:5150/ws".to_string(),
])),
"network.routing_table.bootstrap_keys" => Ok(Box::new(vec![
TypedKey::from_str("VLD0:Vj0lKDdUQXmQ5Ol1SZdlvXkBHUccBcQvGLN9vbLSI7k").unwrap(),
TypedKey::from_str("VLD0:QeQJorqbXtC7v3OlynCZ_W3m76wGNeB5NTF81ypqHAo").unwrap(),
TypedKey::from_str("VLD0:QNdcl-0OiFfYVj9331XVR6IqZ49NG-E18d5P7lwi4TA").unwrap(),
TypedPublicKey::from_str("VLD0:Vj0lKDdUQXmQ5Ol1SZdlvXkBHUccBcQvGLN9vbLSI7k").unwrap(),
TypedPublicKey::from_str("VLD0:QeQJorqbXtC7v3OlynCZ_W3m76wGNeB5NTF81ypqHAo").unwrap(),
TypedPublicKey::from_str("VLD0:QNdcl-0OiFfYVj9331XVR6IqZ49NG-E18d5P7lwi4TA").unwrap(),
])),
"network.routing_table.limit_over_attached" => Ok(Box::new(64u32)),
"network.routing_table.limit_fully_attached" => Ok(Box::new(32u32)),
@ -370,9 +370,9 @@ pub fn test_config() {
assert_eq!(
inner.network.routing_table.bootstrap_keys,
vec![
TypedKey::from_str("VLD0:Vj0lKDdUQXmQ5Ol1SZdlvXkBHUccBcQvGLN9vbLSI7k").unwrap(),
TypedKey::from_str("VLD0:QeQJorqbXtC7v3OlynCZ_W3m76wGNeB5NTF81ypqHAo").unwrap(),
TypedKey::from_str("VLD0:QNdcl-0OiFfYVj9331XVR6IqZ49NG-E18d5P7lwi4TA").unwrap(),
TypedPublicKey::from_str("VLD0:Vj0lKDdUQXmQ5Ol1SZdlvXkBHUccBcQvGLN9vbLSI7k").unwrap(),
TypedPublicKey::from_str("VLD0:QeQJorqbXtC7v3OlynCZ_W3m76wGNeB5NTF81ypqHAo").unwrap(),
TypedPublicKey::from_str("VLD0:QNdcl-0OiFfYVj9331XVR6IqZ49NG-E18d5P7lwi4TA").unwrap(),
],
);
assert_eq!(inner.network.routing_table.limit_over_attached, 64u32);

View file

@ -246,7 +246,7 @@ impl VeilidAPI {
}
// Is this a node id?
if let Ok(nid) = TypedKey::from_str(&s) {
if let Ok(nid) = TypedPublicKey::from_str(&s) {
return Ok(Target::NodeId(nid));
}

View file

@ -14,7 +14,7 @@ impl_veilid_log_facility!("veilid_debug");
#[derive(Default)]
pub(crate) struct DebugCache {
pub imported_routes: Vec<RouteId>,
pub opened_record_contexts: Lazy<LinkedHashMap<TypedKey, RoutingContext>>,
pub opened_record_contexts: Lazy<LinkedHashMap<TypedRecordKey, RoutingContext>>,
}
#[must_use]
@ -228,12 +228,18 @@ fn get_number<T: num_traits::Num + FromStr>(text: &str) -> Option<T> {
T::from_str(text).ok()
}
fn get_typed_key(text: &str) -> Option<TypedKey> {
TypedKey::from_str(text).ok()
fn get_typed_key(text: &str) -> Option<TypedPublicKey> {
TypedPublicKey::from_str(text).ok()
}
fn get_typed_record_key(text: &str) -> Option<TypedRecordKey> {
TypedRecordKey::from_str(text).ok()
}
fn get_public_key(text: &str) -> Option<PublicKey> {
PublicKey::from_str(text).ok()
}
fn get_record_key(text: &str) -> Option<RecordKey> {
RecordKey::from_str(text).ok()
}
fn get_keypair(text: &str) -> Option<KeyPair> {
KeyPair::from_str(text).ok()
}
@ -251,10 +257,10 @@ fn get_crypto_system_version<'a>(
}
}
fn get_dht_key_no_safety(text: &str) -> Option<TypedKey> {
let key = if let Some(key) = get_public_key(text) {
TypedKey::new(best_crypto_kind(), key)
} else if let Some(key) = get_typed_key(text) {
fn get_dht_key_no_safety(text: &str) -> Option<TypedRecordKey> {
let key = if let Some(key) = get_record_key(text) {
TypedRecordKey::new(best_crypto_kind(), key)
} else if let Some(key) = get_typed_record_key(text) {
key
} else {
return None;
@ -265,7 +271,7 @@ fn get_dht_key_no_safety(text: &str) -> Option<TypedKey> {
fn get_dht_key(
registry: VeilidComponentRegistry,
) -> impl FnOnce(&str) -> Option<(TypedKey, Option<SafetySelection>)> {
) -> impl FnOnce(&str) -> Option<(TypedRecordKey, Option<SafetySelection>)> {
move |text| {
// Safety selection
let (text, ss) = if let Some((first, second)) = text.split_once('+') {
@ -278,9 +284,9 @@ fn get_dht_key(
return None;
}
let key = if let Some(key) = get_public_key(text) {
TypedKey::new(best_crypto_kind(), key)
} else if let Some(key) = get_typed_key(text) {
let key = if let Some(key) = get_record_key(text) {
TypedRecordKey::new(best_crypto_kind(), key)
} else if let Some(key) = get_typed_record_key(text) {
key
} else {
return None;
@ -298,7 +304,7 @@ fn resolve_node_ref(
let text = text.to_owned();
Box::pin(async move {
let nr = if let Some(key) = get_public_key(&text) {
let node_id = TypedKey::new(best_crypto_kind(), key);
let node_id = TypedPublicKey::new(best_crypto_kind(), key);
registry
.rpc_processor()
.resolve_node(node_id, safety_selection)
@ -333,7 +339,7 @@ fn resolve_filtered_node_ref(
.unwrap_or((&text, None));
let nr = if let Some(key) = get_public_key(text) {
let node_id = TypedKey::new(best_crypto_kind(), key);
let node_id = TypedPublicKey::new(best_crypto_kind(), key);
registry
.rpc_processor()
.resolve_node(node_id, safety_selection)
@ -2433,7 +2439,7 @@ TableDB Operations:
context: &str,
key: &str,
arg: usize,
) -> VeilidAPIResult<(TypedKey, RoutingContext)> {
) -> VeilidAPIResult<(TypedRecordKey, RoutingContext)> {
let key = match get_debug_argument_at(args, arg, context, key, get_dht_key_no_safety)
.ok()
.or_else(|| {

View file

@ -132,7 +132,7 @@ pub enum VeilidAPIError {
#[error("Key not found: {key}")]
KeyNotFound {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
},
#[error("Internal: {message}")]
Internal { message: String },
@ -180,7 +180,7 @@ impl VeilidAPIError {
message: msg.to_string(),
}
}
pub fn key_not_found(key: TypedKey) -> Self {
pub fn key_not_found(key: TypedRecordKey) -> Self {
Self::KeyNotFound { key }
}
pub fn internal<T: ToString>(msg: T) -> Self {

View file

@ -89,9 +89,9 @@ pub enum CryptoSystemRequestOp {
},
Distance {
#[schemars(with = "String")]
key1: CryptoKey,
key1: PublicKey,
#[schemars(with = "String")]
key2: CryptoKey,
key2: PublicKey,
},
Sign {
#[schemars(with = "String")]
@ -215,7 +215,7 @@ pub enum CryptoSystemResponseOp {
},
Distance {
#[schemars(with = "String")]
value: CryptoKeyDistance,
value: HashDistance,
},
Sign {
#[serde(flatten)]

View file

@ -96,7 +96,7 @@ pub enum RequestOp {
CryptoSystem(CryptoSystemRequest),
VerifySignatures {
#[schemars(with = "Vec<String>")]
node_ids: Vec<TypedKey>,
node_ids: Vec<TypedPublicKey>,
#[serde(with = "as_human_base64")]
#[schemars(with = "String")]
data: Vec<u8>,
@ -207,7 +207,7 @@ pub enum ResponseOp {
VerifySignatures {
#[serde(flatten)]
#[schemars(with = "ApiResult<Option<Vec<String>>>")]
result: ApiResultWithOptVecString<Option<TypedKeyGroup>>,
result: ApiResultWithOptVecString<Option<TypedPublicKeyGroup>>,
},
GenerateSignatures {
#[serde(flatten)]

View file

@ -227,7 +227,7 @@ impl JsonRequestProcessor {
}
// Is this a node id?
if let Ok(nid) = TypedKey::from_str(&s) {
if let Ok(nid) = TypedPublicKey::from_str(&s) {
return Ok(Target::NodeId(nid));
}
@ -551,7 +551,7 @@ impl JsonRequestProcessor {
}
}
CryptoSystemRequestOp::Distance { key1, key2 } => CryptoSystemResponseOp::Distance {
value: csv.distance(&key1, &key2),
value: csv.distance(&HashDigest::from(key1), &HashDigest::from(key2)),
},
CryptoSystemRequestOp::Sign { key, secret, data } => CryptoSystemResponseOp::Sign {
result: to_json_api_result_with_string(csv.sign(&key, &secret, &data)),

View file

@ -47,27 +47,27 @@ pub enum RoutingContextRequestOp {
},
OpenDhtRecord {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
#[schemars(with = "Option<String>")]
writer: Option<KeyPair>,
},
CloseDhtRecord {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
},
DeleteDhtRecord {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
},
GetDhtValue {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
force_refresh: bool,
},
SetDhtValue {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
#[serde(with = "as_human_base64")]
#[schemars(with = "String")]
@ -77,19 +77,19 @@ pub enum RoutingContextRequestOp {
},
WatchDhtValues {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
subkeys: Option<ValueSubkeyRangeSet>,
expiration: Option<Timestamp>,
count: Option<u32>,
},
CancelDhtWatch {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
subkeys: Option<ValueSubkeyRangeSet>,
},
InspectDhtRecord {
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
subkeys: Option<ValueSubkeyRangeSet>,
#[schemars(default)]
scope: DHTReportScope,

View file

@ -9,7 +9,7 @@ impl_veilid_log_facility!("veilid_api");
#[must_use]
pub enum Target {
/// Node by its public key.
NodeId(TypedKey),
NodeId(TypedPublicKey),
/// Remote private route by its id.
PrivateRoute(RouteId),
}
@ -300,7 +300,7 @@ impl RoutingContext {
schema: DHTSchema,
owner_key: &PublicKey,
kind: Option<CryptoKind>,
) -> VeilidAPIResult<TypedKey> {
) -> VeilidAPIResult<TypedRecordKey> {
veilid_log!(self debug
"RoutingContext::get_dht_record_key(self: {:?}, schema: {:?}, owner_key: {:?}, kind: {:?})", self, schema, owner_key, kind);
schema.validate()?;
@ -358,7 +358,7 @@ impl RoutingContext {
#[instrument(target = "veilid_api", level = "debug", fields(__VEILID_LOG_KEY = self.log_key()), ret, err)]
pub async fn open_dht_record(
&self,
key: TypedKey,
key: TypedRecordKey,
default_writer: Option<KeyPair>,
) -> VeilidAPIResult<DHTRecordDescriptor> {
veilid_log!(self debug
@ -376,7 +376,7 @@ impl RoutingContext {
///
/// Closing a record allows you to re-open it with a different routing context.
#[instrument(target = "veilid_api", level = "debug", fields(__VEILID_LOG_KEY = self.log_key()), ret, err)]
pub async fn close_dht_record(&self, key: TypedKey) -> VeilidAPIResult<()> {
pub async fn close_dht_record(&self, key: TypedRecordKey) -> VeilidAPIResult<()> {
veilid_log!(self debug
"RoutingContext::close_dht_record(self: {:?}, key: {:?})", self, key);
@ -392,7 +392,7 @@ impl RoutingContext {
/// Deleting a record does not delete it from the network, but will remove the storage of the record
/// locally, and will prevent its value from being refreshed on the network by this node.
#[instrument(target = "veilid_api", level = "debug", fields(__VEILID_LOG_KEY = self.log_key()), ret, err)]
pub async fn delete_dht_record(&self, key: TypedKey) -> VeilidAPIResult<()> {
pub async fn delete_dht_record(&self, key: TypedRecordKey) -> VeilidAPIResult<()> {
veilid_log!(self debug
"RoutingContext::delete_dht_record(self: {:?}, key: {:?})", self, key);
@ -411,7 +411,7 @@ impl RoutingContext {
#[instrument(target = "veilid_api", level = "debug", fields(__VEILID_LOG_KEY = self.log_key()), ret, err)]
pub async fn get_dht_value(
&self,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
force_refresh: bool,
) -> VeilidAPIResult<Option<ValueData>> {
@ -434,7 +434,7 @@ impl RoutingContext {
#[instrument(target = "veilid_api", level = "debug", skip(data), fields(__VEILID_LOG_KEY = self.log_key(), data = print_data(&data, Some(64))), ret, err)]
pub async fn set_dht_value(
&self,
key: TypedKey,
key: TypedRecordKey,
subkey: ValueSubkey,
data: Vec<u8>,
writer: Option<KeyPair>,
@ -476,7 +476,7 @@ impl RoutingContext {
#[instrument(target = "veilid_api", level = "debug", fields(__VEILID_LOG_KEY = self.log_key()), ret, err)]
pub async fn watch_dht_values(
&self,
key: TypedKey,
key: TypedRecordKey,
subkeys: Option<ValueSubkeyRangeSet>,
expiration: Option<Timestamp>,
count: Option<u32>,
@ -508,7 +508,7 @@ impl RoutingContext {
#[instrument(target = "veilid_api", level = "debug", fields(__VEILID_LOG_KEY = self.log_key()), ret, err)]
pub async fn cancel_dht_watch(
&self,
key: TypedKey,
key: TypedRecordKey,
subkeys: Option<ValueSubkeyRangeSet>,
) -> VeilidAPIResult<bool> {
veilid_log!(self debug
@ -564,7 +564,7 @@ impl RoutingContext {
#[instrument(target = "veilid_api", level = "debug", fields(__VEILID_LOG_KEY = self.log_key()), ret, err)]
pub async fn inspect_dht_record(
&self,
key: TypedKey,
key: TypedRecordKey,
subkeys: Option<ValueSubkeyRangeSet>,
scope: DHTReportScope,
) -> VeilidAPIResult<DHTRecordReport> {

View file

@ -90,21 +90,48 @@ pub fn fix_peerstats() -> PeerStats {
}
}
pub fn fix_cryptokey() -> CryptoKey {
pub fn fix_publickey() -> PublicKey {
let mut fake_key = [0u8; CRYPTO_KEY_LENGTH];
random_bytes(&mut fake_key);
CryptoKey::new(fake_key)
PublicKey::new(fake_key)
}
pub fn fix_typedkey() -> TypedKey {
pub fn fix_recordkey() -> RecordKey {
let mut fake_key = [0u8; CRYPTO_KEY_LENGTH];
random_bytes(&mut fake_key);
TypedKey {
RecordKey::new(fake_key)
}
pub fn fix_routeid() -> RouteId {
let mut fake_key = [0u8; CRYPTO_KEY_LENGTH];
random_bytes(&mut fake_key);
RouteId::new(fake_key)
}
pub fn fix_typedkey() -> TypedPublicKey {
let mut fake_key = [0u8; CRYPTO_KEY_LENGTH];
random_bytes(&mut fake_key);
TypedPublicKey {
kind: FourCC::from_str("FAKE").unwrap(),
value: fix_cryptokey(),
value: fix_publickey(),
}
}
pub fn fix_typedrecordkey() -> TypedRecordKey {
let mut fake_key = [0u8; CRYPTO_KEY_LENGTH];
random_bytes(&mut fake_key);
TypedRecordKey {
kind: FourCC::from_str("FAKE").unwrap(),
value: fix_recordkey(),
}
}
pub fn fix_secretkey() -> SecretKey {
let mut fake_key = [0u8; CRYPTO_KEY_LENGTH];
random_bytes(&mut fake_key);
SecretKey::new(fake_key)
}
pub fn fix_peertabledata() -> PeerTableData {
PeerTableData {
node_ids: vec![fix_typedkey()],
@ -148,10 +175,10 @@ pub fn fix_veilidconfig() -> VeilidConfig {
hole_punch_receipt_time_ms: 9000,
network_key_password: None,
routing_table: VeilidConfigRoutingTable {
node_id: TypedKeyGroup::new(),
node_id_secret: TypedSecretGroup::new(),
node_id: TypedPublicKeyGroup::new(),
node_id_secret: TypedSecretKeyGroup::new(),
bootstrap: vec!["boots".to_string()],
bootstrap_keys: vec![TypedKey::from_str(
bootstrap_keys: vec![TypedPublicKey::from_str(
"VLD0:qrxwD1-aM9xiUw4IAPVXE_4qgoIfyR4Y6MEPyaDl_GQ",
)
.unwrap()],
@ -262,9 +289,9 @@ pub fn fix_veilidconfig() -> VeilidConfig {
pub fn fix_veilidvaluechange() -> VeilidValueChange {
VeilidValueChange {
key: fix_typedkey(),
key: fix_typedrecordkey(),
subkeys: ValueSubkeyRangeSet::new(),
count: 5,
value: Some(ValueData::new_with_seq(23, b"ValueData".to_vec(), fix_cryptokey()).unwrap()),
value: Some(ValueData::new_with_seq(23, b"ValueData".to_vec(), fix_publickey()).unwrap()),
}
}

View file

@ -15,7 +15,7 @@ pub fn test_alignedu64() {
pub fn test_veilidappmessage() {
let orig = VeilidAppMessage::new(
Some(fix_typedkey()),
Some(fix_cryptokey()),
Some(fix_routeid()),
b"Hi there!".to_vec(),
);
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
@ -26,7 +26,7 @@ pub fn test_veilidappmessage() {
pub fn test_veilidappcall() {
let orig = VeilidAppCall::new(
Some(fix_typedkey()),
Some(fix_cryptokey()),
Some(fix_routeid()),
b"Well, hello!".to_vec(),
OperationId::from(123),
);
@ -69,7 +69,7 @@ pub fn test_safetyselection() {
pub fn test_safetyspec() {
let orig = SafetySpec {
preferred_route: Some(fix_cryptokey()),
preferred_route: Some(fix_routeid()),
hop_count: 23,
stability: Stability::default(),
sequencing: Sequencing::default(),
@ -242,8 +242,8 @@ pub fn test_veilidstatenetwork() {
pub fn test_veilidroutechange() {
let orig = VeilidRouteChange {
dead_routes: vec![fix_cryptokey()],
dead_remote_routes: vec![fix_cryptokey()],
dead_routes: vec![fix_routeid()],
dead_remote_routes: vec![fix_routeid()],
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();

View file

@ -6,9 +6,9 @@ use range_set_blaze::*;
pub fn test_dhtrecorddescriptor() {
let orig = DHTRecordDescriptor::new(
fix_typedkey(),
fix_cryptokey(),
Some(fix_cryptokey()),
fix_typedrecordkey(),
fix_publickey(),
Some(fix_secretkey()),
DHTSchema::dflt(4321).unwrap(),
);
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
@ -19,7 +19,7 @@ pub fn test_dhtrecorddescriptor() {
// value_data
pub fn test_valuedata() {
let orig = ValueData::new_with_seq(42, b"Brent Spiner".to_vec(), fix_cryptokey());
let orig = ValueData::new_with_seq(42, b"Brent Spiner".to_vec(), fix_publickey());
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
assert_eq!(orig, copy);

View file

@ -18,11 +18,11 @@ pub fn test_dhtschema() {
91,
vec![
DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_key: fix_publickey(),
m_cnt: 5,
},
DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_key: fix_publickey(),
m_cnt: 6,
},
],
@ -38,7 +38,7 @@ pub fn test_dhtschema() {
pub fn test_dhtschemasmplmember() {
let orig = DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_key: fix_publickey(),
m_cnt: 7,
};
let copy = deserialize_json(&serialize_json(&orig)).unwrap();
@ -51,11 +51,11 @@ pub fn test_dhtschemasmpl() {
91,
vec![
DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_key: fix_publickey(),
m_cnt: 8,
},
DHTSchemaSMPLMember {
m_key: fix_cryptokey(),
m_key: fix_publickey(),
m_cnt: 9,
},
],

View file

@ -11,7 +11,7 @@ pub struct VeilidAppMessage {
all(target_arch = "wasm32", target_os = "unknown"),
tsify(optional, type = "string")
)]
sender: Option<TypedKey>,
sender: Option<TypedPublicKey>,
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
@ -35,7 +35,11 @@ pub struct VeilidAppMessage {
}
impl VeilidAppMessage {
pub fn new(sender: Option<TypedKey>, route_id: Option<RouteId>, message: Vec<u8>) -> Self {
pub fn new(
sender: Option<TypedPublicKey>,
route_id: Option<RouteId>,
message: Vec<u8>,
) -> Self {
Self {
sender,
route_id,
@ -45,7 +49,7 @@ impl VeilidAppMessage {
/// Some(sender) if the message was sent directly, None if received via a private/safety route.
#[must_use]
pub fn sender(&self) -> Option<&TypedKey> {
pub fn sender(&self) -> Option<&TypedPublicKey> {
self.sender.as_ref()
}
@ -70,7 +74,7 @@ pub struct VeilidAppCall {
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
#[cfg_attr(all(target_arch = "wasm32", target_os = "unknown"), tsify(optional))]
sender: Option<TypedKey>,
sender: Option<TypedPublicKey>,
#[serde(with = "as_human_opt_string")]
#[schemars(with = "Option<String>")]
@ -99,7 +103,7 @@ pub struct VeilidAppCall {
impl VeilidAppCall {
pub fn new(
sender: Option<TypedKey>,
sender: Option<TypedPublicKey>,
route_id: Option<RouteId>,
message: Vec<u8>,
call_id: OperationId,
@ -114,7 +118,7 @@ impl VeilidAppCall {
/// Some(sender) if the request was sent directly, None if received via a private/safety route.
#[must_use]
pub fn sender(&self) -> Option<&TypedKey> {
pub fn sender(&self) -> Option<&TypedPublicKey> {
self.sender.as_ref()
}

View file

@ -11,7 +11,7 @@ use super::*;
pub struct DHTRecordDescriptor {
/// DHT Key = Hash(ownerKeyKind) of: [ ownerKeyValue, schema ]
#[schemars(with = "String")]
key: TypedKey,
key: TypedRecordKey,
/// The public key of the owner
#[schemars(with = "String")]
owner: PublicKey,
@ -26,7 +26,7 @@ pub struct DHTRecordDescriptor {
impl DHTRecordDescriptor {
pub(crate) fn new(
key: TypedKey,
key: TypedRecordKey,
owner: PublicKey,
owner_secret: Option<SecretKey>,
schema: DHTSchema,
@ -39,7 +39,7 @@ impl DHTRecordDescriptor {
}
}
pub fn key(&self) -> &TypedKey {
pub fn key(&self) -> &TypedRecordKey {
&self.key
}
pub fn owner(&self) -> &PublicKey {

View file

@ -95,11 +95,11 @@ mod tests {
#[test]
fn value_data_ok() {
assert!(ValueData::new(vec![0; ValueData::MAX_LEN], CryptoKey { bytes: [0; 32] }).is_ok());
assert!(ValueData::new(vec![0; ValueData::MAX_LEN], PublicKey { bytes: [0; 32] }).is_ok());
assert!(ValueData::new_with_seq(
0,
vec![0; ValueData::MAX_LEN],
CryptoKey { bytes: [0; 32] }
PublicKey { bytes: [0; 32] }
)
.is_ok());
}
@ -108,13 +108,13 @@ mod tests {
fn value_data_too_long() {
assert!(ValueData::new(
vec![0; ValueData::MAX_LEN + 1],
CryptoKey { bytes: [0; 32] }
PublicKey { bytes: [0; 32] }
)
.is_err());
assert!(ValueData::new_with_seq(
0,
vec![0; ValueData::MAX_LEN + 1],
CryptoKey { bytes: [0; 32] }
PublicKey { bytes: [0; 32] }
)
.is_err());
}

View file

@ -107,7 +107,7 @@ pub struct PeerTableData {
all(target_arch = "wasm32", target_os = "unknown"),
tsify(type = "string[]")
)]
pub node_ids: Vec<TypedKey>,
pub node_ids: Vec<TypedPublicKey>,
/// The peer's human readable address.
pub peer_address: String,
/// Statistics we have collected on this peer.
@ -162,7 +162,7 @@ pub struct VeilidStateConfig {
pub struct VeilidValueChange {
/// The DHT Record key that changed
#[schemars(with = "String")]
pub key: TypedKey,
pub key: TypedRecordKey,
/// The portion of the DHT Record's subkeys that have changed
/// If the subkey range is empty, any watch present on the value has died.
pub subkeys: ValueSubkeyRangeSet,

View file

@ -496,12 +496,12 @@ impl Default for VeilidConfigRPC {
#[must_use]
pub struct VeilidConfigRoutingTable {
#[schemars(with = "Vec<String>")]
pub node_id: TypedKeyGroup,
pub node_id: TypedPublicKeyGroup,
#[schemars(with = "Vec<String>")]
pub node_id_secret: TypedSecretGroup,
pub node_id_secret: TypedSecretKeyGroup,
pub bootstrap: Vec<String>,
#[schemars(with = "Vec<String>")]
pub bootstrap_keys: Vec<TypedKey>,
pub bootstrap_keys: Vec<TypedPublicKey>,
pub limit_over_attached: u32,
pub limit_fully_attached: u32,
pub limit_attached_strong: u32,
@ -522,16 +522,16 @@ impl Default for VeilidConfigRoutingTable {
}
let bootstrap_keys = vec![
// Primary Veilid Foundation bootstrap signing key
TypedKey::from_str("VLD0:Vj0lKDdUQXmQ5Ol1SZdlvXkBHUccBcQvGLN9vbLSI7k").unwrap(),
TypedPublicKey::from_str("VLD0:Vj0lKDdUQXmQ5Ol1SZdlvXkBHUccBcQvGLN9vbLSI7k").unwrap(),
// Secondary Veilid Foundation bootstrap signing key
TypedKey::from_str("VLD0:QeQJorqbXtC7v3OlynCZ_W3m76wGNeB5NTF81ypqHAo").unwrap(),
TypedPublicKey::from_str("VLD0:QeQJorqbXtC7v3OlynCZ_W3m76wGNeB5NTF81ypqHAo").unwrap(),
// Backup Veilid Foundation bootstrap signing key
TypedKey::from_str("VLD0:QNdcl-0OiFfYVj9331XVR6IqZ49NG-E18d5P7lwi4TA").unwrap(),
TypedPublicKey::from_str("VLD0:QNdcl-0OiFfYVj9331XVR6IqZ49NG-E18d5P7lwi4TA").unwrap(),
];
Self {
node_id: TypedKeyGroup::default(),
node_id_secret: TypedSecretGroup::default(),
node_id: TypedPublicKeyGroup::default(),
node_id_secret: TypedSecretKeyGroup::default(),
bootstrap,
bootstrap_keys,
limit_over_attached: 64,
@ -1082,7 +1082,7 @@ impl VeilidStartupOptions {
let mut safe_cfg = self.inner.read().clone();
// Remove secrets
safe_cfg.network.routing_table.node_id_secret = TypedSecretGroup::new();
safe_cfg.network.routing_table.node_id_secret = TypedSecretKeyGroup::new();
"".clone_into(&mut safe_cfg.protected_store.device_encryption_key_password);
safe_cfg.protected_store.new_device_encryption_key_password = None;
@ -1093,7 +1093,7 @@ impl VeilidStartupOptions {
let mut safe_cfg = self.inner.read().clone();
// Remove secrets
safe_cfg.network.routing_table.node_id_secret = TypedSecretGroup::new();
safe_cfg.network.routing_table.node_id_secret = TypedSecretKeyGroup::new();
"".clone_into(&mut safe_cfg.protected_store.device_encryption_key_password);
safe_cfg.protected_store.new_device_encryption_key_password = None;

View file

@ -713,7 +713,7 @@ pub extern "C" fn routing_context_create_dht_record(
#[no_mangle]
#[instrument(level = "trace", target = "ffi", skip_all)]
pub extern "C" fn routing_context_open_dht_record(port: i64, id: u32, key: FfiStr, writer: FfiStr) {
let key: veilid_core::TypedKey =
let key: veilid_core::TypedRecordKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
let writer: Option<veilid_core::KeyPair> = writer
.into_opt_string()
@ -732,7 +732,7 @@ pub extern "C" fn routing_context_open_dht_record(port: i64, id: u32, key: FfiSt
#[no_mangle]
#[instrument(level = "trace", target = "ffi", skip_all)]
pub extern "C" fn routing_context_close_dht_record(port: i64, id: u32, key: FfiStr) {
let key: veilid_core::TypedKey =
let key: veilid_core::TypedRecordKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
DartIsolateWrapper::new(port).spawn_result(
async move {
@ -748,7 +748,7 @@ pub extern "C" fn routing_context_close_dht_record(port: i64, id: u32, key: FfiS
#[no_mangle]
#[instrument(level = "trace", target = "ffi", skip_all)]
pub extern "C" fn routing_context_delete_dht_record(port: i64, id: u32, key: FfiStr) {
let key: veilid_core::TypedKey =
let key: veilid_core::TypedRecordKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
DartIsolateWrapper::new(port).spawn_result(
async move {
@ -770,7 +770,7 @@ pub extern "C" fn routing_context_get_dht_value(
subkey: u32,
force_refresh: bool,
) {
let key: veilid_core::TypedKey =
let key: veilid_core::TypedRecordKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
DartIsolateWrapper::new(port).spawn_result_json(
async move {
@ -795,7 +795,7 @@ pub extern "C" fn routing_context_set_dht_value(
data: FfiStr,
writer: FfiStr,
) {
let key: veilid_core::TypedKey =
let key: veilid_core::TypedRecordKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
let data: Vec<u8> = data_encoding::BASE64URL_NOPAD
.decode(data.into_opt_string().unwrap().as_bytes())
@ -827,7 +827,7 @@ pub extern "C" fn routing_context_watch_dht_values(
expiration: u64,
count: u32,
) {
let key: veilid_core::TypedKey =
let key: veilid_core::TypedRecordKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
let subkeys: veilid_core::ValueSubkeyRangeSet =
veilid_core::deserialize_opt_json(subkeys.into_opt_string()).unwrap();
@ -854,7 +854,7 @@ pub extern "C" fn routing_context_cancel_dht_watch(
key: FfiStr,
subkeys: FfiStr,
) {
let key: veilid_core::TypedKey =
let key: veilid_core::TypedRecordKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
let subkeys: veilid_core::ValueSubkeyRangeSet =
veilid_core::deserialize_opt_json(subkeys.into_opt_string()).unwrap();
@ -879,7 +879,7 @@ pub extern "C" fn routing_context_inspect_dht_record(
subkeys: FfiStr,
scope: FfiStr,
) {
let key: veilid_core::TypedKey =
let key: veilid_core::TypedRecordKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
let subkeys: veilid_core::ValueSubkeyRangeSet =
veilid_core::deserialize_opt_json(subkeys.into_opt_string()).unwrap();
@ -1289,7 +1289,7 @@ pub extern "C" fn best_crypto_kind() -> u32 {
#[no_mangle]
#[instrument(level = "trace", target = "ffi", skip_all)]
pub extern "C" fn verify_signatures(port: i64, node_ids: FfiStr, data: FfiStr, signatures: FfiStr) {
let node_ids: Vec<veilid_core::TypedKey> =
let node_ids: Vec<veilid_core::TypedPublicKey> =
veilid_core::deserialize_opt_json(node_ids.into_opt_string()).unwrap();
let data: Vec<u8> = data_encoding::BASE64URL_NOPAD
@ -1740,9 +1740,9 @@ pub extern "C" fn crypto_validate_hash(port: i64, kind: u32, data: FfiStr, hash:
pub extern "C" fn crypto_distance(port: i64, kind: u32, key1: FfiStr, key2: FfiStr) {
let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind);
let key1: veilid_core::CryptoKey =
let key1: veilid_core::HashDigest =
veilid_core::deserialize_opt_json(key1.into_opt_string()).unwrap();
let key2: veilid_core::CryptoKey =
let key2: veilid_core::HashDigest =
veilid_core::deserialize_opt_json(key2.into_opt_string()).unwrap();
DartIsolateWrapper::new(port).spawn_result_json(
@ -1768,9 +1768,9 @@ pub extern "C" fn crypto_distance(port: i64, kind: u32, key1: FfiStr, key2: FfiS
pub extern "C" fn crypto_sign(port: i64, kind: u32, key: FfiStr, secret: FfiStr, data: FfiStr) {
let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind);
let key: veilid_core::CryptoKey =
let key: veilid_core::PublicKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
let secret: veilid_core::CryptoKey =
let secret: veilid_core::SecretKey =
veilid_core::deserialize_opt_json(secret.into_opt_string()).unwrap();
let data: Vec<u8> = data_encoding::BASE64URL_NOPAD
.decode(data.into_opt_string().unwrap().as_bytes())
@ -1805,7 +1805,7 @@ pub extern "C" fn crypto_verify(
) {
let kind: veilid_core::CryptoKind = veilid_core::FourCC::from(kind);
let key: veilid_core::CryptoKey =
let key: veilid_core::PublicKey =
veilid_core::deserialize_opt_json(key.into_opt_string()).unwrap();
let data: Vec<u8> = data_encoding::BASE64URL_NOPAD
.decode(data.into_opt_string().unwrap().as_bytes())

View file

@ -296,8 +296,8 @@ class CryptoSystem(ABC):
@abstractmethod
async def distance(
self, key1: types.CryptoKey, key2: types.CryptoKey
) -> types.CryptoKeyDistance:
self, key1: types.HashDigest, key2: types.HashDigest
) -> types.HashDistance:
pass
@abstractmethod

View file

@ -20,8 +20,7 @@ from .operations import (
)
from .state import VeilidState, VeilidUpdate
from .types import (
CryptoKey,
CryptoKeyDistance,
HashDistance,
CryptoKind,
DHTRecordDescriptor,
DHTRecordReport,
@ -1311,11 +1310,11 @@ class _JsonCryptoSystem(CryptoSystem):
)
)
async def distance(self, key1: CryptoKey, key2: CryptoKey) -> CryptoKeyDistance:
assert isinstance(key1, CryptoKey)
assert isinstance(key2, CryptoKey)
async def distance(self, key1: HashDigest, key2: HashDigest) -> HashDistance:
assert isinstance(key1, HashDigest)
assert isinstance(key2, HashDigest)
return CryptoKeyDistance(
return HashDistance(
raise_api_result(
await self.api.send_ndjson_request(
Operation.CRYPTO_SYSTEM,

View file

@ -126,27 +126,23 @@ class EncodedString(str):
return cls(urlsafe_b64encode_no_pad(b))
class CryptoKey(EncodedString):
class HashDistance(EncodedString):
pass
class CryptoKeyDistance(CryptoKey):
class PublicKey(EncodedString):
pass
class PublicKey(CryptoKey):
class SecretKey(EncodedString):
pass
class SecretKey(CryptoKey):
class SharedSecret(EncodedString):
pass
class SharedSecret(CryptoKey):
pass
class HashDigest(CryptoKey):
class HashDigest(EncodedString):
pass

View file

@ -20,7 +20,7 @@ use clap::{Args, Parser};
use server::*;
use settings::LogLevel;
use tools::*;
use veilid_core::{TypedKeyGroup, TypedSecretGroup};
use veilid_core::{TypedPublicKeyGroup, TypedSecretKeyGroup};
use veilid_logs::*;
#[derive(Args, Debug, Clone)]
@ -315,13 +315,13 @@ fn main() -> EyreResult<()> {
settingsrw.logging.terminal.enabled = false;
// Split or get secret
let tks = TypedKeyGroup::from_str(&key_set)
let tks = TypedPublicKeyGroup::from_str(&key_set)
.wrap_err("failed to decode node id set from command line")?;
let buffer = rpassword::prompt_password("Enter secret key set (will not echo): ")
.wrap_err("invalid secret key")?;
let buffer = buffer.trim().to_string();
let tss = TypedSecretGroup::from_str(&buffer).wrap_err("failed to decode secret set")?;
let tss = TypedSecretKeyGroup::from_str(&buffer).wrap_err("failed to decode secret set")?;
settingsrw.core.network.routing_table.node_id = Some(tks);
settingsrw.core.network.routing_table.node_id_secret = Some(tss);
@ -345,10 +345,10 @@ fn main() -> EyreResult<()> {
if let Some(bootstrap_keys) = args.bootstrap_keys {
println!("Overriding bootstrap keys with: ");
let mut bootstrap_keys_list: Vec<veilid_core::TypedKey> = Vec::new();
let mut bootstrap_keys_list: Vec<veilid_core::TypedPublicKey> = Vec::new();
for x in bootstrap_keys.split(',') {
let x = x.trim();
let key = match veilid_core::TypedKey::from_str(x) {
let key = match veilid_core::TypedPublicKey::from_str(x) {
Ok(v) => v,
Err(e) => {
bail!("Failed to parse bootstrap key: {}\n{}", e, x)
@ -425,13 +425,13 @@ fn main() -> EyreResult<()> {
// --- Generate DHT Key ---
if let Some(ckstr) = args.generate_key_pair {
if ckstr.is_empty() {
let mut tks = veilid_core::TypedKeyGroup::new();
let mut tss = veilid_core::TypedSecretGroup::new();
let mut tks = veilid_core::TypedPublicKeyGroup::new();
let mut tss = veilid_core::TypedSecretKeyGroup::new();
for ck in veilid_core::VALID_CRYPTO_KINDS {
let tkp =
veilid_core::Crypto::generate_keypair(ck).wrap_err("invalid crypto kind")?;
tks.add(veilid_core::TypedKey::new(tkp.kind, tkp.value.key));
tss.add(veilid_core::TypedSecret::new(tkp.kind, tkp.value.secret));
tks.add(veilid_core::TypedPublicKey::new(tkp.kind, tkp.value.key));
tss.add(veilid_core::TypedSecretKey::new(tkp.kind, tkp.value.secret));
}
println!("Public Keys:\n{}\nSecret Keys:\n{}\n", tks, tss);
} else {

Some files were not shown because too many files have changed in this diff Show more