Skip to content

Commit

Permalink
[network] Add testing for connection limits
Browse files Browse the repository at this point in the history
  • Loading branch information
gregnazario authored and bors-libra committed Jun 3, 2021
1 parent 244cae3 commit be53de6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 5 deletions.
12 changes: 10 additions & 2 deletions config/management/operational/src/test_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
validator_set::DecryptedValidatorInfo,
TransactionContext,
};
use diem_config::{config, config::Peer};
use diem_config::{config, config::Peer, network_id::NetworkId};
use diem_crypto::{ed25519::Ed25519PublicKey, x25519};
use diem_management::{error::Error, secure_backend::DISK};
use diem_types::{
Expand Down Expand Up @@ -62,14 +62,22 @@ impl OperationalTool {
command.account_resource()
}

pub fn check_endpoint(&self, network_address: NetworkAddress) -> Result<String, Error> {
pub fn check_endpoint(
&self,
network_id: NetworkId,
network_address: NetworkAddress,
) -> Result<String, Error> {
let args = format!(
"
{command}
--address {network_address}
--chain-id {chain_id}
--network-id {network_id}
",
command = command(TOOL_NAME, CommandName::CheckEndpoint),
chain_id = self.chain_id.id(),
network_address = network_address,
network_id = network_id
);
let command = Command::from_iter(args.split_whitespace());
command.check_endpoint()
Expand Down
33 changes: 32 additions & 1 deletion testsuite/diem-swarm/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ use diem_genesis_tool::{
};
use diem_logger::prelude::*;
use diem_temppath::TempPath;
use diem_types::{account_address::AccountAddress, PeerId};
use diem_types::{
account_address::AccountAddress,
network_address::{NetworkAddress, Protocol},
PeerId,
};
use std::{
collections::HashMap,
env,
Expand Down Expand Up @@ -326,6 +330,33 @@ impl DiemNode {
}
}
}

pub fn public_address(&self) -> NetworkAddress {
let network = self
.config
.full_node_networks
.iter()
.find(|network| network.network_id == NetworkId::Public)
.unwrap();
let port = network
.listen_address
.as_slice()
.iter()
.find_map(|proto| {
if let Protocol::Tcp(port) = proto {
Some(port)
} else {
None
}
})
.unwrap();
let key = network.identity_key().public_key();
NetworkAddress::from_str(&format!(
"/ip4/126.0.0.1/tcp/{}/ln-noise-ik/{}/ln-handshake/0",
port, key
))
.unwrap()
}
}

pub enum HealthStatus {
Expand Down
12 changes: 10 additions & 2 deletions testsuite/smoke-test/src/full_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ use crate::{smoke_test_environment::SmokeTestEnvironment, test_utils::compare_ba
use cli::client_proxy::{ClientProxy, IndexAndSequence};
use diem_client::AccountAddress;
use diem_config::{
config::{NodeConfig, Peer, PeerRole, HANDSHAKE_VERSION},
config::{DiscoveryMethod, NodeConfig, Peer, PeerRole, HANDSHAKE_VERSION},
network_id::NetworkId,
};
use diem_operational_tool::test_helper::OperationalTool;
use diem_types::{
account_config::{testnet_dd_account_address, treasury_compliance_account_address},
network_address::{NetworkAddress, Protocol},
};
use std::{collections::HashSet, net::Ipv4Addr};
use diem_config::config::DiscoveryMethod;

// TODO: All of this convenience code below should be put in the client proxy directly, it's
// very hard for users to know what the order of a bunch of random inputs should be
Expand Down Expand Up @@ -378,6 +378,14 @@ fn test_private_full_node() {
vec![(10.0, XUS.to_string())],
get_balances(&mut validator_client, 0),
));

// Check that we can't connect, testing the connection limit
let op_tool = OperationalTool::test();
let mut private_swarm = private_swarm.lock();
let private_node = private_swarm.mut_node(0).unwrap();
op_tool
.check_endpoint(NetworkId::Public, private_node.public_address())
.expect_err("Shouldn't be able to connect to private node anonymously");
}

fn add_node_to_seeds(
Expand Down

0 comments on commit be53de6

Please sign in to comment.