-
Notifications
You must be signed in to change notification settings - Fork 62
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
mickvandijke
merged 19 commits into
maidsafe:main
from
mickvandijke:feat-node-from-code
Jan 23, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9a0a748
feat: add spawnable nodes and networks
mickvandijke 124c249
chore: add shutdown fn to running node and network
mickvandijke 286ed5c
fix: impl clone for `RunningNode`
mickvandijke ecff01c
chore: add peer id to initial peers
mickvandijke 161b57a
fix: unnecessary async
mickvandijke 0a41cd4
chore: spawn local network example
mickvandijke f52d39d
test: improve spawn node test
mickvandijke dfcf028
fix: wait for at least 1 node listen addr
mickvandijke f8f650b
test: update spawn network test and example
mickvandijke c567286
chore: removed unused `EvmTestnet` export
mickvandijke 60460a1
fix: replace unwraps with expects in spawn_local_network example
mickvandijke b9d97a5
fix: missing `env-filter` feat flag
mickvandijke 17b0f20
chore: update spawn network example
mickvandijke 664175f
fix: unintended `LocalSwarmCmd` action
mickvandijke 2e66919
feat: add `get_listen_addrs_with_peer_id` to `RunningNode`
mickvandijke 73f902b
fix: keep `SwarmDriver` shutdown sender in scope for client
mickvandijke 67c01db
refactor: improve node shutdown check in loops
mickvandijke e079555
chore: add missing copyright notices
mickvandijke 3222006
refactor: renamed node and network spawner files
mickvandijke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright 2025 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
use ant_node::spawn::network_spawner::NetworkSpawner; | ||
use std::time::Duration; | ||
use tokio::time::sleep; | ||
use tracing_subscriber::layer::SubscriberExt; | ||
use tracing_subscriber::util::SubscriberInitExt; | ||
use tracing_subscriber::{fmt, EnvFilter}; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
tracing_subscriber::registry() | ||
.with(fmt::layer()) | ||
.with(EnvFilter::from_env("RUST_LOG")) | ||
.init(); | ||
|
||
let network_size = 20; | ||
|
||
let running_network = NetworkSpawner::new() | ||
.with_evm_network(Default::default()) | ||
.with_local(true) | ||
.with_size(network_size) | ||
.spawn() | ||
.await | ||
.expect("Failed to spawn network"); | ||
|
||
// Wait for nodes to dial each other | ||
sleep(Duration::from_secs(10)).await; | ||
|
||
for node in running_network.running_nodes() { | ||
println!("Node listening on: {:?}", node.get_listen_addrs().await); | ||
} | ||
|
||
running_network.shutdown(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright 2025 MaidSafe.net limited. | ||
// | ||
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. | ||
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed | ||
// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. Please review the Licences for the specific language governing | ||
// permissions and limitations relating to use of the SAFE Network Software. | ||
|
||
pub mod network_spawner; | ||
pub mod node_spawner; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 theNodeEventsChannel
below, can this be re-used here?There was a problem hiding this comment.
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 theSwarmDriver
loop it wouldn't make sense, as the broadcast channel usesant_node::event::NodeEvent
, which is inaccessible from theant-networking
crate in which theSwarmDriver
loop resides.