LCOV - code coverage report
Current view: top level - flamenco/gossip - fd_contact_info.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 8 0.0 %
Date: 2025-07-01 05:00:49 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_gossip_fd_contact_info_h
       2             : #define HEADER_fd_src_flamenco_gossip_fd_contact_info_h
       3             : 
       4             : /* APIs to interact with Gossip Contact Infos.
       5             :    Analagous to:
       6             : 
       7             :    https://github.com/anza-xyz/agave/blob/b11ca828cfc658b93cb86a6c5c70561875abe237/gossip/src/contact_info.rs# */
       8             : 
       9             : #include "../types/fd_types.h"
      10             : #include "../../disco/plugin/fd_plugin.h"
      11             : #include "../../util/net/fd_net_headers.h" /* fd_ip4_port_t */
      12             : 
      13             : typedef union fd_ip4_port fd_gossip_peer_addr_t;
      14             : 
      15             : /* Contact info v2 socket tag constants */
      16           0 : #define FD_GOSSIP_SOCKET_TAG_GOSSIP             (0)
      17             : #define FD_GOSSIP_SOCKET_TAG_RPC                (2)
      18             : #define FD_GOSSIP_SOCKET_TAG_RPC_PUBSUB         (3)
      19           0 : #define FD_GOSSIP_SOCKET_TAG_SERVE_REPAIR       (4)
      20             : #define FD_GOSSIP_SOCKET_TAG_SERVE_REPAIR_QUIC  (1)
      21           0 : #define FD_GOSSIP_SOCKET_TAG_TPU                (5)
      22             : #define FD_GOSSIP_SOCKET_TAG_TPU_FORWARDS       (6)
      23             : #define FD_GOSSIP_SOCKET_TAG_TPU_FORWARDS_QUIC  (7)
      24           0 : #define FD_GOSSIP_SOCKET_TAG_TPU_QUIC           (8)
      25           0 : #define FD_GOSSIP_SOCKET_TAG_TPU_VOTE           (9)
      26             : #define FD_GOSSIP_SOCKET_TAG_TPU_VOTE_QUIC      (12)
      27           0 : #define FD_GOSSIP_SOCKET_TAG_TVU                (10)
      28             : #define FD_GOSSIP_SOCKET_TAG_TVU_QUIC           (11)
      29             : 
      30           0 : #define FD_GOSSIP_SOCKET_TAG_MAX                (13)
      31             : 
      32             : /* TODO: update fd_gossip_update_msg_t and change this assert to be ==
      33             :    instead of <= */
      34             : FD_STATIC_ASSERT( sizeof(((fd_gossip_update_msg_t*)0)->addrs) <= FD_GOSSIP_SOCKET_TAG_MAX*6,  fd_gossip_update_msg_addrs_sz );
      35             : 
      36             : typedef fd_gossip_contact_info_v1_t fd_gossip_legacy_contact_info_t;
      37             : 
      38             : /* Internal struct for maintaining a contact_info_v2 entry.
      39             : 
      40             :    Notable difference is we limit the number of
      41             :    socket entries and addrs. Duplicate entries of a
      42             :    socket tag will be dropped during the conversion. This
      43             :    is in-line with Agave's behavior when populating its
      44             :    contact_info_v2.
      45             : 
      46             :    https://github.com/anza-xyz/agave/blob/b11ca828cfc658b93cb86a6c5c70561875abe237/gossip/src/contact_info.rs#L342 */
      47             : typedef struct {
      48             :   fd_gossip_contact_info_v2_t   ci_crd;
      49             :   fd_gossip_ip_addr_t           addrs[FD_GOSSIP_SOCKET_TAG_MAX];
      50             :   fd_gossip_socket_entry_t      sockets[FD_GOSSIP_SOCKET_TAG_MAX];
      51             :   /* uint                       extentions[1]; // Unused, dropped during conversion  */
      52             : 
      53             :   /* Metadata */
      54             :   ushort                        socket_tag_idx[FD_GOSSIP_SOCKET_TAG_MAX]; /* Index of socket tag in sockets array */
      55             :   ushort                        ports[FD_GOSSIP_SOCKET_TAG_MAX]; /* Avoid scanning to get ports, maps to entry in sockets. HOST order. */
      56             : } fd_contact_info_t;
      57             : 
      58           0 : #define FD_CONTACT_INFO_SOCKET_TAG_NULL (USHORT_MAX) /* Denotes a missing socket in socket_tag_idx array */
      59             : 
      60             : void
      61             : fd_contact_info_init( fd_contact_info_t * contact_info );
      62             : 
      63             : ushort
      64             : fd_contact_info_get_shred_version( fd_contact_info_t const * contact_info );
      65             : 
      66             : void
      67             : fd_contact_info_set_shred_version( fd_contact_info_t * contact_info,
      68             :                                    ushort              shred_version );
      69             : 
      70             : int
      71             : fd_contact_info_get_socket_addr( fd_contact_info_t const *  ci_int,
      72             :                                  uchar                      socket_tag,
      73             :                                  fd_gossip_socket_addr_t *  out_addr );
      74             : 
      75             : int
      76             : fd_contact_info_insert_socket( fd_contact_info_t *            ci_int,
      77             :                                fd_gossip_peer_addr_t const *  peer,
      78             :                                uchar                          socket_tag );
      79             : 
      80             : /***** Conversion APIs *****/
      81             : 
      82             : /* Assumes ci_int is initialized properly */
      83             : void
      84             : fd_contact_info_from_ci_v2( fd_gossip_contact_info_v2_t const * ci_v2,
      85             :                             fd_contact_info_t *                 ci_int );
      86             : 
      87             : /* Invariant: ci_int lifetime >= ci_v2 lifetime */
      88             : void
      89             : fd_contact_info_to_ci_v2( fd_contact_info_t const *     ci_int,
      90             :                           fd_gossip_contact_info_v2_t * ci_v2 );
      91             : 
      92             : void
      93             : fd_contact_info_to_update_msg( fd_contact_info_t const * ci_int,
      94             :                                fd_gossip_update_msg_t *  update );
      95             : 
      96             : 
      97             : /* Misc. utility functions for fd_gossip_contact_info_v2_t */
      98             : 
      99             : int
     100             : fd_gossip_contact_info_v2_find_proto_ident( fd_gossip_contact_info_v2_t const * contact_info,
     101             :                                             uchar                               proto_ident,
     102             :                                             fd_gossip_socket_addr_t *           out_addr );
     103             : 
     104             : #endif

Generated by: LCOV version 1.14