|
| 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 | + char const * name ) { |
| 21 | + fd_topob_new( topo, name ); |
| 22 | + topo->max_page_size = 1UL<<21UL; |
| 23 | + |
| 24 | + fd_topob_wksp( topo, "all" ); |
| 25 | + fd_topo_link_t * link = fd_topob_link( topo, "ipecho_out", "all", 4UL, 0UL, 1UL ); |
| 26 | + link->permit_no_consumers = 1; |
| 27 | + fd_topo_tile_t * tile = fd_topob_tile( topo, "ipecho", "all", "all", 0UL, 0, 0 ); |
| 28 | + tile->ipecho.expected_shred_version = 32; |
| 29 | + tile->ipecho.entrypoints_cnt = 0UL; |
| 30 | + tile->ipecho.bind_address = FD_IP4_ADDR(127,0,0,1); |
| 31 | + tile->ipecho.bind_port = 12008; |
| 32 | + fd_topob_tile_out( topo, "ipecho", 0UL, "ipecho_out", 0UL ); |
| 33 | + |
| 34 | + fd_topob_auto_layout( topo, 0 ); |
| 35 | + fd_topob_finish( topo, CALLBACKS ); |
| 36 | +} |
| 37 | + |
| 38 | +extern int * fd_log_private_shared_lock; |
| 39 | + |
| 40 | +static void |
| 41 | +ipecho_server_cmd_topo( config_t * config ) { |
| 42 | + ipecho_topo( &config->topo, config->name ); |
| 43 | +} |
| 44 | + |
| 45 | +static args_t |
| 46 | +configure_args( void ) { |
| 47 | + args_t args = { |
| 48 | + .configure.command = CONFIGURE_CMD_INIT, |
| 49 | + }; |
| 50 | + |
| 51 | + ulong stage_idx = 0UL; |
| 52 | + args.configure.stages[ stage_idx++ ] = &fd_cfg_stage_hugetlbfs; |
| 53 | + args.configure.stages[ stage_idx++ ] = NULL; |
| 54 | + |
| 55 | + return args; |
| 56 | +} |
| 57 | + |
| 58 | +void |
| 59 | +ipecho_server_cmd_perm( args_t * args FD_PARAM_UNUSED, |
| 60 | + fd_cap_chk_t * chk, |
| 61 | + config_t const * config ) { |
| 62 | + args_t c_args = configure_args(); |
| 63 | + configure_cmd_perm( &c_args, chk, config ); |
| 64 | + run_cmd_perm( NULL, chk, config ); |
| 65 | +} |
| 66 | + |
| 67 | +static void |
| 68 | +ipecho_server_cmd_fn( args_t * args, |
| 69 | + config_t * config ) { |
| 70 | + (void)args; |
| 71 | + |
| 72 | + args_t c_args = configure_args(); |
| 73 | + configure_cmd_fn( &c_args, config ); |
| 74 | + |
| 75 | + run_firedancer_init( config, 1 ); |
| 76 | + |
| 77 | + fd_log_private_shared_lock[ 1 ] = 0; |
| 78 | + fd_topo_join_workspaces( &config->topo, FD_SHMEM_JOIN_MODE_READ_WRITE ); |
| 79 | + fd_topo_fill( &config->topo ); |
| 80 | + |
| 81 | + ulong tile_idx1 = fd_topo_find_tile( &config->topo, "ipecho", 0UL ); |
| 82 | + fd_topo_tile_t * ipecho_tile1 = &config->topo.tiles[ tile_idx1 ]; |
| 83 | + ulong volatile * const ipecho_metrics1 = fd_metrics_tile( ipecho_tile1->metrics ); |
| 84 | + (void)ipecho_metrics1; |
| 85 | + |
| 86 | + fd_topo_run_single_process( &config->topo, 2, config->uid, config->gid, fdctl_tile_run ); |
| 87 | + |
| 88 | + ulong tile_idx = fd_topo_find_tile( &config->topo, "ipecho", 0UL ); |
| 89 | + FD_TEST( tile_idx!=ULONG_MAX ); |
| 90 | + fd_topo_tile_t * ipecho_tile = &config->topo.tiles[ tile_idx ]; |
| 91 | + |
| 92 | + sleep(1); |
| 93 | + ulong volatile * const ipecho_metrics = fd_metrics_tile( ipecho_tile->metrics ); |
| 94 | + |
| 95 | + ulong last_conns = ULONG_MAX; |
| 96 | + ulong last_closed_ok = ULONG_MAX; |
| 97 | + ulong last_closed_error = ULONG_MAX; |
| 98 | + |
| 99 | + for(;;) { |
| 100 | + ulong ipecho_conns = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( GAUGE, IPECHO, CONNECTION_COUNT ) ] ); |
| 101 | + ulong ipecho_closed_ok = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( COUNTER, IPECHO, CONNECTIONS_CLOSED_OK ) ] ); |
| 102 | + ulong ipecho_closed_error = FD_VOLATILE_CONST( ipecho_metrics[ MIDX( COUNTER, IPECHO, CONNECTIONS_CLOSED_ERROR ) ] ); |
| 103 | + |
| 104 | + if( FD_UNLIKELY( ipecho_conns!=last_conns || ipecho_closed_ok!=last_closed_ok || ipecho_closed_error!=last_closed_error ) ) { |
| 105 | + FD_LOG_NOTICE(( "connections=%lu closed_ok=%lu closed_err=%lu", ipecho_conns, ipecho_closed_ok, ipecho_closed_error )); |
| 106 | + last_conns = ipecho_conns; |
| 107 | + last_closed_ok = ipecho_closed_ok; |
| 108 | + last_closed_error = ipecho_closed_error; |
| 109 | + } |
| 110 | + |
| 111 | + nanosleep( &(struct timespec){ .tv_sec=0, .tv_nsec=1000L*1000L }, NULL ); |
| 112 | + } |
| 113 | +} |
| 114 | + |
| 115 | +action_t fd_action_ipecho_server = { |
| 116 | + .name = NAME, |
| 117 | + .args = NULL, |
| 118 | + .perm = ipecho_server_cmd_perm, |
| 119 | + .fn = ipecho_server_cmd_fn, |
| 120 | + .topo = ipecho_server_cmd_topo, |
| 121 | +}; |
0 commit comments