-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor Network Subcommands (#108)
### Description Refactors the network subcommands to make them more explicit. Now there is just Discovery subcommand ``` hera disc ``` Gossip subcommand ``` hera gossip ``` --------- Co-authored-by: nicolas <[email protected]>
- Loading branch information
1 parent
9c1af7a
commit 5aec5a5
Showing
9 changed files
with
108 additions
and
58 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//! Discovery subcommand for Hera. | ||
use crate::globals::GlobalArgs; | ||
use clap::Args; | ||
use eyre::Result; | ||
use op_net::discovery::builder::DiscoveryBuilder; | ||
use std::net::{IpAddr, Ipv4Addr, SocketAddr}; | ||
|
||
/// The Hera discovery subcommand. | ||
#[derive(Debug, Clone, Args)] | ||
#[non_exhaustive] | ||
pub struct DiscCommand { | ||
/// Port to listen for gossip on. | ||
#[clap(long, short = 'l', default_value = "9099", help = "Port to listen for gossip on")] | ||
pub gossip_port: u16, | ||
/// Interval to send discovery packets. | ||
#[clap(long, short = 'i', default_value = "1", help = "Interval to send discovery packets")] | ||
pub interval: u64, | ||
} | ||
|
||
impl DiscCommand { | ||
/// Run the discovery subcommand. | ||
pub async fn run(self, args: &GlobalArgs) -> Result<()> { | ||
let socket = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), self.gossip_port); | ||
tracing::info!("Starting discovery service on {:?}", socket); | ||
|
||
let mut discovery_builder = | ||
DiscoveryBuilder::new().with_address(socket).with_chain_id(args.l2_chain_id); | ||
let mut discovery = discovery_builder.build()?; | ||
discovery.interval = std::time::Duration::from_secs(self.interval); | ||
let mut peer_recv = discovery.start()?; | ||
tracing::info!("Discovery service started, receiving peers."); | ||
|
||
loop { | ||
match peer_recv.recv().await { | ||
Some(peer) => { | ||
tracing::info!("Received peer: {:?}", peer); | ||
} | ||
None => { | ||
tracing::warn!("Failed to receive peer"); | ||
} | ||
} | ||
} | ||
} | ||
} |
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
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