Skip to content

Commit e74d014

Browse files
committed
chore(msg-sim): renaming
1 parent 1d1185a commit e74d014

File tree

2 files changed

+31
-23
lines changed

2 files changed

+31
-23
lines changed

msg-sim/src/namespace.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use tokio::sync::oneshot;
88

99
use crate::dynch::{DynCh, DynRequestSender};
1010
use crate::namespace::helpers::current_netns;
11-
use crate::network::RuntimeMakerFn;
11+
use crate::network::RuntimeFactory;
1212

1313
/// Base directory for named network namespaces.
1414
///
@@ -231,7 +231,7 @@ impl NetworkNamespaceInner {
231231
/// `setns(2)`, which is thread-local.
232232
pub fn spawn<Ctx: 'static>(
233233
self,
234-
make_runtime: RuntimeMakerFn,
234+
runtime_factory: RuntimeFactory,
235235
make_ctx: impl FnOnce() -> Ctx + Send + 'static,
236236
) -> (std::thread::JoinHandle<Result<()>>, DynRequestSender<Ctx>) {
237237
let (tx, mut rx) = DynCh::<Ctx>::channel(8);
@@ -247,7 +247,7 @@ impl NetworkNamespaceInner {
247247
// Create mount namespace and remount /proc for namespace-specific sysctl access
248248
helpers::setup_mount_namespace()?;
249249

250-
let rt = make_runtime();
250+
let rt = runtime_factory();
251251

252252
tracing::debug!("started runtime");
253253
drop(_span);
@@ -288,7 +288,7 @@ pub struct NetworkNamespace<Ctx = ()> {
288288
impl NetworkNamespace {
289289
pub async fn new<Ctx: 'static>(
290290
name: impl Into<String>,
291-
make_runtime: RuntimeMakerFn,
291+
runtime_factory: RuntimeFactory,
292292
make_ctx: impl FnOnce() -> Ctx + Send + 'static,
293293
) -> Result<NetworkNamespace<Ctx>> {
294294
let name = name.into();
@@ -299,7 +299,7 @@ impl NetworkNamespace {
299299
let file = tokio::fs::File::open(path).await?.into_std().await;
300300

301301
let inner = NetworkNamespaceInner { name, file };
302-
let (_receiver_task, task_sender) = inner.try_clone()?.spawn(make_runtime, make_ctx);
302+
let (_receiver_task, task_sender) = inner.try_clone()?.spawn(runtime_factory, make_ctx);
303303

304304
Ok(NetworkNamespace::<Ctx> { inner, task_sender, _receiver_task })
305305
}
@@ -353,17 +353,18 @@ mod tests {
353353
const TCP_SLOW_START_AFTER_IDLE: &str = "/proc/sys/net/ipv4/tcp_slow_start_after_idle";
354354

355355
fn default_runtime() -> tokio::runtime::Runtime {
356-
tokio::runtime::Builder::new_multi_thread()
357-
.enable_all()
358-
.build()
359-
.expect("to create runtime")
356+
tokio::runtime::Builder::new_multi_thread().enable_all().build().expect("to create runtime")
360357
}
361358

362359
#[tokio::test(flavor = "multi_thread")]
363360
async fn mount_namespace_isolates_proc() {
364361
// Create two namespaces
365-
let ns1 = NetworkNamespace::new("test-ns-mount-1", Box::new(default_runtime), || ()).await.unwrap();
366-
let ns2 = NetworkNamespace::new("test-ns-mount-2", Box::new(default_runtime), || ()).await.unwrap();
362+
let ns1 = NetworkNamespace::new("test-ns-mount-1", Box::new(default_runtime), || ())
363+
.await
364+
.unwrap();
365+
let ns2 = NetworkNamespace::new("test-ns-mount-2", Box::new(default_runtime), || ())
366+
.await
367+
.unwrap();
367368

368369
// Verify /proc is mounted in ns1 by checking /proc/self/ns/net exists
369370
let proc_mounted_ns1: bool = ns1
@@ -395,8 +396,12 @@ mod tests {
395396
#[tokio::test(flavor = "multi_thread")]
396397
async fn sysctl_values_are_namespace_specific() {
397398
// Create two namespaces
398-
let ns1 = NetworkNamespace::new("test-ns-sysctl-1", Box::new(default_runtime), || ()).await.unwrap();
399-
let ns2 = NetworkNamespace::new("test-ns-sysctl-2", Box::new(default_runtime), || ()).await.unwrap();
399+
let ns1 = NetworkNamespace::new("test-ns-sysctl-1", Box::new(default_runtime), || ())
400+
.await
401+
.unwrap();
402+
let ns2 = NetworkNamespace::new("test-ns-sysctl-2", Box::new(default_runtime), || ())
403+
.await
404+
.unwrap();
400405

401406
// Set different values in each namespace
402407
let write_result_ns1: std::io::Result<()> = ns1
@@ -462,7 +467,9 @@ mod tests {
462467
#[tokio::test(flavor = "multi_thread")]
463468
async fn namespace_has_isolated_network_identity() {
464469
// Create a namespace
465-
let ns = NetworkNamespace::new("test-ns-identity", Box::new(default_runtime), || ()).await.unwrap();
470+
let ns = NetworkNamespace::new("test-ns-identity", Box::new(default_runtime), || ())
471+
.await
472+
.unwrap();
466473

467474
// Get the network namespace inode from inside the namespace
468475
let ns_inode_inside: u64 = ns

msg-sim/src/network.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ impl Peer {
216216
}
217217
}
218218

219-
pub(crate) type RuntimeMakerFn = Box<dyn FnOnce() -> tokio::runtime::Runtime + Send>;
219+
pub(crate) type RuntimeFactory = Box<dyn FnOnce() -> tokio::runtime::Runtime + Send>;
220220

221221
/// Common context provided to all namespaces.
222222
///
@@ -230,13 +230,13 @@ pub struct CommonContext {
230230
}
231231

232232
pub struct HubOptions {
233-
make_runtime: RuntimeMakerFn,
233+
runtime_factory: RuntimeFactory,
234234
}
235235

236236
impl Default for HubOptions {
237237
fn default() -> Self {
238238
Self {
239-
make_runtime: Box::new(|| {
239+
runtime_factory: Box::new(|| {
240240
tokio::runtime::Builder::new_multi_thread()
241241
.enable_all()
242242
.build()
@@ -264,13 +264,13 @@ pub struct PeerContext {
264264

265265
/// Options for configuring a peer.
266266
pub struct PeerOptions {
267-
make_runtime: RuntimeMakerFn,
267+
runtime_factory: RuntimeFactory,
268268
}
269269

270270
impl Default for PeerOptions {
271271
fn default() -> Self {
272272
Self {
273-
make_runtime: Box::new(|| {
273+
runtime_factory: Box::new(|| {
274274
tokio::runtime::Builder::new_multi_thread()
275275
.enable_all()
276276
.build()
@@ -283,9 +283,9 @@ impl Default for PeerOptions {
283283
impl PeerOptions {
284284
/// Create new peer options with a custom runtime factory.
285285
pub fn with_runtime(
286-
make_runtime: impl FnOnce() -> tokio::runtime::Runtime + Send + 'static,
286+
runtime_factory: impl FnOnce() -> tokio::runtime::Runtime + Send + 'static,
287287
) -> Self {
288-
Self { make_runtime: Box::new(make_runtime) }
288+
Self { runtime_factory: Box::new(runtime_factory) }
289289
}
290290
}
291291

@@ -439,7 +439,7 @@ impl Network {
439439

440440
// Create the hub namespace that will host the bridge.
441441
let namespace_hub =
442-
NetworkNamespace::new(Self::hub_namespace_name(), options.make_runtime, make_ctx)
442+
NetworkNamespace::new(Self::hub_namespace_name(), options.runtime_factory, make_ctx)
443443
.await?;
444444
let fd = namespace_hub.fd();
445445

@@ -496,7 +496,8 @@ impl Network {
496496
};
497497

498498
let network_namespace =
499-
NetworkNamespace::new(namespace_name.clone(), options.make_runtime, make_ctx).await?;
499+
NetworkNamespace::new(namespace_name.clone(), options.runtime_factory, make_ctx)
500+
.await?;
500501

501502
// Step 1: Create the veth pair in the host namespace.
502503
// One end (veth_name) will go to the peer, the other (veth_br_name) to the bridge.

0 commit comments

Comments
 (0)