diff --git a/src/rpc.rs b/src/rpc.rs index 31438435..8fff4286 100644 --- a/src/rpc.rs +++ b/src/rpc.rs @@ -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 { @@ -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()); @@ -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( @@ -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, @@ -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, @@ -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, diff --git a/src/rpc/query.rs b/src/rpc/query.rs index 112cab78..2b61766c 100644 --- a/src/rpc/query.rs +++ b/src/rpc/query.rs @@ -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, @@ -35,7 +34,6 @@ impl Query { trace!(?target, ?request, "New Query"); Self { - target, request, candidates: RoutingTable::new().with_id(target), @@ -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 @@ -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"); @@ -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); }