LCOV - code coverage report
Current view: top level - discof/restore/utils - fd_ssping.h (source / functions) Hit Total Coverage
Test: cov.lcov Lines: 0 3 0.0 %
Date: 2026-11-26 02:16:43 Functions: 0 0 -

          Line data    Source code
       1             : #ifndef HEADER_fd_src_discof_restore_utils_fd_ssping_h
       2             : #define HEADER_fd_src_discof_restore_utils_fd_ssping_h
       3             : 
       4             : /* The snapshot pinger (ssping) maintains a list of peers that are
       5             :    reachable for snapshot download and reports their TCP connection
       6             :    latencies through a callback.
       7             : 
       8             :    The peer selector uses these latencies to select the "best" peer:
       9             :    the one with the lowest combined score of TCP connection latency
      10             :    and snapshot age (slots behind the cluster).
      11             : 
      12             :    The snapshot pinger works on the assumption that there is a maximum
      13             :    size of peers that will ever be added, as we expect from the gossip
      14             :    system.  Peers can be added and removed arbitrarily outside of this
      15             :    maximum restriction. */
      16             : 
      17             : #include "../../../util/fd_util_base.h"
      18             : #include "../../../util/net/fd_net_headers.h"
      19             : 
      20             : struct fd_sspeer_selector_private;
      21             : typedef struct fd_sspeer_selector_private fd_sspeer_selector_t;
      22             : 
      23           0 : #define FD_SSPING_FD_MIN 20000
      24           0 : #define FD_SSPING_FD_CNT   247 /* Maximum number of in-flight pings.
      25             :                                   Sockets are preallocated in a contiguous
      26             :                                   range starting at FD_SSPING_FD_MIN.
      27             :                                   snapct includes this pool in its fd
      28             :                                   limit and sandbox allowlist. */
      29             : 
      30           0 : #define FD_SSPING_MAGIC (0xF17EDA2CE55A1A60) /* FIREDANCE SSPING V0 */
      31             : 
      32             : struct fd_ssping_private;
      33             : typedef struct fd_ssping_private fd_ssping_t;
      34             : 
      35             : typedef void
      36             : (* fd_ssping_on_ping_fn_t)( void *        _ctx,
      37             :                             fd_ip4_port_t addr,
      38             :                             ulong         latency );
      39             : 
      40             : FD_PROTOTYPES_BEGIN
      41             : 
      42             : FD_FN_CONST ulong
      43             : fd_ssping_align( void );
      44             : 
      45             : FD_FN_CONST ulong
      46             : fd_ssping_footprint( ulong max_peers );
      47             : 
      48             : void *
      49             : fd_ssping_new( void *                 shmem,
      50             :                ulong                  max_peers,
      51             :                ulong                  seed,
      52             :                fd_ssping_on_ping_fn_t on_ping_cb,
      53             :                void *                 cb_arg,
      54             :                int                    epoll_fd );
      55             : 
      56             : fd_ssping_t *
      57             : fd_ssping_join( void * shping );
      58             : 
      59             : void *
      60             : fd_ssping_leave( fd_ssping_t * ssping );
      61             : 
      62             : void *
      63             : fd_ssping_delete( void * shping );
      64             : 
      65             : /* Add a peer to be tracked by the snapshot pinger, which will from here
      66             :    until it is removed, constantly ping the node to maintain its
      67             :    status.
      68             : 
      69             :    An address can be added multiple times, and the addresses are
      70             :    internally reference counted, so it will need a corresponding number
      71             :    of releases to be removed from ping tracking.
      72             : 
      73             :    The ping tracker cannot be overflowed, and if too many peers are
      74             :    being tracked, trying to add a new peer is a no-op. */
      75             : 
      76             : void
      77             : fd_ssping_add( fd_ssping_t * ssping,
      78             :                fd_ip4_port_t addr );
      79             : 
      80             : /* Remove a peer from tracking by the snapshot pinger.  Peers are
      81             :    reference counted, so this will only remove the peer only if the
      82             :    count goes to zero.  If the peer is not tracked, this is a no-op.
      83             :    Returns whether the peer was removed. */
      84             : 
      85             : int
      86             : fd_ssping_remove( fd_ssping_t * ssping,
      87             :                   fd_ip4_port_t addr );
      88             : 
      89             : /* Mark the peer as invalid for selection for a period of time, probably
      90             :    if they refused a connection or served us a bad snapshot. */
      91             : 
      92             : void
      93             : fd_ssping_invalidate( fd_ssping_t * ssping,
      94             :                       fd_ip4_port_t addr,
      95             :                       long          now );
      96             : 
      97             : /* Returns 1 if the peer at addr is currently in the INVALID state
      98             :    (i.e. temporarily banned), 0 otherwise.  Safe to call with a NULL
      99             :    ssping (returns 0). */
     100             : 
     101             : int
     102             : fd_ssping_is_invalidated( fd_ssping_t * ssping,
     103             :                           fd_ip4_port_t addr );
     104             : 
     105             : /* Advance the ping tracker forward in time until "now".  This should be
     106             :    called periodically to refresh pings and service networking to
     107             :    maintain ping states.  Takes a handle to the peer selector to
     108             :    invalidate peers from both the pinger and the selector. */
     109             : 
     110             : void
     111             : fd_ssping_advance( fd_ssping_t *          ssping,
     112             :                    long                   now,
     113             :                    fd_sspeer_selector_t * selector);
     114             : 
     115             : /* fd_ssping_next_deadline returns the earliest wallclock at which
     116             :    advance has timer work: a ping times out, a valid peer is due a
     117             :    refresh, or an invalid one a retry.  LONG_MAX if none. */
     118             : 
     119             : long
     120             : fd_ssping_next_deadline( fd_ssping_t const * ssping );
     121             : 
     122             : FD_PROTOTYPES_END
     123             : 
     124             : #endif /* HEADER_fd_src_discof_restore_utils_fd_ssping_h */

Generated by: LCOV version 1.14