Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_gossip_fd_gossip_h 2 : #define HEADER_fd_src_flamenco_gossip_fd_gossip_h 3 : 4 : #include "../types/fd_types.h" 5 : #include "../../util/valloc/fd_valloc.h" 6 : 7 : /* Max number of validators that can be known */ 8 0 : #define FD_PEER_KEY_MAX (1<<14) 9 : 10 : /* Contact info v2 socket tag constants */ 11 0 : #define FD_GOSSIP_SOCKET_TAG_GOSSIP (0) 12 : #define FD_GOSSIP_SOCKET_TAG_RPC (2) 13 : #define FD_GOSSIP_SOCKET_TAG_RPC_PUBSUB (3) 14 0 : #define FD_GOSSIP_SOCKET_TAG_SERVE_REPAIR (4) 15 : #define FD_GOSSIP_SOCKET_TAG_SERVE_REPAIR_QUIC (1) 16 0 : #define FD_GOSSIP_SOCKET_TAG_TPU (5) 17 : #define FD_GOSSIP_SOCKET_TAG_TPU_FORWARDS (6) 18 : #define FD_GOSSIP_SOCKET_TAG_TPU_FORWARDS_QUIC (7) 19 0 : #define FD_GOSSIP_SOCKET_TAG_TPU_QUIC (8) 20 0 : #define FD_GOSSIP_SOCKET_TAG_TPU_VOTE (9) 21 0 : #define FD_GOSSIP_SOCKET_TAG_TVU (10) 22 : #define FD_GOSSIP_SOCKET_TAG_TVU_QUIC (11) 23 : 24 : /* Global state of gossip protocol */ 25 : typedef struct fd_gossip fd_gossip_t; 26 : ulong fd_gossip_align ( void ); 27 : ulong fd_gossip_footprint( void ); 28 : void * fd_gossip_new ( void * shmem, ulong seed ); 29 : fd_gossip_t * fd_gossip_join ( void * shmap ); 30 : void * fd_gossip_leave ( fd_gossip_t * join ); 31 : void * fd_gossip_delete ( void * shmap ); 32 : 33 : 34 : union fd_gossip_peer_addr { 35 : struct { 36 : uint addr; /* IPv4 address, network byte order (big endian) */ 37 : ushort port; /* port number, network byte order (big endian) */ 38 : ushort pad; /* Must be zero */ 39 : }; 40 : ulong l; /* Combined port and address */ 41 : }; 42 : typedef union fd_gossip_peer_addr fd_gossip_peer_addr_t; 43 : 44 : int 45 : fd_gossip_from_soladdr(fd_gossip_peer_addr_t * dst, fd_gossip_socket_addr_t const * src ); 46 : 47 : int 48 : fd_gossip_to_soladdr( fd_gossip_socket_addr_t * dst, fd_gossip_peer_addr_t const * src ); 49 : 50 : 51 : void 52 : fd_gossip_contact_info_v2_to_v1( fd_gossip_contact_info_v2_t const * v2, 53 : fd_gossip_contact_info_v1_t * v1 ); 54 : 55 : int 56 : fd_gossip_contact_info_v2_find_proto_ident( fd_gossip_contact_info_v2_t const * contact_info, 57 : uchar proto_ident, 58 : fd_gossip_socket_addr_t * out_addr ); 59 : 60 : /* Callback when a new message is received */ 61 : typedef void (*fd_gossip_data_deliver_fun)(fd_crds_data_t* data, void* arg); 62 : 63 : /* Callback for sending a packet. addr is the address of the destination. */ 64 : typedef void (*fd_gossip_send_packet_fun)( uchar const * msg, size_t msglen, fd_gossip_peer_addr_t const * addr, void * arg ); 65 : 66 : /* Callback for signing */ 67 : typedef void (*fd_gossip_sign_fun)( void * ctx, uchar * sig, uchar const * buffer, ulong len, int sign_type ); 68 : 69 : struct fd_gossip_config { 70 : fd_pubkey_t * public_key; 71 : uchar * private_key; 72 : fd_gossip_peer_addr_t my_addr; 73 : fd_gossip_version_v2_t my_version; 74 : ushort shred_version; 75 : fd_gossip_data_deliver_fun deliver_fun; 76 : void * deliver_arg; 77 : fd_gossip_send_packet_fun send_fun; 78 : void * send_arg; 79 : fd_gossip_sign_fun sign_fun; 80 : void * sign_arg; 81 : }; 82 : typedef struct fd_gossip_config fd_gossip_config_t; 83 : 84 : /* Initialize the gossip data structure */ 85 : int fd_gossip_set_config( fd_gossip_t * glob, const fd_gossip_config_t * config ); 86 : 87 : /* Update the binding addr */ 88 : int fd_gossip_update_addr( fd_gossip_t * glob, const fd_gossip_peer_addr_t * addr ); 89 : 90 : /* Update the repair service addr */ 91 : int fd_gossip_update_repair_addr( fd_gossip_t * glob, const fd_gossip_peer_addr_t * serve ); 92 : 93 : /* Update the tvu rx addr */ 94 : int 95 : fd_gossip_update_tvu_addr( fd_gossip_t * glob, const fd_gossip_peer_addr_t * tvu, const fd_gossip_peer_addr_t * tvu_fwd ); 96 : 97 : /* Update the tpu addr */ 98 : int 99 : fd_gossip_update_tpu_addr( fd_gossip_t * glob, 100 : fd_gossip_peer_addr_t const * tpu, 101 : fd_gossip_peer_addr_t const * tpu_fwd ); 102 : 103 : /* Update the tpu vote addr */ 104 : int fd_gossip_update_tpu_vote_addr( fd_gossip_t * glob, const fd_gossip_peer_addr_t * tpu_vote ); 105 : 106 : /* Set the shred version (after receiving a contact info msg) */ 107 : void fd_gossip_set_shred_version( fd_gossip_t * glob, ushort shred_version ); 108 : 109 : /* Add a peer to talk to */ 110 : int fd_gossip_add_active_peer( fd_gossip_t * glob, fd_gossip_peer_addr_t * addr ); 111 : 112 : /* Publish an outgoing value. The source id and wallclock are set by this function. The gossip key for the value is optionally returned. */ 113 : int fd_gossip_push_value( fd_gossip_t * glob, fd_crds_data_t* data, fd_hash_t * key_opt ); 114 : 115 : /* Set the current protocol time in nanosecs. Call this as often as feasible. */ 116 : void fd_gossip_settime( fd_gossip_t * glob, long ts ); 117 : 118 : /* Get the current protocol time in nanosecs */ 119 : long fd_gossip_gettime( fd_gossip_t * glob ); 120 : 121 : /* Start timed events and other protocol behavior. settime MUST be called before this. */ 122 : int fd_gossip_start( fd_gossip_t * glob ); 123 : 124 : /* Dispatch timed events and other protocol behavior. This should be 125 : * called inside the main spin loop. calling settime first is recommended. */ 126 : int fd_gossip_continue( fd_gossip_t * glob ); 127 : 128 : /* Pass a raw gossip packet into the protocol. addr is the address of the sender */ 129 : int fd_gossip_recv_packet( fd_gossip_t * glob, uchar const * msg, ulong msglen, fd_gossip_peer_addr_t const * addr ); 130 : 131 : const char * fd_gossip_addr_str( char * dst, ulong dstlen, fd_gossip_peer_addr_t const * src ); 132 : 133 : ushort fd_gossip_get_shred_version( fd_gossip_t const * glob ); 134 : 135 : void fd_gossip_set_stake_weights( fd_gossip_t * gossip, fd_stake_weight_t const * stake_weights, ulong stake_weights_cnt ); 136 : 137 : void fd_gossip_set_entrypoints( fd_gossip_t * gossip, uint allowed_entrypoints[static 16], ulong allowed_entrypoints_cnt, ushort * ports ); 138 : 139 : uint fd_gossip_is_allowed_entrypoint( fd_gossip_t * gossip, fd_gossip_peer_addr_t * addr ); 140 : 141 : #endif /* HEADER_fd_src_flamenco_gossip_fd_gossip_h */