File tree Expand file tree Collapse file tree
development/qnet-integration/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -358,24 +358,19 @@ impl BlockchainNode {
358358 8001 // fallback
359359 } ) ;
360360
361- // Start both RPC and API servers for Full/Super nodes
362- let node_clone_rpc = self . clone ( ) ;
361+ // Start unified API/RPC server for Full/Super nodes
363362 let node_clone_api = self . clone ( ) ;
364363
365- tokio:: spawn ( async move {
366- crate :: rpc:: start_rpc_server ( node_clone_rpc, rpc_port) . await ;
367- } ) ;
368-
369364 println ! ( "[Node] 🚀 API server starting on port {}" , api_port) ;
370365 tokio:: spawn ( async move {
371366 crate :: rpc:: start_rpc_server ( node_clone_api, api_port) . await ;
372367 } ) ;
373368
374369 // Store ports for external access
375- std:: env:: set_var ( "QNET_CURRENT_RPC_PORT" , rpc_port . to_string ( ) ) ;
370+ std:: env:: set_var ( "QNET_CURRENT_RPC_PORT" , api_port . to_string ( ) ) ; // Unified port
376371 std:: env:: set_var ( "QNET_CURRENT_API_PORT" , api_port. to_string ( ) ) ;
377372
378- println ! ( "[Node] 🔌 RPC server: port {}" , rpc_port ) ;
373+ println ! ( "[Node] 🔌 RPC server: port {}" , api_port ) ;
379374 println ! ( "[Node] 🌐 API server: port {}" , api_port) ;
380375 } else {
381376 // Light nodes: RPC only, no API server
Original file line number Diff line number Diff line change @@ -231,6 +231,27 @@ pub async fn start_rpc_server(blockchain: BlockchainNode, port: u16) {
231231 . and ( blockchain_filter. clone ( ) )
232232 . and_then ( handle_mempool_transactions) ;
233233
234+ // Peer discovery endpoint (for P2P network)
235+ let peers_endpoint = api_v1
236+ . and ( warp:: path ( "peers" ) )
237+ . and ( warp:: path:: end ( ) )
238+ . and ( warp:: get ( ) )
239+ . and ( blockchain_filter. clone ( ) )
240+ . and_then ( |blockchain : Arc < BlockchainNode > | async move {
241+ let peers = blockchain. get_connected_peers ( ) . await . unwrap_or_default ( ) ;
242+ let peer_list: Vec < serde_json:: Value > = peers. iter ( ) . map ( |peer| {
243+ json ! ( {
244+ "id" : peer. id,
245+ "address" : peer. address,
246+ "node_type" : peer. node_type,
247+ "region" : peer. region,
248+ "last_seen" : peer. last_seen
249+ } )
250+ } ) . collect ( ) ;
251+ println ! ( "[API] 📊 Peers request: returning {} peers" , peer_list. len( ) ) ;
252+ Ok :: < _ , Rejection > ( warp:: reply:: json ( & json ! ( { "peers" : peer_list} ) ) )
253+ } ) ;
254+
234255 // Batch operations endpoints
235256 let batch_claim_rewards = api_v1
236257 . and ( warp:: path ( "batch" ) )
@@ -296,6 +317,7 @@ pub async fn start_rpc_server(blockchain: BlockchainNode, port: u16) {
296317 let routes = rpc_path
297318 . or ( root_path)
298319 . or ( chain_height)
320+ . or ( peers_endpoint)
299321 . or ( microblock_one)
300322 . or ( microblocks_range)
301323 . or ( account_info)
Original file line number Diff line number Diff line change @@ -300,6 +300,12 @@ impl SimplifiedP2P {
300300 continue ;
301301 }
302302
303+ // ADDITIONAL CHECK: Skip if IP matches any of our listening addresses
304+ if ip == "127.0.0.1" || ip == "0.0.0.0" || ip == "localhost" {
305+ println ! ( "[P2P] 🚫 Skipping local address: {}" , ip) ;
306+ continue ;
307+ }
308+
303309 println ! ( "[P2P] 🌐 Attempting to connect to peer: {}" , ip) ;
304310 // PRODUCTION FIX: Test actual HTTP API ports where nodes listen
305311 // 8001 = primary API port, 9877 = RPC port
You can’t perform that action at this time.
0 commit comments