LCOV - code coverage report
Current view: top level - disco/gui - fd_gui_peers.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 76 0.0 %
Date: 2026-02-08 06:05:17 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 "../../util/net/fd_net_headers.h"
      20             : #include "../../disco/metrics/generated/fd_metrics_enums.h"
      21             : #include "../../flamenco/gossip/fd_gossip_types.h"
      22             : #include "../../flamenco/runtime/fd_runtime_const.h"
      23             : 
      24             : #include "../../waltz/http/fd_http_server.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             : #define FD_GUI_PEERS_NODE_NOP    (0)
      90           0 : #define FD_GUI_PEERS_NODE_ADD    (1)
      91           0 : #define FD_GUI_PEERS_NODE_UPDATE (2)
      92           0 : #define FD_GUI_PEERS_NODE_DELETE (3)
      93             : 
      94           0 : #define FD_GUI_PEERS_CI_TABLE_SORT_KEY_CNT                 (256UL) /* maximum number of maintained active sort keys */
      95             : #define FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ                    (200UL) /* the maximum number of rows a client can request for a table viewport */
      96           0 : #define FD_GUI_PEERS_WS_VIEWPORT_UPDATE_INTERVAL_MILLIS    ( 150L)
      97           0 : #define FD_GUI_PEERS_METRIC_RATE_UPDATE_INTERVAL_MILLIS    ( 150L)
      98           0 : #define FD_GUI_PEERS_GOSSIP_STATS_UPDATE_INTERVAL_MILLIS   ( 300L)
      99             : 
     100           0 : #define FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT (64UL)
     101             : 
     102             : /* Some table columns are rates of change, which require keeping a
     103             :    historical value / timestamp. */
     104             : struct fd_gui_peers_metric_rate {
     105             :   ulong cur;
     106             :   ulong ref;
     107             :   long rate_ema; /* units per sec. live_table treaps use this field to sort table entries */
     108             :   long update_timestamp_ns; /* time when cur was last copied over to ref */
     109             : };
     110             : typedef struct fd_gui_peers_metric_rate fd_gui_peers_metric_rate_t;
     111             : 
     112           0 : #define FD_GUI_PEERS_EMA_HALF_LIFE_NS (3000000000UL)
     113             : 
     114             : static inline long
     115             : fd_gui_peers_adaptive_ema( long last_update_time,
     116             :                            long current_time,
     117             :                            long current_value,
     118           0 :                            long value_at_last_update ) {
     119           0 :     if( FD_UNLIKELY( last_update_time==0) ) return current_value;
     120             : 
     121           0 :     long elapsed_time = current_time - last_update_time;
     122           0 :     if( FD_UNLIKELY( elapsed_time<=0 ) ) return value_at_last_update;
     123             : 
     124             :     // Calculate alpha using half-life formula
     125             :     // alpha = 1 - exp(-ln(2) * elapsed_time / half_life)
     126           0 :     double decay_factor = 0.69314718055994 * ((double)elapsed_time / (double)FD_GUI_PEERS_EMA_HALF_LIFE_NS);
     127           0 :     double alpha = 1.0 - exp(-decay_factor);
     128             : 
     129           0 :     if( FD_UNLIKELY( alpha>1.0 ) ) alpha = 1.0;
     130           0 :     if( FD_UNLIKELY( alpha<0.0 ) ) alpha = 0.0;
     131             : 
     132           0 :     return (long)(alpha * (double)current_value + (1.0 - alpha) * (double)value_at_last_update);
     133           0 : }
     134             : 
     135             : struct fd_gui_peers_vote {
     136             :   fd_pubkey_t node_account;
     137             :   fd_pubkey_t vote_account;
     138             :   ulong       stake;
     139             :   ulong       last_vote_slot;
     140             :   long        last_vote_timestamp;
     141             :   uchar       commission;
     142             :   ulong       epoch;
     143             :   ulong       epoch_credits;
     144             : };
     145             : 
     146             : typedef struct fd_gui_peers_vote fd_gui_peers_vote_t;
     147             : 
     148             : struct fd_gui_peers_node {
     149             :   int valid;
     150             :   long update_time_nanos;
     151             :   fd_contact_info_t contact_info;
     152             :   char name[ FD_GUI_CONFIG_PARSE_VALIDATOR_INFO_NAME_SZ + 1UL ];
     153             : 
     154             :   fd_gui_peers_metric_rate_t gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
     155             :   fd_gui_peers_metric_rate_t gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
     156             :   fd_gui_peers_metric_rate_t gossvf_rx_sum; /* sum of gossvf_rx */
     157             :   fd_gui_peers_metric_rate_t gossip_tx_sum; /* sum of gossip_tx */
     158             : 
     159             :   int         has_vote_info;
     160             :   fd_pubkey_t vote_account;
     161             :   ulong       stake; /* if has_vote_info==0 then stake==ULONG_MAX */
     162             :   ulong       last_vote_slot;
     163             :   long        last_vote_timestamp;
     164             :   uchar       commission;
     165             :   ulong       epoch;
     166             :   ulong       epoch_credits;
     167             :   uchar       country_code_idx;
     168             :   uint        city_name_idx;
     169             :   int         delinquent;
     170             : 
     171             :   struct {
     172             :     ulong next;
     173             :     ulong prev;
     174             :   } pubkey_map;
     175             : 
     176             :   struct {
     177             :     ulong next;
     178             :     ulong prev;
     179             :   } sock_map;
     180             : 
     181             :   struct {
     182             :     ulong parent;
     183             :     ulong left;
     184             :     ulong right;
     185             :     ulong prio;
     186             :     ulong next;
     187             :     ulong prev;
     188             :   } treaps_live_table[ FD_GUI_PEERS_CI_TABLE_SORT_KEY_CNT ];
     189             :   struct {
     190             :     ulong next;
     191             :     ulong prev;
     192             :   } dlist_live_table;
     193             :   ulong sort_keys_live_table;
     194             : 
     195             :   struct {
     196             :     ulong parent;
     197             :     ulong left;
     198             :     ulong right;
     199             :     ulong prio;
     200             :     ulong next;
     201             :     ulong prev;
     202             :   } treaps_bandwidth_tracking[ 2UL ];
     203             :     struct {
     204             :     ulong next;
     205             :     ulong prev;
     206             :   } dlist_bandwidth_tracking;
     207             :   ulong sort_keys_bandwidth_tracking;
     208             : };
     209             : typedef struct fd_gui_peers_node fd_gui_peers_node_t;
     210             : 
     211             : struct fd_gui_peers_gossip_stats {
     212             :   long  sample_time;
     213             :   ulong network_health_pull_response_msg_rx_success;
     214             :   ulong network_health_pull_response_msg_rx_failure;
     215             :   ulong network_health_push_msg_rx_success;
     216             :   ulong network_health_push_msg_rx_failure;
     217             :   ulong network_health_push_crds_rx_duplicate;
     218             :   ulong network_health_pull_response_crds_rx_duplicate;
     219             :   ulong network_health_push_crds_rx_success;
     220             :   ulong network_health_push_crds_rx_failure;
     221             :   ulong network_health_pull_response_crds_rx_success;
     222             :   ulong network_health_pull_response_crds_rx_failure;
     223             :   ulong network_health_push_msg_tx;
     224             :   ulong network_health_pull_response_msg_tx;
     225             :   ulong network_health_total_stake; /* lamports */
     226             :   ulong network_health_total_peers;
     227             :   ulong network_health_connected_stake; /* lamports */
     228             :   ulong network_health_connected_staked_peers;
     229             :   ulong network_health_connected_unstaked_peers;
     230             :   ulong network_ingress_total_bytes;
     231             :   ulong network_ingress_peer_sz;
     232             :   long  network_ingress_peer_bytes_per_sec   [ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ];
     233             :   char  network_ingress_peer_names           [ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ][ FD_GUI_CONFIG_PARSE_VALIDATOR_INFO_NAME_SZ + 1UL ];
     234             :   fd_pubkey_t network_ingress_peer_identities[ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ];
     235             :   long  network_ingress_total_bytes_per_sec;
     236             :   ulong network_egress_total_bytes;
     237             :   ulong network_egress_peer_sz;
     238             :   long  network_egress_peer_bytes_per_sec   [ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ];
     239             :   char  network_egress_peer_names           [ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ][ FD_GUI_CONFIG_PARSE_VALIDATOR_INFO_NAME_SZ + 1UL ];
     240             :   fd_pubkey_t network_egress_peer_identities[ FD_GUI_PEERS_GOSSIP_TOP_PEERS_CNT ];
     241             :   long  network_egress_total_bytes_per_sec;
     242             :   ulong storage_capacity;
     243             :   ulong storage_expired_cnt;
     244             :   ulong storage_evicted_cnt;
     245             :   ulong storage_active_cnt[ FD_METRICS_ENUM_CRDS_VALUE_CNT ];
     246             :   ulong storage_cnt_tx    [ FD_METRICS_ENUM_CRDS_VALUE_CNT ];
     247             :   ulong storage_bytes_tx  [ FD_METRICS_ENUM_CRDS_VALUE_CNT ];
     248             :   ulong messages_push_rx_cnt;
     249             :   ulong messages_push_tx_cnt;
     250             :   ulong messages_pull_response_rx_cnt;
     251             :   ulong messages_pull_response_tx_cnt;
     252             :   ulong messages_bytes_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
     253             :   ulong messages_count_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
     254             :   ulong messages_bytes_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
     255             :   ulong messages_count_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_CNT ];
     256             : };
     257             : typedef struct fd_gui_peers_gossip_stats fd_gui_peers_gossip_stats_t;
     258             : 
     259             : #define POOL_NAME fd_gui_peers_node_info_pool
     260           0 : #define POOL_T    fd_gui_config_parse_info_t
     261           0 : #define POOL_NEXT pool.next
     262             : #include "../../util/tmpl/fd_pool.c"
     263             : 
     264             : #define MAP_NAME  fd_gui_peers_node_info_map
     265             : #define MAP_ELE_T fd_gui_config_parse_info_t
     266             : #define MAP_KEY_T fd_pubkey_t
     267           0 : #define MAP_KEY   pubkey
     268           0 : #define MAP_IDX_T ulong
     269           0 : #define MAP_NEXT  map.next
     270           0 : #define MAP_PREV  map.prev
     271           0 : #define MAP_KEY_HASH(k,s) (fd_hash( (s), (k)->uc, sizeof(fd_pubkey_t) ))
     272           0 : #define MAP_KEY_EQ(k0,k1) (!memcmp((k0)->uc, (k1)->uc, 32UL))
     273             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
     274             : #include "../../util/tmpl/fd_map_chain.c"
     275             : 
     276             : #define MAP_NAME  fd_gui_peers_node_pubkey_map
     277           0 : #define MAP_ELE_T fd_gui_peers_node_t
     278             : #define MAP_KEY_T fd_pubkey_t
     279           0 : #define MAP_KEY   contact_info.pubkey
     280           0 : #define MAP_IDX_T ulong
     281           0 : #define MAP_NEXT  pubkey_map.next
     282           0 : #define MAP_PREV  pubkey_map.prev
     283           0 : #define MAP_KEY_HASH(k,s) (fd_hash( (s), (k)->uc, sizeof(fd_pubkey_t) ))
     284           0 : #define MAP_KEY_EQ(k0,k1) (!memcmp((k0)->uc, (k1)->uc, 32UL))
     285             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
     286             : #include "../../util/tmpl/fd_map_chain.c"
     287             : 
     288             : #define MAP_NAME  fd_gui_peers_node_sock_map
     289           0 : #define MAP_ELE_T fd_gui_peers_node_t
     290             : #define MAP_KEY_T fd_ip4_port_t
     291           0 : #define MAP_KEY   contact_info.sockets[ FD_CONTACT_INFO_SOCKET_GOSSIP ]
     292           0 : #define MAP_IDX_T ulong
     293           0 : #define MAP_NEXT  sock_map.next
     294           0 : #define MAP_PREV  sock_map.prev
     295           0 : #define MAP_KEY_HASH(k,s) ( fd_hash( (s), (k), sizeof(uint) + sizeof(ushort) ) )
     296           0 : #define MAP_KEY_EQ(k0,k1) ((k0)->l==(k1)->l )
     297             : #define MAP_OPTIMIZE_RANDOM_ACCESS_REMOVAL 1
     298             : #define MAP_MULTI 1
     299             : #include "../../util/tmpl/fd_map_chain.c"
     300             : 
     301           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;   }
     302           0 : static int live_table_col_long_lt  ( void const * a, void const * b ) { return *(long *)a < *(long *)b;                                              }
     303           0 : static int live_table_col_uchar_lt ( void const * a, void const * b ) { return *(uchar *)a < *(uchar *)b;                                            }
     304           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);                }
     305           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; }
     306           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 ); }
     307             : 
     308             : #define LIVE_TABLE_NAME fd_gui_peers_live_table
     309           0 : #define LIVE_TABLE_TREAP treaps_live_table
     310           0 : #define LIVE_TABLE_SORT_KEYS sort_keys_live_table
     311           0 : #define LIVE_TABLE_DLIST dlist_live_table
     312           0 : #define LIVE_TABLE_COLUMN_CNT (9UL)
     313           0 : #define LIVE_TABLE_MAX_SORT_KEY_CNT FD_GUI_PEERS_CI_TABLE_SORT_KEY_CNT
     314             : #define LIVE_TABLE_ROW_T fd_gui_peers_node_t
     315           0 : #define LIVE_TABLE_COLUMNS LIVE_TABLE_COL_ARRAY( \
     316           0 :   LIVE_TABLE_COL_ENTRY( "Stake",        stake,                                                                    live_table_col_stake_lt  ), \
     317           0 :   LIVE_TABLE_COL_ENTRY( "Pubkey",       contact_info.pubkey,                                                      live_table_col_pubkey_lt ), \
     318           0 :   LIVE_TABLE_COL_ENTRY( "Name",         name,                                                                     live_table_col_name_lt   ), \
     319           0 :   LIVE_TABLE_COL_ENTRY( "Country",      country_code_idx,                                                         live_table_col_uchar_lt  ), \
     320           0 :   LIVE_TABLE_COL_ENTRY( "IP Addr",      contact_info.sockets[ FD_CONTACT_INFO_SOCKET_GOSSIP ].addr,               live_table_col_ipv4_lt   ), \
     321           0 :   LIVE_TABLE_COL_ENTRY( "Ingress Push", gossvf_rx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema,          live_table_col_long_lt   ), \
     322           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   ), \
     323           0 :   LIVE_TABLE_COL_ENTRY( "Egress Push",  gossip_tx[ FD_METRICS_ENUM_GOSSIP_MESSAGE_V_PUSH_IDX ].rate_ema,          live_table_col_long_lt   ), \
     324           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   ), )
     325             : #include "fd_gui_live_table_tmpl.c"
     326             : 
     327           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 } })
     328             : 
     329             : #define LIVE_TABLE_NAME fd_gui_peers_bandwidth_tracking
     330           0 : #define LIVE_TABLE_TREAP treaps_bandwidth_tracking
     331           0 : #define LIVE_TABLE_SORT_KEYS sort_keys_bandwidth_tracking
     332           0 : #define LIVE_TABLE_DLIST dlist_bandwidth_tracking
     333           0 : #define LIVE_TABLE_COLUMN_CNT (2UL)
     334           0 : #define LIVE_TABLE_MAX_SORT_KEY_CNT (2UL)
     335             : #define LIVE_TABLE_ROW_T fd_gui_peers_node_t
     336           0 : #define LIVE_TABLE_COLUMNS LIVE_TABLE_COL_ARRAY( \
     337           0 :   LIVE_TABLE_COL_ENTRY( "Ingress Total", gossvf_rx_sum.rate_ema, live_table_col_long_lt ), \
     338           0 :   LIVE_TABLE_COL_ENTRY( "Egress Total",  gossip_tx_sum.rate_ema, live_table_col_long_lt )  )
     339             : #include "fd_gui_live_table_tmpl.c"
     340             : 
     341           0 : #define FD_GUI_PEERS_BW_TRACKING_INGRESS_SORT_KEY ((fd_gui_peers_bandwidth_tracking_sort_key_t){ .col = { 0, 1 }, .dir = { -1, 0 } })
     342           0 : #define FD_GUI_PEERS_BW_TRACKING_EGRESS_SORT_KEY  ((fd_gui_peers_bandwidth_tracking_sort_key_t){ .col = { 0, 1 }, .dir = { 0, -1 } })
     343             : 
     344             : struct fd_gui_peers_ws_conn {
     345             :   int connected;
     346             :   long connected_time;
     347             : 
     348             :   ulong start_row;
     349             :   ulong row_cnt;
     350             :   fd_gui_peers_node_t viewport[ FD_GUI_PEERS_WS_VIEWPORT_MAX_SZ ];
     351             :   fd_gui_peers_live_table_sort_key_t sort_key;
     352             : };
     353             : 
     354             : typedef struct fd_gui_peers_ws_conn fd_gui_peers_ws_conn_t;
     355             : 
     356             : struct fd_gui_ip_db {
     357             :   fd_gui_geoip_node_t * nodes;
     358             :   char country_code[ FD_GUI_GEOIP_MAX_COUNTRY_CNT ][ 3 ]; /* ISO 3166-1 alpha-2 country codes as cstrings */
     359             :   char city_name[ FD_GUI_GEOIP_MAX_CITY_CNT ][ FD_GUI_GEOIP_MAX_CITY_NAME_SZ ]; /* city_names as cstrings */
     360             : };
     361             : 
     362             : typedef struct fd_gui_ip_db fd_gui_ip_db_t;
     363             : 
     364             : struct fd_gui_peers_ctx {
     365             :   long next_client_nanos; /* ns timestamp when we'll service the next ws client */
     366             :   long next_metric_rate_update_nanos; /* ns timestamp when we'll next update rate-of-change metrics */
     367             :   long next_gossip_stats_update_nanos; /* ns timestamp when we'll next broadcast out gossip stats message */
     368             : 
     369             :   fd_gui_config_parse_info_t * node_info_pool;
     370             :   fd_gui_peers_node_info_map_t * node_info_map;
     371             :   fd_gui_peers_node_pubkey_map_t * node_pubkey_map;
     372             :   fd_gui_peers_node_sock_map_t  * node_sock_map;
     373             :   fd_gui_peers_live_table_t * live_table;
     374             :   fd_gui_peers_bandwidth_tracking_t * bw_tracking;
     375             : 
     376             :   fd_http_server_t * http;
     377             :   fd_topo_t * topo;
     378             : 
     379             :   ulong max_ws_conn_cnt;
     380             :   ulong open_ws_conn_cnt;
     381             :   ulong active_ws_conn_id;
     382             :   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 */
     383             : 
     384             :   fd_gui_peers_gossip_stats_t gossip_stats  [ 1 ];
     385             :   fd_gui_peers_node_t contact_info_table[ FD_CONTACT_INFO_TABLE_SIZE ];
     386             : 
     387             :   ulong slot_voted; /* last vote slot for this validator */
     388             : 
     389             :   fd_gui_peers_vote_t votes        [ FD_RUNTIME_MAX_VOTE_ACCOUNTS ];
     390             :   fd_gui_peers_vote_t votes_scratch[ FD_RUNTIME_MAX_VOTE_ACCOUNTS ]; /* for fast stable sort */
     391             : 
     392             : #if FD_HAS_ZSTD
     393             :   ZSTD_DCtx * zstd_dctx;
     394             : #endif
     395             : 
     396             :   fd_gui_ip_db_t dbip;
     397             : };
     398             : 
     399             : typedef struct fd_gui_peers_ctx fd_gui_peers_ctx_t;
     400             : 
     401             : FD_PROTOTYPES_BEGIN
     402             : 
     403             : FD_FN_CONST ulong
     404             : fd_gui_peers_align( void );
     405             : 
     406             : FD_FN_CONST ulong
     407             : fd_gui_peers_footprint( ulong max_ws_conn_cnt );
     408             : 
     409             : void *
     410             : fd_gui_peers_new( void *             shmem,
     411             :                   fd_http_server_t * http,
     412             :                   fd_topo_t *        topo,
     413             :                   ulong              max_ws_conn_cnt,
     414             :                   long               now );
     415             : 
     416             : fd_gui_peers_ctx_t *
     417             : fd_gui_peers_join( void * shmem );
     418             : 
     419             : /* fd_gui_peers_handle_gossip_message_rx parses gossip messages from the
     420             :    net_gossvf link for ingress messages and the gossip_net link for
     421             :    egress messages and tracks per-peer, per-message bytes.  payload and
     422             :    payload_sz corresponds to the frag data after the network headers
     423             :    have been stripped. is_rx is true if the frag is an incoming message
     424             :    from the net_gossvf link. Otherwise, the frag is assumed to be an
     425             :    outgoing message from the gossip_net link. peer_sock is the ipv4
     426             :    address and port from the stripped net headers, which identifies the
     427             :    peers that sent or will receive the message.
     428             : 
     429             :    Note that gossip_net frags are unverified gossip messages from the
     430             :    network.  Messages that cannot be parsed are ignored. */
     431             : void
     432             : fd_gui_peers_handle_gossip_message( fd_gui_peers_ctx_t *  peers,
     433             :                                     uchar const *         payload,
     434             :                                     ulong                 payload_sz,
     435             :                                     fd_ip4_port_t const * peer_sock,
     436             :                                     int                   is_rx );
     437             : 
     438             : /* fd_gui_peers_handle_gossip_message_tx parses frags on the gossip_out
     439             :    link and uses the contact info update to build up the peer table. */
     440             : 
     441             : void
     442             : fd_gui_peers_handle_gossip_update( fd_gui_peers_ctx_t *               peers,
     443             :                                    fd_gossip_update_message_t const * update,
     444             :                                    long                               now );
     445             : 
     446             : void
     447             : fd_gui_peers_handle_vote_update( fd_gui_peers_ctx_t *  peers,
     448             :                                  fd_gui_peers_vote_t * votes,
     449             :                                  ulong                 vote_cnt,
     450             :                                  long                  now,
     451             :                                  fd_pubkey_t *         identity );
     452             : 
     453             : void
     454             : fd_gui_peers_handle_config_account( fd_gui_peers_ctx_t *  peers,
     455             :                                     uchar const *         data,
     456             :                                     ulong                 sz );
     457             : 
     458             : /* fd_gui_peers_ws_message handles incoming websocket request payloads
     459             :    requesting peer-related responses.  ws_conn_id is the connection id
     460             :    of the requester.  data is a pointer to the start of the
     461             :    json-formatted request payload.  data_len is the length of the
     462             :    request payload. */
     463             : int
     464             : fd_gui_peers_ws_message( fd_gui_peers_ctx_t * peers,
     465             :                          ulong                ws_conn_id,
     466             :                          uchar const *        data,
     467             :                          ulong                data_len );
     468             : 
     469             : /* fd_gui_peers_ws_open is a callback which should be triggered when a
     470             :    new client opens a WebSocket connection.  ws_conn_id is the
     471             :    connection id of the new client.  now is a UNIX nanosecond timestamp
     472             :    for the current time. */
     473             : void
     474             : fd_gui_peers_ws_open( fd_gui_peers_ctx_t *  peers,
     475             :                       ulong                 ws_conn_id,
     476             :                       long                  now );
     477             : 
     478             : /* fd_gui_peers_ws_close is a callback which should be triggered when an
     479             :    existing client closes their WebSocket connection.  ws_conn_id is the
     480             :    connection id of the client.*/
     481             : void
     482             : fd_gui_peers_ws_close( fd_gui_peers_ctx_t * peers,
     483             :                        ulong                ws_conn_id );
     484             : 
     485             : /* fd_gui_peers_poll should be called in a the tile's main spin loop to
     486             :    periodically update peers internal state as well as publish new
     487             :    Websocket messages to clients. now is a UNIX nanosecond timestamp for
     488             :    the current time. */
     489             : int
     490             : fd_gui_peers_poll( fd_gui_peers_ctx_t * peers,
     491             :                    long                 now  );
     492             : 
     493             : FD_PROTOTYPES_END
     494             : 
     495             : #endif /* HEADER_fd_src_disco_gui_fd_gui_peers_h */

Generated by: LCOV version 1.14