Skip to content

Commit

Permalink
remove extra target field in query
Browse files Browse the repository at this point in the history
  • Loading branch information
Nuhvi committed Oct 23, 2024
1 parent b701558 commit 50749dd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ impl Rpc {
query.add_responding_node(Node::new(responder_id, from));
}

let target = query.target;
let target = query.target();

match &message.message_type {
MessageType::Response(ResponseSpecific::GetPeers(GetPeersResponseArguments {
Expand All @@ -451,7 +451,7 @@ impl Rpc {
v, responder_id, ..
},
)) => {
if validate_immutable(v, &query.target) {
if validate_immutable(v, &query.target()) {
let response = Response::Immutable(v.to_owned().into());

query.response(from, response.to_owned());
Expand All @@ -462,7 +462,7 @@ impl Rpc {
});
}

let target = query.target;
let target = query.target();
debug!(?v, ?target, ?responder_id, ?from, from_version = ?message.version, "Invalid immutable value");
}
MessageType::Response(ResponseSpecific::GetMutable(
Expand All @@ -479,10 +479,10 @@ impl Rpc {
RequestTypeSpecific::GetValue(args) => args.salt,
_ => None,
};
let target = query.target;
let target = query.target();

if let Ok(item) = MutableItem::from_dht_message(
&query.target,
&query.target(),
k,
v.to_owned().into(),
seq,
Expand Down Expand Up @@ -518,7 +518,7 @@ impl Rpc {
},
)) => {
debug!(
target= ?query.target,
target= ?query.target(),
salt= ?match query.request.request_type.clone() {
RequestTypeSpecific::GetValue(args) => args.salt,
_ => None,
Expand All @@ -540,7 +540,7 @@ impl Rpc {
..
})) => {
debug!(
target= ?query.target,
target= ?query.target(),
salt= ?match query.request.request_type.clone() {
RequestTypeSpecific::GetValue(args) => args.salt,
_ => None,
Expand Down
10 changes: 6 additions & 4 deletions src/rpc/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use crate::{
/// repeating this process until no closer nodes (that aren't already queried) are found.
#[derive(Debug)]
pub struct Query {
pub target: Id,
pub request: RequestSpecific,
candidates: RoutingTable,
closest_nodes: ClosestNodes,
Expand All @@ -35,7 +34,6 @@ impl Query {
trace!(?target, ?request, "New Query");

Self {
target,
request,

candidates: RoutingTable::new().with_id(target),
Expand All @@ -51,6 +49,10 @@ impl Query {

// === Getters ===

pub fn target(&self) -> Id {
self.closest_nodes.target()
}

/// Return the closest responding nodes after the query is done.
pub fn closest_nodes(&self) -> &ClosestNodes {
&self.closest_nodes
Expand Down Expand Up @@ -102,7 +104,7 @@ impl Query {

/// Add received response
pub fn response(&mut self, from: SocketAddr, response: Response) {
let target = self.target;
let target = self.target();

debug!(?target, ?response, ?from, "Query got response");

Expand Down Expand Up @@ -157,7 +159,7 @@ impl Query {

/// Visit the closest candidates and remove them as candidates
fn visit_closest(&mut self, socket: &mut KrpcSocket) {
for node in self.candidates.closest(&self.target) {
for node in self.candidates.closest(&self.target()) {
if !self.visited.contains(&node.address) {
self.visit(socket, node.address);
}
Expand Down

0 comments on commit 50749dd

Please sign in to comment.