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) is responsible for maintaining a list of 5 : peers that are reachable for snapshot download, and returning the 6 : "best" such peer at any time. 7 : 8 : The "best" peer is defined as the one with the lowest combined score 9 : of TCP connection latency and snapshot age (slots behind the 10 : cluster), as computed by the peer selector. 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 3 : #define FD_SSPING_FD_MIN 20000 24 1488 : #define FD_SSPING_FD_CNT 247 /* Limit to how many pings can be 25 : inflight. Chosen so that it doesn't 26 : overflow the tile limit (256 allowed 27 : fds, less the workspace fd, stderr, 28 : logfile, snapshot dir + 2 output 29 : fds, the 2 netdb fds for DNS, and 30 : the adns UDP socket). */ 31 : 32 3 : #define FD_SSPING_MAGIC (0xF17EDA2CE55A1A60) /* FIREDANCE SSPING V0 */ 33 : 34 : struct fd_ssping_private; 35 : typedef struct fd_ssping_private fd_ssping_t; 36 : 37 : typedef void 38 : (* fd_ssping_on_ping_fn_t)( void * _ctx, 39 : fd_ip4_port_t addr, 40 : ulong latency ); 41 : 42 : FD_PROTOTYPES_BEGIN 43 : 44 : FD_FN_CONST ulong 45 : fd_ssping_align( void ); 46 : 47 : FD_FN_CONST ulong 48 : fd_ssping_footprint( ulong max_peers ); 49 : 50 : void * 51 : fd_ssping_new( void * shmem, 52 : ulong max_peers, 53 : ulong seed, 54 : fd_ssping_on_ping_fn_t on_ping_cb, 55 : void * cb_arg ); 56 : 57 : fd_ssping_t * 58 : fd_ssping_join( void * shping ); 59 : 60 : void * 61 : fd_ssping_leave( fd_ssping_t * ssping ); 62 : 63 : void * 64 : fd_ssping_delete( void * shping ); 65 : 66 : /* Add a peer to be tracked by the snapshot pinger, which will from here 67 : until it is removed, constantly ping the node to maintain its 68 : status. 69 : 70 : An address can be added multiple times, and the addresses are 71 : internally reference counted, so it will need a corresponding number 72 : of releases to be removed from ping tracking. 73 : 74 : The ping tracker cannot be overflowed, and if too many peers are 75 : being tracked, trying to add a new peer is a no-op. */ 76 : 77 : void 78 : fd_ssping_add( fd_ssping_t * ssping, 79 : fd_ip4_port_t addr ); 80 : 81 : /* Remove a peer from tracking by the snapshot pinger. Peers are 82 : reference counted, so this will only remove the peer only if the 83 : count goes to zero. If the peer is not tracked, this is a no-op. 84 : Returns whether the peer was removed. */ 85 : 86 : int 87 : fd_ssping_remove( fd_ssping_t * ssping, 88 : fd_ip4_port_t addr ); 89 : 90 : /* Mark the peer as invalid for selection for a period of time, probably 91 : if they refused a connection or served us a bad snapshot. */ 92 : 93 : void 94 : fd_ssping_invalidate( fd_ssping_t * ssping, 95 : fd_ip4_port_t addr, 96 : long now ); 97 : 98 : /* Returns 1 if the peer at addr is currently in the INVALID state 99 : (i.e. temporarily banned), 0 otherwise. Safe to call with a NULL 100 : ssping (returns 0). */ 101 : 102 : int 103 : fd_ssping_is_invalidated( fd_ssping_t * ssping, 104 : fd_ip4_port_t addr ); 105 : 106 : /* Advance the ping tracker forward in time until "now". This should be 107 : called periodically to refresh pings and service networking to 108 : maintain ping states. Takes a handle to the peer selector to 109 : invalidate peers from both the pinger and the selector. */ 110 : 111 : void 112 : fd_ssping_advance( fd_ssping_t * ssping, 113 : long now, 114 : fd_sspeer_selector_t * selector); 115 : 116 : FD_PROTOTYPES_END 117 : 118 : #endif /* HEADER_fd_src_discof_restore_utils_fd_ssping_h */