Skip to content

Commit

Permalink
Rename remaining places to ip packet router
Browse files Browse the repository at this point in the history
  • Loading branch information
octol committed Nov 2, 2023
1 parent d2a5a48 commit 304f442
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
4 changes: 2 additions & 2 deletions gateway/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::node::storage::error::StorageError;
use nym_ip_packet_router::error::IpForwarderError;
use nym_ip_packet_router::error::IpPacketRouterError;
use nym_network_requester::error::{ClientCoreError, NetworkRequesterError};
use nym_validator_client::nyxd::error::NyxdError;
use nym_validator_client::nyxd::AccountId;
Expand Down Expand Up @@ -110,7 +110,7 @@ pub(crate) enum GatewayError {
#[error("there was an issue with the local ip packet router: {source}")]
IpPacketRouterFailure {
#[from]
source: IpForwarderError,
source: IpPacketRouterError,
},

#[error("failed to startup local network requester")]
Expand Down
2 changes: 1 addition & 1 deletion gateway/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl<St> Gateway<St> {

// TODO: well, wire it up internally to gateway traffic, shutdowns, etc.
let (on_start_tx, on_start_rx) = oneshot::channel();
let mut ip_builder = nym_ip_packet_router::IpForwarderBuilder::new(ip_opts.config.clone())
let mut ip_builder = nym_ip_packet_router::IpPacketRouterBuilder::new(ip_opts.config.clone())
.with_shutdown(shutdown)
.with_custom_gateway_transceiver(Box::new(transceiver))
.with_wait_for_gateway(true)
Expand Down
22 changes: 11 additions & 11 deletions service-providers/ip-packet-router/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ use std::{
path::{Path, PathBuf},
};

use crate::config::persistence::IpForwarderPaths;
use crate::config::persistence::IpPacketRouterPaths;

use self::template::CONFIG_TEMPLATE;

mod persistence;
mod template;

const DEFAULT_IP_FORWARDERS_DIR: &str = "ip-forwarder";
const DEFAULT_IP_PACKET_ROUTER_DIR: &str = "ip-packet-router";

/// Derive default path to ip forwarder's config directory.
/// It should get resolved to `$HOME/.nym/service-providers/ip-forwareder/<id>/config`
/// Derive default path to ip packet routers' config directory.
/// It should get resolved to `$HOME/.nym/service-providers/ip-packet-router/<id>/config`
pub fn default_config_directory<P: AsRef<Path>>(id: P) -> PathBuf {
must_get_home()
.join(NYM_DIR)
.join(DEFAULT_SERVICE_PROVIDERS_DIR)
.join(DEFAULT_IP_FORWARDERS_DIR)
.join(DEFAULT_IP_PACKET_ROUTER_DIR)
.join(id)
.join(DEFAULT_CONFIG_DIR)
}

/// Derive default path to ip forwarder's config file.
/// It should get resolved to `$HOME/.nym/service-providers/ip-forwarder/<id>/config/config.toml`
/// Derive default path to ip packet routers' config file.
/// It should get resolved to `$HOME/.nym/service-providers/ip-packet-router/<id>/config/config.toml`
pub fn default_config_filepath<P: AsRef<Path>>(id: P) -> PathBuf {
default_config_directory(id).join(DEFAULT_CONFIG_FILENAME)
}
Expand All @@ -44,7 +44,7 @@ pub fn default_data_directory<P: AsRef<Path>>(id: P) -> PathBuf {
must_get_home()
.join(NYM_DIR)
.join(DEFAULT_SERVICE_PROVIDERS_DIR)
.join(DEFAULT_IP_FORWARDERS_DIR)
.join(DEFAULT_IP_PACKET_ROUTER_DIR)
.join(id)
.join(DEFAULT_DATA_DIR)
}
Expand All @@ -55,7 +55,7 @@ pub struct Config {
#[serde(flatten)]
pub base: BaseClientConfig,

pub storage_paths: IpForwarderPaths,
pub storage_paths: IpPacketRouterPaths,

pub logging: LoggingSettings,
}
Expand All @@ -70,13 +70,13 @@ impl Config {
pub fn new<S: AsRef<str>>(id: S) -> Self {
Config {
base: BaseClientConfig::new(id.as_ref(), env!("CARGO_PKG_VERSION")),
storage_paths: IpForwarderPaths::new_base(default_data_directory(id.as_ref())),
storage_paths: IpPacketRouterPaths::new_base(default_data_directory(id.as_ref())),
logging: Default::default(),
}
}

pub fn with_data_directory<P: AsRef<Path>>(mut self, data_directory: P) -> Self {
self.storage_paths = IpForwarderPaths::new_base(data_directory);
self.storage_paths = IpPacketRouterPaths::new_base(data_directory);
self
}

Expand Down
8 changes: 4 additions & 4 deletions service-providers/ip-packet-router/src/config/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ use std::path::{Path, PathBuf};
pub const DEFAULT_DESCRIPTION_FILENAME: &str = "description.toml";

#[derive(Debug, Deserialize, PartialEq, Eq, Serialize, Clone)]
pub struct IpForwarderPaths {
pub struct IpPacketRouterPaths {
#[serde(flatten)]
pub common_paths: CommonClientPaths,

/// Location of the file containing our description
pub ip_forwarder_description: PathBuf,
pub ip_packet_router_description: PathBuf,
}

impl IpForwarderPaths {
impl IpPacketRouterPaths {
pub fn new_base<P: AsRef<Path>>(base_data_directory: P) -> Self {
let base_dir = base_data_directory.as_ref();

Self {
common_paths: CommonClientPaths::new_base(base_dir),
ip_forwarder_description: base_dir.join(DEFAULT_DESCRIPTION_FILENAME),
ip_packet_router_description: base_dir.join(DEFAULT_DESCRIPTION_FILENAME),
}
}
}
2 changes: 1 addition & 1 deletion service-providers/ip-packet-router/src/config/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ allowed_list_location = '{{ storage_paths.allowed_list_location }}'
unknown_list_location = '{{ storage_paths.unknown_list_location }}'
# Path to file containing description of this network-requester.
ip_forwarder_description = '{{ storage_paths.ip_forwarder_description }}'
ip_packet_router_description = '{{ storage_paths.ip_packet_router_description }}'
##### logging configuration options #####
Expand Down
2 changes: 1 addition & 1 deletion service-providers/ip-packet-router/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
pub use nym_client_core::error::ClientCoreError;

#[derive(thiserror::Error, Debug)]
pub enum IpForwarderError {
pub enum IpPacketRouterError {
#[error("I/O error: {0}")]
IoError(#[from] std::io::Error),

Expand Down
46 changes: 23 additions & 23 deletions service-providers/ip-packet-router/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{net::IpAddr, path::Path};

use error::IpForwarderError;
use error::IpPacketRouterError;
use futures::{channel::oneshot, StreamExt};
use nym_client_core::{
client::mix_traffic::transceiver::GatewayTransceiver,
Expand Down Expand Up @@ -32,7 +32,7 @@ impl OnStartData {
}
}

pub struct IpForwarderBuilder {
pub struct IpPacketRouterBuilder {
config: Config,
wait_for_gateway: bool,
custom_topology_provider: Option<Box<dyn TopologyProvider + Send + Sync>>,
Expand All @@ -41,7 +41,7 @@ pub struct IpForwarderBuilder {
on_start: Option<oneshot::Sender<OnStartData>>,
}

impl IpForwarderBuilder {
impl IpPacketRouterBuilder {
pub fn new(config: Config) -> Self {
Self {
config,
Expand Down Expand Up @@ -92,13 +92,13 @@ impl IpForwarderBuilder {
pub fn with_stored_topology<P: AsRef<Path>>(
mut self,
file: P,
) -> Result<Self, IpForwarderError> {
) -> Result<Self, IpPacketRouterError> {
self.custom_topology_provider =
Some(Box::new(HardcodedTopologyProvider::new_from_file(file)?));
Ok(self)
}

pub async fn run_service_provider(self) -> Result<(), IpForwarderError> {
pub async fn run_service_provider(self) -> Result<(), IpPacketRouterError> {
// Used to notify tasks to shutdown. Not all tasks fully supports this (yet).
let task_handle: TaskHandle = self.shutdown.map(Into::into).unwrap_or_default();

Expand All @@ -119,7 +119,7 @@ impl IpForwarderBuilder {
let (tun, tun_task_tx, tun_task_response_rx) =
nym_wireguard::tun_device::TunDevice::new(None);

let ip_forwarder_service = IpForwarder {
let ip_packet_router_service = IpPacketRouter {
config: self.config,
tun,
tun_task_tx,
Expand All @@ -134,15 +134,15 @@ impl IpForwarderBuilder {
if let Some(on_start) = self.on_start {
if on_start.send(OnStartData::new(self_address)).is_err() {
// the parent has dropped the channel before receiving the response
return Err(IpForwarderError::DisconnectedParent);
return Err(IpPacketRouterError::DisconnectedParent);
}
}

ip_forwarder_service.run().await
ip_packet_router_service.run().await
}
}

struct IpForwarder {
struct IpPacketRouter {
config: Config,
tun: nym_wireguard::tun_device::TunDevice,
tun_task_tx: nym_wireguard::tun_task_channel::TunTaskTx,
Expand All @@ -151,19 +151,19 @@ struct IpForwarder {
task_handle: TaskHandle,
}

impl IpForwarder {
async fn run(mut self) -> Result<(), IpForwarderError> {
impl IpPacketRouter {
async fn run(mut self) -> Result<(), IpPacketRouterError> {
let mut task_client = self.task_handle.fork("main_loop");
while !task_client.is_shutdown() {
tokio::select! {
_ = task_client.recv() => {
log::debug!("IpForwarderService [main loop]: received shutdown");
log::debug!("IpPacketRouter [main loop]: received shutdown");
},
msg = self.mixnet_client.next() => {
if let Some(msg) = msg {
self.on_message(msg).await.ok();
} else {
log::trace!("IpForwarderService [main loop]: stopping since channel closed");
log::trace!("IpPacketRouter [main loop]: stopping since channel closed");
break;
};
},
Expand All @@ -175,30 +175,30 @@ impl IpForwarder {
// .send(input_message)
// .await
// .tap_err(|err| {
// log::error!("IpForwarderService [main loop]: failed to send packet to mixnet: {err}");
// log::error!("IpPacketRouter [main loop]: failed to send packet to mixnet: {err}");
// })
// .ok();
} else {
log::trace!("IpForwarderService [main loop]: stopping since channel closed");
log::trace!("IpPacketRouter [main loop]: stopping since channel closed");
break;
}
}

}
}
log::info!("IpForwarderService: stopping");
log::info!("IpPacketRouter: stopping");
Ok(())
}

async fn on_message(
&mut self,
reconstructed: ReconstructedMessage,
) -> Result<(), IpForwarderError> {
) -> Result<(), IpPacketRouterError> {
log::info!("Received message: {:?}", reconstructed.sender_tag);

let headers = etherparse::SlicedPacket::from_ip(&reconstructed.message).map_err(|err| {
log::warn!("Received non-IP packet: {err}");
IpForwarderError::PacketParseFailed { source: err }
IpPacketRouterError::PacketParseFailed { source: err }
})?;

let (src_addr, dst_addr): (IpAddr, IpAddr) = match headers.ip {
Expand All @@ -212,7 +212,7 @@ impl IpForwarder {
),
None => {
log::warn!("Received non-IP packet");
return Err(IpForwarderError::PacketMissingHeader);
return Err(IpPacketRouterError::PacketMissingHeader);
}
};
log::info!("Received packet: {src_addr} -> {dst_addr}");
Expand Down Expand Up @@ -242,15 +242,15 @@ async fn create_mixnet_client(
custom_topology_provider: Option<Box<dyn TopologyProvider + Send + Sync>>,
wait_for_gateway: bool,
paths: &CommonClientPaths,
) -> Result<nym_sdk::mixnet::MixnetClient, IpForwarderError> {
) -> Result<nym_sdk::mixnet::MixnetClient, IpPacketRouterError> {
let debug_config = config.debug;

let storage_paths = nym_sdk::mixnet::StoragePaths::from(paths.clone());

let mut client_builder =
nym_sdk::mixnet::MixnetClientBuilder::new_with_default_storage(storage_paths)
.await
.map_err(|err| IpForwarderError::FailedToSetupMixnetClient { source: err })?
.map_err(|err| IpPacketRouterError::FailedToSetupMixnetClient { source: err })?
.network_details(NymNetworkDetails::new_from_env())
.debug_config(debug_config)
.custom_shutdown(shutdown)
Expand All @@ -267,10 +267,10 @@ async fn create_mixnet_client(

let mixnet_client = client_builder
.build()
.map_err(|err| IpForwarderError::FailedToSetupMixnetClient { source: err })?;
.map_err(|err| IpPacketRouterError::FailedToSetupMixnetClient { source: err })?;

mixnet_client
.connect_to_mixnet()
.await
.map_err(|err| IpForwarderError::FailedToConnectToMixnet { source: err })
.map_err(|err| IpPacketRouterError::FailedToConnectToMixnet { source: err })
}

0 comments on commit 304f442

Please sign in to comment.