refactor checkpoint
This commit is contained in:
@@ -5,11 +5,11 @@ pub fn encode_public_internet_node_status(
|
||||
public_internet_node_status: &PublicInternetNodeStatus,
|
||||
builder: &mut veilid_capnp::public_internet_node_status::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
builder.set_will_route(node_status.will_route);
|
||||
builder.set_will_tunnel(node_status.will_tunnel);
|
||||
builder.set_will_signal(node_status.will_signal);
|
||||
builder.set_will_relay(node_status.will_relay);
|
||||
builder.set_will_validate_dial_info(node_status.will_validate_dial_info);
|
||||
builder.set_will_route(public_internet_node_status.will_route);
|
||||
builder.set_will_tunnel(public_internet_node_status.will_tunnel);
|
||||
builder.set_will_signal(public_internet_node_status.will_signal);
|
||||
builder.set_will_relay(public_internet_node_status.will_relay);
|
||||
builder.set_will_validate_dial_info(public_internet_node_status.will_validate_dial_info);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -30,8 +30,8 @@ pub fn encode_local_network_node_status(
|
||||
local_network_node_status: &LocalNetworkNodeStatus,
|
||||
builder: &mut veilid_capnp::local_network_node_status::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
builder.set_will_relay(node_status.will_relay);
|
||||
builder.set_will_validate_dial_info(node_status.will_validate_dial_info);
|
||||
builder.set_will_relay(local_network_node_status.will_relay);
|
||||
builder.set_will_validate_dial_info(local_network_node_status.will_validate_dial_info);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -39,7 +39,7 @@ pub fn encode_local_network_node_status(
|
||||
pub fn decode_local_network_node_status(
|
||||
reader: &veilid_capnp::local_network_node_status::Reader,
|
||||
) -> Result<LocalNetworkNodeStatus, RPCError> {
|
||||
Ok(NodeStatus {
|
||||
Ok(LocalNetworkNodeStatus {
|
||||
will_relay: reader.reborrow().get_will_relay(),
|
||||
will_validate_dial_info: reader.reborrow().get_will_validate_dial_info(),
|
||||
})
|
||||
@@ -50,17 +50,15 @@ pub fn encode_node_status(
|
||||
builder: &mut veilid_capnp::node_status::Builder,
|
||||
) -> Result<(), RPCError> {
|
||||
match node_status {
|
||||
NodeStatus::PublicInternetNodeStatus(ns) => {
|
||||
NodeStatus::PublicInternet(ns) => {
|
||||
let mut pi_builder = builder.reborrow().init_public_internet();
|
||||
encode_public_internet_node_status(&ns, &mut pi_builder)
|
||||
}
|
||||
NodeStatus::LocalNetworkNodeStatus(ns) => {
|
||||
NodeStatus::LocalNetwork(ns) => {
|
||||
let mut ln_builder = builder.reborrow().init_local_network();
|
||||
encode_local_network_node_status(&ns, &mut ln_builder)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn decode_node_status(
|
||||
@@ -72,7 +70,7 @@ pub fn decode_node_status(
|
||||
.map_err(RPCError::map_internal("invalid node status"))?
|
||||
{
|
||||
veilid_capnp::node_status::PublicInternet(pi) => {
|
||||
let r = r.map_err(RPCError::protocol)?;
|
||||
let r = pi.map_err(RPCError::protocol)?;
|
||||
let pins = decode_public_internet_node_status(&r)?;
|
||||
NodeStatus::PublicInternet(pins)
|
||||
}
|
||||
|
@@ -58,22 +58,25 @@ impl RPCOperationKind {
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RPCOperation {
|
||||
op_id: u64,
|
||||
sender_info: Option<SignedNodeInfo>,
|
||||
sender_node_info: Option<SignedNodeInfo>,
|
||||
kind: RPCOperationKind,
|
||||
}
|
||||
|
||||
impl RPCOperation {
|
||||
pub fn new_question(question: RPCQuestion, sender_info: Option<SignedNodeInfo>) -> Self {
|
||||
pub fn new_question(question: RPCQuestion, sender_node_info: Option<SignedNodeInfo>) -> Self {
|
||||
Self {
|
||||
op_id: intf::get_random_u64(),
|
||||
sender_info,
|
||||
sender_node_info,
|
||||
kind: RPCOperationKind::Question(question),
|
||||
}
|
||||
}
|
||||
pub fn new_statement(statement: RPCStatement, sender_info: Option<SignedNodeInfo>) -> Self {
|
||||
pub fn new_statement(
|
||||
statement: RPCStatement,
|
||||
sender_node_info: Option<SignedNodeInfo>,
|
||||
) -> Self {
|
||||
Self {
|
||||
op_id: intf::get_random_u64(),
|
||||
sender_info,
|
||||
sender_node_info,
|
||||
kind: RPCOperationKind::Statement(statement),
|
||||
}
|
||||
}
|
||||
@@ -81,11 +84,11 @@ impl RPCOperation {
|
||||
pub fn new_answer(
|
||||
request: &RPCOperation,
|
||||
answer: RPCAnswer,
|
||||
sender_info: Option<SignedNodeInfo>,
|
||||
sender_node_info: Option<SignedNodeInfo>,
|
||||
) -> Self {
|
||||
Self {
|
||||
op_id: request.op_id,
|
||||
sender_info,
|
||||
sender_node_info,
|
||||
kind: RPCOperationKind::Answer(answer),
|
||||
}
|
||||
}
|
||||
@@ -94,8 +97,8 @@ impl RPCOperation {
|
||||
self.op_id
|
||||
}
|
||||
|
||||
pub fn sender_info(&self) -> Option<&SignedNodeInfo> {
|
||||
self.sender_info.as_ref()
|
||||
pub fn sender_node_info(&self) -> Option<&SignedNodeInfo> {
|
||||
self.sender_node_info.as_ref()
|
||||
}
|
||||
|
||||
pub fn kind(&self) -> &RPCOperationKind {
|
||||
@@ -112,8 +115,10 @@ impl RPCOperation {
|
||||
) -> Result<Self, RPCError> {
|
||||
let op_id = operation_reader.get_op_id();
|
||||
|
||||
let sender_info = if operation_reader.has_sender_info() {
|
||||
let sni_reader = operation_reader.get_sender_info();
|
||||
let sender_node_info = if operation_reader.has_sender_node_info() {
|
||||
let sni_reader = operation_reader
|
||||
.get_sender_node_info()
|
||||
.map_err(RPCError::protocol)?;
|
||||
let sni = decode_signed_node_info(&sni_reader, sender_node_id, true)?;
|
||||
Some(sni)
|
||||
} else {
|
||||
@@ -125,7 +130,7 @@ impl RPCOperation {
|
||||
|
||||
Ok(RPCOperation {
|
||||
op_id,
|
||||
sender_info,
|
||||
sender_node_info,
|
||||
kind,
|
||||
})
|
||||
}
|
||||
@@ -134,9 +139,9 @@ impl RPCOperation {
|
||||
builder.set_op_id(self.op_id);
|
||||
let mut k_builder = builder.reborrow().init_kind();
|
||||
self.kind.encode(&mut k_builder)?;
|
||||
if let Some(sender_info) = self.sender_info {
|
||||
let si_builder = builder.reborrow().init_sender_info();
|
||||
encode_signed_node_info(&self.sender_info, &mut si_builder)?;
|
||||
if let Some(sender_info) = self.sender_node_info {
|
||||
let si_builder = builder.reborrow().init_sender_node_info();
|
||||
encode_signed_node_info(&sender_info, &mut si_builder)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
@@ -48,6 +48,57 @@ impl Destination {
|
||||
safety_route_spec: None,
|
||||
}
|
||||
}
|
||||
// pub fn target_id(&self) -> DHTKey {
|
||||
// match self {
|
||||
// Destination::Direct {
|
||||
// target,
|
||||
// safety_route_spec,
|
||||
// } => target.node_id(),
|
||||
// Destination::Relay {
|
||||
// relay,
|
||||
// target,
|
||||
// safety_route_spec,
|
||||
// } => *target,
|
||||
// Destination::PrivateRoute {
|
||||
// private_route,
|
||||
// safety_route_spec,
|
||||
// } => {}
|
||||
// }
|
||||
// }
|
||||
|
||||
// pub fn best_routing_domain(&self) -> RoutingDomain {
|
||||
// match self {
|
||||
// Destination::Direct {
|
||||
// target,
|
||||
// safety_route_spec,
|
||||
// } => {
|
||||
// if safety_route_spec.is_some() {
|
||||
// RoutingDomain::PublicInternet
|
||||
// } else {
|
||||
// target
|
||||
// .best_routing_domain()
|
||||
// .unwrap_or(RoutingDomain::PublicInternet)
|
||||
// }
|
||||
// }
|
||||
// Destination::Relay {
|
||||
// relay,
|
||||
// target,
|
||||
// safety_route_spec,
|
||||
// } => {
|
||||
// if safety_route_spec.is_some() {
|
||||
// RoutingDomain::PublicInternet
|
||||
// } else {
|
||||
// relay
|
||||
// .best_routing_domain()
|
||||
// .unwrap_or(RoutingDomain::PublicInternet)
|
||||
// }
|
||||
// }
|
||||
// Destination::PrivateRoute {
|
||||
// private_route: _,
|
||||
// safety_route_spec: _,
|
||||
// } => RoutingDomain::PublicInternet,
|
||||
// }
|
||||
// }
|
||||
|
||||
pub fn safety_route_spec(&self) -> Option<Arc<SafetyRouteSpec>> {
|
||||
match self {
|
||||
@@ -100,7 +151,6 @@ impl fmt::Display for Destination {
|
||||
match self {
|
||||
Destination::Direct {
|
||||
target,
|
||||
routing_domain,
|
||||
safety_route_spec,
|
||||
} => {
|
||||
let sr = safety_route_spec
|
||||
|
@@ -200,22 +200,8 @@ impl RPCProcessor {
|
||||
|
||||
/// Determine if a NodeInfo can be placed into the specified routing domain
|
||||
fn filter_node_info(&self, routing_domain: RoutingDomain, node_info: &NodeInfo) -> bool {
|
||||
// reject attempts to include non-public addresses in results
|
||||
for did in &node_info.dial_info_detail_list {
|
||||
if !did.dial_info.is_global() {
|
||||
// non-public address causes rejection
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if let Some(rpi) = &node_info.relay_peer_info {
|
||||
for did in &rpi.signed_node_info.node_info.dial_info_detail_list {
|
||||
if !did.dial_info.is_global() {
|
||||
// non-public address causes rejection
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
true
|
||||
let routing_table = self.routing_table();
|
||||
routing_table.node_info_is_valid_in_routing_domain(routing_domain, &node_info)
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
@@ -360,9 +346,6 @@ impl RPCProcessor {
|
||||
waitable_reply.node_ref.stats_question_lost();
|
||||
}
|
||||
Ok(TimeoutOr::Value((rpcreader, _))) => {
|
||||
// Note that the remote node definitely received this node info since we got a reply
|
||||
waitable_reply.node_ref.set_seen_our_node_info();
|
||||
|
||||
// Reply received
|
||||
let recv_ts = intf::get_timestamp();
|
||||
waitable_reply.node_ref.stats_answer_rcvd(
|
||||
@@ -403,13 +386,11 @@ impl RPCProcessor {
|
||||
match dest {
|
||||
Destination::Direct {
|
||||
target: node_ref,
|
||||
routing_domain,
|
||||
safety_route_spec,
|
||||
}
|
||||
| Destination::Relay {
|
||||
relay: node_ref,
|
||||
target: _,
|
||||
routing_domain,
|
||||
safety_route_spec,
|
||||
} => {
|
||||
// Send to a node without a private route
|
||||
@@ -419,7 +400,6 @@ impl RPCProcessor {
|
||||
let (node_ref, node_id) = if let Destination::Relay {
|
||||
relay: _,
|
||||
target: dht_key,
|
||||
routing_domain: _,
|
||||
safety_route_spec: _,
|
||||
} = dest
|
||||
{
|
||||
@@ -508,6 +488,53 @@ impl RPCProcessor {
|
||||
})
|
||||
}
|
||||
|
||||
// Get signed node info to package with RPC messages to improve
|
||||
// routing table caching when it is okay to do so
|
||||
// This is only done in the PublicInternet routing domain because
|
||||
// as far as we can tell this is the only domain that will really benefit
|
||||
fn get_sender_signed_node_info(&self, dest: &Destination) -> Option<SignedNodeInfo> {
|
||||
// Don't do this if the sender is to remain private
|
||||
if dest.safety_route_spec().is_some() {
|
||||
return None;
|
||||
}
|
||||
// Don't do this if our own signed node info isn't valid yet
|
||||
let routing_table = self.routing_table();
|
||||
if !routing_table.has_valid_own_node_info(RoutingDomain::PublicInternet) {
|
||||
return None;
|
||||
}
|
||||
|
||||
match dest {
|
||||
Destination::Direct {
|
||||
target,
|
||||
safety_route_spec: _,
|
||||
} => {
|
||||
// If the target has seen our node info already don't do this
|
||||
if target.has_seen_our_node_info(RoutingDomain::PublicInternet) {
|
||||
return None;
|
||||
}
|
||||
Some(routing_table.get_own_signed_node_info(RoutingDomain::PublicInternet))
|
||||
}
|
||||
Destination::Relay {
|
||||
relay: _,
|
||||
target,
|
||||
safety_route_spec: _,
|
||||
} => {
|
||||
if let Some(target) = routing_table.lookup_node_ref(*target) {
|
||||
if target.has_seen_our_node_info(RoutingDomain::PublicInternet) {
|
||||
return None;
|
||||
}
|
||||
Some(routing_table.get_own_signed_node_info(RoutingDomain::PublicInternet))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
Destination::PrivateRoute {
|
||||
private_route: _,
|
||||
safety_route_spec: _,
|
||||
} => None,
|
||||
}
|
||||
}
|
||||
|
||||
// Issue a question over the network, possibly using an anonymized route
|
||||
#[instrument(level = "debug", skip(self, question), err)]
|
||||
async fn question(
|
||||
@@ -515,18 +542,11 @@ impl RPCProcessor {
|
||||
dest: Destination,
|
||||
question: RPCQuestion,
|
||||
) -> Result<NetworkResult<WaitableReply>, RPCError> {
|
||||
|
||||
// Get sender info if we should send that
|
||||
let opt_sender_info = if dest.safety_route_spec().is_none() && matches!(question.respond_to(), RespondTo::Sender) {
|
||||
// Sender is not private, send sender info if needed
|
||||
// Get the noderef of the eventual destination or first route hop
|
||||
if let Some(target_nr) = self.routing_table().lookup_node_ref(dest.get_target_id()) {
|
||||
if target_nr.has_seen_our_node_info(R)
|
||||
}
|
||||
}
|
||||
let opt_sender_info = self.get_sender_signed_node_info(&dest);
|
||||
|
||||
// Wrap question in operation
|
||||
let operation = RPCOperation::new_question(question);
|
||||
let operation = RPCOperation::new_question(question, opt_sender_info);
|
||||
let op_id = operation.op_id();
|
||||
|
||||
// Log rpc send
|
||||
@@ -538,7 +558,7 @@ impl RPCProcessor {
|
||||
node_id,
|
||||
node_ref,
|
||||
hop_count,
|
||||
} = self.render_operation(dest, &operation, safety_route_spec)?;
|
||||
} = self.render_operation(dest, &operation)?;
|
||||
|
||||
// If we need to resolve the first hop, do it
|
||||
let node_ref = match node_ref {
|
||||
@@ -594,14 +614,17 @@ impl RPCProcessor {
|
||||
}
|
||||
|
||||
// Issue a statement over the network, possibly using an anonymized route
|
||||
#[instrument(level = "debug", skip(self, statement, safety_route_spec), err)]
|
||||
#[instrument(level = "debug", skip(self, statement), err)]
|
||||
async fn statement(
|
||||
&self,
|
||||
dest: Destination,
|
||||
statement: RPCStatement,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
// Get sender info if we should send that
|
||||
let opt_sender_info = self.get_sender_signed_node_info(&dest);
|
||||
|
||||
// Wrap statement in operation
|
||||
let operation = RPCOperation::new_statement(statement);
|
||||
let operation = RPCOperation::new_statement(statement, opt_sender_info);
|
||||
|
||||
// Log rpc send
|
||||
debug!(target: "rpc_message", dir = "send", kind = "statement", op_id = operation.op_id(), desc = operation.kind().desc(), ?dest);
|
||||
@@ -612,7 +635,7 @@ impl RPCProcessor {
|
||||
node_id,
|
||||
node_ref,
|
||||
hop_count: _,
|
||||
} = self.render_operation(dest, &operation, safety_route_spec)?;
|
||||
} = self.render_operation(dest, &operation)?;
|
||||
|
||||
// If we need to resolve the first hop, do it
|
||||
let node_ref = match node_ref {
|
||||
@@ -662,7 +685,7 @@ impl RPCProcessor {
|
||||
|
||||
// To where should we respond?
|
||||
match respond_to {
|
||||
RespondTo::Sender(_) => {
|
||||
RespondTo::Sender => {
|
||||
// Reply directly to the request's source
|
||||
let sender_id = request.header.envelope.get_sender_id();
|
||||
|
||||
@@ -672,29 +695,32 @@ impl RPCProcessor {
|
||||
// If the sender_id is that of the peer, then this is a direct reply
|
||||
// else it is a relayed reply through the peer
|
||||
if peer_noderef.node_id() == sender_id {
|
||||
Destination::Direct(peer_noderef)
|
||||
Destination::direct(peer_noderef)
|
||||
} else {
|
||||
Destination::Relay(peer_noderef, sender_id)
|
||||
Destination::relay(peer_noderef, sender_id)
|
||||
}
|
||||
}
|
||||
RespondTo::PrivateRoute(pr) => Destination::PrivateRoute(pr.clone()),
|
||||
RespondTo::PrivateRoute(pr) => Destination::private_route(pr.clone()),
|
||||
}
|
||||
}
|
||||
|
||||
// Issue a reply over the network, possibly using an anonymized route
|
||||
// The request must want a response, or this routine fails
|
||||
#[instrument(level = "debug", skip(self, request, answer, safety_route_spec), err)]
|
||||
#[instrument(level = "debug", skip(self, request, answer), err)]
|
||||
async fn answer(
|
||||
&self,
|
||||
request: RPCMessage,
|
||||
answer: RPCAnswer,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
// Wrap answer in operation
|
||||
let operation = RPCOperation::new_answer(&request.operation, answer);
|
||||
|
||||
// Extract destination from respond_to
|
||||
let dest = self.get_respond_to_destination(&request);
|
||||
|
||||
// Get sender info if we should send that
|
||||
let opt_sender_info = self.get_sender_signed_node_info(&dest);
|
||||
|
||||
// Wrap answer in operation
|
||||
let operation = RPCOperation::new_answer(&request.operation, answer, opt_sender_info);
|
||||
|
||||
// Log rpc send
|
||||
debug!(target: "rpc_message", dir = "send", kind = "answer", op_id = operation.op_id(), desc = operation.kind().desc(), ?dest);
|
||||
|
||||
@@ -704,7 +730,7 @@ impl RPCProcessor {
|
||||
node_id,
|
||||
node_ref,
|
||||
hop_count: _,
|
||||
} = self.render_operation(dest, &operation, safety_route_spec)?;
|
||||
} = self.render_operation(dest, &operation)?;
|
||||
|
||||
// If we need to resolve the first hop, do it
|
||||
let node_ref = match node_ref {
|
||||
@@ -747,8 +773,7 @@ impl RPCProcessor {
|
||||
&self,
|
||||
encoded_msg: RPCMessageEncoded,
|
||||
) -> Result<(), RPCError> {
|
||||
|
||||
// Get the routing domain
|
||||
// Get the routing domain this message came over
|
||||
let routing_domain = encoded_msg.header.routing_domain;
|
||||
|
||||
// Decode the operation
|
||||
@@ -764,35 +789,34 @@ impl RPCProcessor {
|
||||
RPCOperation::decode(&op_reader, &sender_node_id)?
|
||||
};
|
||||
|
||||
// Get the sender noderef, incorporating and 'sender node info' we have from a question
|
||||
// Get the sender noderef, incorporating and 'sender node info'
|
||||
let mut opt_sender_nr: Option<NodeRef> = None;
|
||||
match operation.kind() {
|
||||
RPCOperationKind::Question(q) => {
|
||||
match q.respond_to() {
|
||||
RespondTo::Sender(Some(sender_ni)) => {
|
||||
// Sender NodeInfo was specified, update our routing table with it
|
||||
if !self.filter_node_info(&sender_ni.node_info) {
|
||||
return Err(RPCError::invalid_format(
|
||||
"respond_to_sender_signed_node_info has invalid peer scope",
|
||||
));
|
||||
}
|
||||
opt_sender_nr = self.routing_table().register_node_with_signed_node_info(
|
||||
routing_domain,
|
||||
sender_node_id,
|
||||
sender_ni.clone(),
|
||||
false,
|
||||
);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
if let Some(sender_node_info) = operation.sender_node_info() {
|
||||
// Sender NodeInfo was specified, update our routing table with it
|
||||
if !self.filter_node_info(RoutingDomain::PublicInternet, &sender_node_info.node_info) {
|
||||
return Err(RPCError::invalid_format(
|
||||
"sender signednodeinfo has invalid peer scope",
|
||||
));
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
opt_sender_nr = self.routing_table().register_node_with_signed_node_info(
|
||||
routing_domain,
|
||||
sender_node_id,
|
||||
sender_node_info.clone(),
|
||||
false,
|
||||
);
|
||||
}
|
||||
|
||||
// look up sender node, in case it's different than our peer due to relaying
|
||||
if opt_sender_nr.is_none() {
|
||||
// look up sender node, in case it's different than our peer due to relaying
|
||||
opt_sender_nr = self.routing_table().lookup_node_ref(sender_node_id)
|
||||
}
|
||||
|
||||
// Mark this sender as having seen our node info over this routing domain
|
||||
// because it managed to reach us over that routing domain
|
||||
if let Some(sender_nr) = &opt_sender_nr {
|
||||
sender_nr.set_seen_our_node_info(routing_domain);
|
||||
}
|
||||
|
||||
// Make the RPC message
|
||||
let msg = RPCMessage {
|
||||
header: encoded_msg.header,
|
||||
|
@@ -139,7 +139,7 @@ impl RPCProcessor {
|
||||
operation,
|
||||
};
|
||||
let operation =
|
||||
RPCOperation::new_statement(RPCStatement::new(RPCStatementDetail::Route(route)));
|
||||
RPCOperation::new_statement(RPCStatement::new(RPCStatementDetail::Route(route)), None);
|
||||
|
||||
// Convert message to bytes and return it
|
||||
let mut route_msg = ::capnp::message::Builder::new_default();
|
||||
|
@@ -9,7 +9,9 @@ impl RPCProcessor {
|
||||
dest: Destination,
|
||||
key: DHTKey,
|
||||
) -> Result<NetworkResult<Answer<Vec<PeerInfo>>>, RPCError> {
|
||||
let find_node_q = RPCQuestionDetail::FindNodeQ(RPCOperationFindNodeQ { node_id: key });
|
||||
let find_node_q_detail =
|
||||
RPCQuestionDetail::FindNodeQ(RPCOperationFindNodeQ { node_id: key });
|
||||
let find_node_q = RPCQuestion::new(RespondTo::Sender, find_node_q_detail);
|
||||
|
||||
// Send the find_node request
|
||||
let waitable_reply = network_result_try!(self.question(dest, find_node_q).await?);
|
||||
@@ -31,7 +33,10 @@ impl RPCProcessor {
|
||||
|
||||
// Verify peers are in the correct peer scope
|
||||
for peer_info in &find_node_a.peers {
|
||||
if !self.filter_node_info(&peer_info.signed_node_info.node_info) {
|
||||
if !self.filter_node_info(
|
||||
RoutingDomain::PublicInternet,
|
||||
&peer_info.signed_node_info.node_info,
|
||||
) {
|
||||
return Err(RPCError::invalid_format(
|
||||
"find_node response has invalid peer scope",
|
||||
));
|
||||
@@ -61,23 +66,12 @@ impl RPCProcessor {
|
||||
let rt3 = routing_table.clone();
|
||||
|
||||
// find N nodes closest to the target node in our routing table
|
||||
let own_peer_info = routing_table.get_own_peer_info(RoutingDomain::PublicInternet);
|
||||
let own_peer_info_is_valid = own_peer_info.signed_node_info.is_valid();
|
||||
|
||||
let closest_nodes = routing_table.find_closest_nodes(
|
||||
find_node_q.node_id,
|
||||
// filter
|
||||
Some(move |_k, v| {
|
||||
rt2.filter_has_valid_signed_node_info(
|
||||
v,
|
||||
own_peer_info_is_valid,
|
||||
Some(RoutingDomain::PublicInternet),
|
||||
)
|
||||
}),
|
||||
move |_k, v| rt2.filter_has_valid_signed_node_info(RoutingDomain::PublicInternet, v),
|
||||
// transform
|
||||
move |k, v| {
|
||||
rt3.transform_to_peer_info(RoutingDomain::PublicInternet, k, v, &own_peer_info)
|
||||
},
|
||||
move |k, v| rt3.transform_to_peer_info(RoutingDomain::PublicInternet, k, v),
|
||||
);
|
||||
|
||||
// Make status answer
|
||||
@@ -87,11 +81,7 @@ impl RPCProcessor {
|
||||
|
||||
// Send status answer
|
||||
let res = self
|
||||
.answer(
|
||||
msg,
|
||||
RPCAnswer::new(RPCAnswerDetail::FindNodeA(find_node_a)),
|
||||
None,
|
||||
)
|
||||
.answer(msg, RPCAnswer::new(RPCAnswerDetail::FindNodeA(find_node_a)))
|
||||
.await?;
|
||||
tracing::Span::current().record("res", &tracing::field::display(res));
|
||||
Ok(())
|
||||
|
@@ -18,7 +18,9 @@ impl RPCProcessor {
|
||||
// Send the node_info_update request to the specific routing domain requested
|
||||
network_result_try!(
|
||||
self.statement(
|
||||
Destination::direct(target).with_routing_domain(routing_domain),
|
||||
Destination::direct(
|
||||
target.filtered_clone(NodeRefFilter::new().with_routing_domain(routing_domain))
|
||||
),
|
||||
statement,
|
||||
)
|
||||
.await?
|
||||
@@ -30,6 +32,7 @@ impl RPCProcessor {
|
||||
#[instrument(level = "trace", skip(self, msg), fields(msg.operation.op_id), err)]
|
||||
pub(crate) async fn process_node_info_update(&self, msg: RPCMessage) -> Result<(), RPCError> {
|
||||
let sender_node_id = msg.header.envelope.get_sender_id();
|
||||
let routing_domain = msg.header.routing_domain;
|
||||
|
||||
// Get the statement
|
||||
let node_info_update = match msg.operation.into_kind() {
|
||||
@@ -41,14 +44,13 @@ impl RPCProcessor {
|
||||
};
|
||||
|
||||
// Update our routing table with signed node info
|
||||
if !self.filter_node_info(&node_info_update.signed_node_info.node_info) {
|
||||
log_rpc!(debug
|
||||
"node_info_update has invalid peer scope from {}", sender_node_id
|
||||
);
|
||||
if !self.filter_node_info(routing_domain, &node_info_update.signed_node_info.node_info) {
|
||||
log_rpc!(debug "node info doesn't belong in {:?} routing domain: {}", routing_domain, sender_node_id);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
self.routing_table().register_node_with_signed_node_info(
|
||||
routing_domain,
|
||||
sender_node_id,
|
||||
node_info_update.signed_node_info,
|
||||
false,
|
||||
|
@@ -7,7 +7,6 @@ impl RPCProcessor {
|
||||
pub async fn rpc_call_return_receipt<D: AsRef<[u8]>>(
|
||||
self,
|
||||
dest: Destination,
|
||||
safety_route: Option<&SafetyRouteSpec>,
|
||||
receipt: D,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
let receipt = receipt.as_ref().to_vec();
|
||||
@@ -16,7 +15,7 @@ impl RPCProcessor {
|
||||
let statement = RPCStatement::new(RPCStatementDetail::ReturnReceipt(return_receipt));
|
||||
|
||||
// Send the return_receipt request
|
||||
network_result_try!(self.statement(dest, statement, safety_route).await?);
|
||||
network_result_try!(self.statement(dest, statement).await?);
|
||||
|
||||
Ok(NetworkResult::value(()))
|
||||
}
|
||||
|
@@ -7,15 +7,13 @@ impl RPCProcessor {
|
||||
pub async fn rpc_call_signal(
|
||||
self,
|
||||
dest: Destination,
|
||||
safety_route: Option<&SafetyRouteSpec>,
|
||||
signal_info: SignalInfo,
|
||||
) -> Result<NetworkResult<()>, RPCError> {
|
||||
//let signed_node_info = self.routing_table().get_own_signed_node_info();
|
||||
let signal = RPCOperationSignal { signal_info };
|
||||
let statement = RPCStatement::new(RPCStatementDetail::Signal(signal));
|
||||
|
||||
// Send the signal request
|
||||
network_result_try!(self.statement(dest, statement, safety_route).await?);
|
||||
network_result_try!(self.statement(dest, statement).await?);
|
||||
|
||||
Ok(NetworkResult::value(()))
|
||||
}
|
||||
|
@@ -118,17 +118,15 @@ impl RPCProcessor {
|
||||
// Ensure the node status from the question is the kind for the routing domain we received the request in
|
||||
match routing_domain {
|
||||
RoutingDomain::PublicInternet => {
|
||||
if !matches!(status_a.node_status, NodeStatus::PublicInternet(_)) {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"node status doesn't match PublicInternet routing domain",
|
||||
));
|
||||
if !matches!(status_q.node_status, NodeStatus::PublicInternet(_)) {
|
||||
log_rpc!(debug "node status doesn't match PublicInternet routing domain");
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
RoutingDomain::LocalNetwork => {
|
||||
if !matches!(status_a.node_status, NodeStatus::LocalNetwork(_)) {
|
||||
return Ok(NetworkResult::invalid_message(
|
||||
"node status doesn't match LocalNetwork routing domain",
|
||||
));
|
||||
if !matches!(status_q.node_status, NodeStatus::LocalNetwork(_)) {
|
||||
log_rpc!(debug "node status doesn't match LocalNetwork routing domain");
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,7 +32,7 @@ impl RPCProcessor {
|
||||
|
||||
// Send the validate_dial_info request
|
||||
// This can only be sent directly, as relays can not validate dial info
|
||||
network_result_value_or_log!(debug self.statement(Destination::Direct(peer), statement, None)
|
||||
network_result_value_or_log!(debug self.statement(Destination::direct(peer), statement)
|
||||
.await? => {
|
||||
return Ok(false);
|
||||
}
|
||||
@@ -81,6 +81,7 @@ impl RPCProcessor {
|
||||
// an ipv6 address
|
||||
let routing_table = self.routing_table();
|
||||
let sender_id = msg.header.envelope.get_sender_id();
|
||||
let routing_domain = msg.header.routing_domain;
|
||||
let node_count = {
|
||||
let c = self.config.get();
|
||||
c.network.dht.max_find_node_count as usize
|
||||
@@ -88,15 +89,18 @@ impl RPCProcessor {
|
||||
|
||||
// Filter on nodes that can validate dial info, and can reach a specific dial info
|
||||
let outbound_dial_info_entry_filter =
|
||||
RoutingTable::make_outbound_dial_info_entry_filter(dial_info.clone());
|
||||
RoutingTable::make_outbound_dial_info_entry_filter(
|
||||
routing_domain,
|
||||
dial_info.clone(),
|
||||
);
|
||||
let will_validate_dial_info_filter = |e: &BucketEntryInner| {
|
||||
if let Some(status) = &e.peer_stats().status {
|
||||
status.will_validate_dial_info
|
||||
if let Some(status) = &e.node_status(routing_domain) {
|
||||
status.will_validate_dial_info()
|
||||
} else {
|
||||
true
|
||||
}
|
||||
};
|
||||
let filter = RoutingTable::combine_filters(
|
||||
let filter = RoutingTable::combine_entry_filters(
|
||||
outbound_dial_info_entry_filter,
|
||||
will_validate_dial_info_filter,
|
||||
);
|
||||
@@ -126,7 +130,7 @@ impl RPCProcessor {
|
||||
|
||||
// Send the validate_dial_info request
|
||||
// This can only be sent directly, as relays can not validate dial info
|
||||
network_result_value_or_log!(debug self.statement(Destination::Direct(peer), statement, None)
|
||||
network_result_value_or_log!(debug self.statement(Destination::direct(peer), statement)
|
||||
.await? => {
|
||||
return Ok(());
|
||||
}
|
||||
|
Reference in New Issue
Block a user