Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add NodeSpawner and NetworkSpawner #2642

Merged
merged 19 commits into from
Jan 23, 2025

Conversation

mickvandijke
Copy link
Contributor

@mickvandijke mickvandijke commented Jan 17, 2025

REQUIRES mDNS REMOVAL PR: #2652

Adds the option to spawn nodes and networks from code using NodeSpawner and NetworkSpawner.

TODO:

  • Fn to shutdown a node.
  • Fn to shutdown a network.
  • Test that verifies nodes in a network know each other.


/// Once a node is started and running, the user obtains
/// a `NodeRunning` object which can be used to interact with it.
#[derive(Clone)]
pub struct RunningNode {
shutdown_sender: watch::Sender<bool>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We send TerminateNode(String) via the NodeEventsChannel below, can this be re-used here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be reused for the node (NodeEvents) loop, but for the SwarmDriver loop it wouldn't make sense, as the broadcast channel uses ant_node::event::NodeEvent, which is inaccessible from the ant-networking crate in which the SwarmDriver loop resides.

ant-node/examples/spawn_local_network.rs Fixed Show fixed Hide fixed
ant-node/examples/spawn_local_network.rs Fixed Show fixed Hide fixed
ant-node/src/spawn/network.rs Fixed Show fixed Hide fixed
@mickvandijke mickvandijke marked this pull request as ready for review January 21, 2025 11:37
@@ -280,10 +285,15 @@
// TODO: Think about handling the mDNS error here.
let (network, event_receiver, swarm_driver) = network_builder.build_client();

let _swarm_driver = ant_networking::time::spawn(swarm_driver.run());
// TODO: Implement graceful SwarmDriver shutdown for client.

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
Copy link
Member

@maqi maqi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the files under the spawn, as the file names of network.rs and node.rs is very similar to the existing Node Network, can they be renamed to network_spawner.rs node_spawner.rs` to match the struct names ?

Also, seems the functions within the NetworkSpawner and NodeSpawner are very much similar to the existing ones, for example ant_node\src\bin\antnode\main.rs::create_secret_key_file
I am wondering why there is new duplicated functions as well?

It seems NetworkSpawner and NodeSpawner are two utility wrapping struct, which seems the PR title is bit misleading.
Shall the PR Title change to: Add NodeSpawner and NetworkSpawner ?

ant-node/examples/spawn_local_network.rs Outdated Show resolved Hide resolved
ant-node/src/spawn/mod.rs Outdated Show resolved Hide resolved
ant-node/src/spawn/network.rs Outdated Show resolved Hide resolved
ant-node/src/spawn/node.rs Outdated Show resolved Hide resolved
ant-node/src/utils.rs Show resolved Hide resolved
@mickvandijke
Copy link
Contributor Author

for the files under the spawn, as the file names of network.rs and node.rs is very similar to the existing Node Network, can they be renamed to network_spawner.rs node_spawner.rs` to match the struct names ?

Ah yes, great suggestion!

Also, seems the functions within the NetworkSpawner and NodeSpawner are very much similar to the existing ones, for example ant_node\src\bin\antnode\main.rs::create_secret_key_file I am wondering why there is new duplicated functions as well?

Functions like create_secret_key_file etc.. have been moved to ant_node/src/utils.rs. They shouldn't be duplicate.

It seems NetworkSpawner and NodeSpawner are two utility wrapping struct, which seems the PR title is bit misleading. Shall the PR Title change to: Add NodeSpawner and NetworkSpawner ?

Sure, makes sense!

@mickvandijke mickvandijke changed the title feat: add spawnable nodes and networks feat: add NodeSpawner and NetworkSpawner Jan 23, 2025
@mickvandijke mickvandijke added this pull request to the merge queue Jan 23, 2025
Merged via the queue into maidsafe:main with commit 8ad5a4f Jan 23, 2025
24 of 25 checks passed
@mickvandijke mickvandijke deleted the feat-node-from-code branch January 23, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants