Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async fn main() -> Result<()> {

// Create and start the node
let node = P2PNode::new(config).await?;
node.start().await?;

// Handle bootstrap peers
let mut bootstrap_addrs: Vec<Multiaddr> = Vec::new();
Expand Down
1 change: 1 addition & 0 deletions examples/test_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ impl TestNode {
.await
.context("Failed to create P2P node")?,
);
node.start().await.context("Failed to start P2P node")?;

// Get actual listen addresses after node creation
let actual_addrs = node.listen_addrs().await;
Expand Down
1 change: 1 addition & 0 deletions src/messaging/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ impl MessagingService {
}

let node = crate::network::P2PNode::new(node_config).await?;
node.start().await?;
Arc::new(node)
};
let transport = Arc::new(MessageTransport::new(network, dht_client.clone()).await?);
Expand Down
17 changes: 4 additions & 13 deletions src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1037,17 +1037,7 @@ impl P2PNode {
entangled_id: None,
binary_hash,
};
info!("Created P2P node with peer ID: {}", node.peer_id);

// Start the network listeners to populate listen addresses
node.start_network_listeners().await?;

// Update the connection monitor with actual peers reference
node.start_connection_monitor().await;

// Start message receiving system so messages work immediately after node creation
// This is critical for basic P2P messaging to work
node.start_message_receiving_system().await?;
info!("Created P2P node with peer ID: {} (call start() to begin networking)", node.peer_id);

Ok(node)
}
Expand Down Expand Up @@ -1159,12 +1149,13 @@ impl P2PNode {
// Start listening on configured addresses using transport layer
self.start_network_listeners().await?;

// Update the connection monitor with actual peers reference
self.start_connection_monitor().await;

// Log current listen addresses
let listen_addrs = self.listen_addrs.read().await;
info!("P2P node started on addresses: {:?}", *listen_addrs);

// MCP removed

// Start message receiving system
self.start_message_receiving_system().await?;

Expand Down
6 changes: 6 additions & 0 deletions tests/connection_lifecycle_integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ async fn test_connection_lifecycle_with_keepalive() {
};

let node1 = P2PNode::new(config1).await.expect("Failed to create node1");
node1.start().await.expect("Failed to start node1");
let node2 = P2PNode::new(config2).await.expect("Failed to create node2");
node2.start().await.expect("Failed to start node2");

// Get their addresses
let addrs1 = node1.listen_addrs().await;
Expand Down Expand Up @@ -182,7 +184,9 @@ async fn test_send_message_validates_connection_state() {
};

let node1 = P2PNode::new(config1).await.expect("Failed to create node1");
node1.start().await.expect("Failed to start node1");
let node2 = P2PNode::new(config2).await.expect("Failed to create node2");
node2.start().await.expect("Failed to start node2");

// Get addresses and connect
let addrs2 = node2.listen_addrs().await;
Expand Down Expand Up @@ -265,7 +269,9 @@ async fn test_multiple_message_exchanges() {
};

let node1 = P2PNode::new(config1).await.expect("Failed to create node1");
node1.start().await.expect("Failed to start node1");
let node2 = P2PNode::new(config2).await.expect("Failed to create node2");
node2.start().await.expect("Failed to start node2");

// Connect nodes
let addrs2 = node2.listen_addrs().await;
Expand Down
2 changes: 2 additions & 0 deletions tests/connection_lifecycle_proof_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ async fn test_connection_lifecycle_infrastructure_exists() {
};

let node = P2PNode::new(config).await.expect("Failed to create node");
node.start().await.expect("Failed to start node");

info!("Node created successfully");

Expand Down Expand Up @@ -112,6 +113,7 @@ async fn test_keepalive_task_initialized() {
};

let _node = P2PNode::new(config).await.expect("Failed to create node");
_node.start().await.expect("Failed to start node");

// The keepalive task is spawned in P2PNode::new() and runs in the background
// It sends keepalive messages every 15 seconds to prevent the 30-second ant-quic timeout
Expand Down
3 changes: 2 additions & 1 deletion tests/end_to_end_scenarios_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ impl TestUser {

let peer_id = format!("test_user_{}", username);
let node = P2PNode::new(config).await?;
node.start().await?;

Ok(Self {
node: Arc::new(node),
Expand All @@ -55,7 +56,7 @@ impl TestUser {
}

async fn start(&self) -> Result<()> {
// TODO: Implement when node.start() API is available
// Node is already started after P2PNode::new() + start() in TestUser::new()
sleep(Duration::from_millis(100)).await;
Ok(())
}
Expand Down
Loading