@@ -73,8 +73,8 @@ public class PeerToPeerRequestHandler {
73
73
config = URLEndpointListenerConfiguration ( collections: collections!)
74
74
}
75
75
else if database != nil {
76
- let defaultCol = try database? . defaultCollection ( )
77
- config = URLEndpointListenerConfiguration . init ( collections: [ defaultCol! ] )
76
+ let defaultCol = try database! . defaultCollection ( )
77
+ config = URLEndpointListenerConfiguration . init ( collections: [ defaultCol] )
78
78
}
79
79
else {
80
80
throw RequestHandlerError . InvalidArgument ( " Provide collections or database " )
@@ -238,7 +238,7 @@ public class PeerToPeerRequestHandler {
238
238
let serverDBName : String = args. get ( name: " serverDBName " ) !
239
239
let database : Database = args. get ( name: " database " ) !
240
240
let defaultCol = try database. defaultCollection ( )
241
- let colConfig = CollectionConfiguration ( collection: defaultCol)
241
+ var colConfig = CollectionConfiguration ( collection: defaultCol)
242
242
243
243
let continuous : Bool ? = args. get ( name: " continuous " ) !
244
244
let replication_type : String ? = args. get ( name: " replicationType " ) !
@@ -260,6 +260,7 @@ public class PeerToPeerRequestHandler {
260
260
var wsPort : String ?
261
261
let maxRetries : String ? = args. get ( name: " max_retries " )
262
262
let maxRetryWaitTime : String ? = args. get ( name: " max_timeout " )
263
+
263
264
264
265
if let type = replication_type {
265
266
if type == " push " {
@@ -276,93 +277,94 @@ public class PeerToPeerRequestHandler {
276
277
} else {
277
278
wsPort = " ws "
278
279
}
279
-
280
- let url = URL ( string: " \( wsPort ?? " ws " ) :// \( host) : \( port) / \( serverDBName) " ) !
281
- if endPointType == " URLEndPoint " {
282
- let urlEndPoint : URLEndpoint = URLEndpoint ( url: url)
283
- replicatorConfig = ReplicatorConfiguration ( collections: [ colConfig] , target: urlEndPoint)
284
- }
285
- else {
286
- let endpoint = MessageEndpoint ( uid: url. absoluteString, target: url, protocolType: ProtocolType . byteStream, delegate: self )
287
- replicatorConfig = ReplicatorConfiguration ( collections: [ colConfig] , target: endpoint)
288
- }
289
280
290
- if auth != nil {
291
- replicatorConfig. authenticator = auth
292
- }
293
- if serverVerificationMode != false {
294
- replicatorConfig. acceptOnlySelfSignedServerCertificate = true
295
- }
296
-
297
- if tlsAuthType == " self_signed " {
298
- let certData = try ! dataFromResource ( name: " identity/certs " , ofType: " p12 " )
299
- try ! TLSIdentity . deleteIdentity ( withLabel: " CBL-Cert " )
300
- let identity = try ! TLSIdentity . importIdentity ( withData: certData, password: " 123 " , label: " CBL-Cert " )
301
- replicatorConfig. pinnedServerCertificate = identity. certs [ 0 ]
302
- print ( " ======= pinned the certs to Replicator ============ " )
303
- }
304
- if tlsAuthenticator != false {
305
- let clientCertData = try dataFromResource ( name: " identity/client " , ofType: " p12 " )
306
- try ! TLSIdentity . deleteIdentity ( withLabel: " CBL-Cert " )
307
- let identity = try TLSIdentity . importIdentity ( withData: clientCertData, password: " 123 " , label: " CBL-Cert " )
308
- replicatorConfig. authenticator = ClientCertificateAuthenticator ( identity: identity)
309
- print ( " ====== Added Autheticator to Replicator ======== " )
310
- }
311
-
312
- if continuous != nil {
313
- replicatorConfig. continuous = continuous!
314
- }
315
281
if documentIDs != nil {
316
- replicatorConfig . documentIDs = documentIDs
282
+ colConfig . documentIDs = documentIDs
317
283
}
318
284
if pull_filter != false {
319
285
if filter_callback_func == " boolean " {
320
- replicatorConfig . pullFilter = _replicatorBooleanFilterCallback;
286
+ colConfig . pullFilter = _replicatorBooleanFilterCallback;
321
287
} else if filter_callback_func == " deleted " {
322
- replicatorConfig . pullFilter = _replicatorDeletedFilterCallback;
288
+ colConfig . pullFilter = _replicatorDeletedFilterCallback;
323
289
} else if filter_callback_func == " access_revoked " {
324
- replicatorConfig . pullFilter = _replicatorAccessRevokedCallback;
290
+ colConfig . pullFilter = _replicatorAccessRevokedCallback;
325
291
} else {
326
- replicatorConfig . pullFilter = _defaultReplicatorFilterCallback;
292
+ colConfig . pullFilter = _defaultReplicatorFilterCallback;
327
293
}
328
294
}
329
295
if push_filter != false {
330
296
if filter_callback_func == " boolean " {
331
- replicatorConfig . pushFilter = _replicatorBooleanFilterCallback;
297
+ colConfig . pushFilter = _replicatorBooleanFilterCallback;
332
298
} else if filter_callback_func == " deleted " {
333
- replicatorConfig . pushFilter = _replicatorDeletedFilterCallback;
299
+ colConfig . pushFilter = _replicatorDeletedFilterCallback;
334
300
} else if filter_callback_func == " access_revoked " {
335
- replicatorConfig . pushFilter = _replicatorAccessRevokedCallback;
301
+ colConfig . pushFilter = _replicatorAccessRevokedCallback;
336
302
} else {
337
- replicatorConfig . pushFilter = _defaultReplicatorFilterCallback;
303
+ colConfig . pushFilter = _defaultReplicatorFilterCallback;
338
304
}
339
305
}
340
306
switch conflict_resolver {
341
307
case " local_wins " :
342
- replicatorConfig . conflictResolver = LocalWinCustomConflictResolver ( ) ;
308
+ colConfig . conflictResolver = LocalWinCustomConflictResolver ( ) ;
343
309
break
344
310
case " remote_wins " :
345
- replicatorConfig . conflictResolver = RemoteWinCustomConflictResolver ( ) ;
311
+ colConfig . conflictResolver = RemoteWinCustomConflictResolver ( ) ;
346
312
break ;
347
313
case " null " :
348
- replicatorConfig . conflictResolver = NullWinCustomConflictResolver ( ) ;
314
+ colConfig . conflictResolver = NullWinCustomConflictResolver ( ) ;
349
315
break ;
350
316
case " merge " :
351
- replicatorConfig . conflictResolver = MergeWinCustomConflictResolver ( ) ;
317
+ colConfig . conflictResolver = MergeWinCustomConflictResolver ( ) ;
352
318
break ;
353
319
case " incorrect_doc_id " :
354
- replicatorConfig . conflictResolver = IncorrectDocIdCustomConflictResolver ( ) ;
320
+ colConfig . conflictResolver = IncorrectDocIdCustomConflictResolver ( ) ;
355
321
break ;
356
322
case " delayed_local_win " :
357
- replicatorConfig . conflictResolver = DelayedLocalWinCustomConflictResolver ( ) ;
323
+ colConfig . conflictResolver = DelayedLocalWinCustomConflictResolver ( ) ;
358
324
break ;
359
325
case " exception_thrown " :
360
- replicatorConfig . conflictResolver = ExceptionThrownCustomConflictResolver ( ) ;
326
+ colConfig . conflictResolver = ExceptionThrownCustomConflictResolver ( ) ;
361
327
break ;
362
328
default :
363
- replicatorConfig . conflictResolver = ConflictResolver . default
329
+ colConfig . conflictResolver = ConflictResolver . default
364
330
break ;
365
331
}
332
+
333
+ let url = URL ( string: " \( wsPort ?? " ws " ) :// \( host) : \( port) / \( serverDBName) " ) !
334
+ if endPointType == " URLEndPoint " {
335
+ let urlEndPoint : URLEndpoint = URLEndpoint ( url: url)
336
+ replicatorConfig = ReplicatorConfiguration ( collections: [ colConfig] , target: urlEndPoint)
337
+ }
338
+ else {
339
+ let endpoint = MessageEndpoint ( uid: url. absoluteString, target: url, protocolType: ProtocolType . byteStream, delegate: self )
340
+ replicatorConfig = ReplicatorConfiguration ( collections: [ colConfig] , target: endpoint)
341
+ }
342
+
343
+ if auth != nil {
344
+ replicatorConfig. authenticator = auth
345
+ }
346
+ if serverVerificationMode != false {
347
+ replicatorConfig. acceptOnlySelfSignedServerCertificate = true
348
+ }
349
+
350
+ if tlsAuthType == " self_signed " {
351
+ let certData = try ! dataFromResource ( name: " identity/certs " , ofType: " p12 " )
352
+ try ! TLSIdentity . deleteIdentity ( withLabel: " CBL-Cert " )
353
+ let identity = try ! TLSIdentity . importIdentity ( withData: certData, password: " 123 " , label: " CBL-Cert " )
354
+ replicatorConfig. pinnedServerCertificate = identity. certs [ 0 ]
355
+ print ( " ======= pinned the certs to Replicator ============ " )
356
+ }
357
+ if tlsAuthenticator != false {
358
+ let clientCertData = try dataFromResource ( name: " identity/client " , ofType: " p12 " )
359
+ try ! TLSIdentity . deleteIdentity ( withLabel: " CBL-Cert " )
360
+ let identity = try TLSIdentity . importIdentity ( withData: clientCertData, password: " 123 " , label: " CBL-Cert " )
361
+ replicatorConfig. authenticator = ClientCertificateAuthenticator ( identity: identity)
362
+ print ( " ====== Added Autheticator to Replicator ======== " )
363
+ }
364
+
365
+ if continuous != nil {
366
+ replicatorConfig. continuous = continuous!
367
+ }
366
368
if let heartbeat = heartbeat, let heartbeatDouble = Double ( heartbeat) {
367
369
replicatorConfig. heartbeat = heartbeatDouble
368
370
}
@@ -391,7 +393,7 @@ public class PeerToPeerRequestHandler {
391
393
case " peerToPeer_removeReplicatorEventListener " :
392
394
let replication_obj : Replicator = args. get ( name: " replicator " ) !
393
395
let changeListener : MyDocumentReplicationListener = ( args. get ( name: " changeListener " ) ) !
394
- replication_obj . removeChangeListener ( withToken : changeListener. listenerToken!)
396
+ changeListener. listenerToken!. remove ( )
395
397
396
398
case " peerToPeer_replicatorEventChangesCount " :
397
399
let changeListener : MyDocumentReplicationListener = ( args. get ( name: " changeListener " ) ) !
@@ -415,6 +417,9 @@ public class PeerToPeerRequestHandler {
415
417
default :
416
418
throw RequestHandlerError . MethodNotFound ( method)
417
419
}
420
+
421
+ return PeerToPeerRequestHandler . VOID
422
+
418
423
}
419
424
}
420
425
#if COUCHBASE_ENTERPRISE
0 commit comments