Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions node/src/proxy_server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,10 +247,11 @@ impl ProxyServer {
}

fn handle_dns_resolve_failure(&mut self, msg: &ExpiredCoresPackage<DnsResolveFailure_0v1>) {
let return_route_info = match self.get_return_route_info(&msg.remaining_route) {
Some(rri) => rri,
None => return, // TODO: Eventually we'll have to do something better here, but we'll probably need some heuristics.
};
let return_route_info =
match self.get_return_route_info(&msg.remaining_route, "dns resolve failure") {
Some(rri) => rri,
None => return, // TODO: Eventually we'll have to do something better here, but we'll probably need some heuristics.
};
let exit_public_key = {
// ugly, ugly
let self_public_key = self.main_cryptde.public_key();
Expand Down Expand Up @@ -336,10 +337,11 @@ impl ProxyServer {
"Relaying ClientResponsePayload (stream key {}, sequence {}, length {}) from Hopper to Dispatcher for client",
response.stream_key, response.sequenced_packet.sequence_number, response.sequenced_packet.data.len()
);
let return_route_info = match self.get_return_route_info(&msg.remaining_route) {
Some(rri) => rri,
None => return,
};
let return_route_info =
match self.get_return_route_info(&msg.remaining_route, "client response") {
Some(rri) => rri,
None => return,
};
match self.keys_and_addrs.a_to_b(&response.stream_key) {
Some(socket_addr) => {
self.report_response_services_consumed(
Expand Down Expand Up @@ -879,7 +881,11 @@ impl ProxyServer {
}
}

fn get_return_route_info(&self, remaining_route: &Route) -> Option<Rc<AddReturnRouteMessage>> {
fn get_return_route_info(
&self,
remaining_route: &Route,
source: &str,
) -> Option<Rc<AddReturnRouteMessage>> {
let mut mut_remaining_route = remaining_route.clone();
mut_remaining_route
.shift(self.main_cryptde)
Expand All @@ -894,7 +900,7 @@ impl ProxyServer {
match self.route_ids_to_return_routes.get(&return_route_id) {
Some(rri) => Some(rri),
None => {
error!(self.logger, "Can't report services consumed: received response with bogus return-route ID {}. Ignoring", return_route_id);
error!(self.logger, "Can't report services consumed: received response with bogus return-route ID {} for {}. Ignoring", return_route_id, source);
None
}
}
Expand Down Expand Up @@ -3997,7 +4003,7 @@ mod tests {

System::current().stop_with_code(0);
system.run();
TestLogHandler::new().exists_log_containing("ERROR: ProxyServer: Can't report services consumed: received response with bogus return-route ID 1234. Ignoring");
TestLogHandler::new().exists_log_containing("ERROR: ProxyServer: Can't report services consumed: received response with bogus return-route ID 1234 for client response. Ignoring");
assert_eq!(dispatcher_recording_arc.lock().unwrap().len(), 0);
assert_eq!(accountant_recording_arc.lock().unwrap().len(), 0);
}
Expand Down Expand Up @@ -4116,7 +4122,7 @@ mod tests {
);
subject_addr.try_send(expired_cores_package).unwrap();

TestLogHandler::new().await_log_containing("ERROR: ProxyServer: Can't report services consumed: received response with bogus return-route ID 1234. Ignoring", 1000);
TestLogHandler::new().await_log_containing("ERROR: ProxyServer: Can't report services consumed: received response with bogus return-route ID 1234 for client response. Ignoring", 1000);
}

#[test]
Expand Down
47 changes: 34 additions & 13 deletions node/src/test_utils/database_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,40 @@ pub fn bring_db_0_back_to_life_and_return_connection(db_path: &PathBuf) -> Conne
Err(e) => panic!("Unexpected but serious error: {}", e),
_ => (),
};
let conn = Connection::open(&db_path).unwrap();
let file_path = current_dir()
.unwrap()
.join("src")
.join("test_utils")
.join("database_version_0_sql.txt");
let mut file = File::open(file_path).unwrap();
let mut buffer = String::new();
file.read_to_string(&mut buffer).unwrap();
buffer.lines().for_each(|stm| {
conn.execute(stm, []).unwrap();
});
conn
let connection = Connection::open(&db_path).unwrap();
[
"create table config (
name text not null,
value text,
encrypted integer not null )",
"create unique index idx_config_name on config (name)",
"insert into config (name, value, encrypted) values ('example_encrypted', null, 1)",
"insert into config (name, value, encrypted) values ('clandestine_port', '2897', 0)",
"insert into config (name, value, encrypted) values ('consuming_wallet_derivation_path', null, 0)",
"insert into config (name, value, encrypted) values ('consuming_wallet_public_key', null, 0)",
"insert into config (name, value, encrypted) values ('earning_wallet_address', null, 0)",
"insert into config (name, value, encrypted) values ('schema_version', '0', 0)",
"insert into config (name, value, encrypted) values ('seed', null, 0)",
"insert into config (name, value, encrypted) values ('start_block', 8688171, 0)",
"insert into config (name, value, encrypted) values ('gas_price', '1', 0)",
"insert into config (name, value, encrypted) values ('past_neighbors', null, 1)",
"create table payable (
wallet_address text primary key,
balance integer not null,
last_paid_timestamp integer not null,
pending_payment_transaction text null
)",
"create unique index idx_payable_wallet_address on payable (wallet_address)",
"create table receivable (
wallet_address text primary key,
balance integer not null,
last_received_timestamp integer not null
)",
"create unique index idx_receivable_wallet_address on receivable (wallet_address)",
"create table banned ( wallet_address text primary key )",
"create unique index idx_banned_wallet_address on banned (wallet_address)"
].iter().for_each(|statement|{connection.execute(statement,NO_PARAMS).unwrap();});
connection
}

#[derive(Default)]
Expand Down