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