checkpoint

This commit is contained in:
John Smith
2022-10-16 19:59:59 -04:00
parent e85d72f21a
commit 63768580c6
10 changed files with 225 additions and 149 deletions

View File

@@ -8,8 +8,7 @@ pub enum Destination {
/// The node to send to
target: NodeRef,
/// Require safety route or not
xxx convert back to safety spec, bubble up to api
safety: bool,
safety: Option<SafetySpec>,
},
/// Send to node for relay purposes
Relay {
@@ -18,14 +17,14 @@ pub enum Destination {
/// The final destination the relay should send to
target: DHTKey,
/// Require safety route or not
safety: bool,
safety: Option<SafetySpec>,
},
/// Send to private route (privateroute)
PrivateRoute {
/// A private route to send to
private_route: PrivateRoute,
/// Require safety route or not
safety: bool,
safety: Option<SafetySpec>,
/// Prefer reliability or not
reliable: bool,
},
@@ -35,29 +34,29 @@ impl Destination {
pub fn direct(target: NodeRef) -> Self {
Self::Direct {
target,
safety: false,
safety: None,
}
}
pub fn relay(relay: NodeRef, target: DHTKey) -> Self {
Self::Relay {
relay,
target,
safety: false,
safety: None,
}
}
pub fn private_route(private_route: PrivateRoute, reliable: bool) -> Self {
Self::PrivateRoute {
private_route,
safety: false,
safety: None,
reliable,
}
}
pub fn with_safety(self) -> Self {
pub fn with_safety(self, spec: SafetySpec) -> Self {
match self {
Destination::Direct { target, safety: _ } => Self::Direct {
target,
safety: true,
safety: Some(spec),
},
Destination::Relay {
relay,
@@ -66,7 +65,7 @@ impl Destination {
} => Self::Relay {
relay,
target,
safety: true,
safety: Some(spec),
},
Destination::PrivateRoute {
private_route,
@@ -74,7 +73,7 @@ impl Destination {
reliable,
} => Self::PrivateRoute {
private_route,
safety: true,
safety: Some(spec),
reliable,
},
}
@@ -85,7 +84,7 @@ impl fmt::Display for Destination {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
Destination::Direct { target, safety } => {
let sr = if *safety { "+SR" } else { "" };
let sr = if safety.is_some() { "+SR" } else { "" };
write!(f, "{}{}", target, sr)
}
@@ -94,7 +93,7 @@ impl fmt::Display for Destination {
target,
safety,
} => {
let sr = if *safety { "+SR" } else { "" };
let sr = if safety.is_some() { "+SR" } else { "" };
write!(f, "{}@{}{}", target.encode(), relay, sr)
}
@@ -103,7 +102,7 @@ impl fmt::Display for Destination {
safety,
reliable,
} => {
let sr = if *safety { "+SR" } else { "" };
let sr = if safety.is_some() { "+SR" } else { "" };
let rl = if *reliable { "+RL" } else { "" };
write!(f, "{}{}{}", private_route, sr, rl)

View File

@@ -409,13 +409,6 @@ impl RPCProcessor {
rss.compile_safety_route(safety_spec, private_route)
})?;
// Verify hop count isn't larger than out maximum routed hop count
if compiled_route.safety_route.hop_count as usize > self.unlocked_inner.max_route_hop_count
{
return Err(RPCError::internal("hop count too long for route"))
.map_err(logthru_rpc!(warn));
}
// Encrypt routed operation
// Xmsg + ENC(Xmsg, DH(PKapr, SKbsr))
let nonce = Crypto::get_random_nonce();
@@ -613,17 +606,6 @@ impl RPCProcessor {
hop_count,
} = self.render_operation(dest, &operation)?;
// If we need to resolve the first hop, do it
let node_ref = match node_ref {
None => match self.resolve_node(node_id).await? {
None => {
return Ok(NetworkResult::no_connection_other(node_id));
}
Some(nr) => nr,
},
Some(nr) => nr,
};
// Calculate answer timeout
// Timeout is number of hops times the timeout per hop
let timeout = self.unlocked_inner.timeout * (hop_count as u64);
@@ -687,17 +669,6 @@ impl RPCProcessor {
hop_count: _,
} = self.render_operation(dest, &operation)?;
// If we need to resolve the first hop, do it
let node_ref = match node_ref {
None => match self.resolve_node(node_id).await? {
None => {
return Ok(NetworkResult::no_connection_other(node_id));
}
Some(nr) => nr,
},
Some(nr) => nr,
};
// Send statement
let bytes = message.len() as u64;
let send_ts = intf::get_timestamp();
@@ -782,17 +753,6 @@ impl RPCProcessor {
hop_count: _,
} = self.render_operation(dest, &operation)?;
// If we need to resolve the first hop, do it
let node_ref = match node_ref {
None => match self.resolve_node(node_id).await? {
None => {
return Ok(NetworkResult::no_connection_other(node_id));
}
Some(nr) => nr,
},
Some(nr) => nr,
};
// Send the reply
let bytes = message.len() as u64;
let send_ts = intf::get_timestamp();