Line data Source code
1 : #ifndef HEADER_fd_src_discof_ipecho_fd_ipecho_server_port_check_h 2 : #define HEADER_fd_src_discof_ipecho_fd_ipecho_server_port_check_h 3 : 4 : /* Agave joiner nodes have a "port check" option, which is on by 5 : default. When this is enabled, the joiner node expects the 6 : entrypoint to send a UDP packet to every UDP port listed in the 7 : IpEchoServerMessage and complete a TCP handshake with every listed 8 : TCP port. 9 : 10 : fd_ipecho_server_port_check_t is a data structure for managing 11 : this on the server side. */ 12 : 13 : #include "../../util/fd_util_base.h" 14 : 15 0 : #define FD_IPECHO_SERVER_PORT_CHECK_MAGIC (0xF17EDA2CE5190C4EUL) /* FIREDANCER IPECHO SERVER PORT CHECK V0 */ 16 : 17 : struct fd_ipecho_server_port_check; 18 : typedef struct fd_ipecho_server_port_check fd_ipecho_server_port_check_t; 19 : 20 : /* Result of an attempt to complete a port check TCP port handshake */ 21 0 : #define FD_IPECHO_SERVER_PORT_CHECK_TCP_CONNECTED (0) 22 0 : #define FD_IPECHO_SERVER_PORT_CHECK_TCP_FAILED (1) 23 0 : #define FD_IPECHO_SERVER_PORT_CHECK_TCP_TIMEOUT (2) 24 0 : #define FD_IPECHO_SERVER_PORT_CHECK_TCP_DROPPED (3) 25 0 : #define FD_IPECHO_SERVER_PORT_CHECK_TCP_REJECTED_PER_IP (4) 26 0 : #define FD_IPECHO_SERVER_PORT_CHECK_TCP_EVICTED (5) 27 : #define FD_IPECHO_SERVER_PORT_CHECK_TCP_CNT (6) 28 : 29 : /* Total number of outgoing TCP connections the port checker can have 30 : in flight at any one time. This number is arbitrary. 2048 is what 31 : Agave uses. */ 32 : 33 0 : #define FD_IPECHO_SERVER_PORT_CHECK_CONN_MAX (2048UL) 34 : 35 : struct fd_ipecho_server_port_check_metrics { 36 : ulong udp_sent; 37 : ulong tcp[ FD_IPECHO_SERVER_PORT_CHECK_TCP_CNT ]; 38 : ulong active; 39 : }; 40 : 41 : typedef struct fd_ipecho_server_port_check_metrics fd_ipecho_server_port_check_metrics_t; 42 : 43 : FD_PROTOTYPES_BEGIN 44 : 45 : FD_FN_CONST ulong 46 : fd_ipecho_server_port_check_align( void ); 47 : 48 : FD_FN_CONST ulong 49 : fd_ipecho_server_port_check_footprint( void ); 50 : 51 : void * 52 : fd_ipecho_server_port_check_new( void * shmem ); 53 : 54 : fd_ipecho_server_port_check_t * 55 : fd_ipecho_server_port_check_join( void * shpc ); 56 : 57 : void 58 : fd_ipecho_server_port_check_init( fd_ipecho_server_port_check_t * pc, 59 : uint address ); 60 : 61 : void 62 : fd_ipecho_server_port_check_fini( fd_ipecho_server_port_check_t * pc ); 63 : 64 : /* fd_ipecho_server_port_check_close_all closes all TCP connections. */ 65 : 66 : void 67 : fd_ipecho_server_port_check_close_all( fd_ipecho_server_port_check_t * pc ); 68 : 69 : /* fd_ipecho_server_port_check_udp sends a UDP packet to the given 70 : address:port, synchronously. We don't need any response from this 71 : packet, we just send it best-effort. Joiners that are expecting 72 : this packet will join this entrypoint once they have received a 73 : UDP packet for each UDP port they specify in the 74 : IpEchoServerMessage. If they do not receive the packet from us, 75 : the joining will fail and they will try again. */ 76 : 77 : void 78 : fd_ipecho_server_port_check_udp( fd_ipecho_server_port_check_t * pc, 79 : uint ipv4, 80 : ushort port ); 81 : 82 : /* fd_ipecho_server_port_check_tcp begins a TCP connection to the given 83 : address:port, asynchronously. This function will return once the 84 : connection has started, but before the handshake has successfully 85 : completed. Once the handshake has successfully completed, or failed, 86 : the caller needs to call fd_ipecho_server_port_check_handle_event. 87 : 88 : This function returns an id identifying the connection (it fits in 89 : 32 bits), which should be stored in the epoll data and passed back to 90 : fd_ipecho_server_port_check_conn_fd and 91 : fd_ipecho_server_port_check_handle_event. ULONG_MAX is returned if we 92 : didn't manage to start the connection successfully. */ 93 : 94 : ulong 95 : fd_ipecho_server_port_check_tcp( fd_ipecho_server_port_check_t * pc, 96 : uint ipv4, 97 : ushort port, 98 : long now ); 99 : 100 : int 101 : fd_ipecho_server_port_check_conn_fd( fd_ipecho_server_port_check_t * pc, 102 : ulong id ); 103 : 104 : /* fd_ipecho_server_port_check_handle_event handles an epoll event for 105 : the connection identified by id. An event for a connection that 106 : has since finished, or whose slot has since been reused, is ignored. */ 107 : 108 : void 109 : fd_ipecho_server_port_check_handle_event( fd_ipecho_server_port_check_t * pc, 110 : ulong id ); 111 : 112 : /* fd_ipecho_server_port_check_prune closes TCP connections that are 113 : taking too long to complete the handshake 114 : (FD_IPECHO_SERVER_PORT_CHECK_TIMEOUT_NS). */ 115 : 116 : void 117 : fd_ipecho_server_port_check_prune( fd_ipecho_server_port_check_t * pc, 118 : long now ); 119 : 120 : fd_ipecho_server_port_check_metrics_t * 121 : fd_ipecho_server_port_check_metrics( fd_ipecho_server_port_check_t * pc ); 122 : 123 : int 124 : fd_ipecho_server_port_check_udp_sockfd( fd_ipecho_server_port_check_t * pc ); 125 : 126 : FD_PROTOTYPES_END 127 : 128 : #endif /* HEADER_fd_src_discof_ipecho_fd_ipecho_server_port_check_h */