bug fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use core::sync::atomic::{AtomicU32, Ordering};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use rkyv::with::Skip;
|
||||
|
||||
/// Reliable pings are done with increased spacing between pings
|
||||
|
||||
@@ -40,10 +40,11 @@ pub enum BucketEntryState {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, PartialOrd, Ord, Hash)]
|
||||
struct LastConnectionKey(ProtocolType, AddressType);
|
||||
pub struct LastConnectionKey(ProtocolType, AddressType);
|
||||
|
||||
/// Bucket entry information specific to the LocalNetwork RoutingDomain
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct BucketEntryPublicInternet {
|
||||
/// The PublicInternet node info
|
||||
signed_node_info: Option<Box<SignedNodeInfo>>,
|
||||
@@ -54,7 +55,8 @@ pub struct BucketEntryPublicInternet {
|
||||
}
|
||||
|
||||
/// Bucket entry information specific to the LocalNetwork RoutingDomain
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct BucketEntryLocalNetwork {
|
||||
/// The LocalNetwork node info
|
||||
signed_node_info: Option<Box<SignedNodeInfo>>,
|
||||
@@ -65,16 +67,18 @@ pub struct BucketEntryLocalNetwork {
|
||||
}
|
||||
|
||||
/// A range of cryptography versions supported by this entry
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Copy, Clone, Debug, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct VersionRange {
|
||||
/// The minimum cryptography version supported by this entry
|
||||
min: u8,
|
||||
pub min: u8,
|
||||
/// The maximum cryptography version supported by this entry
|
||||
max: u8,
|
||||
pub max: u8,
|
||||
}
|
||||
|
||||
/// The data associated with each bucket entry
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[derive(Debug, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct BucketEntryInner {
|
||||
/// The minimum and maximum range of cryptography versions supported by the node,
|
||||
/// inclusive of the requirements of any relay the node may be using
|
||||
@@ -83,7 +87,7 @@ pub struct BucketEntryInner {
|
||||
/// and dial info has last changed, for example when our IP address changes
|
||||
updated_since_last_network_change: bool,
|
||||
/// The last connection descriptors used to contact this node, per protocol type
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
last_connections: BTreeMap<LastConnectionKey, (ConnectionDescriptor, u64)>,
|
||||
/// The node info for this entry on the publicinternet routing domain
|
||||
public_internet: BucketEntryPublicInternet,
|
||||
@@ -92,18 +96,18 @@ pub struct BucketEntryInner {
|
||||
/// Statistics gathered for the peer
|
||||
peer_stats: PeerStats,
|
||||
/// The accounting for the latency statistics
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
latency_stats_accounting: LatencyStatsAccounting,
|
||||
/// The accounting for the transfer statistics
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
transfer_stats_accounting: TransferStatsAccounting,
|
||||
/// Tracking identifier for NodeRef debugging
|
||||
#[cfg(feature = "tracking")]
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
next_track_id: usize,
|
||||
/// Backtraces for NodeRef debugging
|
||||
#[cfg(feature = "tracking")]
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
node_ref_tracks: HashMap<usize, backtrace::Backtrace>,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::*;
|
||||
|
||||
impl RoutingTable {
|
||||
pub fn debug_info_nodeinfo(&self) -> String {
|
||||
pub(crate) fn debug_info_nodeinfo(&self) -> String {
|
||||
let mut out = String::new();
|
||||
let inner = self.inner.read();
|
||||
out += "Routing Table Info:\n";
|
||||
@@ -23,7 +23,7 @@ impl RoutingTable {
|
||||
out
|
||||
}
|
||||
|
||||
pub async fn debug_info_txtrecord(&self) -> String {
|
||||
pub(crate) async fn debug_info_txtrecord(&self) -> String {
|
||||
let mut out = String::new();
|
||||
|
||||
let gdis = self.dial_info_details(RoutingDomain::PublicInternet);
|
||||
@@ -71,7 +71,7 @@ impl RoutingTable {
|
||||
out
|
||||
}
|
||||
|
||||
pub fn debug_info_dialinfo(&self) -> String {
|
||||
pub(crate) fn debug_info_dialinfo(&self) -> String {
|
||||
let ldis = self.dial_info_details(RoutingDomain::LocalNetwork);
|
||||
let gdis = self.dial_info_details(RoutingDomain::PublicInternet);
|
||||
let mut out = String::new();
|
||||
@@ -100,7 +100,7 @@ impl RoutingTable {
|
||||
out
|
||||
}
|
||||
|
||||
pub fn debug_info_entries(&self, limit: usize, min_state: BucketEntryState) -> String {
|
||||
pub(crate) fn debug_info_entries(&self, limit: usize, min_state: BucketEntryState) -> String {
|
||||
let inner = self.inner.read();
|
||||
let inner = &*inner;
|
||||
let cur_ts = intf::get_timestamp();
|
||||
@@ -148,7 +148,7 @@ impl RoutingTable {
|
||||
out
|
||||
}
|
||||
|
||||
pub fn debug_info_entry(&self, node_id: DHTKey) -> String {
|
||||
pub(crate) fn debug_info_entry(&self, node_id: DHTKey) -> String {
|
||||
let mut out = String::new();
|
||||
out += &format!("Entry {:?}:\n", node_id);
|
||||
if let Some(nr) = self.lookup_node_ref(node_id) {
|
||||
@@ -160,7 +160,7 @@ impl RoutingTable {
|
||||
out
|
||||
}
|
||||
|
||||
pub fn debug_info_buckets(&self, min_state: BucketEntryState) -> String {
|
||||
pub(crate) fn debug_info_buckets(&self, min_state: BucketEntryState) -> String {
|
||||
let inner = self.inner.read();
|
||||
let inner = &*inner;
|
||||
let cur_ts = intf::get_timestamp();
|
||||
|
||||
@@ -239,7 +239,7 @@ impl RoutingTable {
|
||||
let tdb = table_store.open("routing_table", 1).await?;
|
||||
let bucket_count = bucketvec.len();
|
||||
let mut dbx = tdb.transact();
|
||||
if let Err(e) = dbx.store_frozen(0, b"bucket_count", &bucket_count) {
|
||||
if let Err(e) = dbx.store_rkyv(0, b"bucket_count", &bucket_count) {
|
||||
dbx.rollback();
|
||||
return Err(e);
|
||||
}
|
||||
@@ -845,8 +845,8 @@ impl RoutingTable {
|
||||
}
|
||||
|
||||
// node can not be its own relay
|
||||
if let Some(rpi) = &p.signed_node_info.node_info.relay_peer_info {
|
||||
if rpi.node_id == p.node_id {
|
||||
if let Some(rid) = &p.signed_node_info.relay_id() {
|
||||
if rid.key == p.node_id.key {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::*;
|
||||
use crate::veilid_api::*;
|
||||
use serde::*;
|
||||
use rkyv::with::Skip;
|
||||
|
||||
/// Compiled route (safety route + private route)
|
||||
#[derive(Clone, Debug)]
|
||||
@@ -13,32 +13,40 @@ pub struct CompiledRoute {
|
||||
pub first_hop: NodeRef,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
struct RouteSpecDetail {
|
||||
#[derive(Clone, Debug, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct KeyPair {
|
||||
key: DHTKey,
|
||||
secret: DHTKeySecret,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct RouteSpecDetail {
|
||||
/// Secret key
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
pub secret_key: DHTKeySecret,
|
||||
/// Route hops
|
||||
pub hops: Vec<DHTKey>,
|
||||
/// Route noderefs
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
hop_node_refs: Vec<NodeRef>,
|
||||
/// Transfers up and down
|
||||
transfer_stats_down_up: TransferStatsDownUp,
|
||||
/// Latency stats
|
||||
latency_stats: LatencyStats,
|
||||
/// Accounting mechanism for this route's RPC latency
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
latency_stats_accounting: LatencyStatsAccounting,
|
||||
/// Accounting mechanism for the bandwidth across this route
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
transfer_stats_accounting: TransferStatsAccounting,
|
||||
/// Published private route, do not reuse for ephemeral routes
|
||||
/// Not serialized because all routes should be re-published when restarting
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
published: bool,
|
||||
// Can optimize the rendering of this route, using node ids only instead of full peer info
|
||||
#[serde(skip)]
|
||||
#[with(Skip)]
|
||||
reachable: bool,
|
||||
/// Timestamp of when the route was created
|
||||
created_ts: u64,
|
||||
@@ -47,6 +55,7 @@ struct RouteSpecDetail {
|
||||
/// Timestamp of when the route was last used for anything
|
||||
last_used_ts: Option<u64>,
|
||||
/// Directions this route is guaranteed to work in
|
||||
#[with(RkyvEnumSet)]
|
||||
directions: DirectionSet,
|
||||
/// Stability preference (prefer reliable nodes over faster)
|
||||
pub stability: Stability,
|
||||
@@ -55,7 +64,8 @@ struct RouteSpecDetail {
|
||||
}
|
||||
|
||||
/// The core representation of the RouteSpecStore that can be serialized
|
||||
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Default, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
|
||||
#[archive_attr(repr(C), derive(CheckBytes))]
|
||||
pub struct RouteSpecStoreContent {
|
||||
/// All of the routes we have allocated so far
|
||||
details: HashMap<DHTKey, RouteSpecDetail>,
|
||||
@@ -225,7 +235,7 @@ impl RouteSpecStore {
|
||||
let table_store = routing_table.network_manager().table_store();
|
||||
let rsstdb = table_store.open("RouteSpecStore", 1).await?;
|
||||
let mut content: RouteSpecStoreContent =
|
||||
rsstdb.load_json(0, b"content")?.unwrap_or_default();
|
||||
rsstdb.load_rkyv(0, b"content")?.unwrap_or_default();
|
||||
|
||||
// Look up all route hop noderefs since we can't serialize those
|
||||
let mut dead_keys = Vec::new();
|
||||
@@ -245,17 +255,17 @@ impl RouteSpecStore {
|
||||
|
||||
// Load secrets from pstore
|
||||
let pstore = routing_table.network_manager().protected_store();
|
||||
let out: Vec<(DHTKey, DHTKeySecret)> = pstore
|
||||
let out: Vec<KeyPair> = pstore
|
||||
.load_user_secret_rkyv("RouteSpecStore")
|
||||
.await?
|
||||
.unwrap_or_default();
|
||||
|
||||
let mut dead_keys = Vec::new();
|
||||
for (k, v) in out {
|
||||
if let Some(rsd) = content.details.get_mut(&k) {
|
||||
rsd.secret_key = v;
|
||||
for KeyPair { key, secret } in out {
|
||||
if let Some(rsd) = content.details.get_mut(&key) {
|
||||
rsd.secret_key = secret;
|
||||
} else {
|
||||
dead_keys.push(k);
|
||||
dead_keys.push(key);
|
||||
}
|
||||
}
|
||||
for k in dead_keys {
|
||||
@@ -296,7 +306,7 @@ impl RouteSpecStore {
|
||||
.network_manager()
|
||||
.table_store();
|
||||
let rsstdb = table_store.open("RouteSpecStore", 1).await?;
|
||||
rsstdb.store_json(0, b"content", &content)?;
|
||||
rsstdb.store_rkyv(0, b"content", &content)?;
|
||||
|
||||
// // Keep secrets in protected store as well
|
||||
let pstore = self
|
||||
@@ -305,14 +315,15 @@ impl RouteSpecStore {
|
||||
.network_manager()
|
||||
.protected_store();
|
||||
|
||||
let mut out: Vec<(DHTKey, DHTKeySecret)> = Vec::with_capacity(content.details.len());
|
||||
let mut out: Vec<KeyPair> = Vec::with_capacity(content.details.len());
|
||||
for (k, v) in &content.details {
|
||||
out.push((*k, v.secret_key));
|
||||
out.push(KeyPair {
|
||||
key: *k,
|
||||
secret: v.secret_key,
|
||||
});
|
||||
}
|
||||
|
||||
let _ = pstore
|
||||
.save_user_secret_frozen("RouteSpecStore", &out)
|
||||
.await?; // ignore if this previously existed or not
|
||||
let _ = pstore.save_user_secret_rkyv("RouteSpecStore", &out).await?; // ignore if this previously existed or not
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user