| 1 |
use clap::Args; |
| 2 |
use anyhow::{Context, Result}; |
| 3 |
use tracing::info; |
| 4 |
|
| 5 |
use crate::config::Config; |
| 6 |
use crate::client::ZephyrClient; |
| 7 |
use super::Command; |
| 8 |
|
| 9 |
#[derive(Debug, Args)] |
| 10 |
pub struct JoinCommand { |
| 11 |
/// Bootstrap peer address (host:port) |
| 12 |
bootstrap_peer: String, |
| 13 |
|
| 14 |
/// Timeout in seconds |
| 15 |
#[arg(short, long, default_value = "30")] |
| 16 |
timeout: u64, |
| 17 |
|
| 18 |
/// Skip connectivity test |
| 19 |
#[arg(long)] |
| 20 |
skip_test: bool, |
| 21 |
} |
| 22 |
|
| 23 |
#[async_trait::async_trait] |
| 24 |
impl Command for JoinCommand { |
| 25 |
async fn execute(&self, config: &Config) -> Result<()> { |
| 26 |
info!("Joining ZephyrFS network via bootstrap peer: {}", self.bootstrap_peer); |
| 27 |
|
| 28 |
let client = ZephyrClient::new(config); |
| 29 |
|
| 30 |
// Test connectivity to bootstrap peer if not skipped |
| 31 |
if !self.skip_test { |
| 32 |
println!("Testing connectivity to bootstrap peer..."); |
| 33 |
// TODO: Implement ping/connectivity test |
| 34 |
} |
| 35 |
|
| 36 |
// Join the network |
| 37 |
println!("Joining network..."); |
| 38 |
client.join_network(&self.bootstrap_peer).await |
| 39 |
.context("Failed to join network")?; |
| 40 |
|
| 41 |
// Verify connection |
| 42 |
println!("Verifying connection..."); |
| 43 |
let node_info = client.get_node_status().await |
| 44 |
.context("Failed to get node status after joining")?; |
| 45 |
|
| 46 |
println!("✓ Successfully joined ZephyrFS network!"); |
| 47 |
println!(" Bootstrap peer: {}", self.bootstrap_peer); |
| 48 |
println!(" Connected peers: {}", node_info.peers_connected); |
| 49 |
println!(" Node status: {}", node_info.status); |
| 50 |
|
| 51 |
if node_info.peers_connected == 0 { |
| 52 |
println!("\n⚠ Warning: No peers connected yet. This might be expected for a new network."); |
| 53 |
} |
| 54 |
|
| 55 |
Ok(()) |
| 56 |
} |
| 57 |
} |