LCOV - code coverage report
Current view: top level - app/firedancer-dev/commands - ipecho_server.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 65 0.0 %
Date: 2026-09-17 04:28:31 Functions: 0 5 0.0 %

          Line data    Source code
       1             : 
       2             : #include "../../shared/commands/configure/configure.h"
       3             : #include "../../shared/commands/run/run.h"
       4             : #include "../../../disco/metrics/fd_metrics.h"
       5             : #include "../../../disco/topo/fd_topob.h"
       6             : 
       7             : #include <time.h>
       8             : #include <stdio.h>
       9             : #include <unistd.h>
      10             : 
      11             : #define NAME "ipecho-server"
      12             : 
      13             : extern fd_topo_obj_callbacks_t * CALLBACKS[];
      14             : 
      15             : fd_topo_run_tile_t
      16             : fdctl_tile_run( fd_topo_tile_t const * tile );
      17             : 
      18             : static void
      19             : ipecho_topo( fd_topo_t *  topo,
      20           0 :              char const * name ) {
      21           0 :   fd_topob_new( topo, name );
      22           0 :   topo->max_page_size = 1UL<<21UL;
      23             : 
      24           0 :   fd_topob_wksp( topo, "all" );
      25           0 :   fd_topo_link_t * link = fd_topob_link( topo, "ipecho_out", "all", 4UL, 0UL, 1UL );
      26           0 :   link->permit_no_consumers = 1;
      27           0 :   fd_topo_tile_t * tile = fd_topob_tile( topo, "ipecho", "all", "all", 0UL, 0, 0, 0, 1 );
      28           0 :   tile->ipecho.expected_shred_version = 32;
      29           0 :   tile->ipecho.entrypoints_cnt = 0UL;
      30           0 :   tile->ipecho.bind_address = FD_IP4_ADDR(127,0,0,1);
      31           0 :   tile->ipecho.bind_port    = 12008;
      32           0 :   fd_topob_tile_out( topo, "ipecho", 0UL, "ipecho_out", 0UL );
      33             : 
      34           0 :   fd_topob_auto_layout( topo, 0 );
      35           0 :   fd_topob_waker( topo );
      36           0 :   fd_topob_finish( topo, CALLBACKS );
      37           0 : }
      38             : 
      39             : static void
      40           0 : ipecho_server_cmd_topo( config_t * config ) {
      41           0 :   ipecho_topo( &config->topo, config->name );
      42           0 : }
      43             : 
      44             : static args_t
      45           0 : configure_args( void ) {
      46           0 :   args_t args = {
      47           0 :     .configure.command = CONFIGURE_CMD_INIT,
      48           0 :   };
      49             : 
      50           0 :   ulong stage_idx = 0UL;
      51           0 :   args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs;
      52           0 :   args.configure.stages[ stage_idx++ ] = NULL;
      53             : 
      54           0 :   return args;
      55           0 : }
      56             : 
      57             : void
      58             : ipecho_server_cmd_perm( args_t *    args FD_PARAM_UNUSED,
      59             :                    fd_cap_chk_t *   chk,
      60           0 :                    config_t const * config ) {
      61           0 :   args_t c_args = configure_args();
      62           0 :   configure_cmd_perm( &c_args, chk, config );
      63           0 :   run_cmd_perm( NULL, chk, config );
      64           0 : }
      65             : 
      66             : static void
      67             : ipecho_server_cmd_fn( args_t *   args,
      68           0 :                       config_t * config ) {
      69           0 :   (void)args;
      70             : 
      71           0 :   args_t c_args = configure_args();
      72           0 :   configure_cmd_fn( &c_args, config );
      73             : 
      74           0 :   run_firedancer_init( config, 1, 0 );
      75             : 
      76           0 :   fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE, FD_TOPO_CORE_DUMP_LEVEL_DISABLED );
      77           0 :   fd_topo_fill( &config->topo );
      78             : 
      79           0 :   ulong tile_idx1 = fd_topo_find_tile( &config->topo, "ipecho", 0UL );
      80           0 :   fd_topo_tile_t * ipecho_tile1 = &config->topo.tiles[ tile_idx1 ];
      81           0 :   ulong volatile * const ipecho_metrics1 = fd_metrics_tile( ipecho_tile1->metrics );
      82           0 :   (void)ipecho_metrics1;
      83             : 
      84           0 :   fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run );
      85             : 
      86           0 :   ulong tile_idx = fd_topo_find_tile( &config->topo, "ipecho", 0UL );
      87           0 :   FD_TEST( tile_idx!=ULONG_MAX );
      88           0 :   fd_topo_tile_t * ipecho_tile = &config->topo.tiles[ tile_idx ];
      89             : 
      90           0 :   sleep(1);
      91           0 :   ulong volatile * const ipecho_metrics = fd_metrics_tile( ipecho_tile->metrics );
      92             : 
      93           0 :   ulong last_conns = ULONG_MAX;
      94           0 :   ulong last_closed_ok = ULONG_MAX;
      95           0 :   ulong last_closed_error = ULONG_MAX;
      96             : 
      97           0 :   for(;;) {
      98           0 :     ulong ipecho_conns = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( GAUGE, IPECHO, CONN_ACTIVE ) ] );
      99           0 :     ulong ipecho_closed_ok = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( COUNTER, IPECHO, CONN_CLOSED_OK ) ] );
     100           0 :     ulong ipecho_closed_error = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( COUNTER, IPECHO, CONN_CLOSED_ERROR ) ] );
     101             : 
     102           0 :     if( FD_UNLIKELY( ipecho_conns!=last_conns || ipecho_closed_ok!=last_closed_ok || ipecho_closed_error!=last_closed_error ) ) {
     103           0 :       FD_LOG_NOTICE(( "connections=%lu closed_ok=%lu closed_err=%lu", ipecho_conns, ipecho_closed_ok, ipecho_closed_error ));
     104           0 :       last_conns = ipecho_conns;
     105           0 :       last_closed_ok = ipecho_closed_ok;
     106           0 :       last_closed_error = ipecho_closed_error;
     107           0 :     }
     108             : 
     109             :     nanosleep( &(struct timespec){ .tv_sec=0, .tv_nsec=1000L*1000L }, NULL );
     110           0 :   }
     111           0 : }
     112             : 
     113             : action_t fd_action_ipecho_server = {
     114             :   .name        = NAME,
     115             :   .args        = NULL,
     116             :   .perm        = ipecho_server_cmd_perm,
     117             :   .fn          = ipecho_server_cmd_fn,
     118             :   .topo        = ipecho_server_cmd_topo,
     119             :   .description = "Run a standalone IP echo protocol server for testing",
     120             : };

Generated by: LCOV version 1.14