nodes are not connecting to themselves anymore

Signed-off-by: Valentyn Faychuk <valy@detee.ltd>
This commit is contained in:
Valentyn Faychuk 2024-12-24 02:14:29 +02:00
parent 3b960ed596
commit e5e4109007
Signed by: valy
GPG Key ID: F1AB995E20FEADC5
3 changed files with 14 additions and 30 deletions

20
Cargo.lock generated

@ -1470,20 +1470,6 @@ dependencies = [
"parking_lot_core", "parking_lot_core",
] ]
[[package]]
name = "dashmap"
version = "6.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5041cc499144891f3790297212f32a74fb938e5136a14943f338ef9e0ae276cf"
dependencies = [
"cfg-if",
"crossbeam-utils",
"hashbrown 0.14.5",
"lock_api",
"once_cell",
"parking_lot_core",
]
[[package]] [[package]]
name = "data-encoding" name = "data-encoding"
version = "2.6.0" version = "2.6.0"
@ -2113,13 +2099,11 @@ dependencies = [
"actix-web", "actix-web",
"async-stream", "async-stream",
"chrono", "chrono",
"dashmap 6.1.0",
"detee-sgx", "detee-sgx",
"env_logger 0.11.5", "env_logger 0.11.5",
"hyper 1.4.1", "hyper 1.4.1",
"hyper-rustls 0.27.3", "hyper-rustls 0.27.3",
"hyper-util", "hyper-util",
"once_cell",
"prost", "prost",
"prost-types", "prost-types",
"public-ip", "public-ip",
@ -4277,7 +4261,7 @@ checksum = "67169e4f1faabb717ce81b5ca93960da21e3ac5c9b75cb6792f9b3ce38db459f"
dependencies = [ dependencies = [
"async-trait", "async-trait",
"bincode", "bincode",
"dashmap 5.5.3", "dashmap",
"futures", "futures",
"futures-util", "futures-util",
"indexmap 2.6.0", "indexmap 2.6.0",
@ -4753,7 +4737,7 @@ dependencies = [
"async-channel", "async-channel",
"bytes", "bytes",
"crossbeam-channel", "crossbeam-channel",
"dashmap 5.5.3", "dashmap",
"futures-util", "futures-util",
"histogram", "histogram",
"indexmap 2.6.0", "indexmap 2.6.0",

@ -122,14 +122,14 @@ impl State {
fn delete_mratls_conn(&self, ip: &str) { fn delete_mratls_conn(&self, ip: &str) {
if let Ok(mut conns) = self.conns.write() { if let Ok(mut conns) = self.conns.write() {
conns.insert(ip.to_string()); conns.remove(ip);
} }
} }
pub fn increase_mint_requests(&self) { pub fn increase_mint_requests(&self) {
if let Ok(mut nodes) = self.nodes.write() { if let Ok(mut nodes) = self.nodes.write() {
if let Some(my_info) = nodes.get_mut(&self.my_ip) { if let Some(my_info) = nodes.get_mut(&self.my_ip) {
my_info.mint_requests += 1; *my_info = NodeInfo { mint_requests: my_info.mint_requests + 1, ..my_info.clone() };
} }
} }
} }
@ -137,7 +137,7 @@ impl State {
pub fn increase_mints(&self) { pub fn increase_mints(&self) {
if let Ok(mut nodes) = self.nodes.write() { if let Ok(mut nodes) = self.nodes.write() {
if let Some(my_info) = nodes.get_mut(&self.my_ip) { if let Some(my_info) = nodes.get_mut(&self.my_ip) {
my_info.mints += 1; *my_info = NodeInfo { mints: my_info.mints + 1, ..my_info.clone() };
} }
} }
} }
@ -145,7 +145,7 @@ impl State {
pub fn increase_mratls_conns(&self) { pub fn increase_mratls_conns(&self) {
if let Ok(mut nodes) = self.nodes.write() { if let Ok(mut nodes) = self.nodes.write() {
if let Some(my_info) = nodes.get_mut(&self.my_ip) { if let Some(my_info) = nodes.get_mut(&self.my_ip) {
my_info.mratls_conns += 1; *my_info = NodeInfo { mratls_conns: my_info.mratls_conns + 1, ..my_info.clone() };
} }
} }
} }
@ -154,7 +154,8 @@ impl State {
if let Ok(mut nodes) = self.nodes.write() { if let Ok(mut nodes) = self.nodes.write() {
if let Some(my_info) = nodes.get_mut(&self.my_ip) { if let Some(my_info) = nodes.get_mut(&self.my_ip) {
if my_info.mratls_conns > 0 { if my_info.mratls_conns > 0 {
my_info.mratls_conns -= 1; *my_info =
NodeInfo { mratls_conns: my_info.mratls_conns - 1, ..my_info.clone() };
} }
} }
} }
@ -163,7 +164,7 @@ impl State {
pub fn increase_disk_attacks(&self) { pub fn increase_disk_attacks(&self) {
if let Ok(mut nodes) = self.nodes.write() { if let Ok(mut nodes) = self.nodes.write() {
if let Some(my_info) = nodes.get_mut(&self.my_ip) { if let Some(my_info) = nodes.get_mut(&self.my_ip) {
my_info.disk_attacks += 1; *my_info = NodeInfo { disk_attacks: my_info.disk_attacks + 1, ..my_info.clone() };
} }
} }
} }
@ -171,7 +172,7 @@ impl State {
pub fn increase_net_attacks(&self) { pub fn increase_net_attacks(&self) {
if let Ok(mut nodes) = self.nodes.write() { if let Ok(mut nodes) = self.nodes.write() {
if let Some(my_info) = nodes.get_mut(&self.my_ip) { if let Some(my_info) = nodes.get_mut(&self.my_ip) {
my_info.net_attacks += 1; *my_info = NodeInfo { net_attacks: my_info.net_attacks + 1, ..my_info.clone() };
} }
} }
} }
@ -179,7 +180,7 @@ impl State {
pub fn declare_myself_public(&self) { pub fn declare_myself_public(&self) {
if let Ok(mut nodes) = self.nodes.write() { if let Ok(mut nodes) = self.nodes.write() {
if let Some(my_info) = nodes.get_mut(&self.my_ip) { if let Some(my_info) = nodes.get_mut(&self.my_ip) {
my_info.public = true; *my_info = NodeInfo { public: true, ..my_info.clone() };
} }
} }
} }
@ -223,8 +224,7 @@ impl State {
.map(|ip| ip.to_string()) .map(|ip| ip.to_string())
.filter(|ip| ip != &self.my_ip && !conn_ips.contains(ip)) .filter(|ip| ip != &self.my_ip && !conn_ips.contains(ip))
.cycle() .cycle()
.skip(skip) .nth(skip);
.next();
} }
None None
} }
@ -240,7 +240,7 @@ impl State {
.map(|curr_info| node_info.is_newer_than(&curr_info)) .map(|curr_info| node_info.is_newer_than(&curr_info))
.unwrap_or(true); .unwrap_or(true);
if is_update_new { if is_update_new {
nodes.insert(node_ip.clone(), node_info.clone()); let _ = nodes.insert(node_ip.clone(), node_info.clone());
} }
} }
if is_update_new { if is_update_new {

@ -14,7 +14,7 @@ pub async fn grpc_new_conn(
ra_cfg: RaTlsConfig, ra_cfg: RaTlsConfig,
tx: Sender<InternalNodeUpdate>, tx: Sender<InternalNodeUpdate>,
) { ) {
if Ipv4Addr::from_str(&node_ip).is_err() { if Ipv4Addr::from_str(&node_ip).is_err() || node_ip == state.get_my_ip() {
println!("IPv4 address is invalid: {node_ip}"); println!("IPv4 address is invalid: {node_ip}");
return; return;
} }