LCOV - code coverage report
Current view: top level - disco/gui - fd_gui_peers.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 78 0.0 %
Date: 2026-04-30 06:50:00 Functions: 0 28 0.0 %

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

Generated by: LCOV version 1.14