refactor checkpoint
This commit is contained in:
@@ -2002,25 +2002,6 @@ impl VeilidAPI {
|
||||
.map_err(|e| VeilidAPIError::internal(e))
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Safety / Private Route Handling
|
||||
|
||||
#[instrument(level = "debug", err, skip(self))]
|
||||
pub async fn new_safety_route_spec(
|
||||
&self,
|
||||
_hops: u8,
|
||||
) -> Result<SafetyRouteSpec, VeilidAPIError> {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
|
||||
#[instrument(level = "debug", err, skip(self))]
|
||||
pub async fn new_private_route_spec(
|
||||
&self,
|
||||
_hops: u8,
|
||||
) -> Result<PrivateRouteSpec, VeilidAPIError> {
|
||||
panic!("unimplemented");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
// Routing Context
|
||||
|
||||
|
@@ -9,35 +9,17 @@ pub struct RouteHopSpec {
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct PrivateRouteSpec {
|
||||
pub struct RouteSpec {
|
||||
//
|
||||
pub public_key: DHTKey,
|
||||
pub secret_key: DHTKeySecret,
|
||||
pub hops: Vec<RouteHopSpec>,
|
||||
}
|
||||
|
||||
impl PrivateRouteSpec {
|
||||
impl RouteSpec {
|
||||
pub fn new() -> Self {
|
||||
let (pk, sk) = generate_secret();
|
||||
PrivateRouteSpec {
|
||||
public_key: pk,
|
||||
secret_key: sk,
|
||||
hops: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
||||
pub struct SafetyRouteSpec {
|
||||
pub public_key: DHTKey,
|
||||
pub secret_key: DHTKeySecret,
|
||||
pub hops: Vec<RouteHopSpec>,
|
||||
}
|
||||
|
||||
impl SafetyRouteSpec {
|
||||
pub fn new() -> Self {
|
||||
let (pk, sk) = generate_secret();
|
||||
SafetyRouteSpec {
|
||||
RouteSpec {
|
||||
public_key: pk,
|
||||
secret_key: sk,
|
||||
hops: Vec::new(),
|
||||
|
@@ -10,10 +10,8 @@ pub enum Target {
|
||||
pub struct RoutingContextInner {}
|
||||
|
||||
pub struct RoutingContextUnlockedInner {
|
||||
/// Safety route specified here is for _this_ node's anonymity as a sender, used via the 'route' operation
|
||||
safety_route_spec: Option<Arc<SafetyRouteSpec>>,
|
||||
/// Private route specified here is for _this_ node's anonymity as a receiver, passed out via the 'respond_to' field for replies
|
||||
private_route_spec: Option<Arc<PrivateRouteSpec>>,
|
||||
/// Enforce use of private routing
|
||||
privacy: bool,
|
||||
/// Choose reliable protocols over unreliable/faster protocols when available
|
||||
reliable: bool,
|
||||
}
|
||||
@@ -43,24 +41,18 @@ impl RoutingContext {
|
||||
api,
|
||||
inner: Arc::new(Mutex::new(RoutingContextInner {})),
|
||||
unlocked_inner: Arc::new(RoutingContextUnlockedInner {
|
||||
safety_route_spec: None,
|
||||
private_route_spec: None,
|
||||
privacy: false,
|
||||
reliable: false,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_privacy(
|
||||
self,
|
||||
safety_route_spec: SafetyRouteSpec,
|
||||
private_route_spec: PrivateRouteSpec,
|
||||
) -> Self {
|
||||
pub fn with_privacy(self) -> Self {
|
||||
Self {
|
||||
api: self.api.clone(),
|
||||
inner: Arc::new(Mutex::new(RoutingContextInner {})),
|
||||
unlocked_inner: Arc::new(RoutingContextUnlockedInner {
|
||||
safety_route_spec: Some(Arc::new(safety_route_spec)),
|
||||
private_route_spec: Some(Arc::new(private_route_spec)),
|
||||
privacy: true,
|
||||
reliable: self.unlocked_inner.reliable,
|
||||
}),
|
||||
}
|
||||
@@ -71,8 +63,7 @@ impl RoutingContext {
|
||||
api: self.api.clone(),
|
||||
inner: Arc::new(Mutex::new(RoutingContextInner {})),
|
||||
unlocked_inner: Arc::new(RoutingContextUnlockedInner {
|
||||
safety_route_spec: self.unlocked_inner.safety_route_spec.clone(),
|
||||
private_route_spec: self.unlocked_inner.private_route_spec.clone(),
|
||||
privacy: self.unlocked_inner.privacy,
|
||||
reliable: true,
|
||||
}),
|
||||
}
|
||||
@@ -102,12 +93,13 @@ impl RoutingContext {
|
||||
}
|
||||
Ok(rpc_processor::Destination::Direct {
|
||||
target: nr,
|
||||
safety_route_spec: self.unlocked_inner.safety_route_spec.clone(),
|
||||
safety: self.unlocked_inner.privacy,
|
||||
})
|
||||
}
|
||||
Target::PrivateRoute(pr) => Ok(rpc_processor::Destination::PrivateRoute {
|
||||
private_route: pr,
|
||||
safety_route_spec: self.unlocked_inner.safety_route_spec.clone(),
|
||||
safety: self.unlocked_inner.privacy,
|
||||
reliable: self.unlocked_inner.reliable,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
@@ -113,3 +113,18 @@ pub mod opt_json_as_string {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub mod arc_serialize {
|
||||
use alloc::sync::Arc;
|
||||
use serde::{Deserialize, Deserializer, Serialize, Serializer};
|
||||
|
||||
pub fn serialize<T: Serialize, S: Serializer>(v: &Arc<T>, s: S) -> Result<S::Ok, S::Error> {
|
||||
T::serialize(v.as_ref(), s)
|
||||
}
|
||||
|
||||
pub fn deserialize<'de, T: Deserialize<'de>, D: Deserializer<'de>>(
|
||||
d: D,
|
||||
) -> Result<Arc<T>, D::Error> {
|
||||
Ok(Arc::new(T::deserialize(d)?))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user