Problem setting up CBL P2P replication test

363 views
Skip to first unread message

Andrew Reslan

unread,
Feb 20, 2013, 1:25:11 PM2/20/13
to mobile-c...@googlegroups.com
Hi

I'm trying to setup a simple P2P replication test between devices on the same WiFi network, bonjour is working, the listener appears to be working and replication starts but no files are replicated via P2P.

P2P replication is between and iPhone (console logs) and an iPad.

Here are the P2P code sections and console logs.

Listener start

    //Start the HTTP server and publish a bonjour service

    CBLManager* manager = [CBLManager sharedInstance];

    CBLListener *_listener = [[CBLListener alloc] initWithManager: manager port: 0];

    _listener.readOnly = YES// Do this to prevent writes to your databases

    _listener.passwords = @{@"naomi": @"letmein"};

    [_listener setBonjourName: [UUID generateUUID] type: @"_myservice._tcp"];

    BOOL ok = [_listener start];


Bonjour browser start

    //start bonjour client to listen for peers

    serviceBrowser = [[NSNetServiceBrowser alloc] init];

    [serviceBrowser setDelegate:self];

    [serviceBrowser searchForServicesOfType:@"_myservice._tcp" inDomain:@""];



Continuous Pull replication creation on service resolution


    NSString *peerDB = [NSString stringWithFormat:@"http://%@:%@@%@:%d/mydb/",@"naomi",@"letmein",netService.hostName,netService.port];

    NSURL *peerURL = [NSURL URLWithString:peerDB];

 

    CBLReplication *syncPullRepl = [self.database pullFromURL:peerURL];


    syncPullRepl.continuous = YES;

    syncPullRepl.persistent = NO;

    

    [syncPullRepl start];


Pointing Safari on my Mac on the same wifi network at the constructed URL


http://naomi:let...@myipad.local.:53548/mydb


gives


{
  "doc_count" : 52,
  "db_name" : "mydb",
  "disk_size" : 28096002,
  "update_seq" : 66,
  "db_uuid" : "BD3FD33F-1E8C-4459-864E-2F14DD479258"
}

Console log


17:58:35.582| Sync: CBL_Puller[http://naomi:let...@myipad.local.:53563/mydb/] STARTING ...
17:58:35.583| CBLBasicAuthorizer initWith <http://naomi:letmein@myipad.local.:53563/mydb/>
17:58:35.600| Sync: CBL_Puller[http://naomi:letmein@myipad.local.:53563/mydb/]: Reachability state = <myipad.local.>:reachable (20002)
17:58:35.601| Sync: CBL_Puller[http://naomi:letmein@myipad.local.:53563/mydb/]: Going online
17:58:35.969| Sync: CBL_Puller[http://naomi:letmein@myipad.local.:53563/mydb/]: Replicating from lastSequence=(null)
17:58:50.426|  WARNING*** : CBLSocketChangeTracker[0x1edd6bd0 mydb]: Can't connect, giving up: Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)"
17:58:50.431| Sync: CBL_Puller[http://naomi:letmein@myipad.local.:53563/mydb/]: ChangeTracker stopped; error=Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)"


I can't find the meaning of error 1005, not sure how to debug this through.

Andy



Jens Alfke

unread,
Feb 20, 2013, 3:54:40 PM2/20/13
to mobile-c...@googlegroups.com

On Feb 20, 2013, at 10:25 AM, Andrew Reslan <andrew...@mac.com> wrote:

> 17:58:50.431| Sync: CBL_Puller[http://naomi:let...@myipad.local.:53563/mydb/]: ChangeTracker stopped; error=Error Domain=NSURLErrorDomain Code=-1005 "The operation couldn’t be completed. (NSURLErrorDomain error -1005.)"
>
> I can't find the meaning of error 1005, not sure how to debug this through.

If you look up the symbol NSURLErrorDomain, it’s declared in <Foundation/NSURLError.h>, which also defines the error codes. They’re defined in terms of corresponding CF error codes, so you have to go to <CFNetwork/CFNetworkErrors.h> to find the numeric codes. There you find:
kCFURLErrorNetworkConnectionLost = -1005,
So this means the remote peer unexpectedly closed the socket. This usually means something went wrong on the remote peer — have you checked the logs on the iPad to see if it threw any exceptions or logged errors?

—Jens

Andrew Reslan

unread,
Feb 20, 2013, 5:52:27 PM2/20/13
to mobile-c...@googlegroups.com
Jens

Hi, thanks for the pointer to CFNetworkError.h.

There are no erros or stack traces on the iPad.

I have enabled CBLListener logging, if there are any other logging modules that would be useful to enable please let me know.

This is what I get from CBLListener on iPad:

22:44:46.283| CBLListener: Login attempted for user 'naomi'

22:44:46.284| CBLListener: GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124

22:44:46.285| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124]: Starting...

22:44:46.286| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124]: Returning from -init

22:44:46.288| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] answers delayResponseHeaders=1

22:44:46.293| CBLListener:     Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] --> 404

22:44:46.293| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] adding 34 bytes

22:44:46.293| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] Finished!

22:44:46.293| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] prettifying response body

22:44:46.294| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] answers delayResponseHeaders=0

22:44:46.294| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] answers isChunked=0

22:44:46.295| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] answers status=404

22:44:46.295| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] answers httpHeaders={2 headers}

22:44:46.295| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] sending 46 bytes

22:44:46.296| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] answers isDone=1

22:44:46.296| CBLListenerVerbose: Response[GET /mydb/_local/0dfd3196fdb264858e5024f18e9523ec652d2124] sending nil bytes


Would the 404 response manifest as the CBLSocketChangeTracker error on the client side?


I know there is an issue against CBL _local document access but I thought this was provided by the REST API (CBLListener?)


Andy

Jens Alfke

unread,
Feb 20, 2013, 7:02:13 PM2/20/13
to mobile-c...@googlegroups.com

On Feb 20, 2013, at 2:52 PM, Andrew Reslan <andrew...@mac.com> wrote:

> Would the 404 response manifest as the CBLSocketChangeTracker error on the client side?

No; kCFURLErrorNetworkConnectionLost comes from the connection closing before any response is sent.

Also, the change tracker only accesses the _changes feed, so the relevant URL path would be like "/mydb/_changes?……”

—Jens

Andrew Reslan

unread,
Feb 20, 2013, 7:34:30 PM2/20/13
to mobile-c...@googlegroups.com
Jens

Hi, I removed the credentials from both the server and client sides of the test, I now get an exception thrown on the device acting as the server and the App crashes. But I am not sure if this is the original issue.

Andy

Last Exception Backtrace:

0   CoreFoundation                0x3257129e __exceptionPreprocess + 158

1   libobjc.A.dylib               0x3925397a objc_exception_throw + 26

2   CoreFoundation                0x325711c0 +[NSException raise:format:] + 100

3   Foundation                    0x38c17a98 _writeJSONValue + 644

4   Foundation                    0x38c19672 ___writeJSONArray_block_invoke_0 + 102

5   CoreFoundation                0x3256599c __NSArrayEnumerate + 392

6   CoreFoundation                0x324c7b66 -[NSArray enumerateObjectsWithOptions:usingBlock:] + 58

7   Foundation                    0x38c195b4 _writeJSONArray + 232

8   Foundation                    0x38c17a28 _writeJSONValue + 532

9   Foundation                    0x38c19776 ___writeJSONObject_block_invoke_0 + 230

10  CoreFoundation                0x3256e62a __NSDictionaryEnumerate + 710

11  Foundation                    0x38c193f8 _writeJSONObject + 508

12  Foundation                    0x38c179f4 _writeJSONValue + 480

13  Foundation                    0x38c177de -[_NSJSONWriter dataWithRootObject:options:error:] + 122

14  Foundation                    0x38c186d4 +[NSJSONSerialization dataWithJSONObject:options:error:] + 332

15  meyumeapp                     0x001bcbb8 +[CBLJSON dataWithJSONObject:options:error:] (CBLJSON.m:43)

16  meyumeapp                     0x00185f94 -[CBL_Body asJSON] (CBL_Body.m:72)

17  meyumeapp                     0x00226892 -[CBL_Router sendResponseBodyAndFinish:] (CBL_Router.m:536)

18  meyumeapp                     0x00225804 -[CBL_Router run] (CBL_Router.m:415)

19  meyumeapp                     0x00226f1c __19-[CBL_Router start]_block_invoke_0 (CBL_Router.m:583)

20  meyumeapp                     0x0018a7ce __34-[CBL_Server tellDatabaseManager:]_block_invoke_0 (CBL_Server.m:154)

21  meyumeapp                     0x001e552c -[NSObject(MYBlockUtils) my_run_as_block] (MYBlockUtils.m:22)

22  Foundation                    0x38bc58e8 __NSThreadPerformPerform + 456

23  CoreFoundation                0x3254667e __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 10

24  CoreFoundation                0x32545ee4 __CFRunLoopDoSources0 + 208

25  CoreFoundation                0x32544cb2 __CFRunLoopRun + 642

26  CoreFoundation                0x324b7eb8 CFRunLoopRunSpecific + 352

27  CoreFoundation                0x324b7d44 CFRunLoopRunInMode + 100

28  Foundation                    0x38b1878a -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 250

29  meyumeapp                     0x0018a420 -[CBL_Server runServerThread] (CBL_Server.m:130)

30  Foundation                    0x38bc5678 __NSThread__main__ + 968

31  libsystem_c.dylib             0x391d430c _pthread_start + 304

32  libsystem_c.dylib             0x391d41d4 thread_start + 4

Jens Alfke

unread,
Feb 20, 2013, 9:56:33 PM2/20/13
to mobile-c...@googlegroups.com

On Feb 20, 2013, at 4:34 PM, Andrew Reslan <andrew...@mac.com> wrote:

Hi, I removed the credentials from both the server and client sides of the test, I now get an exception thrown on the device acting as the server and the App crashes.

This is a regression I fixed last week (commit 95d22e0). Update your Couchbase Lite sources and it should go away.

—Jens

Andrew Reslan

unread,
Feb 24, 2013, 1:39:15 PM2/24/13
to mobile-c...@googlegroups.com
Jens

Hi, thanks I have pulled the latest CBL and the replications are now running without error, I am seeing some runtime issues which I'll create new posts for.

Andy 

Alex Lai

unread,
Feb 5, 2015, 2:56:07 AM2/5/15
to mobile-c...@googlegroups.com
Hi, buddy. Do you still work on CBL P2P replication?  P2P replication really caught me sight and I am working on this. May I have your this program's source code? Thank you.

在 2013年2月25日星期一 UTC+9上午3:39:15,Andrew Reslan写道:

Jens Alfke

unread,
Feb 5, 2015, 11:20:12 AM2/5/15
to mobile-c...@googlegroups.com

On Feb 4, 2015, at 11:56 PM, Alex Lai <alex...@gmail.com> wrote:

Hi, buddy. Do you still work on CBL P2P replication?  P2P replication really caught me sight and I am working on this. May I have your this program's source code? Thank you.

We have an up-to-date P2P sample app called PhotoDrop.

—Jens

Yonah Forst

unread,
Jun 11, 2015, 12:43:12 PM6/11/15
to mobile-c...@googlegroups.com
Hi Andrew,

Were you ever able to re-enable credentials? I'm getting the exact same error (1005 on the client side and 404 on the CBLListener side). It works great when I disable the credentials...

Jens Alfke

unread,
Jun 11, 2015, 2:12:34 PM6/11/15
to mobile-c...@googlegroups.com

On Jun 11, 2015, at 9:43 AM, Yonah Forst <yonah...@gmail.com> wrote:

Were you ever able to re-enable credentials? I'm getting the exact same error (1005 on the client side and 404 on the CBLListener side). It works great when I disable the credentials...

You’re replying to a thread that’s over 2 years old, so whatever was described there is likely to be irrelevant now.

Could you start over and describe your problem?

—Jens

Brendan Duddridge

unread,
Jun 11, 2015, 3:09:00 PM6/11/15
to mobile-c...@googlegroups.com
Noticed the P2P PhotoDrop example doesn't compile for iOS 9 or Xcode 7. An objective-c example would be helpful too. I've dabbled in Swift, but not really fluent in it yet. 

Jens Alfke

unread,
Jun 11, 2015, 4:12:47 PM6/11/15
to mobile-c...@googlegroups.com

On Jun 11, 2015, at 12:09 PM, Brendan Duddridge <bren...@gmail.com> wrote:

Noticed the P2P PhotoDrop example doesn't compile for iOS 9 or Xcode 7. An objective-c example would be helpful too. I've dabbled in Swift, but not really fluent in it yet. 

Most Swift code will require fixup to compile in Swift 2. Did you let Xcode update the Swift syntax?

(Also note that you can Xcode 6.3 and Xcode 7 installed simultaneously, since they’re both just apps. I am switching back and forth between them, and probably will until Xcode 7 goes final.)

—Jens

Brendan Duddridge

unread,
Jun 11, 2015, 7:27:54 PM6/11/15
to mobile-c...@googlegroups.com
I've reverted to 6.3 for the P2P testing of the PhotoDrop app.  So it compiles just fine now.

I've not been able to get it to work though. After the QR code is scanned from my iPhone 6 to my iPhone 6+, I just eventually get a timeout error sometime after the listener has started:

CBLRemoteJSONRequest[GET https://iPhone-6-Plus.local:54734/db/_local/0253a83e5ef3796a22adea200a869db0106a2f5a]: Got error Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo=0x14ced6370 {NSUnderlyingError=0x14ced44b0 "The request timed out.", NSErrorFailingURLStringKey=https://iphone-6-plus.local:54734/db/_local/0253a83e5ef3796a22adea200a869db0106a2f5a, NSErrorFailingURLKey=https://iphone-6-plus.local:54734/db/_local/0253a83e5ef3796a22adea200a869db0106a2f5a, _kCFStreamErrorDomainKey=4, _kCFStreamErrorCodeKey=-2102, NSLocalizedDescription=The request timed out.}


I originally thought it was due to using http for the connection because iOS 9 doesn't allow that anymore, so I turned on self signed SSL connections. No problems there, but just nothing happening between the two devices and nothing obvious in the logs.

The last thing the listener displays is:

2015-06-11 17:19:13.093 PhotoDrop[525:322749] HTTPServer: Started HTTP server on port 54734



And then eventually the iPhone 6 displays in the log the timeout error and displays Sending Abort in the view.

Could it be an iOS 9 issue whereby it's not letting anything connect? Seems like it should be fine since it's a high port number. I'm on the same WiFi network on both devices.

Sorry for hijacking this thread, but I saw the comment on here and this seemed relevant to the discussion.


Thanks,

Brendan

Yonah Forst

unread,
Jun 14, 2015, 6:26:35 AM6/14/15
to mobile-c...@googlegroups.com
Hi Jens,

Sure, sorry about that.

I'm not able to replicate from a CBLListener with authentication turned on. Works great with authentication turned off.

CBLListener code:

self.listener = [[CBLListener alloc] initWithManager:[CBLManager sharedInstance] port:52021];

self.listener.requiresAuth = YES;

[self.listener setPasswords:@{[self authenticatorUsername] : [self authenticatorPassword]}];

[self.listener setBonjourName:[self myUUID] type: [self bonjourType]];

[self.listener start:&error]


Client code:

NSURL *serviceURL = [NSURL URLWithString:[NSString stringWithFormat:@"http://%@:%li", service.hostName, service.port]];

NSURL *databaseURL = [NSURL URLWithString:[[self database] name] relativeToURL:serviceURL];

NSURLComponents *components = [NSURLComponents componentsWithURL:databaseURL resolvingAgainstBaseURL:YES];

components.user = [self authenticatorUsername];

components.password = [self authenticatorPassword];

self.pullReplication = [[self database] createPullReplication:components.URL];

self.pullReplication.continuous = self.isContinuous;

self.pullReplication.customProperties = @{@"websocket": @NO};

self.pullReplication.filter = @"exceptUUIDAndMinUpdatedAt";

self.pullReplication.filterParams = @{@"exceptUUID": uuid, @"minUpdatedAt": [CBLJSON JSONObjectWithDate:minUpdatedAt]};


[self.pullReplication start];


Logs from the client here: https://gist.github.com/joshblour/59b76b2531dd0f2eb3b4

The error seems to happen on the CBLListener side: 

CBLListener: Login attempted for user 'p2p_v1'

CBLListener: GET /proximator/_local/e95ce455ab12e1261e4f6b592ee4cc8f478c8eaa

CBLListener:     Response[GET /proximator/_local/e95ce455ab12e1261e4f6b592ee4cc8f478c8eaa] --> 404



Reply all
Reply to author
Forward
0 new messages