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 // Deprecated 21 // Parameter: (String) IP:PORT 22 //ADD_NET_OPTION("local_address", 10, String); 23 24 // Deprecated 25 // Parameter: (String) path to cluster file 26 //ADD_NET_OPTION("cluster_file", 20, String); 27 28 /* Enables trace output to a file in a directory of the clients choosing 29 * Parameter: (String) path to output directory (or NULL for current working 30 * directory) 31 */ 32 static void setTraceEnable(const string value) 33 { 34 setNetworkOption(NetworkOption.TRACE_ENABLE, value); 35 } 36 37 /* Set internal tuning or debugging knobs 38 * Parameter: (String) knob_name=knob_value 39 */ 40 static void setKnob(const string value) 41 { 42 setNetworkOption(NetworkOption.KNOB, value); 43 } 44 45 /* Set the TLS plugin to load. This option, if used, must be set before any 46 * other TLS options 47 * Parameter: (String) file path or linker-resolved name 48 */ 49 static void setTlsPlugin(const string value) 50 { 51 setNetworkOption(NetworkOption.TLS_PLUGIN, value); 52 } 53 54 /* Set the certificate chain 55 * Parameter: (Bytes) certificates 56 */ 57 static void setTlsCertBytes(const ubyte[] value) 58 { 59 setNetworkOption(NetworkOption.TLS_CERT_BYTES, value); 60 } 61 62 /* Set the file from which to load the certificate chain 63 * Parameter: (String) file path 64 */ 65 static void setTlsCertPath(const string value) 66 { 67 setNetworkOption(NetworkOption.TLS_CERT_PATH, value); 68 } 69 70 /* Set the private key corresponding to your own certificate 71 * Parameter: (Bytes) key 72 */ 73 static void setTlsKeyBytes(const ubyte[] value) 74 { 75 setNetworkOption(NetworkOption.TLS_KEY_BYTES, value); 76 } 77 78 /* Set the file from which to load the private key corresponding to your own 79 * certificate 80 * Parameter: (String) file path 81 */ 82 static void setTlsKeyPath(const string value) 83 { 84 setNetworkOption(NetworkOption.TLS_KEY_PATH, value); 85 } 86 87 /* Set the peer certificate field verification criteria 88 * Parameter: (Bytes) verification pattern 89 */ 90 static void setTlsVerifyPeers(const ubyte[] value) { 91 setNetworkOption(NetworkOption.TLS_VERIFY_PEERS, value); 92 } 93 94 private static void setNetworkOption(const NetworkOption op) 95 { 96 enforceError(fdb_network_set_option(op, null, 0)); 97 } 98 99 private static void setNetworkOption( 100 const NetworkOption op, 101 const ubyte[] value) 102 { 103 const auto err = fdb_network_set_option( 104 op, 105 cast(immutable(char)*)value, 106 cast(int)value.length); 107 enforceError(err); 108 } 109 110 private static void setNetworkOption( 111 const NetworkOption op, 112 const string value) 113 { 114 const auto err = fdb_network_set_option( 115 op, 116 value.toStringz, 117 cast(int)value.length); 118 enforceError(err); 119 } 120 };