LCOV - code coverage report
Current view: top level - app/fdctl/run/tiles - fd_gui.c (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 28 263 10.6 %
Date: 2025-01-08 12:08:44 Functions: 4 17 23.5 %

          Line data    Source code
       1             : /* The frontend assets are pre-built and statically compiled into the
       2             :    binary here.  To regenerate them, run
       3             : 
       4             :     $ git clone https://github.com/firedancer-io/firedancer-frontend.git frontend
       5             :     $ make frontend
       6             : 
       7             :    from the repository root. */
       8             : 
       9             : #include "generated/http_import_dist.h"
      10           3 : #define DIST_COMPRESSION_LEVEL (19)
      11             : 
      12             : #include <sys/socket.h> /* SOCK_CLOEXEC, SOCK_NONBLOCK needed for seccomp filter */
      13             : #if defined(__aarch64__)
      14             : #include "generated/gui.arm64_seccomp.h"
      15             : #else
      16             : #include "generated/gui_seccomp.h"
      17             : #endif
      18             : 
      19             : #include "../../version.h"
      20             : 
      21             : #include "../../../../disco/keyguard/fd_keyload.h"
      22             : #include "../../../../disco/gui/fd_gui.h"
      23             : #include "../../../../disco/plugin/fd_plugin.h"
      24             : #include "../../../../ballet/http/fd_http_server.h"
      25             : #include "../../../../ballet/json/cJSON.h"
      26             : 
      27             : #include <sys/types.h>
      28             : #include <unistd.h>
      29             : #include <string.h>
      30             : #include <poll.h>
      31             : #include <stdio.h>
      32             : 
      33             : #if FD_HAS_ZSTD
      34             : #define ZSTD_STATIC_LINKING_ONLY
      35             : #include <zstd.h>
      36             : #endif
      37             : 
      38             : FD_IMPORT_BINARY( firedancer_svg, "book/public/fire.svg" );
      39             : 
      40             : #define FD_HTTP_SERVER_GUI_MAX_CONNS             1024
      41             : #define FD_HTTP_SERVER_GUI_MAX_REQUEST_LEN       1024
      42             : #define FD_HTTP_SERVER_GUI_MAX_WS_CONNS          1024
      43             : #define FD_HTTP_SERVER_GUI_MAX_WS_RECV_FRAME_LEN 1024
      44             : #define FD_HTTP_SERVER_GUI_MAX_WS_SEND_FRAME_CNT 8192
      45             : #define FD_HTTP_SERVER_GUI_OUTGOING_BUFFER_SZ    (5UL<<30UL) /* 5GiB reserved for buffering GUI websockets */
      46             : 
      47             : const fd_http_server_params_t GUI_PARAMS = {
      48             :   .max_connection_cnt    = FD_HTTP_SERVER_GUI_MAX_CONNS,
      49             :   .max_ws_connection_cnt = FD_HTTP_SERVER_GUI_MAX_WS_CONNS,
      50             :   .max_request_len       = FD_HTTP_SERVER_GUI_MAX_REQUEST_LEN,
      51             :   .max_ws_recv_frame_len = FD_HTTP_SERVER_GUI_MAX_WS_RECV_FRAME_LEN,
      52             :   .max_ws_send_frame_cnt = FD_HTTP_SERVER_GUI_MAX_WS_SEND_FRAME_CNT,
      53             :   .outgoing_buffer_sz    = FD_HTTP_SERVER_GUI_OUTGOING_BUFFER_SZ,
      54             : };
      55             : 
      56             : typedef struct {
      57             :   fd_topo_t * topo;
      58             : 
      59             :   fd_gui_t * gui;
      60             : 
      61             :   /* This needs to be max(plugin_msg) across all kinds of messages.
      62             :      Currently this is just figured out manually, it's a gossip update
      63             :      message assuming the table is completely full (40200) of peers. */
      64             :   uchar      buf[ 8UL+40200UL*(58UL+12UL*34UL) ] __attribute__((aligned(8)));
      65             : 
      66             :   fd_http_server_t * gui_server;
      67             : 
      68             :   char          version_string[ 16UL ];
      69             :   uchar const * identity_key;
      70             : 
      71             :   fd_wksp_t * in_mem;
      72             :   ulong       in_chunk0;
      73             :   ulong       in_wmark;
      74             : } fd_gui_ctx_t;
      75             : 
      76             : FD_FN_CONST static inline ulong
      77           3 : scratch_align( void ) {
      78           3 :   return 128UL;
      79           3 : }
      80             : 
      81             : FD_FN_PURE static inline ulong
      82           3 : scratch_footprint( fd_topo_tile_t const * tile ) {
      83           3 :   (void)tile;
      84             : 
      85           3 :   ulong l = FD_LAYOUT_INIT;
      86           3 :   l = FD_LAYOUT_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
      87           3 :   l = FD_LAYOUT_APPEND( l, fd_http_server_align(),  fd_http_server_footprint( GUI_PARAMS ) );
      88           3 :   l = FD_LAYOUT_APPEND( l, fd_gui_align(),          fd_gui_footprint() );
      89           3 :   l = FD_LAYOUT_APPEND( l, fd_alloc_align(),        fd_alloc_footprint() );
      90           3 :   ulong sz = FD_LAYOUT_FINI( l, scratch_align() );
      91             : 
      92           3 : # if FD_HAS_ZSTD
      93           3 :   sz = fd_ulong_max( sz, ZSTD_estimateCCtxSize( DIST_COMPRESSION_LEVEL ) );
      94           3 : # endif
      95             : 
      96           3 :   return sz;
      97           3 : }
      98             : 
      99             : /* dist_file_sz returns the sum of static asset file sizes */
     100             : 
     101             : static ulong
     102           3 : dist_file_sz( void ) {
     103           3 :   ulong tot_sz = 0UL;
     104          36 :   for( fd_http_static_file_t * f = STATIC_FILES; f->name; f++ ) {
     105          33 :     tot_sz += *(f->data_len);
     106          33 :   }
     107           3 :   return tot_sz;
     108           3 : }
     109             : 
     110             : FD_FN_PURE static inline ulong
     111           3 : loose_footprint( fd_topo_tile_t const * tile FD_FN_UNUSED ) {
     112             :   /* Reserve total size of files for compression buffers */
     113           3 :   return fd_spad_footprint( dist_file_sz() ) +
     114           3 :     256UL * (1UL<<20UL); /* 256MiB of heap space for the cJSON allocator */
     115           3 : }
     116             : 
     117             : static int
     118             : before_credit( fd_gui_ctx_t *      ctx,
     119             :                fd_stem_context_t * stem,
     120           0 :                int *               charge_busy ) {
     121           0 :   (void)stem;
     122             : 
     123           0 :   int charge_busy_server = fd_http_server_poll( ctx->gui_server );
     124           0 :   int charge_poll        = fd_gui_poll( ctx->gui );
     125             : 
     126           0 :   *charge_busy = charge_busy_server | charge_poll;
     127             : 
     128           0 :   return 0;
     129           0 : }
     130             : 
     131             : static inline void
     132             : during_frag( fd_gui_ctx_t * ctx,
     133             :              ulong          in_idx,
     134             :              ulong          seq,
     135             :              ulong          sig,
     136             :              ulong          chunk,
     137           0 :              ulong          sz ) {
     138           0 :   (void)in_idx;
     139           0 :   (void)seq;
     140           0 :   (void)sig;
     141             : 
     142           0 :   uchar * src = (uchar *)fd_chunk_to_laddr( ctx->in_mem, chunk );
     143             : 
     144             :    /* ... todo... sigh, sz is not correct since it's too big */
     145           0 :   if( FD_LIKELY( sig==FD_PLUGIN_MSG_GOSSIP_UPDATE || sig==FD_PLUGIN_MSG_VALIDATOR_INFO ) ) {
     146           0 :     ulong peer_cnt = ((ulong *)src)[ 0 ];
     147           0 :     FD_TEST( peer_cnt<=40200 );
     148           0 :     sz = 8UL + peer_cnt*FD_GOSSIP_LINK_MSG_SIZE;
     149           0 :   } else if( FD_LIKELY( sig==FD_PLUGIN_MSG_VOTE_ACCOUNT_UPDATE ) ) {
     150           0 :     ulong peer_cnt = ((ulong *)src)[ 0 ];
     151           0 :     FD_TEST( peer_cnt<=40200 );
     152           0 :     sz = 8UL + peer_cnt*112UL;
     153           0 :   } else if( FD_UNLIKELY( sig==FD_PLUGIN_MSG_LEADER_SCHEDULE ) ) {
     154           0 :     ulong staked_cnt = ((ulong *)src)[ 1 ];
     155           0 :     FD_TEST( staked_cnt<=50000UL );
     156           0 :     sz = 40UL + staked_cnt*40UL;
     157           0 :   }
     158             : 
     159           0 :   if( FD_UNLIKELY( chunk<ctx->in_chunk0 || chunk>ctx->in_wmark || sz>sizeof( ctx->buf ) ) )
     160           0 :     FD_LOG_ERR(( "chunk %lu %lu corrupt, not in range [%lu,%lu]", chunk, sz, ctx->in_chunk0, ctx->in_wmark ));
     161             : 
     162           0 :   fd_memcpy( ctx->buf, src, sz );
     163           0 : }
     164             : 
     165             : static inline void
     166             : after_frag( fd_gui_ctx_t *      ctx,
     167             :             ulong               in_idx,
     168             :             ulong               seq,
     169             :             ulong               sig,
     170             :             ulong               sz,
     171             :             ulong               tsorig,
     172           0 :             fd_stem_context_t * stem ) {
     173           0 :   (void)in_idx;
     174           0 :   (void)seq;
     175           0 :   (void)sz;
     176           0 :   (void)tsorig;
     177           0 :   (void)stem;
     178             : 
     179           0 :   fd_gui_plugin_message( ctx->gui, sig, ctx->buf );
     180           0 : }
     181             : 
     182             : static fd_http_server_response_t
     183           0 : gui_http_request( fd_http_server_request_t const * request ) {
     184           0 :   if( FD_UNLIKELY( request->method!=FD_HTTP_SERVER_METHOD_GET ) ) {
     185           0 :     return (fd_http_server_response_t){
     186           0 :       .status = 405,
     187           0 :     };
     188           0 :   }
     189             : 
     190           0 :   if( FD_LIKELY( !strcmp( request->path, "/websocket" ) ) ) {
     191           0 :     return (fd_http_server_response_t){
     192           0 :       .status            = 200,
     193           0 :       .upgrade_websocket = 1,
     194           0 :     };
     195           0 :   } else if( FD_LIKELY( !strcmp( request->path, "/favicon.svg" ) ) ) {
     196           0 :     return (fd_http_server_response_t){
     197           0 :       .status            = 200,
     198           0 :       .static_body       = firedancer_svg,
     199           0 :       .static_body_len   = firedancer_svg_sz,
     200           0 :       .content_type      = "image/svg+xml",
     201           0 :       .upgrade_websocket = 0,
     202           0 :     };
     203           0 :   }
     204             : 
     205           0 :   int is_vite_page = !strcmp( request->path, "/" ) ||
     206           0 :                      !strcmp( request->path, "/leaderSchedule" ) ||
     207           0 :                      !strcmp( request->path, "/gossip" );
     208             : 
     209           0 :   for( fd_http_static_file_t * f = STATIC_FILES; f->name; f++ ) {
     210           0 :     if( !strcmp( request->path, f->name ) ||
     211           0 :         (!strcmp( f->name, "/index.html" ) && is_vite_page) ) {
     212           0 :       char const * content_type = NULL;
     213             : 
     214           0 :       char const * ext = strrchr( f->name, '.' );
     215           0 :       if( FD_LIKELY( ext ) ) {
     216           0 :         if( !strcmp( ext, ".html" ) ) content_type = "text/html; charset=utf-8";
     217           0 :         else if( !strcmp( ext, ".css" ) ) content_type = "text/css";
     218           0 :         else if( !strcmp( ext, ".js" ) ) content_type = "application/javascript";
     219           0 :         else if( !strcmp( ext, ".svg" ) ) content_type = "image/svg+xml";
     220           0 :         else if( !strcmp( ext, ".woff" ) ) content_type = "font/woff";
     221           0 :         else if( !strcmp( ext, ".woff2" ) ) content_type = "font/woff2";
     222           0 :       }
     223             : 
     224           0 :       char const * cache_control = NULL;
     225           0 :       if( FD_LIKELY( !strncmp( request->path, "/assets", 7 ) ) ) cache_control = "public, max-age=31536000, immutable";
     226             : 
     227           0 :       const uchar * data = f->data;
     228           0 :       ulong data_len = *(f->data_len);
     229             : 
     230           0 :       int accepts_zstd = 0;
     231           0 :       if( FD_LIKELY( request->headers.accept_encoding ) ) {
     232           0 :         accepts_zstd = !!strstr( request->headers.accept_encoding, "zstd" );
     233           0 :       }
     234             : 
     235           0 :       char const * content_encoding = NULL;
     236           0 :       if( FD_LIKELY( accepts_zstd && f->zstd_data ) ) {
     237           0 :         content_encoding = "zstd";
     238           0 :         data = f->zstd_data;
     239           0 :         data_len = f->zstd_data_len;
     240           0 :       }
     241             : 
     242           0 :       return (fd_http_server_response_t){
     243           0 :         .status            = 200,
     244           0 :         .static_body       = data,
     245           0 :         .static_body_len   = data_len,
     246           0 :         .content_type      = content_type,
     247           0 :         .cache_control     = cache_control,
     248           0 :         .content_encoding  = content_encoding,
     249           0 :         .upgrade_websocket = 0,
     250           0 :       };
     251           0 :     }
     252           0 :   }
     253             : 
     254           0 :   return (fd_http_server_response_t){
     255           0 :     .status            = 404,
     256           0 :   };
     257           0 : }
     258             : 
     259             : static void
     260             : gui_ws_open( ulong  conn_id,
     261           0 :              void * _ctx ) {
     262           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     263             : 
     264           0 :   fd_gui_ws_open( ctx->gui, conn_id );
     265           0 : }
     266             : 
     267             : static void
     268             : gui_ws_message( ulong         ws_conn_id,
     269             :                 uchar const * data,
     270             :                 ulong         data_len,
     271           0 :                 void *        _ctx ) {
     272           0 :   fd_gui_ctx_t * ctx = (fd_gui_ctx_t *)_ctx;
     273             : 
     274           0 :   int close = fd_gui_ws_message( ctx->gui, ws_conn_id, data, data_len );
     275           0 :   if( FD_UNLIKELY( close<0 ) ) fd_http_server_ws_close( ctx->gui_server, ws_conn_id, close );
     276           0 : }
     277             : 
     278             : static void
     279             : privileged_init( fd_topo_t *      topo,
     280           0 :                  fd_topo_tile_t * tile ) {
     281           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     282             : 
     283           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     284           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     285             : 
     286           0 :   fd_http_server_t * _gui = FD_SCRATCH_ALLOC_APPEND( l, fd_http_server_align(), fd_http_server_footprint( GUI_PARAMS ) );
     287             : 
     288           0 :   fd_http_server_callbacks_t gui_callbacks = {
     289           0 :     .request    = gui_http_request,
     290           0 :     .ws_open    = gui_ws_open,
     291           0 :     .ws_message = gui_ws_message,
     292           0 :   };
     293           0 :   ctx->gui_server = fd_http_server_join( fd_http_server_new( _gui, GUI_PARAMS, gui_callbacks, ctx ) );
     294           0 :   fd_http_server_listen( ctx->gui_server, tile->gui.listen_addr, tile->gui.listen_port );
     295             : 
     296           0 :   if( FD_UNLIKELY( !strcmp( tile->gui.identity_key_path, "" ) ) )
     297           0 :     FD_LOG_ERR(( "identity_key_path not set" ));
     298             : 
     299           0 :   ctx->identity_key = fd_keyload_load( tile->gui.identity_key_path, /* pubkey only: */ 1 );
     300           0 : }
     301             : 
     302             : #if FD_HAS_ZSTD
     303             : 
     304             : /* pre_compress_files compresses static assets into wksp-provided
     305             :    buffers using Zstandard.  Logs warning and continues if insufficient
     306             :    wksp space is available. */
     307             : 
     308             : static void
     309             : pre_compress_files( fd_wksp_t * wksp,
     310           0 :                     ZSTD_CCtx * cctx ) {
     311           0 :   ulong glo, ghi;
     312           0 :   if( FD_UNLIKELY( !fd_wksp_alloc_at_least( wksp, FD_SPAD_ALIGN, loose_footprint( NULL ), 1UL, &glo, &ghi ) ) ) {
     313           0 :     FD_LOG_WARNING(( "Failed to allocate space for compressing assets" ));
     314           0 :     return;
     315           0 :   }
     316           0 :   fd_spad_t * spad = fd_spad_join( fd_spad_new( fd_wksp_laddr_fast( wksp, glo ), fd_spad_mem_max_max( ghi-glo ) ) );
     317           0 :   fd_spad_push( spad );
     318             : 
     319           0 :   for( fd_http_static_file_t * f=STATIC_FILES; f->name; f++ ) {
     320           0 :     char const * ext = strrchr( f->name, '.' );
     321           0 :     if( !ext ) continue;
     322           0 :     if( !strcmp( ext, ".html" ) ||
     323           0 :         !strcmp( ext, ".css"  ) ||
     324           0 :         !strcmp( ext, ".js"   ) ||
     325           0 :         !strcmp( ext, ".svg"  ) ) {}
     326           0 :     else continue;
     327             : 
     328           0 :     ulong   zstd_bufsz = fd_spad_alloc_max( spad, 1UL );
     329           0 :     uchar * zstd_buf   = fd_spad_prepare( spad, 1UL, zstd_bufsz );
     330           0 :     ulong zstd_sz = ZSTD_compressCCtx( cctx, zstd_buf, zstd_bufsz, f->data, *f->data_len, DIST_COMPRESSION_LEVEL );
     331           0 :     if( ZSTD_isError( zstd_sz ) ) {
     332           0 :       fd_spad_cancel( spad );
     333           0 :       FD_LOG_WARNING(( "ZSTD_compressCCtx(%s) failed (%s)", f->name, ZSTD_getErrorName( zstd_sz ) ));
     334           0 :       break;
     335           0 :     }
     336           0 :     f->zstd_data     = zstd_buf;
     337           0 :     f->zstd_data_len = zstd_sz;
     338           0 :     fd_spad_publish( spad, zstd_sz );
     339           0 :   }
     340             : 
     341           0 :   ulong uncompressed_sz = 0UL;
     342           0 :   ulong compressed_sz   = 0UL;
     343           0 :   for( fd_http_static_file_t * f=STATIC_FILES; f->name; f++ ) {
     344           0 :     uncompressed_sz += *f->data_len;
     345           0 :     compressed_sz   += fd_ulong_if( !!f->zstd_data_len, f->zstd_data_len, *f->data_len );
     346           0 :   }
     347             : 
     348           0 :   FD_LOG_INFO(( "Compressed assets (%lu bytes => %lu bytes)", uncompressed_sz, compressed_sz ));
     349           0 : }
     350             : 
     351             : #endif /* FD_HAS_ZSTD */
     352             : 
     353             : static FD_TL fd_alloc_t * cjson_alloc_ctx;
     354             : 
     355             : static void *
     356           0 : cjson_alloc( ulong sz ) {
     357           0 :   if( FD_LIKELY( cjson_alloc_ctx ) ) {
     358           0 :     return fd_alloc_malloc( cjson_alloc_ctx, 8UL, sz );
     359           0 :   } else {
     360           0 :     return malloc( sz );
     361           0 :   }
     362           0 : }
     363             : 
     364             : static void
     365           0 : cjson_free( void * ptr ) {
     366           0 :   if( FD_LIKELY( cjson_alloc_ctx ) ) {
     367           0 :     fd_alloc_free( cjson_alloc_ctx, ptr );
     368           0 :   } else {
     369           0 :     free( ptr );
     370           0 :   }
     371           0 : }
     372             : 
     373             : static void
     374             : unprivileged_init( fd_topo_t *      topo,
     375           0 :                    fd_topo_tile_t * tile ) {
     376           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     377             : 
     378           0 : # if FD_HAS_ZSTD
     379             :   /* Temporarily use tile memory to compress dist assets */
     380           0 :   ZSTD_CCtx * cctx = ZSTD_initStaticCCtx( scratch, topo->objs[ tile->tile_obj_id ].footprint );
     381           0 :   pre_compress_files( fd_wksp_containing( scratch ), cctx );
     382             :   /* zstd.h: there is no corresponding "free" function */
     383           0 :   cctx = NULL;
     384           0 : # endif
     385             : 
     386           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     387           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     388           0 :                        FD_SCRATCH_ALLOC_APPEND( l, fd_http_server_align(), fd_http_server_footprint( GUI_PARAMS ) );
     389           0 :   void * _gui        = FD_SCRATCH_ALLOC_APPEND( l, fd_gui_align(),         fd_gui_footprint() );
     390           0 :   void * _alloc      = FD_SCRATCH_ALLOC_APPEND( l, fd_alloc_align(),       fd_alloc_footprint() );
     391             : 
     392           0 :   FD_TEST( fd_cstr_printf_check( ctx->version_string, sizeof( ctx->version_string ), NULL, "%lu.%lu.%lu", FDCTL_MAJOR_VERSION, FDCTL_MINOR_VERSION, FDCTL_PATCH_VERSION ) );
     393             : 
     394           0 :   ctx->topo = topo;
     395           0 :   ctx->gui  = fd_gui_join( fd_gui_new( _gui, ctx->gui_server, ctx->version_string, tile->gui.cluster, ctx->identity_key, tile->gui.is_voting, ctx->topo ) );
     396           0 :   FD_TEST( ctx->gui );
     397             :   
     398           0 :   cjson_alloc_ctx = fd_alloc_join( fd_alloc_new( _alloc, 1UL ), 1UL );
     399           0 :   FD_TEST( cjson_alloc_ctx );
     400           0 :   cJSON_Hooks hooks = {
     401           0 :     .malloc_fn = cjson_alloc,
     402           0 :     .free_fn   = cjson_free,
     403           0 :   };
     404           0 :   cJSON_InitHooks( &hooks );
     405             : 
     406           0 :   fd_topo_link_t * link = &topo->links[ tile->in_link_id[ 0 ] ];
     407           0 :   fd_topo_wksp_t * link_wksp = &topo->workspaces[ topo->objs[ link->dcache_obj_id ].wksp_id ];
     408             : 
     409           0 :   ctx->in_mem    = link_wksp->wksp;
     410           0 :   ctx->in_chunk0 = fd_dcache_compact_chunk0( ctx->in_mem, link->dcache );
     411           0 :   ctx->in_wmark  = fd_dcache_compact_wmark ( ctx->in_mem, link->dcache, link->mtu );
     412             : 
     413           0 :   ulong scratch_top = FD_SCRATCH_ALLOC_FINI( l, 1UL );
     414           0 :   if( FD_UNLIKELY( scratch_top > (ulong)scratch + scratch_footprint( tile ) ) )
     415           0 :     FD_LOG_ERR(( "scratch overflow %lu %lu %lu", scratch_top - (ulong)scratch - scratch_footprint( tile ), scratch_top, (ulong)scratch + scratch_footprint( tile ) ));
     416             : 
     417           0 :   FD_LOG_WARNING(( "GUI server listening at http://" FD_IP4_ADDR_FMT ":%u", FD_IP4_ADDR_FMT_ARGS( tile->gui.listen_addr ), tile->gui.listen_port ));
     418           0 : }
     419             : 
     420             : static ulong
     421             : populate_allowed_seccomp( fd_topo_t const *      topo,
     422             :                           fd_topo_tile_t const * tile,
     423             :                           ulong                  out_cnt,
     424           0 :                           struct sock_filter *   out ) {
     425           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     426           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     427           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     428             : 
     429           0 :   populate_sock_filter_policy_gui( out_cnt, out, (uint)fd_log_private_logfile_fd(), (uint)fd_http_server_fd( ctx->gui_server ) );
     430           0 :   return sock_filter_policy_gui_instr_cnt;
     431           0 : }
     432             : 
     433             : static ulong
     434             : populate_allowed_fds( fd_topo_t const *      topo,
     435             :                       fd_topo_tile_t const * tile,
     436             :                       ulong                  out_fds_cnt,
     437           0 :                       int *                  out_fds ) {
     438           0 :   void * scratch = fd_topo_obj_laddr( topo, tile->tile_obj_id );
     439           0 :   FD_SCRATCH_ALLOC_INIT( l, scratch );
     440           0 :   fd_gui_ctx_t * ctx = FD_SCRATCH_ALLOC_APPEND( l, alignof( fd_gui_ctx_t ), sizeof( fd_gui_ctx_t ) );
     441             : 
     442           0 :   if( FD_UNLIKELY( out_fds_cnt<3UL ) ) FD_LOG_ERR(( "out_fds_cnt %lu", out_fds_cnt ));
     443             : 
     444           0 :   ulong out_cnt = 0UL;
     445           0 :   out_fds[ out_cnt++ ] = 2; /* stderr */
     446           0 :   if( FD_LIKELY( -1!=fd_log_private_logfile_fd() ) )
     447           0 :     out_fds[ out_cnt++ ] = fd_log_private_logfile_fd(); /* logfile */
     448           0 :   out_fds[ out_cnt++ ] = fd_http_server_fd( ctx->gui_server ); /* gui listen socket */
     449           0 :   return out_cnt;
     450           0 : }
     451             : 
     452           0 : #define STEM_BURST (1UL)
     453             : 
     454           0 : #define STEM_CALLBACK_CONTEXT_TYPE  fd_gui_ctx_t
     455           0 : #define STEM_CALLBACK_CONTEXT_ALIGN alignof(fd_gui_ctx_t)
     456             : 
     457           0 : #define STEM_CALLBACK_BEFORE_CREDIT before_credit
     458           0 : #define STEM_CALLBACK_DURING_FRAG   during_frag
     459           0 : #define STEM_CALLBACK_AFTER_FRAG    after_frag
     460             : 
     461             : #include "../../../../disco/stem/fd_stem.c"
     462             : 
     463             : fd_topo_run_tile_t fd_tile_gui = {
     464             :   .name                     = "gui",
     465             :   .rlimit_file_cnt          = FD_HTTP_SERVER_GUI_MAX_CONNS+FD_HTTP_SERVER_GUI_MAX_WS_CONNS+5UL, /* pipefd, socket, stderr, logfile, and one spare for new accept() connections */
     466             :   .populate_allowed_seccomp = populate_allowed_seccomp,
     467             :   .populate_allowed_fds     = populate_allowed_fds,
     468             :   .scratch_align            = scratch_align,
     469             :   .scratch_footprint        = scratch_footprint,
     470             :   .loose_footprint          = loose_footprint,
     471             :   .privileged_init          = privileged_init,
     472             :   .unprivileged_init        = unprivileged_init,
     473             :   .run                      = stem_run,
     474             : };

Generated by: LCOV version 1.14