checkpoint

This commit is contained in:
John Smith
2023-02-11 15:54:55 -05:00
parent 064e6c018c
commit 1ba0cdb9cf
42 changed files with 655 additions and 350 deletions

View File

@@ -167,7 +167,7 @@ impl VeilidAPI {
// Private route allocation
#[instrument(level = "debug", skip(self))]
pub async fn new_private_route(&self) -> Result<(PublicKey, Vec<u8>), VeilidAPIError> {
pub async fn new_private_route(&self) -> Result<(TypedKey, Vec<u8>), VeilidAPIError> {
self.new_custom_private_route(Stability::default(), Sequencing::default())
.await
}
@@ -177,7 +177,7 @@ impl VeilidAPI {
&self,
stability: Stability,
sequencing: Sequencing,
) -> Result<(PublicKey, Vec<u8>), VeilidAPIError> {
) -> Result<(TypedKey, Vec<u8>), VeilidAPIError> {
let default_route_hop_count: usize = {
let config = self.config()?;
let c = config.get();
@@ -223,14 +223,14 @@ impl VeilidAPI {
}
#[instrument(level = "debug", skip(self))]
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> Result<PublicKey, VeilidAPIError> {
pub fn import_remote_private_route(&self, blob: Vec<u8>) -> Result<TypedKey, VeilidAPIError> {
let rss = self.routing_table()?.route_spec_store();
rss.import_remote_private_route(blob)
.map_err(|e| VeilidAPIError::invalid_argument(e, "blob", "private route blob"))
}
#[instrument(level = "debug", skip(self))]
pub fn release_private_route(&self, key: &PublicKey) -> Result<(), VeilidAPIError> {
pub fn release_private_route(&self, key: &TypedKey) -> Result<(), VeilidAPIError> {
let rss = self.routing_table()?.route_spec_store();
if rss.release_route(key) {
Ok(())

View File

@@ -7,7 +7,7 @@ use routing_table::*;
#[derive(Default, Debug)]
struct DebugCache {
imported_routes: Vec<PublicKey>,
imported_routes: Vec<TypedKey>,
}
static DEBUG_CACHE: Mutex<DebugCache> = Mutex::new(DebugCache {
@@ -30,12 +30,12 @@ fn get_string(text: &str) -> Option<String> {
Some(text.to_owned())
}
fn get_route_id(rss: RouteSpecStore) -> impl Fn(&str) -> Option<PublicKey> {
fn get_route_id(rss: RouteSpecStore) -> impl Fn(&str) -> Option<TypedKey> {
return move |text: &str| {
if text.is_empty() {
return None;
}
match PublicKey::try_decode(text).ok() {
match TypedKey::try_decode(text).ok() {
Some(key) => {
let routes = rss.list_allocated_routes(|k, _| Some(*k));
if routes.contains(&key) {
@@ -187,8 +187,8 @@ fn get_destination(routing_table: RoutingTable) -> impl FnOnce(&str) -> Option<D
fn get_number(text: &str) -> Option<usize> {
usize::from_str(text).ok()
}
fn get_dht_key(text: &str) -> Option<PublicKey> {
PublicKey::try_decode(text).ok()
fn get_dht_key(text: &str) -> Option<TypedKey> {
TypedKey::try_decode(text).ok()
}
fn get_node_ref(routing_table: RoutingTable) -> impl FnOnce(&str) -> Option<NodeRef> {

View File

@@ -108,11 +108,11 @@ pub enum VeilidAPIError {
#[error("Shutdown")]
Shutdown,
#[error("Key not found: {key}")]
KeyNotFound { key: PublicKey },
KeyNotFound { key: TypedKey },
#[error("No connection: {message}")]
NoConnection { message: String },
#[error("No peer info: {node_id}")]
NoPeerInfo { node_id: PublicKey },
NoPeerInfo { node_id: TypedKey },
#[error("Internal: {message}")]
Internal { message: String },
#[error("Unimplemented: {message}")]
@@ -147,7 +147,7 @@ impl VeilidAPIError {
pub fn shutdown() -> Self {
Self::Shutdown
}
pub fn key_not_found(key: PublicKey) -> Self {
pub fn key_not_found(key: TypedKey) -> Self {
Self::KeyNotFound { key }
}
pub fn no_connection<T: ToString>(msg: T) -> Self {
@@ -155,7 +155,7 @@ impl VeilidAPIError {
message: msg.to_string(),
}
}
pub fn no_peer_info(node_id: PublicKey) -> Self {
pub fn no_peer_info(node_id: TypedKey) -> Self {
Self::NoPeerInfo { node_id }
}
pub fn internal<T: ToString>(msg: T) -> Self {

View File

@@ -4,8 +4,8 @@ use super::*;
#[derive(Clone, Debug)]
pub enum Target {
NodeId(PublicKey),
PrivateRoute(PublicKey),
NodeId(TypedKey),
PrivateRoute(TypedKey),
}
pub struct RoutingContextInner {}

View File

@@ -256,7 +256,7 @@ pub struct VeilidStateAttachment {
)]
#[archive_attr(repr(C), derive(CheckBytes))]
pub struct PeerTableData {
pub node_ids: Vec<TypedKey>,
pub node_ids: TypedKeySet,
pub peer_address: PeerAddress,
pub peer_stats: PeerStats,
}
@@ -279,8 +279,8 @@ pub struct VeilidStateNetwork {
)]
#[archive_attr(repr(C), derive(CheckBytes))]
pub struct VeilidStateRoute {
pub dead_routes: Vec<PublicKey>,
pub dead_remote_routes: Vec<PublicKey>,
pub dead_routes: Vec<TypedKey>,
pub dead_remote_routes: Vec<TypedKey>,
}
#[derive(
@@ -513,7 +513,7 @@ impl SafetySelection {
#[archive_attr(repr(C), derive(CheckBytes))]
pub struct SafetySpec {
/// preferred safety route if it still exists
pub preferred_route: Option<PublicKey>,
pub preferred_route: Option<TypedKey>,
/// must be greater than 0
pub hop_count: usize,
/// prefer reliability over speed
@@ -1924,7 +1924,7 @@ impl SignedDirectNodeInfo {
#[archive_attr(repr(C), derive(CheckBytes))]
pub struct SignedRelayedNodeInfo {
pub node_info: NodeInfo,
pub relay_ids: Vec<TypedKey>,
pub relay_ids: TypedKeySet,
pub relay_info: SignedDirectNodeInfo,
pub timestamp: Timestamp,
pub signatures: Vec<TypedSignature>,
@@ -1935,7 +1935,7 @@ impl SignedRelayedNodeInfo {
crypto: Crypto,
node_ids: &[TypedKey],
node_info: NodeInfo,
relay_ids: Vec<TypedKey>,
relay_ids: TypedKeySet,
relay_info: SignedDirectNodeInfo,
timestamp: Timestamp,
typed_signatures: Vec<TypedSignature>,
@@ -1955,7 +1955,7 @@ impl SignedRelayedNodeInfo {
pub fn make_signatures(
crypto: Crypto,
node_info: NodeInfo,
relay_ids: Vec<TypedKey>,
relay_ids: TypedKeySet,
relay_info: SignedDirectNodeInfo,
typed_key_pairs: Vec<TypedKeyPair>,
) -> Result<Self, VeilidAPIError> {
@@ -2043,9 +2043,9 @@ impl SignedNodeInfo {
SignedNodeInfo::Relayed(r) => &r.node_info,
}
}
pub fn relay_ids(&self) -> Vec<TypedKey> {
pub fn relay_ids(&self) -> TypedKeySet {
match self {
SignedNodeInfo::Direct(_) => Vec::new(),
SignedNodeInfo::Direct(_) => TypedKeySet::new(),
SignedNodeInfo::Relayed(r) => r.relay_ids.clone(),
}
}
@@ -2107,12 +2107,12 @@ impl SignedNodeInfo {
#[derive(Clone, Debug, Serialize, Deserialize, RkyvArchive, RkyvSerialize, RkyvDeserialize)]
#[archive_attr(repr(C), derive(CheckBytes))]
pub struct PeerInfo {
pub node_ids: Vec<TypedKey>,
pub node_ids: TypedKeySet,
pub signed_node_info: SignedNodeInfo,
}
impl PeerInfo {
pub fn new(node_ids: Vec<TypedKey>, signed_node_info: SignedNodeInfo) -> Self {
pub fn new(node_ids: TypedKeySet, signed_node_info: SignedNodeInfo) -> Self {
Self {
node_ids,
signed_node_info,