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