refactor and change protocol selection for new connections

This commit is contained in:
John Smith
2023-06-24 18:12:17 -04:00
parent 197b7fef6e
commit 355040a3e4
14 changed files with 835 additions and 614 deletions

View File

@@ -529,6 +529,7 @@ impl RPCProcessor {
async fn wait_for_reply(
&self,
waitable_reply: WaitableReply,
debug_string: String,
) -> Result<TimeoutOr<(RPCMessage, TimestampDuration)>, RPCError> {
let out = self
.unlocked_inner
@@ -536,7 +537,20 @@ impl RPCProcessor {
.wait_for_op(waitable_reply.handle, waitable_reply.timeout_us)
.await;
match &out {
Err(_) | Ok(TimeoutOr::Timeout) => {
Err(e) => {
let msg = format!("RPC Lost ({}): {}", debug_string, e);
log_rpc!(debug "{}", msg.bright_magenta());
self.record_question_lost(
waitable_reply.send_ts,
waitable_reply.node_ref.clone(),
waitable_reply.safety_route,
waitable_reply.remote_private_route,
waitable_reply.reply_private_route,
);
}
Ok(TimeoutOr::Timeout) => {
let msg = format!("RPC Lost ({}): Timeout", debug_string);
log_rpc!(debug "{}", msg.bright_cyan());
self.record_question_lost(
waitable_reply.send_ts,
waitable_reply.node_ref.clone(),
@@ -878,8 +892,6 @@ impl RPCProcessor {
) {
// Record for node if this was not sent via a route
if safety_route.is_none() && remote_private_route.is_none() {
log_rpc!(debug "RPC Question Lost: {:?}", node_ref);
node_ref.stats_question_lost();
// Also clear the last_connections for the entry so we make a new connection next time

View File

@@ -9,6 +9,8 @@ impl RPCProcessor {
dest: Destination,
message: Vec<u8>,
) -> Result<NetworkResult<Answer<Vec<u8>>>, RPCError> {
let debug_string = format!("AppCall(message(len)={}) => {}", message.len(), dest);
let app_call_q = RPCOperationAppCallQ::new(message)?;
let question = RPCQuestion::new(
network_result_try!(self.get_destination_respond_to(&dest)?),
@@ -19,7 +21,7 @@ impl RPCProcessor {
let waitable_reply = network_result_try!(self.question(dest, question, None).await?);
// Wait for reply
let (msg, latency) = match self.wait_for_reply(waitable_reply).await? {
let (msg, latency) = match self.wait_for_reply(waitable_reply, debug_string).await? {
TimeoutOr::Timeout => return Ok(NetworkResult::Timeout),
TimeoutOr::Value(v) => v,
};

View File

@@ -32,11 +32,13 @@ impl RPCProcessor {
find_node_q_detail,
);
let debug_string = format!("FindNode(node_id={}) => {}", node_id, dest);
// Send the find_node request
let waitable_reply = network_result_try!(self.question(dest, find_node_q, None).await?);
// Wait for reply
let (msg, latency) = match self.wait_for_reply(waitable_reply).await? {
let (msg, latency) = match self.wait_for_reply(waitable_reply, debug_string).await? {
TimeoutOr::Timeout => return Ok(NetworkResult::Timeout),
TimeoutOr::Value(v) => v,
};

View File

@@ -39,6 +39,18 @@ impl RPCProcessor {
return Err(RPCError::internal("No node id for crypto kind"));
};
let debug_string = format!(
"GetValue(key={} subkey={} last_descriptor={}) => {}",
key,
subkey,
if last_descriptor.is_some() {
"Some"
} else {
"None"
},
dest
);
// Send the getvalue question
let get_value_q = RPCOperationGetValueQ::new(key, subkey, last_descriptor.is_none());
let question = RPCQuestion::new(
@@ -58,7 +70,7 @@ impl RPCProcessor {
);
// Wait for reply
let (msg, latency) = match self.wait_for_reply(waitable_reply).await? {
let (msg, latency) = match self.wait_for_reply(waitable_reply, debug_string).await? {
TimeoutOr::Timeout => return Ok(NetworkResult::Timeout),
TimeoutOr::Value(v) => v,
};

View File

@@ -39,6 +39,16 @@ impl RPCProcessor {
return Err(RPCError::internal("No node id for crypto kind"));
};
let debug_string = format!(
"SetValue(key={} subkey={} value_data(writer)={} value_data(len)={} send_descriptor={}) => {}",
key,
subkey,
value.value_data().writer(),
value.value_data().data().len(),
send_descriptor,
dest
);
// Send the setvalue question
let set_value_q = RPCOperationSetValueQ::new(
key,
@@ -59,13 +69,14 @@ impl RPCProcessor {
subkey,
vcrypto: vcrypto.clone(),
});
let waitable_reply = network_result_try!(
self.question(dest, question, Some(question_context))
.await?
);
// Wait for reply
let (msg, latency) = match self.wait_for_reply(waitable_reply).await? {
let (msg, latency) = match self.wait_for_reply(waitable_reply, debug_string).await? {
TimeoutOr::Timeout => return Ok(NetworkResult::Timeout),
TimeoutOr::Value(v) => v,
};

View File

@@ -101,6 +101,8 @@ impl RPCProcessor {
RPCQuestionDetail::StatusQ(status_q),
);
let debug_string = format!("Status => {}", dest);
// Send the info request
let waitable_reply =
network_result_try!(self.question(dest.clone(), question, None).await?);
@@ -109,7 +111,7 @@ impl RPCProcessor {
let send_data_kind = waitable_reply.send_data_kind;
// Wait for reply
let (msg, latency) = match self.wait_for_reply(waitable_reply).await? {
let (msg, latency) = match self.wait_for_reply(waitable_reply, debug_string).await? {
TimeoutOr::Timeout => return Ok(NetworkResult::Timeout),
TimeoutOr::Value(v) => v,
};