34
34
#include "objectbox-c.h"
35
35
36
36
#if defined(static_assert ) || defined(__cplusplus )
37
- static_assert (OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 19 && OBX_VERSION_PATCH == 0 , // NOLINT
37
+ static_assert (OBX_VERSION_MAJOR == 0 && OBX_VERSION_MINOR == 21 && OBX_VERSION_PATCH == 0 , // NOLINT
38
38
"Versions of objectbox.h and objectbox-sync.h files do not match, please update" );
39
39
#endif
40
40
@@ -51,10 +51,16 @@ extern "C" {
51
51
struct OBX_sync ;
52
52
typedef struct OBX_sync OBX_sync ;
53
53
54
+ /// Specifies user-side credential types as well as server-side authenticator types.
55
+ /// Some credentail types do not make sense as authenticators such as OBXSyncCredentialsType_USER_PASSWORD which
56
+ /// specifies a generic client-side credential type.
54
57
typedef enum {
55
58
OBXSyncCredentialsType_NONE = 1 ,
56
59
OBXSyncCredentialsType_SHARED_SECRET = 2 ,
57
60
OBXSyncCredentialsType_GOOGLE_AUTH = 3 ,
61
+ OBXSyncCredentialsType_SHARED_SECRET_SIPPED = 4 ,
62
+ OBXSyncCredentialsType_OBX_ADMIN_USER = 5 ,
63
+ OBXSyncCredentialsType_USER_PASSWORD = 6 ,
58
64
} OBXSyncCredentialsType ;
59
65
60
66
// TODO sync prefix
@@ -91,6 +97,13 @@ typedef enum {
91
97
OBXSyncCode_TX_VIOLATED_UNIQUE = 71 ,
92
98
} OBXSyncCode ;
93
99
100
+ /// Sync-level error reporting codes, passed via obx_sync_listener_error().
101
+ typedef enum {
102
+ /// Sync client received rejection of transaction writes due to missing permissions.
103
+ /// Until reconnecting with new credentials client will run in receive-only mode.
104
+ OBXSyncError_REJECT_TX_NO_PERMISSION = 1
105
+ } OBXSyncError ;
106
+
94
107
typedef enum {
95
108
OBXSyncObjectType_FlatBuffers = 1 ,
96
109
OBXSyncObjectType_String = 2 ,
@@ -150,6 +163,11 @@ typedef void OBX_sync_listener_login_failure(void* arg, OBXSyncCode code);
150
163
/// @param arg is a pass-through argument passed to the called API
151
164
typedef void OBX_sync_listener_complete (void * arg );
152
165
166
+ /// Callend when sync-level errors occur
167
+ /// @param arg is a pass-through argument passed to the called API
168
+ /// @param error error code indicating sync-level error events
169
+ typedef void OBX_sync_listener_error (void * arg , OBXSyncError error );
170
+
153
171
/// Called with fine grained sync changes (IDs of put and removed entities)
154
172
/// @param arg is a pass-through argument passed to the called API
155
173
typedef void OBX_sync_listener_change (void * arg , const OBX_sync_change_array * changes );
@@ -168,6 +186,10 @@ typedef void OBX_sync_listener_msg_objects(void* arg, const OBX_sync_msg_objects
168
186
/// To configure this differently, call obx_sync_request_updates_mode() with the wanted mode.
169
187
OBX_C_API OBX_sync * obx_sync (OBX_store * store , const char * server_url );
170
188
189
+ /// Creates a sync client associated with the given store and a list of sync server URL.
190
+ /// For details, see obx_sync()
191
+ OBX_C_API OBX_sync * obx_sync_urls (OBX_store * store , const char * server_urls [], size_t server_urls_count );
192
+
171
193
/// Stops and closes (deletes) the sync client, freeing its resources.
172
194
OBX_C_API obx_err obx_sync_close (OBX_sync * sync );
173
195
@@ -177,6 +199,14 @@ OBX_C_API obx_err obx_sync_close(OBX_sync* sync);
177
199
/// @param data may be NULL in combination with OBXSyncCredentialsType_NONE
178
200
OBX_C_API obx_err obx_sync_credentials (OBX_sync * sync , OBXSyncCredentialsType type , const void * data , size_t size );
179
201
202
+ /// Set username/password credentials to authenticate the client with the server.
203
+ /// This is suitable for OBXSyncCredentialsType_OBX_ADMIN_USER and OBXSyncCredentialsType_USER_PASSWORD credential
204
+ /// types. Use obx_sync_credentials() for other credential types.
205
+ /// @param type should be OBXSyncCredentialsType_OBX_ADMIN_USER or OBXSyncCredentialsType_USER_PASSWORD
206
+ /// @returns OBX_ERROR_ILLEGAL_ARGUMENT if credential type does not support username/password authentication.
207
+ OBX_C_API obx_err obx_sync_credentials_user_password (OBX_sync * sync , OBXSyncCredentialsType type , const char * username ,
208
+ const char * password );
209
+
180
210
/// Configures the maximum number of outgoing TX messages that can be sent without an ACK from the server.
181
211
/// @returns OBX_ERROR_ILLEGAL_ARGUMENT if value is not in the range 1-20
182
212
OBX_C_API obx_err obx_sync_max_messages_in_flight (OBX_sync * sync , int value );
@@ -343,6 +373,50 @@ OBX_C_API void obx_sync_listener_server_time(OBX_sync* sync, OBX_sync_listener_s
343
373
OBX_C_API void obx_sync_listener_msg_objects (OBX_sync * sync , OBX_sync_listener_msg_objects * listener ,
344
374
void * listener_arg );
345
375
376
+ /// Set or overwrite a previously set 'error' listener - provides information about occurred sync-level errors.
377
+ /// @param listener set NULL to reset
378
+ /// @param listener_arg is a pass-through argument passed to the listener
379
+ OBX_C_API void obx_sync_listener_error (OBX_sync * sync , OBX_sync_listener_error * error , void * listener_arg );
380
+
381
+ //----------------------------------------------
382
+ // Sync Stats
383
+ //----------------------------------------------
384
+
385
+ /// Stats counter type IDs as passed to obx_sync_stats_u64().
386
+ typedef enum {
387
+ /// Total number of connects (u64)
388
+ OBXSyncStats_connects = 1 ,
389
+
390
+ /// Total number of succesful logins (u64)
391
+ OBXSyncStats_logins = 2 ,
392
+
393
+ /// Total number of messages received (u64)
394
+ OBXSyncStats_messagesReceived = 3 ,
395
+
396
+ /// Total number of messages sent (u64)
397
+ OBXSyncStats_messagesSent = 4 ,
398
+
399
+ /// Total number of errors during message sending (u64)
400
+ OBXSyncStats_messageSendFailures = 5 ,
401
+
402
+ /// Total number of bytes received via messages.
403
+ /// Note: this is measured on the application level and thus may not match e.g. the network level. (u64)
404
+ OBXSyncStats_messageBytesReceived = 6 ,
405
+
406
+ /// Total number of bytes sent via messages.
407
+ /// Note: this is measured on the application level and thus may not match e.g. the network level.
408
+ /// E.g. messages may be still enqueued so at least the timing will differ. (u64)
409
+ OBXSyncStats_messageBytesSent = 7 ,
410
+
411
+ } OBXSyncStats ;
412
+
413
+ /// Get u64 value for sync statistics.
414
+ /// @param counter_type the counter value to be read.
415
+ /// @param out_count receives the counter value.
416
+ /// @return OBX_SUCCESS if the counter has been successfully retrieved.
417
+ /// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined.
418
+ OBX_C_API obx_err obx_sync_stats_u64 (OBX_sync * sync , OBXSyncStats counter_type , uint64_t * out_count );
419
+
346
420
struct OBX_sync_server ;
347
421
typedef struct OBX_sync_server OBX_sync_server ;
348
422
@@ -385,6 +459,12 @@ OBX_C_API obx_err obx_sync_server_certificate_path(OBX_sync_server* server, cons
385
459
OBX_C_API obx_err obx_sync_server_credentials (OBX_sync_server * server , OBXSyncCredentialsType type , const void * data ,
386
460
size_t size );
387
461
462
+ /// Enables authenticator for server. Can be called multiple times. Use before obx_sync_server_start().
463
+ /// Use obx_sync_server_credentials() for authenticators which requires additional credentials data (i.e. Google Auth
464
+ /// and shared secrets authenticators).
465
+ /// @param type should be one of the available authentications, it should not be OBXSyncCredentialsType_USER_PASSWORD.
466
+ OBX_C_API obx_err obx_sync_server_enable_auth (OBX_sync_server * server , OBXSyncCredentialsType type );
467
+
388
468
/// Sets the number of worker threads. Use before obx_sync_server_start().
389
469
/// @param thread_count The default is "0" which is hardware dependent, e.g. a multiple of CPU "cores".
390
470
OBX_C_API obx_err obx_sync_server_worker_threads (OBX_sync_server * server , int thread_count );
@@ -432,6 +512,192 @@ OBX_C_API uint16_t obx_sync_server_port(OBX_sync_server* server);
432
512
/// Returns the number of clients connected to this server.
433
513
OBX_C_API uint64_t obx_sync_server_connections (OBX_sync_server * server );
434
514
515
+ //----------------------------------------------
516
+ // Sync Server Stats
517
+ //----------------------------------------------
518
+
519
+ /// Stats counter type IDs as passed to obx_sync_server_stats_u64() (for u64 values) and obx_sync_server_stats_f64()
520
+ /// (for double (f64) values).
521
+ typedef enum {
522
+ /// Total number of client connections established (u64)
523
+ OBXSyncServerStats_connects = 1 ,
524
+
525
+ /// Total number of messages received from clients (u64)
526
+ OBXSyncServerStats_messagesReceived = 2 ,
527
+
528
+ /// Total number of messages sent to clients (u64)
529
+ OBXSyncServerStats_messagesSent = 3 ,
530
+
531
+ /// Total number of bytes received from clients via messages. (u64)
532
+ /// Note: this is measured on the application level and thus may not match e.g. the network level.
533
+ OBXSyncServerStats_messageBytesReceived = 4 ,
534
+
535
+ /// Total number of bytes sent to clients via messages. (u64)
536
+ /// Note: this is measured on the application level and thus may not match e.g. the network level.
537
+ /// E.g. messages may be still enqueued so at least the timing will differ.
538
+ OBXSyncServerStats_messageBytesSent = 5 ,
539
+
540
+ /// Full syncs performed (u64)
541
+ OBXSyncServerStats_fullSyncs = 6 ,
542
+
543
+ /// Processing was aborted due to clients disconnected (u64)
544
+ OBXSyncServerStats_disconnectAborts = 7 ,
545
+
546
+ /// Total number of client transactions applied (u64)
547
+ OBXSyncServerStats_clientTxsApplied = 8 ,
548
+
549
+ /// Total size in bytes of client transactions applied (u64)
550
+ OBXSyncServerStats_clientTxBytesApplied = 9 ,
551
+
552
+ /// Total size in number of operations of transactions applied (u64)
553
+ OBXSyncServerStats_clientTxOpsApplied = 10 ,
554
+
555
+ /// Total number of local (server initiated) transactions applied (u64)
556
+ OBXSyncServerStats_localTxsApplied = 11 ,
557
+
558
+ /// AsyncQ committed TXs (u64)
559
+ OBXSyncServerStats_asyncDbCommits = 12 ,
560
+
561
+ /// Total number of skipped transactions duplicates (have been already applied before) (u64)
562
+ OBXSyncServerStats_skippedTxDups = 13 ,
563
+
564
+ /// Total number of login successes (u64)
565
+ OBXSyncServerStats_loginSuccesses = 14 ,
566
+
567
+ /// Total number of login failures (u64)
568
+ OBXSyncServerStats_loginFailures = 15 ,
569
+
570
+ /// Total number of login failures due to bad user credentials (u64)
571
+ OBXSyncServerStats_loginFailuresUserBadCredentials = 16 ,
572
+
573
+ /// Total number of login failures due to authenticator not available (u64)
574
+ OBXSyncServerStats_loginFailuresAuthUnavailable = 17 ,
575
+
576
+ /// Total number of login failures due to user has no permissions (u64)
577
+ OBXSyncServerStats_loginFailuresUserNoPermission = 18 ,
578
+
579
+ /// Total number of errors during message sending (u64)
580
+ OBXSyncServerStats_messageSendFailures = 19 ,
581
+
582
+ /// Total number of protocol errors; e.g. offending clients (u64)
583
+ OBXSyncServerStats_errorsProtocol = 20 ,
584
+
585
+ /// Total number of errors in message handlers (u64)
586
+ OBXSyncServerStats_errorsInHandlers = 21 ,
587
+
588
+ /// Total number of times a client has been disconnected due to heart failure (u64)
589
+ OBXSyncServerStats_heartbeatFailures = 22 ,
590
+
591
+ /// Total number of received client heartbeats (u64)
592
+ OBXSyncServerStats_heartbeatsReceived = 23 ,
593
+
594
+ /// Total APPLY_TX messages HistoryPusher has sent out (u64)
595
+ OBXSyncServerStats_historicUpdateTxsSent = 24 ,
596
+
597
+ /// Total APPLY_TX messages newDataPusher has sent out (u64)
598
+ OBXSyncServerStats_newUpdateTxsSent = 25 ,
599
+
600
+ /// Total number of messages received from clients (u64)
601
+ OBXSyncServerStats_forwardedMessagesReceived = 26 ,
602
+
603
+ /// Total number of messages sent to clients (u64)
604
+ OBXSyncServerStats_forwardedMessagesSent = 27 ,
605
+
606
+ /// Total number of global-to-local cache hits (u64)
607
+ OBXSyncServerStats_cacheGlobalToLocalHits = 28 ,
608
+
609
+ /// Total number of global-to-local cache misses (u64)
610
+ OBXSyncServerStats_cacheGlobalToLocalMisses = 29 ,
611
+
612
+ /// Internal dev stat for ID Map caching (u64)
613
+ OBXSyncServerStats_cacheGlobalToLocalSize = 30 ,
614
+
615
+ /// Internal dev stat for ID Map caching (u64)
616
+ OBXSyncServerStats_cachePeerToLocalHits = 31 ,
617
+
618
+ /// Internal dev stat for ID Map caching (u64)
619
+ OBXSyncServerStats_cachePeerToLocalMisses = 32 ,
620
+
621
+ /// Internal dev stat for ID Map caching (u64)
622
+ OBXSyncServerStats_cacheLocalToPeerHits = 33 ,
623
+
624
+ /// Internal dev stat for ID Map caching (u64)
625
+ OBXSyncServerStats_cacheLocalToPeerMisses = 34 ,
626
+
627
+ /// Internal dev stat for ID Map caching (u64)
628
+ OBXSyncServerStats_cachePeerSize = 35 ,
629
+
630
+ /// Current cluster peer state (0 = unknown, 1 = leader, 2 = follower, 3 = candidate) (u64)
631
+ OBXSyncServerStats_clusterPeerState = 36 ,
632
+
633
+ /// Number of transactions between the current Tx and the oldest Tx currently ACKed on any client (current)
634
+ /// (f64)
635
+ OBXSyncServerStats_clientTxsBehind = 37 ,
636
+
637
+ /// Number of transactions between the current Tx and the oldest Tx currently ACKed on any client (minimum)
638
+ /// (u64)
639
+ OBXSyncServerStats_clientTxsBehind_min = 38 ,
640
+
641
+ /// Number of transactions between the current Tx and the oldest Tx currently ACKed on any client (maximum)
642
+ /// (u64)
643
+ OBXSyncServerStats_clientTxsBehind_max = 39 ,
644
+
645
+ /// Number of connected clients (current) (f64)
646
+ OBXSyncServerStats_connectedClients = 40 ,
647
+
648
+ /// Number of connected clients (minimum) (u64)
649
+ OBXSyncServerStats_connectedClients_min = 41 ,
650
+
651
+ /// Number of connected clients (maximum) (u64)
652
+ OBXSyncServerStats_connectedClients_max = 42 ,
653
+
654
+ /// Length of the queue for regular Tasks (current) (f64)
655
+ OBXSyncServerStats_queueLength = 43 ,
656
+
657
+ /// Length of the queue for regular Tasks (minimum) (u64)
658
+ OBXSyncServerStats_queueLength_min = 44 ,
659
+
660
+ /// Length of the queue for regular Tasks (maximum) (u64)
661
+ OBXSyncServerStats_queueLength_max = 45 ,
662
+
663
+ /// Length of the async queue (current) (f64)
664
+ OBXSyncServerStats_queueLengthAsync = 46 ,
665
+
666
+ /// Length of the async queue (minimum) (u64)
667
+ OBXSyncServerStats_queueLengthAsync_min = 47 ,
668
+
669
+ /// Length of the async queue (maximum) (u64)
670
+ OBXSyncServerStats_queueLengthAsync_max = 48 ,
671
+
672
+ /// Sequence number of TX log history (current) (f64)
673
+ OBXSyncServerStats_txHistorySequence = 49 ,
674
+
675
+ /// Sequence number of TX log history (minimum) (u64)
676
+ OBXSyncServerStats_txHistorySequence_min = 50 ,
677
+
678
+ /// Sequence number of TX log history (maximum) (u64)
679
+ OBXSyncServerStats_txHistorySequence_max = 51 ,
680
+
681
+ } OBXSyncServerStats ;
682
+
683
+ /// Get u64 value for sync server statistics.
684
+ /// @param counter_type the counter value to be read (make sure to choose a uint64_t (u64) metric value type).
685
+ /// @param out_count receives the counter value.
686
+ /// @return OBX_SUCCESS if the counter has been successfully retrieved.
687
+ /// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined (this also happens if the wrong type is requested)
688
+ /// @return OBX_ERROR_ILLEGAL_STATE if the server is not started.
689
+ OBX_C_API obx_err obx_sync_server_stats_u64 (OBX_sync_server * server , OBXSyncServerStats counter_type ,
690
+ uint64_t * out_value );
691
+
692
+ /// Get double value for sync server statistics.
693
+ /// @param counter_type the counter value to be read (make sure to use a double (f64) metric value type).
694
+ /// @param out_count receives the counter value.
695
+ /// @return OBX_SUCCESS if the counter has been successfully retrieved.
696
+ /// @return OBX_ERROR_ILLEGAL_ARGUMENT if counter_type is undefined (this also happens if the wrong type is requested)
697
+ /// @return OBX_ERROR_ILLEGAL_STATE if the server is not started.
698
+ OBX_C_API obx_err obx_sync_server_stats_f64 (OBX_sync_server * server , OBXSyncServerStats counter_type ,
699
+ double * out_value );
700
+
435
701
/// Get server runtime statistics.
436
702
/// The returned char* is valid until another call to obx_sync_server_stats_string() or the server is closed.
437
703
OBX_C_API const char * obx_sync_server_stats_string (OBX_sync_server * server , bool include_zero_values );
0 commit comments