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

Generated by: LCOV version 1.14