Line data Source code
1 : #ifndef HEADER_fd_src_disco_events_fd_event_client_h 2 : #define HEADER_fd_src_disco_events_fd_event_client_h 3 : 4 : #include "fd_circq.h" 5 : #include "../keyguard/fd_keyguard_client.h" 6 : #include "../../ballet/x509/fd_x509_ca_store.h" 7 : #include "../../discof/genesis/fd_genesi_tile.h" 8 : 9 : #include <zstd.h> /* ZSTD_COMPRESSBOUND */ 10 : 11 : /* FD_EVENT_CLIENT_ZSTD_OUT_MAX is the worst case compressed size of 12 : raw_sz bytes of events (with their varint length prefixes) in one 13 : flushed or ended zstd chunk. */ 14 0 : #define FD_EVENT_CLIENT_ZSTD_OUT_MAX( raw_sz ) ( ZSTD_COMPRESSBOUND( (raw_sz) ) + 64UL ) 15 : 16 : /* FD_EVENT_CLIENT_FITS is whether an event of event_sz bytes always 17 : fits a client with gRPC buffer buf_max: its worst case compressed 18 : chunk with the 5 byte gRPC message prefix and a 9 byte HTTP/2 DATA 19 : frame header per 16 KiB frame. */ 20 : #define FD_EVENT_CLIENT_FITS( event_sz, buf_max ) \ 21 : ( FD_EVENT_CLIENT_ZSTD_OUT_MAX( 10UL+(event_sz) )+5UL+ \ 22 : 9UL*( ( FD_EVENT_CLIENT_ZSTD_OUT_MAX( 10UL+(event_sz) )+5UL+16383UL )/16384UL )<=(buf_max) ) 23 : 24 0 : #define FD_EVENT_CLIENT_STATE_DISCONNECTED (0) 25 0 : #define FD_EVENT_CLIENT_STATE_CONNECTING (1) 26 0 : #define FD_EVENT_CLIENT_STATE_AUTHENTICATING (2) 27 0 : #define FD_EVENT_CLIENT_STATE_CONNECTED (3) 28 : 29 : struct fd_event_client; 30 : typedef struct fd_event_client fd_event_client_t; 31 : 32 : struct fd_event_client_metrics { 33 : ulong transport_fail_cnt; 34 : ulong transport_success_cnt; 35 : ulong events_sent; 36 : ulong events_acked; 37 : ulong last_acked_id; 38 : ulong bytes_written; 39 : ulong bytes_read; 40 : ulong auth_fail_cnt; 41 : ulong invalid_msg_cnt; 42 : ulong connect_attempt_cnt; 43 : ulong handshake_timeout_cnt; 44 : ulong credit_stall_cnt; 45 : }; 46 : 47 : typedef struct fd_event_client_metrics fd_event_client_metrics_t; 48 : 49 : FD_PROTOTYPES_BEGIN 50 : 51 : FD_FN_CONST ulong 52 : fd_event_client_align( void ); 53 : 54 : ulong 55 : fd_event_client_footprint( ulong buf_max ); 56 : 57 : void * 58 : fd_event_client_new( void * shmem, 59 : fd_keyguard_client_t * keyguard_client, 60 : fd_rng_t * rng, 61 : fd_circq_t * circq, 62 : int epoll_fd, 63 : int so_sndbuf, 64 : char const * endpoint, 65 : uchar const * identity_pubkey, 66 : char const * client_version, 67 : char const * commit_hash, 68 : char const * action, 69 : ulong instance_id, 70 : ulong boot_id, 71 : ulong machine_id, 72 : ulong buf_max, 73 : int use_tls, 74 : fd_x509_ca_store_t const * ca_store ); 75 : 76 : fd_event_client_t * 77 : fd_event_client_join( void * shec ); 78 : 79 : fd_event_client_metrics_t const * 80 : fd_event_client_metrics( fd_event_client_t const * client ); 81 : 82 : ulong 83 : fd_event_client_state( fd_event_client_t const * client ); 84 : 85 : ulong 86 : fd_event_client_id_reserve( fd_event_client_t * client ); 87 : 88 : void 89 : fd_event_client_init_genesis( fd_event_client_t * client, 90 : fd_genesis_meta_t const * genesis_meta ); 91 : 92 : void 93 : fd_event_client_init_shred_version( fd_event_client_t * client, 94 : ushort shred_version ); 95 : 96 : void 97 : fd_event_client_set_identity( fd_event_client_t * client, 98 : uchar const * identity_pubkey ); 99 : 100 : void 101 : fd_event_client_poll( fd_event_client_t * client, 102 : long now, 103 : int * charge_busy ); 104 : 105 : /* fd_event_client_next_deadline returns when fd_event_client_poll 106 : next needs to run absent any fd event: the earliest pending 107 : timeout (reconnect, connect, auth, response, heartbeat, gRPC 108 : deadlines). Returns now if TLS bytes are buffered inside OpenSSL 109 : (no fd event will announce them), LONG_MAX while awaiting the 110 : genesis/shred version frags. */ 111 : 112 : long 113 : fd_event_client_next_deadline( fd_event_client_t const * client, 114 : long now ); 115 : 116 : FD_PROTOTYPES_END 117 : 118 : #endif /* HEADER_fd_src_disco_events_fd_event_client_h */