Skip to content

Commit

Permalink
Add initial location for gateways
Browse files Browse the repository at this point in the history
  • Loading branch information
iduartgomez committed Jun 11, 2024
1 parent 3a68fdb commit 7bc29a7
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
4 changes: 4 additions & 0 deletions crates/core/src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/node/p2p_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<OpManager>,
notification_channel: EventLoopNotificationsReceiver,
Expand Down
21 changes: 19 additions & 2 deletions crates/core/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -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 {
Expand Down

0 comments on commit 7bc29a7

Please sign in to comment.