Line data Source code
1 : #ifndef HEADER_fd_src_discof_restore_utils_fd_sshttp_h 2 : #define HEADER_fd_src_discof_restore_utils_fd_sshttp_h 3 : 4 : struct fd_sshttp_private; 5 : typedef struct fd_sshttp_private fd_sshttp_t; 6 : 7 : #include "../../../util/net/fd_net_headers.h" 8 : 9 : #include <sys/uio.h> 10 : 11 : FD_PROTOTYPES_BEGIN 12 : 13 : FD_FN_CONST ulong 14 : fd_sshttp_align( void ); 15 : 16 : FD_FN_CONST ulong 17 : fd_sshttp_footprint( void ); 18 : 19 : void * 20 : fd_sshttp_new( void * shmem, 21 : int epoll_fd ); 22 : 23 : fd_sshttp_t * 24 : fd_sshttp_join( void * sshttp ); 25 : 26 : /* fd_sshttp_load_ca_store loads the system CA certificate bundle for 27 : TLS certificate chain validation. If no bundle is found, subsequent 28 : fd_sshttp_init calls with is_https set fail before connecting. */ 29 : 30 : void 31 : fd_sshttp_load_ca_store( fd_sshttp_t * http ); 32 : 33 : char const * 34 : fd_sshttp_snapshot_name( fd_sshttp_t const * http ); 35 : 36 : ulong 37 : fd_sshttp_content_len( fd_sshttp_t const * http ); 38 : 39 : ulong 40 : fd_sshttp_resolved_slot( fd_sshttp_t const * http ); 41 : 42 : uchar const * 43 : fd_sshttp_resolved_hash( fd_sshttp_t const * http ); 44 : 45 : /* fd_sshttp_init initializes an sshttp connection to the given server. 46 : addr is the resolved IP address and port. hostname is a 47 : null-terminated string used for the Host header and TLS SNI. The 48 : hostname and path are copied; no caller memory is borrowed. 49 : is_https indicates whether TLS should be used. path points to the 50 : URL path of length path_len. hops is the maximum number of HTTP 51 : redirects to follow, pass ULONG_MAX to preserve the current hops 52 : value (e.g. when following a redirect internally). now is the 53 : current timestamp. Returns 0 on success and -1 on failure. */ 54 : 55 : int 56 : fd_sshttp_init( fd_sshttp_t * http, 57 : fd_ip4_port_t addr, 58 : char const * hostname, 59 : int is_https, 60 : char const * path, 61 : ulong path_len, 62 : ulong hops, 63 : long now ); 64 : 65 : void 66 : fd_sshttp_cancel( fd_sshttp_t * http ); 67 : 68 : /* fd_sshttp_deadline returns the wallclock at which the current step 69 : times out, or LONG_MAX when idle. */ 70 : 71 : long 72 : fd_sshttp_deadline( fd_sshttp_t const * http ); 73 : 74 0 : #define FD_SSHTTP_ADVANCE_ERROR (-1) 75 0 : #define FD_SSHTTP_ADVANCE_AGAIN ( 0) 76 0 : #define FD_SSHTTP_ADVANCE_DATA ( 1) 77 0 : #define FD_SSHTTP_ADVANCE_DONE ( 2) 78 : 79 : /* fd_sshttp_advance drives the connection. Body bytes fill iov 80 : front to back; on ADVANCE_DATA *data_len is the total written. 81 : Bytes received alongside headers only ever fill iov[0]. */ 82 : 83 : #define FD_SSHTTP_IOV_MAX (2UL) 84 : 85 : /* SO_RCVBUF for download sockets. Bypasses the net.ipv4.tcp_rmem 86 : autotuning cap, which is too small for high bandwidth-delay links. 87 : Clamped by net.core.rmem_max, which the sysctl stage raises. */ 88 : 89 0 : #define FD_SSHTTP_SO_RCVBUF (128UL<<20) 90 : 91 : /* SO_RCVLOWAT for plaintext body downloads. The socket reports 92 : readable (to epoll) only once this many body bytes are queued, 93 : lowered to the remaining length for the tail of the body, so every 94 : wake is followed by large reads instead of one per arriving 95 : segment. */ 96 : 97 0 : #define FD_SSHTTP_SO_RCVLOWAT (1UL<<20) 98 : 99 : int 100 : fd_sshttp_advance( fd_sshttp_t * http, 101 : struct iovec const * iov, 102 : ulong iov_cnt, 103 : ulong * data_len, 104 : int * downloading, 105 : long now ); 106 : 107 : /* fd_sshttp_rx_parked returns 1 if http is downloading a plaintext 108 : body and its last socket read found nothing queued. The caller may 109 : then batch reads by skipping fd_sshttp_advance until its readiness 110 : notification (epoll) reports the socket readable; up to 111 : FD_SSHTTP_SO_RCVLOWAT-1 bytes may be queued meanwhile. Readiness 112 : covers the end of the body and peer close or error. */ 113 : 114 : int 115 : fd_sshttp_rx_parked( fd_sshttp_t const * http ); 116 : 117 : FD_PROTOTYPES_END 118 : 119 : #endif /* HEADER_fd_src_discof_restore_utils_fd_sshttp_h */