Couchbase Lite C
Couchbase Lite C API
Loading...
Searching...
No Matches
CBLReplicator.h
Go to the documentation of this file.
1//
2// CBLReplicator.h
3//
4// Copyright (c) 2018 Couchbase, Inc All rights reserved.
5//
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17//
18
19#pragma once
20#include "CBLBase.h"
21#include "CBLTLSIdentity.h"
22
24
29
32
35
37typedef struct CBLEndpoint CBLEndpoint;
38
50 CBLError* _cbl_nullable outError) CBLAPI;
51
52#ifdef COUCHBASE_ENTERPRISE
56#endif
57
60
61
64
68
74
75#ifdef COUCHBASE_ENTERPRISE
76
81
82#endif
83
86
87
94
95
101
102
111typedef bool (*CBLReplicationFilter)(void* _cbl_nullable context,
112 CBLDocument* document,
113 CBLDocumentFlags flags);
114
138 FLString documentID,
139 const CBLDocument* _cbl_nullable localDocument,
140 const CBLDocument* _cbl_nullable remoteDocument);
141
144
145
151
152
161
162#ifdef COUCHBASE_ENTERPRISE
163
186 void* context,
187 FLString scope,
188 FLString collection,
189 FLString documentID,
190 FLDict properties,
191 FLString keyPath,
192 FLSlice input,
193 FLStringResult* algorithm,
194 FLStringResult* kid,
195 CBLError* error
196);
197
222 void* context,
223 FLString scope,
224 FLString collection,
225 FLString documentID,
226 FLDict properties,
227 FLString keyPath,
228 FLSlice input,
229 FLString algorithm,
230 FLString kid,
231 CBLError* error
232);
233
234#endif
235
256
260
262typedef struct {
263 //-- Required fields:
264
267
271
274
275 //-- Core options and context:
276
279
282
285
288
289 //-- TLS settings:
290
294
295 //-- Auto Purge:
296
304
305 //-- Retry Logic:
306
311 unsigned maxAttempts;
312
316
317 //-- WebSocket:
318
321 unsigned heartbeat;
322
323 //-- HTTP settings:
324
327
330
340
341#ifdef __CBL_REPLICATOR_NETWORK_INTERFACE__
344 FLString networkInterface;
345#endif
346
347 //-- Advance TLS Settings:
348
351
352#ifdef COUCHBASE_ENTERPRISE
355#endif
356
357#ifdef COUCHBASE_ENTERPRISE
358 //-- Property Encryption
359
362
365#endif
367
369
370
373
375
379 CBLError* _cbl_nullable outError) CBLAPI;
380
383
393 bool resetCheckpoint) CBLAPI;
394
399
406 bool reachable) CBLAPI;
407
414
416
417
421
430
435typedef struct {
436 float complete;
437 uint64_t documentCount;
439
446
449
460 const CBLCollection* collection,
461 CBLError* _cbl_nullable outError) CBLAPI;
462
472 FLString docID,
473 const CBLCollection* collection,
474 CBLError* _cbl_nullable outError) CBLAPI;
475
487 const CBLCollection* collection,
488 CBLError* _cbl_nullable outError) CBLAPI;
489
500 FLString docID,
501 const CBLCollection* collection,
502 CBLError* _cbl_nullable outError) CBLAPI;
503
511typedef void (*CBLReplicatorChangeListener)(void* _cbl_nullable context,
512 CBLReplicator *replicator,
513 const CBLReplicatorStatus *status);
514
519 void* _cbl_nullable context) CBLAPI;
520
521
530
540typedef void (*CBLDocumentReplicationListener)(void *context,
541 CBLReplicator *replicator,
542 bool isPush,
543 unsigned numDocuments,
544 const CBLReplicatedDocument* documents);
545
550 void* _cbl_nullable context) CBLAPI;
551
552#ifdef COUCHBASE_ENTERPRISE
553
558
559
560#endif
561
564
#define CBL_OPTIONS(_type, _name)
Definition CBL_Compat.h:63
#define CBLAPI
Definition CBL_Compat.h:105
#define _cbl_nullable
Definition CBL_Compat.h:92
#define CBL_CAPI_BEGIN
Definition CBL_Compat.h:107
#define CBL_CAPI_END
Definition CBL_Compat.h:108
#define CBL_PUBLIC
Definition CBL_Compat.h:125
#define CBL_ENUM(_type, _name)
Definition CBL_Compat.h:62
#define _cbl_warn_unused
Definition CBL_Compat.h:40
FLSliceResult FLStringResult
Definition FLSlice.h:99
FLSlice FLString
Definition FLSlice.h:98
struct CBLCert CBLCert
An opaque object representing the X.509 Certifcate.
Definition CBLBase.h:249
struct CBLTLSIdentity CBLTLSIdentity
An opaque object representing the TLSIdentity.
Definition CBLTLSIdentity.h:269
struct CBLCollection CBLCollection
A collection, a document container.
Definition CBLBase.h:195
struct CBLDatabase CBLDatabase
A connection to an open database.
Definition CBLBase.h:183
struct CBLDocument CBLDocument
An in-memory copy of a document.
Definition CBLBase.h:204
struct CBLListenerToken CBLListenerToken
An opaque 'cookie' representing a registered listener callback.
Definition CBLBase.h:284
#define CBL_REFCOUNTED(TYPE, NAME)
Definition CBLBase.h:171
CBLProxyType
Definition CBLReplicator.h:147
struct CBLAuthenticator CBLAuthenticator
An opaque object representing authentication credentials for a remote server.
Definition CBLReplicator.h:63
_cbl_warn_unused CBLAuthenticator * CBLAuth_CreateSession(FLString sessionID, FLString cookieName)
Creates an authenticator using a Couchbase Sync Gateway login session identifier, and optionally a co...
struct CBLEndpoint CBLEndpoint
An opaque object representing the location of a database to replicate with.
Definition CBLReplicator.h:37
bool(* CBLReplicationFilter)(void *_cbl_nullable context, CBLDocument *document, CBLDocumentFlags flags)
A callback that can decide whether a particular document should be pushed or pulled.
Definition CBLReplicator.h:111
void CBLReplicator_Start(CBLReplicator *replicator, bool resetCheckpoint)
Starts a replicator, asynchronously.
_cbl_warn_unused CBLAuthenticator * CBLAuth_CreatePassword(FLString username, FLString password)
Creates an authenticator for HTTP Basic (username/password) auth.
_cbl_warn_unused CBLCert *_cbl_nullable CBLReplicator_ServerCertificate(CBLReplicator *)
Gets the TLS certificate received when connecting to the server.
FLDict _cbl_nullable CBLReplicator_PendingDocumentIDs2(CBLReplicator *, const CBLCollection *collection, CBLError *_cbl_nullable outError)
Indicates which documents in the given collection have local changes that have not yet been pushed to...
FLDict _cbl_nullable CBLReplicator_PendingDocumentIDs(CBLReplicator *, const CBLCollection *collection, CBLError *_cbl_nullable outError)
Indicates which documents in the given collection have local changes that have not yet been pushed to...
FLSliceResult(* CBLDocumentPropertyEncryptor)(void *context, FLString scope, FLString collection, FLString documentID, FLDict properties, FLString keyPath, FLSlice input, FLStringResult *algorithm, FLStringResult *kid, CBLError *error)
Callback that encrypts CBLEncryptable properties in the documents pushed by the replicator.
Definition CBLReplicator.h:185
CBL_PUBLIC const FLString kCBLAuthDefaultCookieName
The name of the HTTP cookie used by Sync Gateway to store session keys.
bool CBLReplicator_IsDocumentPending(CBLReplicator *repl, FLString docID, const CBLCollection *collection, CBLError *_cbl_nullable outError)
Indicates whether the document with the given ID in the given collection has local changes that have ...
void CBLReplicator_Stop(CBLReplicator *)
Stops a running replicator, asynchronously.
struct CBLReplicator CBLReplicator
A background task that syncs a CBLDatabase with a remote server or peer.
Definition CBLBase.h:235
_cbl_warn_unused CBLReplicator *_cbl_nullable CBLReplicator_Create(const CBLReplicatorConfiguration *, CBLError *_cbl_nullable outError)
Creates a replicator with the given configuration.
void(* CBLReplicatorChangeListener)(void *_cbl_nullable context, CBLReplicator *replicator, const CBLReplicatorStatus *status)
A callback that notifies you when the replicator's status changes.
Definition CBLReplicator.h:511
CBLReplicatorStatus CBLReplicator_Status(CBLReplicator *)
Returns the replicator's current status.
void CBLEndpoint_Free(CBLEndpoint *_cbl_nullable)
Frees a CBLEndpoint object.
void(* CBLDocumentReplicationListener)(void *context, CBLReplicator *replicator, bool isPush, unsigned numDocuments, const CBLReplicatedDocument *documents)
A callback that notifies you when documents are replicated.
Definition CBLReplicator.h:540
CBL_PUBLIC const CBLConflictResolver CBLDefaultConflictResolver
Default conflict resolver.
CBLReplicatorActivityLevel
Definition CBLReplicator.h:423
bool CBLReplicator_IsDocumentPending2(CBLReplicator *repl, FLString docID, const CBLCollection *collection, CBLError *_cbl_nullable outError)
Indicates whether the document with the given ID in the given collection has local changes that have ...
_cbl_warn_unused CBLListenerToken * CBLReplicator_AddChangeListener(CBLReplicator *, CBLReplicatorChangeListener, void *_cbl_nullable context)
Registers a listener that will be called when the replicator's status changes.
void CBLAuth_Free(CBLAuthenticator *_cbl_nullable)
Frees a CBLAuthenticator object.
CBLDocumentFlags
Definition CBLReplicator.h:97
CBLCollectionConfiguration CBLReplicationCollection
Deprecated alias for backward compatibility.
Definition CBLReplicator.h:259
_cbl_warn_unused CBLAuthenticator * CBLAuth_CreateCertificate(CBLTLSIdentity *identity)
Creates an authenticator that presents a client certificate to the server during the initial SSL/TLS ...
FLSliceResult(* CBLDocumentPropertyDecryptor)(void *context, FLString scope, FLString collection, FLString documentID, FLDict properties, FLString keyPath, FLSlice input, FLString algorithm, FLString kid, CBLError *error)
Callback that decrypts encrypted CBLEncryptable properties in documents pulled by the replicator.
Definition CBLReplicator.h:221
CBLReplicatorType
Definition CBLReplicator.h:89
void CBLReplicator_SetSuspended(CBLReplicator *repl, bool suspended)
Puts the replicator in or out of "suspended" state.
void CBLReplicator_SetHostReachable(CBLReplicator *, bool reachable)
Informs the replicator whether it's considered possible to reach the remote host with the current net...
_cbl_warn_unused CBLEndpoint * CBLEndpoint_CreateWithLocalDB(CBLDatabase *)
Creates a new endpoint representing another local database.
const CBLDocument *_cbl_nullable(* CBLConflictResolver)(void *_cbl_nullable context, FLString documentID, const CBLDocument *_cbl_nullable localDocument, const CBLDocument *_cbl_nullable remoteDocument)
Conflict-resolution callback for use in replications.
Definition CBLReplicator.h:137
_cbl_warn_unused CBLListenerToken * CBLReplicator_AddDocumentReplicationListener(CBLReplicator *, CBLDocumentReplicationListener, void *_cbl_nullable context)
Registers a listener that will be called when documents are replicated.
_cbl_warn_unused CBLEndpoint *_cbl_nullable CBLEndpoint_CreateWithURL(FLString url, CBLError *_cbl_nullable outError)
Creates a new endpoint representing a server-based database at the given URL.
const CBLReplicatorConfiguration * CBLReplicator_Config(CBLReplicator *)
Returns the configuration of an existing replicator.
@ kCBLProxyHTTP
HTTP proxy; must support 'CONNECT' method.
Definition CBLReplicator.h:148
@ kCBLProxyHTTPS
HTTPS proxy; must support 'CONNECT' method.
Definition CBLReplicator.h:149
@ kCBLReplicatorConnecting
The replicator is connecting to the remote host.
Definition CBLReplicator.h:426
@ kCBLReplicatorOffline
The replicator is offline, as the remote host is unreachable.
Definition CBLReplicator.h:425
@ kCBLReplicatorStopped
The replicator is unstarted, finished, or hit a fatal error.
Definition CBLReplicator.h:424
@ kCBLReplicatorIdle
The replicator is inactive, waiting for changes to sync.
Definition CBLReplicator.h:427
@ kCBLReplicatorBusy
The replicator is actively transferring data.
Definition CBLReplicator.h:428
@ kCBLDocumentFlagsAccessRemoved
Lost access to the document on the server.
Definition CBLReplicator.h:99
@ kCBLDocumentFlagsDeleted
The document has been deleted.
Definition CBLReplicator.h:98
@ kCBLReplicatorTypePushAndPull
Bidirectional; both push and pull.
Definition CBLReplicator.h:90
@ kCBLReplicatorTypePush
Pushing changes to the target.
Definition CBLReplicator.h:91
@ kCBLReplicatorTypePull
Pulling changes from the target.
Definition CBLReplicator.h:92
const struct _FLDict * FLDict
A reference to a dictionary (map) value.
Definition FLBase.h:37
const struct _FLArray * FLArray
A reference to an array value.
Definition FLBase.h:36
The collection and the configuration that can be configured specifically for the replication.
Definition CBLReplicator.h:237
CBLConflictResolver _cbl_nullable conflictResolver
Conflict-resolver callback.
Definition CBLReplicator.h:242
CBLCollection * collection
The collection (Required)
Definition CBLReplicator.h:239
CBLReplicationFilter _cbl_nullable pullFilter
Callback to filter which docs are pulled.
Definition CBLReplicator.h:248
FLArray _cbl_nullable documentIDs
Set of document IDs to replicate.
Definition CBLReplicator.h:254
FLArray _cbl_nullable channels
Set of channels to pull from.
Definition CBLReplicator.h:251
CBLReplicationFilter _cbl_nullable pushFilter
Callback to filter which docs are pushed.
Definition CBLReplicator.h:245
A struct holding information about an error.
Definition CBLBase.h:105
Proxy settings for the replicator.
Definition CBLReplicator.h:154
uint16_t port
Proxy server port.
Definition CBLReplicator.h:157
FLString hostname
Proxy server hostname or IP address.
Definition CBLReplicator.h:156
FLString password
Password for proxy auth.
Definition CBLReplicator.h:159
FLString username
Username for proxy auth (optional)
Definition CBLReplicator.h:158
CBLProxyType type
Type of proxy.
Definition CBLReplicator.h:155
Information about a document that's been pushed or pulled.
Definition CBLReplicator.h:523
CBLError error
If the code is nonzero, the document failed to replicate.
Definition CBLReplicator.h:526
FLString collection
The collection name.
Definition CBLReplicator.h:528
CBLDocumentFlags flags
Indicates whether the document was deleted or removed.
Definition CBLReplicator.h:525
FLString ID
The document ID.
Definition CBLReplicator.h:524
FLString scope
The scope name of the collection.
Definition CBLReplicator.h:527
The configuration of a replicator.
Definition CBLReplicator.h:262
void *_cbl_nullable context
Arbitrary value that will be passed to callbacks.
Definition CBLReplicator.h:287
unsigned maxAttemptWaitTime
Max wait time between retry attempts in seconds.
Definition CBLReplicator.h:315
const CBLProxySettings *_cbl_nullable proxy
HTTP client proxy settings.
Definition CBLReplicator.h:329
CBLCollectionConfiguration * collections
The collections to replicate with the target's endpoint (Required).
Definition CBLReplicator.h:266
bool disableAutoPurge
If auto purge is active, documents that the replicating user loses access to will be purged automatic...
Definition CBLReplicator.h:303
bool continuous
Continuous replication?
Definition CBLReplicator.h:281
CBLReplicatorType replicatorType
Push, pull or both.
Definition CBLReplicator.h:278
FLSlice pinnedServerCertificate
X.509 certificate (PEM or DER) to pin for TLS connections.
Definition CBLReplicator.h:293
unsigned heartbeat
The heartbeat interval in seconds.
Definition CBLReplicator.h:321
unsigned maxAttempts
Max retry attempts where the initial connect to replicate counts toward the given value.
Definition CBLReplicator.h:311
bool acceptParentDomainCookies
The option to remove the restriction that does not allow the replicator to save the parent-domain coo...
Definition CBLReplicator.h:339
FLDict _cbl_nullable headers
Extra HTTP headers to add to the WebSocket request.
Definition CBLReplicator.h:326
size_t collectionCount
The number of collections (Required).
Definition CBLReplicator.h:270
CBLAuthenticator *_cbl_nullable authenticator
Authentication credentials, if needed.
Definition CBLReplicator.h:284
CBLEndpoint * endpoint
The replication endpoint to replicate with (Required).
Definition CBLReplicator.h:273
CBLDocumentPropertyEncryptor _cbl_nullable documentPropertyEncryptor
Callback to encrypt CBLEncryptable values.
Definition CBLReplicator.h:361
CBLDocumentPropertyDecryptor _cbl_nullable documentPropertyDecryptor
Callback to decrypt encrypted CBLEncryptable values.
Definition CBLReplicator.h:364
FLSlice trustedRootCertificates
Set of anchor certs (PEM format)
Definition CBLReplicator.h:350
bool acceptOnlySelfSignedServerCertificate
Accept only self-signed certificates; any other certificates are rejected.
Definition CBLReplicator.h:354
A fractional progress value, ranging from 0.0 to 1.0 as replication progresses.
Definition CBLReplicator.h:435
uint64_t documentCount
Number of documents transferred so far.
Definition CBLReplicator.h:437
float complete
Very-approximate fractional completion, from 0.0 to 1.0.
Definition CBLReplicator.h:436
A replicator's current status.
Definition CBLReplicator.h:441
CBLError error
Error, if any.
Definition CBLReplicator.h:444
CBLReplicatorActivityLevel activity
Current state.
Definition CBLReplicator.h:442
CBLReplicatorProgress progress
Approximate fraction complete.
Definition CBLReplicator.h:443
A simple reference to a block of memory.
Definition FLSlice.h:45
A heap-allocated block of memory returned from an API call.
Definition FLSlice.h:66