cleanup dht stuff and client/server api
This commit is contained in:
@@ -71,9 +71,9 @@ pub struct BucketEntryLocalNetwork {
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct BucketEntryInner {
|
||||
/// The node ids matching this bucket entry, with the cryptography versions supported by this node as the 'kind' field
|
||||
validated_node_ids: TypedKeySet,
|
||||
validated_node_ids: TypedKeyGroup,
|
||||
/// The node ids claimed by the remote node that use cryptography versions we do not support
|
||||
unsupported_node_ids: TypedKeySet,
|
||||
unsupported_node_ids: TypedKeyGroup,
|
||||
/// 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
|
||||
@@ -123,7 +123,7 @@ impl BucketEntryInner {
|
||||
}
|
||||
|
||||
/// Get all node ids
|
||||
pub fn node_ids(&self) -> TypedKeySet {
|
||||
pub fn node_ids(&self) -> TypedKeyGroup {
|
||||
let mut node_ids = self.validated_node_ids.clone();
|
||||
node_ids.add_all(&self.unsupported_node_ids);
|
||||
node_ids
|
||||
@@ -786,8 +786,8 @@ impl BucketEntry {
|
||||
|
||||
let now = get_aligned_timestamp();
|
||||
let inner = BucketEntryInner {
|
||||
validated_node_ids: TypedKeySet::from(first_node_id),
|
||||
unsupported_node_ids: TypedKeySet::new(),
|
||||
validated_node_ids: TypedKeyGroup::from(first_node_id),
|
||||
unsupported_node_ids: TypedKeyGroup::new(),
|
||||
envelope_support: Vec::new(),
|
||||
updated_since_last_network_change: false,
|
||||
last_connections: BTreeMap::new(),
|
||||
|
@@ -82,9 +82,9 @@ pub struct RoutingTableUnlockedInner {
|
||||
network_manager: NetworkManager,
|
||||
|
||||
/// The current node's public DHT keys
|
||||
node_id: TypedKeySet,
|
||||
node_id: TypedKeyGroup,
|
||||
/// The current node's public DHT secrets
|
||||
node_id_secret: TypedSecretSet,
|
||||
node_id_secret: TypedSecretGroup,
|
||||
/// Buckets to kick on our next kick task
|
||||
kick_queue: Mutex<BTreeSet<BucketIndex>>,
|
||||
/// Background process for computing statistics
|
||||
@@ -131,7 +131,7 @@ impl RoutingTableUnlockedInner {
|
||||
self.node_id_secret.get(kind).unwrap().value
|
||||
}
|
||||
|
||||
pub fn node_ids(&self) -> TypedKeySet {
|
||||
pub fn node_ids(&self) -> TypedKeyGroup {
|
||||
self.node_id.clone()
|
||||
}
|
||||
|
||||
@@ -648,7 +648,7 @@ impl RoutingTable {
|
||||
inner.get_all_nodes(self.clone(), cur_ts)
|
||||
}
|
||||
|
||||
fn queue_bucket_kicks(&self, node_ids: TypedKeySet) {
|
||||
fn queue_bucket_kicks(&self, node_ids: TypedKeyGroup) {
|
||||
for node_id in node_ids.iter() {
|
||||
// Skip node ids we didn't add to buckets
|
||||
if !VALID_CRYPTO_KINDS.contains(&node_id.kind) {
|
||||
|
@@ -106,7 +106,7 @@ pub trait NodeRefBase: Sized {
|
||||
fn routing_table(&self) -> RoutingTable {
|
||||
self.common().routing_table.clone()
|
||||
}
|
||||
fn node_ids(&self) -> TypedKeySet {
|
||||
fn node_ids(&self) -> TypedKeyGroup {
|
||||
self.operate(|_rti, e| e.node_ids())
|
||||
}
|
||||
fn best_node_id(&self) -> TypedKey {
|
||||
|
@@ -59,8 +59,8 @@ impl RouteSetSpecDetail {
|
||||
pub fn get_route_by_key_mut(&mut self, key: &PublicKey) -> Option<&mut RouteSpecDetail> {
|
||||
self.route_set.get_mut(key)
|
||||
}
|
||||
pub fn get_route_set_keys(&self) -> TypedKeySet {
|
||||
let mut tks = TypedKeySet::new();
|
||||
pub fn get_route_set_keys(&self) -> TypedKeyGroup {
|
||||
let mut tks = TypedKeyGroup::new();
|
||||
for (k, v) in &self.route_set {
|
||||
tks.add(TypedKey::new(v.crypto_kind, *k));
|
||||
}
|
||||
|
@@ -117,14 +117,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: &TypedKeySet) -> usize {
|
||||
pub fn get_used_node_count(&self, node_ids: &TypedKeyGroup) -> 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: &TypedKeySet) -> usize {
|
||||
pub fn get_used_end_node_count(&self, node_ids: &TypedKeyGroup) -> usize {
|
||||
node_ids.iter().fold(0usize, |acc, k| {
|
||||
acc + self
|
||||
.used_end_nodes
|
||||
|
@@ -658,7 +658,7 @@ impl RoutingTableInner {
|
||||
fn create_node_ref<F>(
|
||||
&mut self,
|
||||
outer_self: RoutingTable,
|
||||
node_ids: &TypedKeySet,
|
||||
node_ids: &TypedKeyGroup,
|
||||
update_func: F,
|
||||
) -> EyreResult<NodeRef>
|
||||
where
|
||||
@@ -873,7 +873,7 @@ impl RoutingTableInner {
|
||||
descriptor: ConnectionDescriptor,
|
||||
timestamp: Timestamp,
|
||||
) -> EyreResult<NodeRef> {
|
||||
let nr = self.create_node_ref(outer_self, &TypedKeySet::from(node_id), |_rti, e| {
|
||||
let nr = self.create_node_ref(outer_self, &TypedKeyGroup::from(node_id), |_rti, e| {
|
||||
// this node is live because it literally just connected to us
|
||||
e.touch_last_seen(timestamp);
|
||||
})?;
|
||||
|
@@ -7,7 +7,7 @@ pub const BOOTSTRAP_TXT_VERSION_0: u8 = 0;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct BootstrapRecord {
|
||||
node_ids: TypedKeySet,
|
||||
node_ids: TypedKeyGroup,
|
||||
envelope_support: Vec<u8>,
|
||||
dial_info_details: Vec<DialInfoDetail>,
|
||||
}
|
||||
@@ -63,7 +63,7 @@ impl RoutingTable {
|
||||
envelope_support.sort();
|
||||
|
||||
// Node Id
|
||||
let mut node_ids = TypedKeySet::new();
|
||||
let mut node_ids = TypedKeyGroup::new();
|
||||
for node_id_str in records[2].split(",") {
|
||||
let node_id_str = node_id_str.trim();
|
||||
let node_id = match TypedKey::from_str(&node_id_str) {
|
||||
|
@@ -83,7 +83,7 @@ pub async fn test_routingtable_buckets_round_trip() {
|
||||
}
|
||||
|
||||
pub async fn test_round_trip_peerinfo() {
|
||||
let mut tks = TypedKeySet::new();
|
||||
let mut tks = TypedKeyGroup::new();
|
||||
tks.add(TypedKey::new(
|
||||
CRYPTO_KIND_VLD0,
|
||||
CryptoKey::new([
|
||||
|
@@ -5,12 +5,12 @@ use super::*;
|
||||
)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct PeerInfo {
|
||||
node_ids: TypedKeySet,
|
||||
node_ids: TypedKeyGroup,
|
||||
signed_node_info: SignedNodeInfo,
|
||||
}
|
||||
|
||||
impl PeerInfo {
|
||||
pub fn new(node_ids: TypedKeySet, signed_node_info: SignedNodeInfo) -> Self {
|
||||
pub fn new(node_ids: TypedKeyGroup, signed_node_info: SignedNodeInfo) -> Self {
|
||||
assert!(node_ids.len() > 0 && node_ids.len() <= MAX_CRYPTO_KINDS);
|
||||
Self {
|
||||
node_ids,
|
||||
@@ -27,13 +27,13 @@ impl PeerInfo {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn node_ids(&self) -> &TypedKeySet {
|
||||
pub fn node_ids(&self) -> &TypedKeyGroup {
|
||||
&self.node_ids
|
||||
}
|
||||
pub fn signed_node_info(&self) -> &SignedNodeInfo {
|
||||
&self.signed_node_info
|
||||
}
|
||||
pub fn destructure(self) -> (TypedKeySet, SignedNodeInfo) {
|
||||
pub fn destructure(self) -> (TypedKeyGroup, SignedNodeInfo) {
|
||||
(self.node_ids, self.signed_node_info)
|
||||
}
|
||||
|
||||
|
@@ -22,7 +22,11 @@ impl SignedDirectNodeInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate(&self, node_ids: &TypedKeySet, crypto: Crypto) -> VeilidAPIResult<TypedKeySet> {
|
||||
pub fn validate(
|
||||
&self,
|
||||
node_ids: &TypedKeyGroup,
|
||||
crypto: Crypto,
|
||||
) -> VeilidAPIResult<TypedKeyGroup> {
|
||||
let node_info_bytes = Self::make_signature_bytes(&self.node_info, self.timestamp)?;
|
||||
|
||||
// Verify the signatures that we can
|
||||
|
@@ -10,7 +10,11 @@ pub enum SignedNodeInfo {
|
||||
}
|
||||
|
||||
impl SignedNodeInfo {
|
||||
pub fn validate(&self, node_ids: &TypedKeySet, crypto: Crypto) -> VeilidAPIResult<TypedKeySet> {
|
||||
pub fn validate(
|
||||
&self,
|
||||
node_ids: &TypedKeyGroup,
|
||||
crypto: Crypto,
|
||||
) -> VeilidAPIResult<TypedKeyGroup> {
|
||||
match self {
|
||||
SignedNodeInfo::Direct(d) => d.validate(node_ids, crypto),
|
||||
SignedNodeInfo::Relayed(r) => r.validate(node_ids, crypto),
|
||||
@@ -36,9 +40,9 @@ impl SignedNodeInfo {
|
||||
SignedNodeInfo::Relayed(r) => &r.node_info(),
|
||||
}
|
||||
}
|
||||
pub fn relay_ids(&self) -> TypedKeySet {
|
||||
pub fn relay_ids(&self) -> TypedKeyGroup {
|
||||
match self {
|
||||
SignedNodeInfo::Direct(_) => TypedKeySet::new(),
|
||||
SignedNodeInfo::Direct(_) => TypedKeyGroup::new(),
|
||||
SignedNodeInfo::Relayed(r) => r.relay_ids().clone(),
|
||||
}
|
||||
}
|
||||
|
@@ -7,7 +7,7 @@ use super::*;
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct SignedRelayedNodeInfo {
|
||||
node_info: NodeInfo,
|
||||
relay_ids: TypedKeySet,
|
||||
relay_ids: TypedKeyGroup,
|
||||
relay_info: SignedDirectNodeInfo,
|
||||
timestamp: Timestamp,
|
||||
signatures: Vec<TypedSignature>,
|
||||
@@ -19,7 +19,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: TypedKeySet,
|
||||
relay_ids: TypedKeyGroup,
|
||||
relay_info: SignedDirectNodeInfo,
|
||||
timestamp: Timestamp,
|
||||
signatures: Vec<TypedSignature>,
|
||||
@@ -33,7 +33,11 @@ impl SignedRelayedNodeInfo {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn validate(&self, node_ids: &TypedKeySet, crypto: Crypto) -> VeilidAPIResult<TypedKeySet> {
|
||||
pub fn validate(
|
||||
&self,
|
||||
node_ids: &TypedKeyGroup,
|
||||
crypto: Crypto,
|
||||
) -> VeilidAPIResult<TypedKeyGroup> {
|
||||
// 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(),
|
||||
@@ -64,7 +68,7 @@ impl SignedRelayedNodeInfo {
|
||||
crypto: Crypto,
|
||||
typed_key_pairs: Vec<TypedKeyPair>,
|
||||
node_info: NodeInfo,
|
||||
relay_ids: TypedKeySet,
|
||||
relay_ids: TypedKeyGroup,
|
||||
relay_info: SignedDirectNodeInfo,
|
||||
) -> VeilidAPIResult<Self> {
|
||||
let timestamp = get_aligned_timestamp();
|
||||
@@ -128,7 +132,7 @@ impl SignedRelayedNodeInfo {
|
||||
pub fn timestamp(&self) -> Timestamp {
|
||||
self.timestamp
|
||||
}
|
||||
pub fn relay_ids(&self) -> &TypedKeySet {
|
||||
pub fn relay_ids(&self) -> &TypedKeyGroup {
|
||||
&self.relay_ids
|
||||
}
|
||||
pub fn relay_info(&self) -> &SignedDirectNodeInfo {
|
||||
|
Reference in New Issue
Block a user