From 7bc29a7b2b8750b8b29bcea1530b39cbf8e0dc2f Mon Sep 17 00:00:00 2001 From: Ignacio Duart Date: Tue, 11 Jun 2024 21:36:35 +0200 Subject: [PATCH] Add initial location for gateways --- crates/core/src/node.rs | 4 ++++ crates/core/src/node/p2p_impl.rs | 2 +- crates/core/src/server.rs | 21 +++++++++++++++++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/core/src/node.rs b/crates/core/src/node.rs index fb28dd006..94992dab6 100644 --- a/crates/core/src/node.rs +++ b/crates/core/src/node.rs @@ -66,6 +66,10 @@ pub(crate) mod testing_impl; pub struct Node(NodeP2P); impl Node { + pub fn update_location(&mut self, location: Location) { + self.0.op_manager.ring.update_location(Some(location)); + } + pub async fn run(self) -> anyhow::Result<()> { self.0.run_node().await?; Ok(()) diff --git a/crates/core/src/node/p2p_impl.rs b/crates/core/src/node/p2p_impl.rs index 26b04cacb..887191f0f 100644 --- a/crates/core/src/node/p2p_impl.rs +++ b/crates/core/src/node/p2p_impl.rs @@ -24,7 +24,7 @@ use crate::{ use super::OpManager; -pub(super) struct NodeP2P { +pub(crate) struct NodeP2P { pub(crate) peer_pub_key: TransportPublicKey, pub(crate) op_manager: Arc, notification_channel: EventLoopNotificationsReceiver, diff --git a/crates/core/src/server.rs b/crates/core/src/server.rs index 2a2d06ec2..559496af1 100644 --- a/crates/core/src/server.rs +++ b/crates/core/src/server.rs @@ -179,7 +179,11 @@ pub mod network_node { use anyhow::Context; use tower_http::trace::TraceLayer; - use crate::{client_events::websocket::WebSocketProxy, config::Config, dev_tool::NodeConfig}; + use crate::{ + client_events::websocket::WebSocketProxy, + config::Config, + dev_tool::{Location, NodeConfig}, + }; use super::{http_gateway::HttpGateway, serve}; @@ -195,11 +199,24 @@ pub mod network_node { .await .with_context(|| "failed while loading node config")?; let is_gateway = node_config.is_gateway; - let node = node_config + let location = is_gateway + .then(|| { + node_config + .peer_id + .clone() + .map(|id| Location::from_address(&id.addr())) + }) + .flatten(); + let mut node = node_config .build([Box::new(gw), Box::new(ws_proxy)]) .await .with_context(|| "failed while building the node")?; + if let Some(location) = location { + tracing::info!("Setting initial location: {location}"); + node.update_location(location); + } + tracing::info!("Starting node"); match node.run().await {