1 module fdb.networkoptions; 2 3 import 4 std.conv, 5 std.exception, 6 std..string; 7 8 import 9 fdb.error, 10 fdb.fdb_c, 11 fdb.fdb_c_options; 12 13 class NetworkOptions 14 { 15 static void init() 16 { 17 setNetworkOption(NetworkOption.NONE); 18 } 19 20 /** 21 * Enables trace output to a file in a directory of the clients choosing 22 * Params: 23 * value = path to output directory (or NULL for current working 24 * directory) 25 */ 26 static void setTraceEnable(in string value) 27 { 28 setNetworkOption(NetworkOption.TRACE_ENABLE, value); 29 } 30 31 /** 32 * Sets the maximum size in bytes of a single trace output file. 33 * This value should be in the range ``[0, long.max]``. 34 * If the value is set to 0, there is no limit on individual file size. 35 * The default is a maximum size of 10,485,760 bytes. 36 * Params: 37 * value = max size of a single trace output file 38 */ 39 static void setTraceRollSize(in long value) 40 { 41 setNetworkOption(NetworkOption.TRACE_ROLL_SIZE, value); 42 } 43 44 /** 45 * Sets the maximum size of a all the trace output files put together. 46 * This value should be in the range ``[0, long.max]``. 47 * If the value is set to 0, there is no limit on the total size of the 48 * files. 49 * The default is a maximum size of 104,857,600 bytes. 50 * If the default roll size is used, this means that a maximum of 10 trace 51 * files will be written at a time. 52 * Params: 53 * value = max total size of trace files 54 */ 55 static void setTraceMaxLogSize(in long value) 56 { 57 setNetworkOption(NetworkOption.TRACE_MAX_LOG_SIZE, value); 58 } 59 60 /** 61 * Set internal tuning or debugging knobs 62 * Params: 63 * value = knob_name=knob_value 64 */ 65 static void setKnob(in string value) 66 { 67 setNetworkOption(NetworkOption.KNOB, value); 68 } 69 70 /** 71 * Set the TLS plugin to load. This option, if used, must be set before any 72 * other TLS options 73 * Params: 74 * value = file path or linker-resolved name 75 */ 76 static void setTlsPlugin(in string value) 77 { 78 setNetworkOption(NetworkOption.TLS_PLUGIN, value); 79 } 80 81 /** 82 * Set the certificate chain 83 * Params: 84 * value = certificates 85 */ 86 static void setTlsCertBytes(in ubyte[] value) 87 { 88 setNetworkOption(NetworkOption.TLS_CERT_BYTES, value); 89 } 90 91 /** 92 * Set the file from which to load the certificate chain 93 * Params: 94 * value = file path 95 */ 96 static void setTlsCertPath(in string value) 97 { 98 setNetworkOption(NetworkOption.TLS_CERT_PATH, value); 99 } 100 101 /** 102 * Set the private key corresponding to your own certificate 103 * Params: 104 * value = key 105 */ 106 static void setTlsKeyBytes(in ubyte[] value) 107 { 108 setNetworkOption(NetworkOption.TLS_KEY_BYTES, value); 109 } 110 111 /** 112 * Set the file from which to load the private key corresponding to your 113 * own certificate 114 * Params: 115 * value = file path 116 */ 117 static void setTlsKeyPath(in string value) 118 { 119 setNetworkOption(NetworkOption.TLS_KEY_PATH, value); 120 } 121 122 /** 123 * Set the peer certificate field verification criteria 124 * Params: 125 * value = verification pattern 126 */ 127 static void setTlsVerifyPeers(in ubyte[] value) { 128 setNetworkOption(NetworkOption.TLS_VERIFY_PEERS, value); 129 } 130 131 private static void setNetworkOption(in NetworkOption op) 132 { 133 enforceError(fdb_network_set_option(op, null, 0)); 134 } 135 136 private static void setNetworkOption(in NetworkOption op, in ubyte[] value) 137 { 138 const auto err = fdb_network_set_option( 139 op, 140 cast(immutable(char)*)value, 141 cast(int)value.length); 142 enforceError(err); 143 } 144 145 private static void setNetworkOption(in NetworkOption op, in long value) 146 { 147 const auto err = fdb_network_set_option( 148 op, 149 cast(immutable(char)*)&value, 150 cast(int)value.sizeof); 151 enforceError(err); 152 } 153 154 private static void setNetworkOption(in NetworkOption op, in string value) 155 { 156 const auto err = fdb_network_set_option( 157 op, 158 value.toStringz, 159 cast(int)value.length); 160 enforceError(err); 161 } 162 };