Line data Source code
1 : #ifndef HEADER_fd_src_disco_gui_fd_gui_peers_h
2 : #define HEADER_fd_src_disco_gui_fd_gui_peers_h
3 :
4 : /* fd_gui_peers defines methods that maintain metrics and metadata about
5 : Solana cluster peers that are active on the Gossip network.
6 :
7 : Peer identifiers are added and removed by incoming update messages
8 : from the gossip tile. Additional information about the peer is
9 : obtained from other places and merged into the a large peers table
10 : with live updates.
11 :
12 : fd_gui_peers also defines methods for handling messages from a
13 : WebSocket client. These messages contain peer related information,
14 : including a live view of the peer table with the option to order the
15 : table a custom sort key. */
16 :
17 : #include "fd_gui_config_parse.h"
18 :
19 : #include "../../disco/metrics/generated/fd_metrics_enums.h"
20 : #include "../../flamenco/gossip/fd_gossip_message.h"
21 : #include "../../flamenco/runtime/fd_runtime_const.h"
22 :
23 : #include "../../waltz/http/fd_http_server.h"
24 : #include "../topo/fd_topo.h"
25 :
26 : #if FD_HAS_ZSTD
27 : #define FD_GUI_GEOIP_ZSTD_COMPRESSION_LEVEL 19
28 0 : #define FD_GUI_GEOIP_ZSTD_WINDOW_LOG 23
29 : #define ZSTD_STATIC_LINKING_ONLY
30 : #include <zstd.h>
31 : #endif
32 :
33 : #include <math.h>
34 :
35 : /* Node in an IP geolocation binary trie. The trie is built from a
36 : compressed binary file with the following format:
37 :
38 : GeoIp Binary layout
39 : | country_code_cnt (8 bytes) |
40 : | country_codes (2*country_code_cnt bytes) |
41 : | city_names_cnt (8 bytes) |
42 : | city_names (see below) |
43 : | record_cnt (8 bytes) |
44 : | records (record_cnt*10UL) |
45 :
46 : Record binary layout
47 : | ip (4 bytes) |
48 : | prefix_sz (1 byte) |
49 : | country_code_idx (1 byte) |
50 : | city_name_idx (4 bytes) |
51 :
52 : country_code_cnt: ulong count of country codes (little-endian)
53 : country_codes: Array of 2-byte ASCII country codes, not null-terminated.
54 : city_names_cnt: ulong count of city names (little-endian).
55 : city_names: Concatenation of variable-length, null-terminated city names
56 : record_cnt: ulong count of CIDR IP ranges in records
57 : records: Series of 10-byte records containing:
58 : ip: network ipv4 address (big-endian)
59 : prefix_sz: uchar count of 1 bits (up to 32) in the netmask of the CIDR address
60 : country_code_idx: uchar country code index, into country_codes
61 : city_name_idx: uint city name index, into city_names.
62 :
63 : In the trie, each node represents one bit position in an IP address.
64 : Paths follow 0 (left child) and 1 (right child) bits from the IP's MSB
65 : to LSB. Nodes with has_prefix=1 indicate a match at that prefix
66 : length country_code_idx references the 2-letter country code in the
67 : table. Maximum depth is 32 levels (for IPv4).
68 :
69 : FD_GUI_GEOIP_*_MAX_NODES should be larger than 2*num_records (since
70 : records are stored in the leaves of a binary tree). */
71 :
72 0 : #define FD_GUI_GEOIP_DBIP_MAX_NODES (1UL<<24UL) /* 16M nodes */
73 0 : #define FD_GUI_GEOIP_MAX_CITY_NAME_SZ (80UL)
74 : #define FD_GUI_GEOIP_MAX_CITY_CNT (160000UL)
75 : #define FD_GUI_GEOIP_MAX_COUNTRY_CNT (254UL)
76 :
77 : struct fd_gui_geoip_node {
78 : uchar has_prefix;
79 : uchar country_code_idx;
80 : uint city_name_idx;
81 :
82 : struct fd_gui_geoip_node * left;
83 : struct fd_gui_geoip_node * right;
84 : };
85 :
86 : typedef struct fd_gui_geoip_node fd_gui_geoip_node_t;
87 :
88 : #define FD_GUI_PEERS_NODE_NOP (0)
89 0 : #define FD_GUI_PEERS_NODE_ADD (1)
90 0 : #define FD_GUI_PEERS_NODE_UPDATE (2)
91 0 : #define FD_GUI_PEERS_NODE_DELETE (3)
92 :
93 0 : #define FD_GUI_PEERS_CI_TABLE_SORT_KEY_CNT (256UL) /* maximum number of maintained active sort keys */
94 : #define FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ (200UL) /* the maximum number of rows a client can request for a table viewport */
95 0 : #define FD_GUI_PEERS_WS_VIEWPORT_UPDATE_INTERVAL_MILLIS ( 150L)
96 0 : #define FD_GUI_PEERS_METRIC_RATE_UPDATE_INTERVAL_MILLIS ( 150L)
97 0 : #define FD_GUI_PEERS_GOSSIP_STATS_UPDATE_INTERVAL_MILLIS ( 300L)
98 :
99 0 : #define FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT (64UL)
100 :
101 : /* Some table columns are rates of change, which require keeping a
102 : historical value / timestamp. */
103 : struct fd_gui_peers_metric_rate {
104 : ulong cur;
105 : ulong ref;
106 : long rate_ema; /* units per sec. live_table treaps use this field to sort table entries */
107 : long update_timestamp_ns; /* time when cur was last copied over to ref */
108 : };
109 : typedef struct fd_gui_peers_metric_rate fd_gui_peers_metric_rate_t;
110 :
111 0 : #define FD_GUI_PEERS_EMA_HALF_LIFE_NS (3000000000UL)
112 :
113 : static inline long
114 : fd_gui_peers_adaptive_ema( long last_update_time,
115 : long current_time,
116 : long current_value,
117 0 : long value_at_last_update ) {
118 0 : if( FD_UNLIKELY( last_update_time==0) ) return current_value;
119 :
120 0 : long elapsed_time = current_time - last_update_time;
121 0 : if( FD_UNLIKELY( elapsed_time<=0 ) ) return value_at_last_update;
122 :
123 : // Calculate alpha using half-life formula
124 : // alpha = 1 - exp(-ln(2) * elapsed_time / half_life)
125 0 : double decay_factor = 0.69314718055994 * ((double)elapsed_time / (double)FD_GUI_PEERS_EMA_HALF_LIFE_NS);
126 0 : double alpha = 1.0 - exp(-decay_factor);
127 :
128 0 : if( FD_UNLIKELY( alpha>1.0 ) ) alpha = 1.0;
129 0 : if( FD_UNLIKELY( alpha<0.0 ) ) alpha = 0.0;
130 :
131 0 : return (long)(alpha * (double)current_value + (1.0 - alpha) * (double)value_at_last_update);
132 0 : }
133 :
134 : struct fd_gui_peers_vote {
135 : fd_pubkey_t node_account;
136 : fd_pubkey_t vote_account;
137 : ulong stake;
138 : ulong last_vote_slot;
139 : long last_vote_timestamp;
140 : uchar commission;
141 : ulong epoch;
142 : ulong epoch_credits;
143 : };
144 :
145 : typedef struct fd_gui_peers_vote fd_gui_peers_vote_t;
146 :
147 : struct fd_gui_peers_node {
148 : int valid;
149 : long update_time_nanos;
150 : fd_pubkey_t pubkey;
151 : long wallclock_nanos;
152 : fd_gossip_contact_info_t contact_info;
153 : char name[ FD_GUI_CONFIG_PARSE_VALIDATOR_INFO_NAME_SZ + 1UL ];
154 :
155 : fd_gui_peers_metric_rate_t gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
156 : fd_gui_peers_metric_rate_t gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
157 : fd_gui_peers_metric_rate_t gossvf_rx_sum; /* sum of gossvf_rx */
158 : fd_gui_peers_metric_rate_t gossip_tx_sum; /* sum of gossip_tx */
159 :
160 : int has_vote_info;
161 : fd_pubkey_t vote_account;
162 : ulong stake; /* if has_vote_info==0 then stake==ULONG_MAX */
163 : ulong last_vote_slot;
164 : long last_vote_timestamp;
165 : uchar commission;
166 : ulong epoch;
167 : ulong epoch_credits;
168 : uchar country_code_idx;
169 : uint city_name_idx;
170 : int delinquent;
171 :
172 : struct {
173 : ulong next;
174 : ulong prev;
175 : } pubkey_map;
176 :
177 : struct {
178 : ulong next;
179 : ulong prev;
180 : } sock_map;
181 :
182 : struct {
183 : ulong parent;
184 : ulong left;
185 : ulong right;
186 : ulong prio;
187 : ulong next;
188 : ulong prev;
189 : } treaps_live_table[ FD_GUI_PEERS_CI_TABLE_SORT_KEY_CNT ];
190 : struct {
191 : ulong next;
192 : ulong prev;
193 : } dlist_live_table;
194 : ulong sort_keys_live_table;
195 :
196 : struct {
197 : ulong parent;
198 : ulong left;
199 : ulong right;
200 : ulong prio;
201 : ulong next;
202 : ulong prev;
203 : } treaps_bandwidth_tracking[ 2UL ];
204 : struct {
205 : ulong next;
206 : ulong prev;
207 : } dlist_bandwidth_tracking;
208 : ulong sort_keys_bandwidth_tracking;
209 : };
210 : typedef struct fd_gui_peers_node fd_gui_peers_node_t;
211 :
212 : struct fd_gui_peers_gossip_stats {
213 : long sample_time;
214 : ulong network_health_pull_response_msg_rx_success;
215 : ulong network_health_pull_response_msg_rx_failure;
216 : ulong network_health_push_msg_rx_success;
217 : ulong network_health_push_msg_rx_failure;
218 : ulong network_health_push_crds_rx_duplicate;
219 : ulong network_health_pull_response_crds_rx_duplicate;
220 : ulong network_health_push_crds_rx_success;
221 : ulong network_health_push_crds_rx_failure;
222 : ulong network_health_pull_response_crds_rx_success;
223 : ulong network_health_pull_response_crds_rx_failure;
224 : ulong network_health_push_msg_tx;
225 : ulong network_health_pull_response_msg_tx;
226 : ulong network_health_total_stake; /* lamports */
227 : ulong network_health_total_peers;
228 : ulong network_health_connected_stake; /* lamports */
229 : ulong network_health_connected_staked_peers;
230 : ulong network_health_connected_unstaked_peers;
231 : ulong network_ingress_total_bytes;
232 : ulong network_ingress_peer_sz;
233 : long network_ingress_peer_bytes_per_sec [ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ];
234 : char network_ingress_peer_names [ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ][ FD_GUI_CONFIG_PARSE_VALIDATOR_INFO_NAME_SZ + 1UL ];
235 : fd_pubkey_t network_ingress_peer_identities[ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ];
236 : long network_ingress_total_bytes_per_sec;
237 : ulong network_egress_total_bytes;
238 : ulong network_egress_peer_sz;
239 : long network_egress_peer_bytes_per_sec [ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ];
240 : char network_egress_peer_names [ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ][ FD_GUI_CONFIG_PARSE_VALIDATOR_INFO_NAME_SZ + 1UL ];
241 : fd_pubkey_t network_egress_peer_identities[ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ];
242 : long network_egress_total_bytes_per_sec;
243 : ulong storage_capacity;
244 : ulong storage_expired_cnt;
245 : ulong storage_evicted_cnt;
246 : ulong storage_active_cnt[ FD_METRICS_ENUM_CRDS_VALUE_CNT ];
247 : ulong storage_cnt_tx [ FD_METRICS_ENUM_CRDS_VALUE_CNT ];
248 : ulong storage_bytes_tx [ FD_METRICS_ENUM_CRDS_VALUE_CNT ];
249 : ulong messages_push_rx_cnt;
250 : ulong messages_push_tx_cnt;
251 : ulong messages_pull_response_rx_cnt;
252 : ulong messages_pull_response_tx_cnt;
253 : ulong messages_bytes_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
254 : ulong messages_count_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
255 : ulong messages_bytes_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
256 : ulong messages_count_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
257 : };
258 : typedef struct fd_gui_peers_gossip_stats fd_gui_peers_gossip_stats_t;
259 :
260 : #define POOL_NAME fd_gui_peers_node_info_pool
261 0 : #define POOL_T fd_gui_config_parse_info_t
262 0 : #define POOL_NEXT pool.next
263 : #include "../../util/tmpl/fd_pool.c"
264 :
265 : #define MAP_NAME fd_gui_peers_node_info_map
266 : #define MAP_ELE_T fd_gui_config_parse_info_t
267 : #define MAP_KEY_T fd_pubkey_t
268 0 : #define MAP_KEY pubkey
269 0 : #define MAP_IDX_T ulong
270 0 : #define MAP_NEXT map.next
271 0 : #define MAP_PREV map.prev
272 0 : #define MAP_KEY_HASH(k,s) (fd_hash( (s), (k)->uc, sizeof(fd_pubkey_t) ))
273 0 : #define MAP_KEY_EQ(k0,k1) (!memcmp((k0)->uc, (k1)->uc, 32UL))
274 : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
275 : #include "../../util/tmpl/fd_map_chain.c"
276 :
277 : #define MAP_NAME fd_gui_peers_node_pubkey_map
278 0 : #define MAP_ELE_T fd_gui_peers_node_t
279 : #define MAP_KEY_T fd_pubkey_t
280 0 : #define MAP_KEY pubkey
281 0 : #define MAP_IDX_T ulong
282 0 : #define MAP_NEXT pubkey_map.next
283 0 : #define MAP_PREV pubkey_map.prev
284 0 : #define MAP_KEY_HASH(k,s) (fd_hash( (s), (k)->uc, sizeof(fd_pubkey_t) ))
285 0 : #define MAP_KEY_EQ(k0,k1) (!memcmp((k0)->uc, (k1)->uc, 32UL))
286 : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
287 : #include "../../util/tmpl/fd_map_chain.c"
288 :
289 : #define MAP_NAME fd_gui_peers_node_sock_map
290 0 : #define MAP_ELE_T fd_gui_peers_node_t
291 : #define MAP_KEY_T fd_gossip_socket_t
292 0 : #define MAP_KEY contact_info.sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ]
293 0 : #define MAP_IDX_T ulong
294 0 : #define MAP_NEXT sock_map.next
295 0 : #define MAP_PREV sock_map.prev
296 0 : #define MAP_KEY_HASH(k,s) ( fd_hash( (s), (k), sizeof(uint) + sizeof(ushort) ) )
297 0 : #define MAP_KEY_EQ(k0,k1) ((k0)->is_ipv6==(k1)->is_ipv6 && (k0)->port==(k1)->port && (!((k0)->is_ipv6) ? (k0)->ip4==(k1)->ip4 : !memcmp((k0)->ip6,(k1)->ip6,16UL)) )
298 : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
299 : #define MAP_MULTI 1
300 : #include "../../util/tmpl/fd_map_chain.c"
301 :
302 0 : static int live_table_col_pubkey_lt( void const * a, void const * b ) { return memcmp( ((fd_pubkey_t *)a)->uc, ((fd_pubkey_t *)b)->uc, 32UL ) < 0; }
303 0 : static int live_table_col_long_lt ( void const * a, void const * b ) { return *(long *)a < *(long *)b; }
304 0 : static int live_table_col_uchar_lt ( void const * a, void const * b ) { return *(uchar *)a < *(uchar *)b; }
305 0 : static int live_table_col_ipv4_lt ( void const * a, void const * b ) { return fd_uint_bswap(*(uint *)a) < fd_uint_bswap(*(uint *)b); }
306 0 : static int live_table_col_name_lt ( void const * a, void const * b ) { return memcmp( (char *)a, (char *)b, FD_GUI_CONFIG_PARSE_VALIDATOR_INFO_NAME_SZ + 1UL ) < 0; }
307 0 : static int live_table_col_stake_lt ( void const * a, void const * b ) { return fd_long_if( *(ulong *)a>LONG_MAX, -1L, (long)*(ulong *)a ) < fd_long_if( *(ulong *)b>LONG_MAX, -1L, (long)*(ulong *)b ); }
308 :
309 : #define LIVE_TABLE_NAME fd_gui_peers_live_table
310 0 : #define LIVE_TABLE_TREAP treaps_live_table
311 0 : #define LIVE_TABLE_SORT_KEYS sort_keys_live_table
312 0 : #define LIVE_TABLE_DLIST dlist_live_table
313 0 : #define LIVE_TABLE_COLUMN_CNT (9UL)
314 0 : #define LIVE_TABLE_MAX_SORT_KEY_CNT FD_GUI_PEERS_CI_TABLE_SORT_KEY_CNT
315 : #define LIVE_TABLE_ROW_T fd_gui_peers_node_t
316 0 : #define LIVE_TABLE_COLUMNS LIVE_TABLE_COL_ARRAY( \
317 0 : LIVE_TABLE_COL_ENTRY( "Stake", stake, live_table_col_stake_lt ), \
318 0 : LIVE_TABLE_COL_ENTRY( "Pubkey", pubkey, live_table_col_pubkey_lt ), \
319 0 : LIVE_TABLE_COL_ENTRY( "Name", name, live_table_col_name_lt ), \
320 0 : LIVE_TABLE_COL_ENTRY( "Country", country_code_idx, live_table_col_uchar_lt ), \
321 0 : LIVE_TABLE_COL_ENTRY( "IP Addr", contact_info.sockets[ FD_GOSSIP_CONTACT_INFO_SOCKET_GOSSIP ].ip4, live_table_col_ipv4_lt ), \
322 0 : LIVE_TABLE_COL_ENTRY( "Ingress Push", gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema, live_table_col_long_lt ), \
323 0 : LIVE_TABLE_COL_ENTRY( "Ingress Pull", gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PULL_RESPONSE_IDX ].rate_ema, live_table_col_long_lt ), \
324 0 : LIVE_TABLE_COL_ENTRY( "Egress Push", gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema, live_table_col_long_lt ), \
325 0 : LIVE_TABLE_COL_ENTRY( "Egress Pull", gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PULL_RESPONSE_IDX ].rate_ema, live_table_col_long_lt ), )
326 : #include "fd_gui_live_table_tmpl.c"
327 :
328 0 : #define FD_GUI_PEERS_LIVE_TABLE_DEFAULT_SORT_KEY ((fd_gui_peers_live_table_sort_key_t){ .col = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }, .dir = { -1, -1, -1, -1, -1, -1, -1, -1, -1 } })
329 :
330 : #define LIVE_TABLE_NAME fd_gui_peers_bandwidth_tracking
331 0 : #define LIVE_TABLE_TREAP treaps_bandwidth_tracking
332 0 : #define LIVE_TABLE_SORT_KEYS sort_keys_bandwidth_tracking
333 0 : #define LIVE_TABLE_DLIST dlist_bandwidth_tracking
334 0 : #define LIVE_TABLE_COLUMN_CNT (2UL)
335 0 : #define LIVE_TABLE_MAX_SORT_KEY_CNT (2UL)
336 : #define LIVE_TABLE_ROW_T fd_gui_peers_node_t
337 0 : #define LIVE_TABLE_COLUMNS LIVE_TABLE_COL_ARRAY( \
338 0 : LIVE_TABLE_COL_ENTRY( "Ingress Total", gossvf_rx_sum.rate_ema, live_table_col_long_lt ), \
339 0 : LIVE_TABLE_COL_ENTRY( "Egress Total", gossip_tx_sum.rate_ema, live_table_col_long_lt ) )
340 : #include "fd_gui_live_table_tmpl.c"
341 :
342 0 : #define FD_GUI_PEERS_BW_TRACKING_INGRESS_SORT_KEY ((fd_gui_peers_bandwidth_tracking_sort_key_t){ .col = { 0, 1 }, .dir = { -1, 0 } })
343 0 : #define FD_GUI_PEERS_BW_TRACKING_EGRESS_SORT_KEY ((fd_gui_peers_bandwidth_tracking_sort_key_t){ .col = { 0, 1 }, .dir = { 0, -1 } })
344 :
345 : struct fd_gui_peers_ws_conn {
346 : int connected;
347 : long connected_time;
348 :
349 : ulong start_row;
350 : ulong row_cnt;
351 : fd_gui_peers_node_t viewport[ FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ ];
352 : fd_gui_peers_live_table_sort_key_t sort_key;
353 : };
354 :
355 : typedef struct fd_gui_peers_ws_conn fd_gui_peers_ws_conn_t;
356 :
357 : struct fd_gui_ip_db {
358 : fd_gui_geoip_node_t * nodes;
359 : char country_code[ FD_GUI_GEOIP_MAX_COUNTRY_CNT ][ 3 ]; /* ISO 3166-1 alpha-2 country codes as cstrings */
360 : char city_name[ FD_GUI_GEOIP_MAX_CITY_CNT ][ FD_GUI_GEOIP_MAX_CITY_NAME_SZ ]; /* city_names as cstrings */
361 : };
362 :
363 : typedef struct fd_gui_ip_db fd_gui_ip_db_t;
364 :
365 : struct fd_gui_peers_ctx {
366 : long next_client_nanos; /* ns timestamp when we'll service the next ws client */
367 : long next_metric_rate_update_nanos; /* ns timestamp when we'll next update rate-of-change metrics */
368 : long next_gossip_stats_update_nanos; /* ns timestamp when we'll next broadcast out gossip stats message */
369 :
370 : fd_gui_config_parse_info_t * node_info_pool;
371 : fd_gui_peers_node_info_map_t * node_info_map;
372 : fd_gui_peers_node_pubkey_map_t * node_pubkey_map;
373 : fd_gui_peers_node_sock_map_t * node_sock_map;
374 : fd_gui_peers_live_table_t * live_table;
375 : fd_gui_peers_bandwidth_tracking_t * bw_tracking;
376 :
377 : fd_http_server_t * http;
378 : fd_topo_t * topo;
379 :
380 : ulong max_ws_conn_cnt;
381 : ulong open_ws_conn_cnt;
382 : ulong active_ws_conn_id;
383 : fd_gui_peers_ws_conn_t * client_viewports; /* points to 2D array with max_ws_conn_cnt rows and FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ columns */
384 :
385 : fd_gui_peers_gossip_stats_t gossip_stats [ 1 ];
386 : fd_gui_peers_node_t contact_info_table[ FD_CONTACT_INFO_TABLE_SIZE ];
387 :
388 : ulong slot_voted; /* last vote slot for this validator */
389 :
390 : fd_gui_peers_vote_t votes [ FD_RUNTIME_MAX_VOTE_ACCOUNTS ];
391 : fd_gui_peers_vote_t votes_scratch[ FD_RUNTIME_MAX_VOTE_ACCOUNTS ]; /* for fast stable sort */
392 :
393 : #if FD_HAS_ZSTD
394 : ZSTD_DCtx * zstd_dctx;
395 : #endif
396 :
397 : fd_gui_ip_db_t dbip;
398 : };
399 :
400 : typedef struct fd_gui_peers_ctx fd_gui_peers_ctx_t;
401 :
402 : FD_PROTOTYPES_BEGIN
403 :
404 : FD_FN_CONST ulong
405 : fd_gui_peers_align( void );
406 :
407 : FD_FN_CONST ulong
408 : fd_gui_peers_footprint( ulong max_ws_conn_cnt );
409 :
410 : void *
411 : fd_gui_peers_new( void * shmem,
412 : fd_http_server_t * http,
413 : fd_topo_t * topo,
414 : ulong max_ws_conn_cnt,
415 : long now );
416 :
417 : fd_gui_peers_ctx_t *
418 : fd_gui_peers_join( void * shmem );
419 :
420 : /* fd_gui_peers_handle_gossip_message_rx parses gossip messages from the
421 : net_gossvf link for ingress messages and the gossip_net link for
422 : egress messages and tracks per-peer, per-message bytes. payload and
423 : payload_sz corresponds to the frag data after the network headers
424 : have been stripped. is_rx is true if the frag is an incoming message
425 : from the net_gossvf link. Otherwise, the frag is assumed to be an
426 : outgoing message from the gossip_net link. peer_sock is the ipv4
427 : address and port from the stripped net headers, which identifies the
428 : peers that sent or will receive the message.
429 :
430 : Note that gossip_net frags are unverified gossip messages from the
431 : network. Messages that cannot be parsed are ignored. */
432 : void
433 : fd_gui_peers_handle_gossip_message( fd_gui_peers_ctx_t * peers,
434 : uchar const * payload,
435 : ulong payload_sz,
436 : fd_gossip_socket_t const * peer_sock,
437 : int is_rx );
438 :
439 : /* fd_gui_peers_handle_gossip_message_tx parses frags on the gossip_out
440 : link and uses the contact info update to build up the peer table. */
441 :
442 : void
443 : fd_gui_peers_handle_gossip_update( fd_gui_peers_ctx_t * peers,
444 : fd_gossip_update_message_t const * update,
445 : long now );
446 :
447 : void
448 : fd_gui_peers_handle_vote_update( fd_gui_peers_ctx_t * peers,
449 : fd_gui_peers_vote_t * votes,
450 : ulong vote_cnt,
451 : long now,
452 : fd_pubkey_t * identity );
453 :
454 : void
455 : fd_gui_peers_handle_config_account( fd_gui_peers_ctx_t * peers,
456 : uchar const * data,
457 : ulong sz );
458 :
459 : /* fd_gui_peers_ws_message handles incoming websocket request payloads
460 : requesting peer-related responses. ws_conn_id is the connection id
461 : of the requester. data is a pointer to the start of the
462 : json-formatted request payload. data_len is the length of the
463 : request payload. */
464 : int
465 : fd_gui_peers_ws_message( fd_gui_peers_ctx_t * peers,
466 : ulong ws_conn_id,
467 : uchar const * data,
468 : ulong data_len );
469 :
470 : /* fd_gui_peers_ws_open is a callback which should be triggered when a
471 : new client opens a WebSocket connection. ws_conn_id is the
472 : connection id of the new client. now is a UNIX nanosecond timestamp
473 : for the current time. */
474 : void
475 : fd_gui_peers_ws_open( fd_gui_peers_ctx_t * peers,
476 : ulong ws_conn_id,
477 : long now );
478 :
479 : /* fd_gui_peers_ws_close is a callback which should be triggered when an
480 : existing client closes their WebSocket connection. ws_conn_id is the
481 : connection id of the client.*/
482 : void
483 : fd_gui_peers_ws_close( fd_gui_peers_ctx_t * peers,
484 : ulong ws_conn_id );
485 :
486 : /* fd_gui_peers_poll should be called in a the tile's main spin loop to
487 : periodically update peers internal state as well as publish new
488 : Websocket messages to clients. now is a UNIX nanosecond timestamp for
489 : the current time. */
490 : int
491 : fd_gui_peers_poll( fd_gui_peers_ctx_t * peers,
492 : long now );
493 :
494 : FD_PROTOTYPES_END
495 :
496 : #endif /* HEADER_fd_src_disco_gui_fd_gui_peers_h */
|