mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-10 23:27:56 -05:00
net/protocol_address: filter out transports not meant to be shared like Socks5 and Socks5+tls
This commit is contained in:
@@ -34,7 +34,7 @@ use super::{
|
||||
protocol_base::{ProtocolBase, ProtocolBasePtr},
|
||||
protocol_jobs_manager::{ProtocolJobsManager, ProtocolJobsManagerPtr},
|
||||
};
|
||||
use crate::{Error, Result};
|
||||
use crate::Result;
|
||||
|
||||
/// Defines address and get-address messages.
|
||||
///
|
||||
@@ -141,18 +141,20 @@ impl ProtocolAddress {
|
||||
"Received GetAddrs({}) message from {}", get_addrs_msg.max, self.channel.address(),
|
||||
);
|
||||
|
||||
// Check that this peer isn't requesting more transports than we support
|
||||
// (the max number of all transports, plus mixing).
|
||||
if get_addrs_msg.transports.len() > TRANSPORT_COMBOS.len() {
|
||||
return Err(Error::InvalidTransportRequest);
|
||||
}
|
||||
// Filter out transports not meant to be shared like Socks5 and Socks5+tls
|
||||
let requested_transports: Vec<String> = get_addrs_msg
|
||||
.transports
|
||||
.iter()
|
||||
.filter(|tp| TRANSPORT_COMBOS.contains(&tp.as_str()))
|
||||
.cloned()
|
||||
.collect();
|
||||
|
||||
// First we grab address with the requested transports from the gold list
|
||||
debug!(target: "net::protocol_address::handle_receive_get_addrs()",
|
||||
"Fetching gold entries with schemes");
|
||||
let mut addrs = self.hosts.container.fetch_n_random_with_schemes(
|
||||
HostColor::Gold,
|
||||
&get_addrs_msg.transports,
|
||||
&requested_transports,
|
||||
get_addrs_msg.max,
|
||||
);
|
||||
|
||||
@@ -161,7 +163,7 @@ impl ProtocolAddress {
|
||||
"Fetching whitelist entries with schemes");
|
||||
addrs.append(&mut self.hosts.container.fetch_n_random_with_schemes(
|
||||
HostColor::White,
|
||||
&get_addrs_msg.transports,
|
||||
&requested_transports,
|
||||
get_addrs_msg.max,
|
||||
));
|
||||
|
||||
@@ -174,7 +176,7 @@ impl ProtocolAddress {
|
||||
let remain = 2 * get_addrs_msg.max - addrs.len() as u32;
|
||||
addrs.append(&mut self.hosts.container.fetch_n_random_excluding_schemes(
|
||||
HostColor::Gold,
|
||||
&get_addrs_msg.transports,
|
||||
&requested_transports,
|
||||
remain,
|
||||
));
|
||||
|
||||
@@ -184,7 +186,7 @@ impl ProtocolAddress {
|
||||
let remain = 2 * get_addrs_msg.max - addrs.len() as u32;
|
||||
addrs.append(&mut self.hosts.container.fetch_n_random_excluding_schemes(
|
||||
HostColor::White,
|
||||
&get_addrs_msg.transports,
|
||||
&requested_transports,
|
||||
remain,
|
||||
));
|
||||
|
||||
@@ -200,6 +202,9 @@ impl ProtocolAddress {
|
||||
let remain = 2 * get_addrs_msg.max - addrs.len() as u32;
|
||||
addrs.append(&mut self.hosts.container.fetch_n_random(HostColor::Dark, remain));
|
||||
|
||||
// Filter out transports not meant to be shared like Socks5 and Socks5+tls
|
||||
addrs.retain(|addr| TRANSPORT_COMBOS.contains(&addr.0.scheme()));
|
||||
|
||||
debug!(
|
||||
target: "net::protocol_address::handle_receive_get_addrs()",
|
||||
"Sending {} addresses to {}", addrs.len(), self.channel.address(),
|
||||
|
||||
Reference in New Issue
Block a user