@@ -7,6 +7,7 @@ use crate::retry_policy::CassRetryPolicy;
7
7
use crate :: retry_policy:: RetryPolicy :: * ;
8
8
use crate :: ssl:: CassSsl ;
9
9
use crate :: types:: * ;
10
+ use crate :: uuid:: CassUuid ;
10
11
use openssl:: ssl:: SslContextBuilder ;
11
12
use openssl_sys:: SSL_CTX_up_ref ;
12
13
use scylla:: execution_profile:: ExecutionProfileBuilder ;
@@ -16,6 +17,7 @@ use scylla::load_balancing::{DefaultPolicyBuilder, LoadBalancingPolicy};
16
17
use scylla:: retry_policy:: RetryPolicy ;
17
18
use scylla:: speculative_execution:: SimpleSpeculativeExecutionPolicy ;
18
19
use scylla:: statement:: { Consistency , SerialConsistency } ;
20
+ use scylla:: transport:: SelfIdentity ;
19
21
use scylla:: { SessionBuilder , SessionConfig } ;
20
22
use std:: collections:: HashMap ;
21
23
use std:: convert:: TryInto ;
@@ -32,6 +34,9 @@ include!(concat!(env!("OUT_DIR"), "/cppdriver_compression_types.rs"));
32
34
const DEFAULT_CONSISTENCY : Consistency = Consistency :: LocalOne ;
33
35
const DEFAULT_REQUEST_TIMEOUT_MILLIS : u64 = 12000 ;
34
36
37
+ const DRIVER_NAME : & str = "ScyllaDB Cpp-Rust Driver" ;
38
+ const DRIVER_VERSION : & str = env ! ( "CARGO_PKG_VERSION" ) ;
39
+
35
40
#[ derive( Clone , Debug ) ]
36
41
pub ( crate ) struct LoadBalancingConfig {
37
42
pub ( crate ) token_awareness_enabled : bool ,
@@ -85,6 +90,8 @@ pub struct CassCluster {
85
90
use_beta_protocol_version : bool ,
86
91
auth_username : Option < String > ,
87
92
auth_password : Option < String > ,
93
+
94
+ client_id : Option < uuid:: Uuid > ,
88
95
}
89
96
90
97
impl CassCluster {
@@ -106,6 +113,11 @@ impl CassCluster {
106
113
pub ( crate ) fn get_contact_points ( & self ) -> & [ String ] {
107
114
& self . contact_points
108
115
}
116
+
117
+ #[ inline]
118
+ pub ( crate ) fn get_client_id ( & self ) -> Option < uuid:: Uuid > {
119
+ self . client_id
120
+ }
109
121
}
110
122
111
123
pub struct CassCustomPayload ;
@@ -140,8 +152,13 @@ pub unsafe extern "C" fn cass_cluster_new() -> *mut CassCluster {
140
152
. consistency ( DEFAULT_CONSISTENCY )
141
153
. request_timeout ( Some ( Duration :: from_millis ( DEFAULT_REQUEST_TIMEOUT_MILLIS ) ) ) ;
142
154
155
+ // Set DRIVER_NAME and DRIVER_VERSION of cpp-rust driver.
156
+ let custom_identity = SelfIdentity :: new ( )
157
+ . with_custom_driver_name ( DRIVER_NAME )
158
+ . with_custom_driver_version ( DRIVER_VERSION ) ;
159
+
143
160
Box :: into_raw ( Box :: new ( CassCluster {
144
- session_builder : SessionBuilder :: new ( ) ,
161
+ session_builder : SessionBuilder :: new ( ) . custom_identity ( custom_identity ) ,
145
162
port : 9042 ,
146
163
contact_points : Vec :: new ( ) ,
147
164
// Per DataStax documentation: Without additional configuration the C/C++ driver
@@ -152,6 +169,7 @@ pub unsafe extern "C" fn cass_cluster_new() -> *mut CassCluster {
152
169
default_execution_profile_builder,
153
170
execution_profile_map : Default :: default ( ) ,
154
171
load_balancing_config : Default :: default ( ) ,
172
+ client_id : None ,
155
173
} ) )
156
174
}
157
175
@@ -219,6 +237,74 @@ pub unsafe extern "C" fn cass_cluster_set_use_randomized_contact_points(
219
237
CassError :: CASS_OK
220
238
}
221
239
240
+ #[ no_mangle]
241
+ pub unsafe extern "C" fn cass_cluster_set_application_name (
242
+ cluster_raw : * mut CassCluster ,
243
+ app_name : * const c_char ,
244
+ ) {
245
+ cass_cluster_set_application_name_n ( cluster_raw, app_name, strlen ( app_name) )
246
+ }
247
+
248
+ #[ no_mangle]
249
+ pub unsafe extern "C" fn cass_cluster_set_application_name_n (
250
+ cluster_raw : * mut CassCluster ,
251
+ app_name : * const c_char ,
252
+ app_name_len : size_t ,
253
+ ) {
254
+ let cluster = ptr_to_ref_mut ( cluster_raw) ;
255
+ let app_name = ptr_to_cstr_n ( app_name, app_name_len) . unwrap ( ) . to_string ( ) ;
256
+
257
+ cluster
258
+ . session_builder
259
+ . config
260
+ . identity
261
+ . set_application_name ( app_name)
262
+ }
263
+
264
+ #[ no_mangle]
265
+ pub unsafe extern "C" fn cass_cluster_set_application_version (
266
+ cluster_raw : * mut CassCluster ,
267
+ app_version : * const c_char ,
268
+ ) {
269
+ cass_cluster_set_application_version_n ( cluster_raw, app_version, strlen ( app_version) )
270
+ }
271
+
272
+ #[ no_mangle]
273
+ pub unsafe extern "C" fn cass_cluster_set_application_version_n (
274
+ cluster_raw : * mut CassCluster ,
275
+ app_version : * const c_char ,
276
+ app_version_len : size_t ,
277
+ ) {
278
+ let cluster = ptr_to_ref_mut ( cluster_raw) ;
279
+ let app_version = ptr_to_cstr_n ( app_version, app_version_len)
280
+ . unwrap ( )
281
+ . to_string ( ) ;
282
+
283
+ cluster
284
+ . session_builder
285
+ . config
286
+ . identity
287
+ . set_application_version ( app_version) ;
288
+ }
289
+
290
+ #[ no_mangle]
291
+ pub unsafe extern "C" fn cass_cluster_set_client_id (
292
+ cluster_raw : * mut CassCluster ,
293
+ client_id : CassUuid ,
294
+ ) {
295
+ let cluster = ptr_to_ref_mut ( cluster_raw) ;
296
+
297
+ let client_uuid: uuid:: Uuid = client_id. into ( ) ;
298
+ let client_uuid_str = client_uuid. to_string ( ) ;
299
+
300
+ cluster. client_id = Some ( client_uuid) ;
301
+ cluster
302
+ . session_builder
303
+ . config
304
+ . identity
305
+ . set_client_id ( client_uuid_str)
306
+ }
307
+
222
308
#[ no_mangle]
223
309
pub unsafe extern "C" fn cass_cluster_set_use_schema (
224
310
cluster_raw : * mut CassCluster ,
0 commit comments