|
|
@@ -93,6 +93,11 @@ impl ProtocolAddress {
|
|
|
|
|
|
// TODO: We might want to close the channel here if we're getting
|
|
|
// corrupted addresses.
|
|
|
+ // Validate addreses length
|
|
|
+ if addrs_msg.addrs.len() > self.settings.outbound_connections {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
self.hosts.store(&addrs_msg.addrs).await;
|
|
|
}
|
|
|
}
|
|
|
@@ -113,7 +118,20 @@ impl ProtocolAddress {
|
|
|
"Received GetAddrs({}) message from {}", get_addrs_msg.max, self.channel.address(),
|
|
|
);
|
|
|
|
|
|
- let addrs = self.hosts.fetch_n_random(get_addrs_msg.max).await;
|
|
|
+ // Validate transports length
|
|
|
+ // TODO: Verify this limit. It should be the max number of all our allowed transports,
|
|
|
+ // plus their mixing.
|
|
|
+ if get_addrs_msg.transports.len() > 20 {
|
|
|
+ // TODO: Should this error out, effectively ending the connection?
|
|
|
+ let addrs_msg = AddrsMessage { addrs: vec![] };
|
|
|
+ self.channel.send(&addrs_msg).await?;
|
|
|
+ continue
|
|
|
+ }
|
|
|
+
|
|
|
+ let addrs = self
|
|
|
+ .hosts
|
|
|
+ .fetch_n_random_with_schemes(&get_addrs_msg.transports, get_addrs_msg.max)
|
|
|
+ .await;
|
|
|
debug!(
|
|
|
target: "net::protocol_address::handle_receive_get_addrs()",
|
|
|
"Sending {} addresses to {}", addrs.len(), self.channel.address(),
|
|
|
@@ -160,7 +178,10 @@ impl ProtocolBase for ProtocolAddress {
|
|
|
self.jobsman.spawn(self.clone().handle_receive_get_addrs(), ex).await;
|
|
|
|
|
|
// Send get_address message.
|
|
|
- let get_addrs = GetAddrsMessage { max: self.settings.outbound_connections as u32 };
|
|
|
+ let get_addrs = GetAddrsMessage {
|
|
|
+ max: self.settings.outbound_connections as u32,
|
|
|
+ transports: self.settings.allowed_transports.clone(),
|
|
|
+ };
|
|
|
self.channel.send(&get_addrs).await?;
|
|
|
|
|
|
debug!(target: "net::protocol_address::start()", "END => address={}", self.channel.address());
|