LCOV - code coverage report
Current view: top level - flamenco/repair - fd_repair.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 4 0.0 %
Date: 2025-03-20 12:08:36 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_flamenco_repair_fd_repair_h
       2             : #define HEADER_fd_src_flamenco_repair_fd_repair_h
       3             : 
       4             : #include "../gossip/fd_gossip.h"
       5             : #include "../../ballet/shred/fd_shred.h"
       6             : #include "../runtime/context/fd_exec_epoch_ctx.h"
       7             : #include "../../disco/metrics/generated/fd_metrics_repair.h"
       8             : 
       9             : 
      10             : #define FD_REPAIR_DELIVER_FAIL_TIMEOUT -1
      11           0 : #define FD_REPAIR_DELIVER_FAIL_REQ_LIMIT_EXCEEDED -2
      12             : 
      13             : /* Maximum size of a network packet */
      14           0 : #define FD_REPAIR_MAX_PACKET_SIZE 1232
      15             : 
      16             : /* Scratch space is used by the repair library to allocate an
      17             :    active element table and to shuffle that table.
      18             :    TODO: update comment to reflect the reasoning behind
      19             :    these constants once they are fully understood and updated. */
      20           0 : #define FD_REPAIR_SCRATCH_MAX    (1UL << 30UL)
      21           0 : #define FD_REPAIR_SCRATCH_DEPTH  (1UL << 11UL)
      22             : 
      23             : /* Global state of repair protocol */
      24             : typedef struct fd_repair fd_repair_t;
      25             : FD_FN_CONST ulong         fd_repair_align    ( void );
      26             : FD_FN_CONST ulong         fd_repair_footprint( void );
      27             :             void *        fd_repair_new      ( void * shmem, ulong seed );
      28             :             fd_repair_t * fd_repair_join     ( void * shmap );
      29             :             void *        fd_repair_leave    ( fd_repair_t * join );
      30             :             void *        fd_repair_delete   ( void * shmap );
      31             : 
      32             : typedef fd_gossip_peer_addr_t fd_repair_peer_addr_t;
      33             : 
      34             : /* Callback when a new shred is received */
      35             : typedef void (*fd_repair_shred_deliver_fun)( fd_shred_t const * shred, ulong shred_len, fd_repair_peer_addr_t const * from, fd_pubkey_t const * id, void * arg );
      36             : 
      37             : /* Callbacks when a repair is requested. shred_idx==-1 means the last index. */
      38             : typedef long (*fd_repair_serv_get_shred_fun)( ulong slot, uint shred_idx, void * buf, ulong buf_max, void * arg );
      39             : typedef ulong (*fd_repair_serv_get_parent_fun)( ulong slot, void * arg );
      40             : 
      41             : /* Callback for sending a packet. addr is the address of the destination. */
      42             : typedef void (*fd_repair_send_packet_fun)( uchar const * msg, size_t msglen, fd_repair_peer_addr_t const * dst_addr, uint src_ip4_addr, void * arg );
      43             : 
      44             : /* Callback signing */
      45             : typedef void (*fd_repair_sign_fun)( void * ctx, uchar * sig, uchar const * buffer, ulong len, int sign_type );
      46             : 
      47             : /* Callback for when a request fails. Echoes back the request parameters. */
      48             : typedef void (*fd_repair_shred_deliver_fail_fun)( fd_pubkey_t const * id, ulong slot, uint shred_index, void * arg, int reason );
      49             : 
      50             : struct fd_repair_config {
      51             :     fd_pubkey_t * public_key;
      52             :     uchar * private_key;
      53             :     fd_repair_peer_addr_t service_addr;
      54             :     fd_repair_peer_addr_t intake_addr;
      55             :     fd_repair_shred_deliver_fun deliver_fun;
      56             :     fd_repair_serv_get_shred_fun serv_get_shred_fun;
      57             :     fd_repair_serv_get_parent_fun serv_get_parent_fun;
      58             :     fd_repair_send_packet_fun clnt_send_fun; /* sending client requests */
      59             :     fd_repair_send_packet_fun serv_send_fun; /* sending service responses */
      60             :     fd_repair_shred_deliver_fail_fun deliver_fail_fun;
      61             :     void * fun_arg;
      62             :     fd_repair_sign_fun sign_fun;
      63             :     void * sign_arg;
      64             :     int good_peer_cache_file_fd;
      65             : };
      66             : typedef struct fd_repair_config fd_repair_config_t;
      67             : 
      68             : /* Initialize the repair data structure */
      69             : int fd_repair_set_config( fd_repair_t * glob, const fd_repair_config_t * config );
      70             : 
      71             : /* Update the binding addr */
      72             : int fd_repair_update_addr( fd_repair_t * glob, const fd_repair_peer_addr_t * intake_addr, const fd_repair_peer_addr_t * service_addr );
      73             : 
      74             : /* Add a peer to talk to */
      75             : int fd_repair_add_active_peer( fd_repair_t * glob, fd_repair_peer_addr_t const * addr, fd_pubkey_t const * id );
      76             : 
      77             : /* Set the current protocol time in nanosecs. Call this as often as feasible. */
      78             : void fd_repair_settime( fd_repair_t * glob, long ts );
      79             : 
      80             : /* Get the current protocol time in nanosecs */
      81             : long fd_repair_gettime( fd_repair_t * glob );
      82             : 
      83             : /* Start timed events and other protocol behavior. settime MUST be called before this. */
      84             : int fd_repair_start( fd_repair_t * glob );
      85             : 
      86             : /* Dispatch timed events and other protocol behavior. This should be
      87             :  * called inside the main spin loop. calling settime first is recommended. */
      88             : int fd_repair_continue( fd_repair_t * glob );
      89             : 
      90             : /* Pass a raw client response packet into the protocol. addr is the address of the sender */
      91             : int
      92             : fd_repair_recv_clnt_packet( fd_repair_t *                 glob,
      93             :                             uchar const *                 msg,
      94             :                             ulong                         msglen,
      95             :                             fd_repair_peer_addr_t const * src_addr,
      96             :                             uint                          dst_ip4_addr );
      97             : 
      98             : /* Pass a raw service request packet into the protocol.
      99             :    src_addr is the address of the sender
     100             :    dst_ip4_addr is the dst IPv4 address of the incoming packet (i.e. our IP) */
     101             : int
     102             : fd_repair_recv_serv_packet( fd_repair_t *                 glob,
     103             :                             uchar const *                 msg,
     104             :                             ulong                         msglen,
     105             :                             fd_repair_peer_addr_t const * src_addr,
     106             :                             uint                          dst_ip4_addr );
     107             : 
     108             : /* Determine if the request queue is full */
     109             : int fd_repair_is_full( fd_repair_t * glob );
     110             : 
     111             : /* Register a request for a shred */
     112             : int fd_repair_need_window_index( fd_repair_t * glob, ulong slot, uint shred_index );
     113             : 
     114             : int fd_repair_need_highest_window_index( fd_repair_t * glob, ulong slot, uint shred_index );
     115             : 
     116             : int fd_repair_need_orphan( fd_repair_t * glob, ulong slot );
     117             : 
     118             : void fd_repair_add_sticky( fd_repair_t * glob, fd_pubkey_t const * id );
     119             : 
     120             : void fd_repair_set_stake_weights( fd_repair_t * repair,
     121             :                                   fd_stake_weight_t const * stake_weights,
     122             :                                   ulong stake_weights_cnt );
     123             : 
     124             : /* Repair Metrics */
     125             : struct fd_repair_metrics {
     126             :   ulong recv_clnt_pkt;
     127             :   ulong recv_serv_pkt;
     128             :   ulong recv_serv_corrupt_pkt;
     129             :   ulong recv_serv_invalid_signature;
     130             :   ulong recv_serv_full_ping_table;
     131             :   ulong recv_serv_pkt_types[FD_METRICS_ENUM_REPAIR_SERV_PKT_TYPES_CNT];
     132             :   ulong recv_pkt_corrupted_msg;
     133             :   ulong send_pkt_cnt;
     134             :   ulong sent_pkt_types[FD_METRICS_ENUM_REPAIR_SENT_REQUEST_TYPES_CNT];
     135             : };
     136             : typedef struct fd_repair_metrics fd_repair_metrics_t;
     137             : #define FD_REPAIR_METRICS_FOOTPRINT ( sizeof( fd_repair_metrics_t ) )
     138             : 
     139             : fd_repair_metrics_t *
     140             : fd_repair_get_metrics( fd_repair_t * repair );
     141             : 
     142             : 
     143             : #endif /* HEADER_fd_src_flamenco_repair_fd_repair_h */

Generated by: LCOV version 1.14