Browse files

Don't do reachability checks on replication to a local touchdb: URL.

Fixes #228
  • Loading branch information...
1 parent f765301 commit 75b9cebd6320bca64946b1beeb91fdf22f20a811 @snej snej committed Jan 24, 2013
Showing with 30 additions and 17 deletions.
  1. +2 −1 Source/TDReplicator.h
  2. +16 −11 Source/TDReplicator.m
  3. +3 −0 Source/TDURLProtocol.h
  4. +9 −5 Source/TDURLProtocol.m
View
3 Source/TDReplicator.h
@@ -26,7 +26,6 @@ extern NSString* TDReplicatorStoppedNotification;
NSThread* _thread;
TD_Database* __weak _db;
NSURL* _remote;
- TDReachability* _host;
BOOL _continuous;
NSString* _filterName;
NSDictionary* _filterParameters;
@@ -46,6 +45,8 @@ extern NSString* TDReplicatorStoppedNotification;
id<TDAuthorizer> _authorizer;
NSDictionary* _options;
NSDictionary* _requestHeaders;
+ @private
+ TDReachability* _host;
}
+ (NSString *)progressChangedNotification;
View
27 Source/TDReplicator.m
@@ -21,6 +21,7 @@
#import "TDAuthorizer.h"
#import "TDBatcher.h"
#import "TDReachability.h"
+#import "TDURLProtocol.h"
#import "TDInternal.h"
#import "TDMisc.h"
#import "TDBase64.h"
@@ -239,18 +240,22 @@ - (void) start {
object: nil];
#endif
- // Start reachability checks. (This creates another ref cycle, because
- // the block also retains a ref to self. Cycle is also broken in -stopped.)
_online = NO;
- _host = [[TDReachability alloc] initWithHostName: _remote.host];
-
- __weak id weakSelf = self;
- _host.onChange = ^{
- TDReplicator *strongSelf = weakSelf;
- [strongSelf reachabilityChanged:strongSelf->_host];
- };
- [_host start];
- [self reachabilityChanged: _host];
+ if ([TDURLProtocol handlesURL: _remote]) {
+ [self goOnline]; // local-to-local replication
+ } else {
+ // Start reachability checks. (This creates another ref cycle, because
+ // the block also retains a ref to self. Cycle is also broken in -stopped.)
+ _host = [[TDReachability alloc] initWithHostName: _remote.host];
+
+ __weak id weakSelf = self;
+ _host.onChange = ^{
+ TDReplicator *strongSelf = weakSelf;
+ [strongSelf reachabilityChanged:strongSelf->_host];
+ };
+ [_host start];
+ [self reachabilityChanged: _host];
+ }
}
View
3 Source/TDURLProtocol.h
@@ -43,4 +43,7 @@
/** Returns the server registered with the hostname "localhost". */
+ (TD_Server*) server;
+/** Returns YES if TDURLProtocol will handle this URL. */
++ (BOOL) handlesURL: (NSURL*)url;
+
@end
View
14 Source/TDURLProtocol.m
@@ -134,18 +134,22 @@ + (NSURL*) HTTPURLForServerURL: (NSURL*)serverURL {
}
-#pragma mark - INITIALIZATION:
-
-
-+ (BOOL)canInitWithRequest:(NSURLRequest *)request {
- NSURL* url = request.URL;
++ (BOOL) handlesURL: (NSURL*)url {
if ([url.scheme caseInsensitiveCompare: kScheme] == 0)
return YES;
else
return [self serverForURL: url] != nil;
}
+#pragma mark - INITIALIZATION:
+
+
++ (BOOL)canInitWithRequest:(NSURLRequest *)request {
+ return [self handlesURL: request.URL];
+}
+
+
+ (NSURLRequest*) canonicalRequestForRequest: (NSURLRequest*)request {
return request;
}

0 comments on commit 75b9ceb

Please sign in to comment.