1 // This file is autogenerated by: 2 // cbindgen --config cbindgen.toml src/lib.rs -o include/lib.rs.h 3 // Don't modify manually. 4 5 #pragma once 6 7 /* Generated with cbindgen:0.24.2 */ 8 9 #include <stdint.h> 10 #include <sys/types.h> 11 12 namespace test { 13 namespace rust { 14 15 constexpr static const uintptr_t DNS_HEADER_SIZE = 12; 16 17 constexpr static const uintptr_t MAX_UDP_PAYLOAD_SIZE = 1350; 18 19 constexpr static const uintptr_t CONN_ID_LEN = 8; 20 21 /// Default value for max_idle_timeout transport parameter. 22 constexpr static const uint64_t QUICHE_IDLE_TIMEOUT_MS = 10000; 23 24 /// Default value for initial_max_streams_bidi transport parameter. 25 constexpr static const uint64_t MAX_STREAMS_BIDI = 100; 26 27 /// Frontend object. 28 struct DohFrontend; 29 30 struct Stats { 31 /// The number of accumulated DoH queries that are received. 32 uint32_t queries_received; 33 /// The number of accumulated QUIC connections accepted. 34 uint32_t connections_accepted; 35 /// The number of QUIC connections alive. 36 uint32_t alive_connections; 37 /// The number of QUIC connections using session resumption. 38 uint32_t resumed_connections; 39 /// The number of QUIC connections that received early data. 40 uint32_t early_data_connections; 41 }; 42 43 extern "C" { 44 45 /// Creates a DohFrontend object by the given IP addresss and ports. Returns the pointer of 46 /// the object if the creation succeeds; otherwise, returns a null pointer. 47 /// 48 /// # Safety 49 /// 50 /// The parameters `addr`, `port`, `backend_addr`, and `backend_port` must all point to null 51 /// terminated UTF-8 encoded strings. 52 DohFrontend* frontend_new(const char* addr, const char* port, const char* backend_addr, 53 const char* backend_port); 54 55 /// Starts the `DohFrontend` worker thread. Returns true if the worker thread is spawned 56 /// successfully; otherwise, it returns false. 57 bool frontend_start(DohFrontend* doh); 58 59 /// Stops the `DohFrontend` worker thread. 60 bool frontend_stop(DohFrontend* doh); 61 62 /// Deletes the `DohFrontend` created from `frontend_new`. 63 /// If the caller has called `frontend_start` to start `DohFrontend`, it has to call 64 /// call `frontend_stop` to stop the worker thread before deleting the object. 65 /// 66 /// # Safety 67 /// 68 /// The DohFrontend is not set to null pointer, caller needs to do it on its own. 69 void frontend_delete(DohFrontend* doh); 70 71 /// Sets server certificate to `DohFrontend`. 72 /// 73 /// # Safety 74 /// 75 /// The given certificate must be a null-terminated UTF-8 encoded string. 76 bool frontend_set_certificate(DohFrontend* doh, const char* certificate); 77 78 /// Sets server private key to `DohFrontend`. 79 /// 80 /// # Safety 81 /// 82 /// The given private key must be a null-terminated UTF-8 encoded string. 83 bool frontend_set_private_key(DohFrontend* doh, const char* private_key); 84 85 /// Configures the `DohFrontend` not to process DoH queries until a given number of DoH queries 86 /// are received. This function works even in the middle of the worker thread. 87 bool frontend_set_delay_queries(DohFrontend* doh, int32_t count); 88 89 /// Configures the `DohFrontend` to use the given value for max_idle_timeout transport parameter. 90 bool frontend_set_max_idle_timeout(DohFrontend* doh, uint64_t value); 91 92 /// Configures the `DohFrontend` to use the given value for these transport parameters. 93 /// - initial_max_data 94 /// - initial_max_stream_data_bidi_local 95 /// - initial_max_stream_data_bidi_remote 96 /// - initial_max_stream_data_uni 97 bool frontend_set_max_buffer_size(DohFrontend* doh, uint64_t value); 98 99 /// Configures the `DohFrontend` to use the given value for initial_max_streams_bidi transport 100 /// parameter. 101 bool frontend_set_max_streams_bidi(DohFrontend* doh, uint64_t value); 102 103 /// Sets the `DohFrontend` to block or unblock sending any data. 104 bool frontend_block_sending(DohFrontend* doh, bool block); 105 106 /// If this function is called, the `DohFrontend` will send RESET_STREAM frame as a response 107 /// instead of a DoH answer on the stream |stream_id|. This will make the client fail to receive 108 /// this DoH answer. 109 bool frontend_set_reset_stream_id(DohFrontend* doh, uint64_t stream_id); 110 111 /// Gets the statistics of the `DohFrontend` and writes the result to |out|. 112 bool frontend_stats(DohFrontend* doh, Stats* out); 113 114 /// Resets `queries_received` field of `Stats` owned by the `DohFrontend`. 115 bool frontend_stats_clear_queries(const DohFrontend* doh); 116 117 /// Enable Rust debug logging. 118 void init_android_logger(); 119 120 } // extern "C" 121 122 } // namespace rust 123 } // namespace test 124