Current, working example of peer to peer replication?

I’m working on a proof of concept for an app that requires peer to peer replication. I thought Couchbase Lite would be a great candidate for this. However, after working on this for a few days, I’m still unable to get it working with version 1.3. Here’s a summary of the issues I’ve run into:

  • The only sample code I could find for peer replication was the photo-drop app, which hasn’t been changed in more than a year and needs to be updated to work with 1.3. If peer to peer replication truly is a supported feature of this product, then why isn’t there an actively maintained sample app?

  • After getting CB Lite running in an iOS app w/out SSL for the moment, I ran into authentication problems using Basic Auth. I discovered that the CB listener has been updated to require digest authentication if SSL is not used, but this is apparently not documented anywhere. Why is the documentation not keeping up with the code?

  • I decided to go ahead and get SSL configured, since I’d want to use that in a production app anyway. However, I’m working in React Native, and the react-native-couchbase-lite package doesn’t provide for SSL configuration. I find that odd, since SSL would clearly be a requirement for a production app, so I assume this package is just a demo/example and not meant for production use. Anyway, I forked that package and added in SSL configuration support.

  • After getting setup with a self-signed SSL cert and disabling app transport security to disable trust verification, I got past the authentication problem, only to get a different network error:
    ‘Error return from CBL at’, ‘POST’, ‘https://localhost:5984/_replicate’, { type: ‘default’,
    status: 500,
    ok: false,
    statusText: undefined,
    { map:
    { ‘accept-ranges’: [ ‘bytes’ ],
    ‘content-length’: [ ‘130’ ],
    server: [ ‘CouchbaseLite 1.3.1 (build 6)’ ],
    ‘content-type’: [ ‘application/json’ ],
    date: [ ‘Tue, 25 Oct 2016 01:33:44 GMT’ ] } },
    url: ‘https://localhost:5984/_replicate’,
    _bodyInit: ‘{“reason”:“The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)”,“error”:“kCFErrorDomainCFNetwork -1005”}’,
    _bodyText: ‘{“reason”:“The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1005.)”,“error”:“kCFErrorDomainCFNetwork -1005”}’ }

At this point I question whether Couchbase Mobile actually supports peer to peer replication as a tested, proven, production-ready use case. Is anyone using P2P replication in production? Can anyone point me to sample code that shows P2P replication working on Couchbase Mobile 3.x?

P2P is not an off-the-shelf feature of Couchbase Lite. You can build a P2P system out of the components we’ve provided, but it’s not trivial. I would love for us to add the higher layers that would make it easy to deploy P2P, but we just haven’t had the time.

  • There is a branch of our Grocery-Sync sample app that demonstrates a simple working P2P system. I wrote it for last year’s Connect conference. The P2P code in it is separable from the app and should be useable in other apps, or at least you can look at it and rewrite it if you’re not using Swift.
  • Sorry about that; I’ve filed ticket to get the docs updated.
  • The React Native package is not an official supported product (that’s why it’s in couchbaselabs) although some Couchbase engineers are working on it. Their README doesn’t make this clear, and I’ve sent a request to clarify it.
  • Hm, kCFErrorDomainCFNetwork is defined in <CFNetwork/CFNetworkErrors.h>. -1005 is kCFURLErrorNetworkConnectionLost, i.e. the peer closed the socket unexpectedly. So look at the peer you were connecting to — it probably got an error and aborted the connection.

Yes, one of our biggest customers (a major airline) is using P2P for in-flight communication between flight attendants. But as I said before, it was not an off-the-shelf solution.

Thanks for your quick response, Jens. I’ll look at your Grocery-Sync sample to see what I can learn from it. I’ve gotten past the -1005 error, which was due to a bug in my code. Now I am facing a trust error with the self-signed certificate (setting NSAllowsArbitraryLoads allowed HTTP, but didn’t disable trust verification) and trying to figure out a solution to that.

The production deployment you describe is reassuring. I’ll keep plugging away for a bit and see where I get.

It turns out the error I’m getting is “Untrustworthy SSL certificate”, which is coming from CBLSocketChangeTracker after its attempt to check the SSL certificate fails. I’m looking into how/if I can get the certificate trusted by iOS for my app. Is there a way I can configure CB Lite to bypass
the trust check?

There’s a wiki page about SSL in the listener, which may be of use.

Yes, it was helpful. I changed my code to replicate using the host name I get from bonjour instead of the IP address and the “.local” in the name is bypassing trust evaluation. I’ve managed to get documents to replicate between two devices! Thanks much for your help.

1 Like