aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient/private
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2016-10-28 12:09:59 -0700
committerGravatar Muxi Yan <mxyan@google.com>2016-10-28 12:16:54 -0700
commit61274cac9053878155dc0f00e85e1f5daa4fcfae (patch)
tree0a989f30c0b1e22aa0e7faabd0560eea0aa35c2e /src/objective-c/GRPCClient/private
parent2c88b4616a3a59ed82eadd3b5506fabfc61456b5 (diff)
Revert format changes in related files
Diffstat (limited to 'src/objective-c/GRPCClient/private')
-rw-r--r--src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h15
-rw-r--r--src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m68
-rw-r--r--src/objective-c/GRPCClient/private/GRPCHost.m81
3 files changed, 68 insertions, 96 deletions
diff --git a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h
index 941b596d2c..54eaa271c0 100644
--- a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h
+++ b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.h
@@ -45,7 +45,7 @@
*/
#define GRPC_XMACRO_ITEM(methodName, FlagName) \
- @property(nonatomic, readonly) BOOL methodName;
+@property(nonatomic, readonly) BOOL methodName;
#include "GRPCReachabilityFlagNames.xmacro.h"
#undef GRPC_XMACRO_ITEM
@@ -60,18 +60,17 @@
- (nonnull instancetype)init NS_UNAVAILABLE;
/**
- * Queue on which callbacks will be dispatched. Default is the main queue. Set
- * it before calling handleLossWithHandler:.
+ * Queue on which callbacks will be dispatched. Default is the main queue. Set it before calling
+ * handleLossWithHandler:.
*/
// TODO(jcanizales): Default to a serial background queue instead.
@property(nonatomic, strong, null_resettable) dispatch_queue_t queue;
/**
- * Calls handler every time the connectivity to this instance's host is lost. If
- * this instance is released before that happens, the handler won't be called.
- * Only one handler is active at a time, so if this method is called again
- * before the previous handler has been called, it might never be called at all
- * (or yes, if it has already been queued).
+ * Calls handler every time the connectivity to this instance's host is lost. If this instance is
+ * released before that happens, the handler won't be called.
+ * Only one handler is active at a time, so if this method is called again before the previous
+ * handler has been called, it might never be called at all (or yes, if it has already been queued).
*/
- (void)handleLossWithHandler:(nonnull void (^)())handler
wifiStatusChangeHandler:(nonnull void (^)())wifiStatusChangeHandler;
diff --git a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m
index fec6391d39..9cc53797ff 100644
--- a/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m
+++ b/src/objective-c/GRPCClient/private/GRPCConnectivityMonitor.m
@@ -58,20 +58,19 @@
}
*/
-#define GRPC_XMACRO_ITEM(methodName, FlagName) \
- -(BOOL)methodName { \
- return !!(_flags & kSCNetworkReachabilityFlags##FlagName); \
- }
+#define GRPC_XMACRO_ITEM(methodName, FlagName) \
+- (BOOL)methodName { \
+ return !!(_flags & kSCNetworkReachabilityFlags ## FlagName); \
+}
#include "GRPCReachabilityFlagNames.xmacro.h"
#undef GRPC_XMACRO_ITEM
- (BOOL)isHostReachable {
- // Note: connectionOnDemand means it'll be reachable only if using the
- // CFSocketStream API or APIs on top of it.
- // connectionRequired means we can't tell until a connection is attempted
- // (e.g. for VPN on demand).
- return self.reachable && !self.interventionRequired &&
- !self.connectionOnDemand;
+ // Note: connectionOnDemand means it'll be reachable only if using the CFSocketStream API or APIs
+ // on top of it.
+ // connectionRequired means we can't tell until a connection is attempted (e.g. for VPN on
+ // demand).
+ return self.reachable && !self.interventionRequired && !self.connectionOnDemand;
}
- (NSString *)description {
@@ -80,9 +79,9 @@
/*
* For each flag, add its name to the array if it's ON. Example:
- if (self.isCell) {
- [activeOptions addObject:@"isCell"];
- }
+ if (self.isCell) {
+ [activeOptions addObject:@"isCell"];
+ }
*/
#define GRPC_XMACRO_ITEM(methodName, FlagName) \
@@ -92,14 +91,12 @@
#include "GRPCReachabilityFlagNames.xmacro.h"
#undef GRPC_XMACRO_ITEM
- return activeOptions.count == 0
- ? @"(none)"
- : [activeOptions componentsJoinedByString:@", "];
+ return activeOptions.count == 0 ? @"(none)" : [activeOptions componentsJoinedByString:@", "];
}
- (BOOL)isEqual:(id)object {
return [object isKindOfClass:[GRPCReachabilityFlags class]] &&
- _flags == ((GRPCReachabilityFlags *)object)->_flags;
+ _flags == ((GRPCReachabilityFlags *)object)->_flags;
}
- (NSUInteger)hash {
@@ -109,16 +106,15 @@
#pragma mark Connectivity Monitor
-// Assumes the third argument is a block that accepts a GRPCReachabilityFlags
-// object, and passes the received ones to it.
+// Assumes the third argument is a block that accepts a GRPCReachabilityFlags object, and passes the
+// received ones to it.
static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
SCNetworkReachabilityFlags flags,
void *info) {
-#pragma unused(target)
- // This can be called many times with the same info. The info is retained by
- // SCNetworkReachability while this function is being executed.
- void (^handler)(GRPCReachabilityFlags *) =
- (__bridge void (^)(GRPCReachabilityFlags *))info;
+ #pragma unused (target)
+ // This can be called many times with the same info. The info is retained by SCNetworkReachability
+ // while this function is being executed.
+ void (^handler)(GRPCReachabilityFlags *) = (__bridge void (^)(GRPCReachabilityFlags *))info;
handler([[GRPCReachabilityFlags alloc] initWithFlags:flags]);
}
@@ -127,8 +123,7 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
GRPCReachabilityFlags *_previousReachabilityFlags;
}
-- (nullable instancetype)initWithReachability:
- (nullable SCNetworkReachabilityRef)reachability {
+- (nullable instancetype)initWithReachability:(nullable SCNetworkReachabilityRef)reachability {
if (!reachability) {
return nil;
}
@@ -149,8 +144,7 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
SCNetworkReachabilityRef reachability =
SCNetworkReachabilityCreateWithName(NULL, hostName);
- GRPCConnectivityMonitor *returnValue =
- [[self alloc] initWithReachability:reachability];
+ GRPCConnectivityMonitor *returnValue = [[self alloc] initWithReachability:reachability];
if (reachability) {
CFRelease(reachability);
}
@@ -176,19 +170,17 @@ static void PassFlagsToContextInfoBlock(SCNetworkReachabilityRef target,
}
- (void)startListeningWithHandler:(void (^)(GRPCReachabilityFlags *))handler {
- // Copy to ensure the handler block is in the heap (and so can't be
- // deallocated when this method returns).
+ // Copy to ensure the handler block is in the heap (and so can't be deallocated when this method
+ // returns).
void (^copiedHandler)(GRPCReachabilityFlags *) = [handler copy];
SCNetworkReachabilityContext context = {
- .version = 0,
- .info = (__bridge void *)copiedHandler,
- .retain = CFRetain,
- .release = CFRelease,
+ .version = 0,
+ .info = (__bridge void *)copiedHandler,
+ .retain = CFRetain,
+ .release = CFRelease,
};
- // The following will retain context.info, and release it when the callback is
- // set to NULL.
- SCNetworkReachabilitySetCallback(_reachabilityRef,
- PassFlagsToContextInfoBlock, &context);
+ // The following will retain context.info, and release it when the callback is set to NULL.
+ SCNetworkReachabilitySetCallback(_reachabilityRef, PassFlagsToContextInfoBlock, &context);
SCNetworkReachabilitySetDispatchQueue(_reachabilityRef, _queue);
}
diff --git a/src/objective-c/GRPCClient/private/GRPCHost.m b/src/objective-c/GRPCClient/private/GRPCHost.m
index 0524472f53..3f9b024eaa 100644
--- a/src/objective-c/GRPCClient/private/GRPCHost.m
+++ b/src/objective-c/GRPCClient/private/GRPCHost.m
@@ -33,9 +33,9 @@
#import "GRPCHost.h"
-#import <GRPCClient/GRPCCall.h>
#include <grpc/grpc.h>
#include <grpc/grpc_security.h>
+#import <GRPCClient/GRPCCall.h>
#ifdef GRPC_COMPILE_WITH_CRONET
#import <GRPCClient/GRPCCall+ChannelArg.h>
#import <GRPCClient/GRPCCall+Cronet.h>
@@ -48,8 +48,7 @@
NS_ASSUME_NONNULL_BEGIN
-// TODO(jcanizales): Generate the version in a standalone header, from
-// templates. Like
+// TODO(jcanizales): Generate the version in a standalone header, from templates. Like
// templates/src/core/surface/version.c.template .
#define GRPC_OBJC_VERSION_STRING @"1.0.0"
@@ -62,8 +61,7 @@ static NSMutableDictionary *kHostCache;
static GRPCConnectivityMonitor *connectivityMonitor = nil;
@implementation GRPCHost {
- // TODO(mlumish): Investigate whether caching channels with strong links is a
- // good idea.
+ // TODO(mlumish): Investigate whether caching channels with strong links is a good idea.
GRPCChannel *_channel;
}
@@ -83,13 +81,11 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
return nil;
}
- // To provide a default port, we try to interpret the address. If it's just a
- // host name without scheme and without port, we'll use port 443. If it has a
- // scheme, we pass it untouched to the C gRPC library.
- // TODO(jcanizales): Add unit tests for the types of addresses we want to let
- // pass untouched.
- NSURL *hostURL =
- [NSURL URLWithString:[@"https://" stringByAppendingString:address]];
+ // To provide a default port, we try to interpret the address. If it's just a host name without
+ // scheme and without port, we'll use port 443. If it has a scheme, we pass it untouched to the C
+ // gRPC library.
+ // TODO(jcanizales): Add unit tests for the types of addresses we want to let pass untouched.
+ NSURL *hostURL = [NSURL URLWithString:[@"https://" stringByAppendingString:address]];
if (hostURL.host && !hostURL.port) {
address = [hostURL.host stringByAppendingString:@":443"];
}
@@ -99,7 +95,6 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
dispatch_once(&cacheInitialization, ^{
kHostCache = [NSMutableDictionary dictionary];
});
-
@synchronized(kHostCache) {
GRPCHost *cachedHost = kHostCache[address];
if (cachedHost) {
@@ -137,7 +132,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
}
+ (void)resetAllHostSettings {
- @synchronized(kHostCache) {
+ @synchronized (kHostCache) {
kHostCache = [NSMutableDictionary dictionary];
}
}
@@ -163,19 +158,16 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
static NSError *kDefaultRootsError;
static dispatch_once_t loading;
dispatch_once(&loading, ^{
- NSString *defaultPath = @"gRPCCertificates.bundle/roots"; // .pem
- // Do not use NSBundle.mainBundle, as it's nil for tests of library
- // projects.
+ NSString *defaultPath = @"gRPCCertificates.bundle/roots"; // .pem
+ // Do not use NSBundle.mainBundle, as it's nil for tests of library projects.
NSBundle *bundle = [NSBundle bundleForClass:self.class];
NSString *path = [bundle pathForResource:defaultPath ofType:@"pem"];
NSError *error;
- // Files in PEM format can have non-ASCII characters in their comments (e.g.
- // for the name of the issuer). Load them as UTF8 and produce an ASCII
- // equivalent.
- NSString *contentInUTF8 =
- [NSString stringWithContentsOfFile:path
- encoding:NSUTF8StringEncoding
- error:&error];
+ // Files in PEM format can have non-ASCII characters in their comments (e.g. for the name of the
+ // issuer). Load them as UTF8 and produce an ASCII equivalent.
+ NSString *contentInUTF8 = [NSString stringWithContentsOfFile:path
+ encoding:NSUTF8StringEncoding
+ error:&error];
if (contentInUTF8 == nil) {
kDefaultRootsError = error;
return;
@@ -193,15 +185,11 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
if (errorPtr) {
*errorPtr = kDefaultRootsError;
}
- NSAssert(kDefaultRootsASCII,
- @"Could not read gRPCCertificates.bundle/roots.pem. This file, "
- "with the root certificates, is needed to establish secure "
- "(TLS) connections. "
- "Because the file is distributed with the gRPC library, this "
- "error is usually a sign "
- "that the library wasn't configured correctly for your "
- "project. Error: %@",
- kDefaultRootsError);
+ NSAssert(kDefaultRootsASCII, @"Could not read gRPCCertificates.bundle/roots.pem. This file, "
+ "with the root certificates, is needed to establish secure (TLS) connections. "
+ "Because the file is distributed with the gRPC library, this error is usually a sign "
+ "that the library wasn't configured correctly for your project. Error: %@",
+ kDefaultRootsError);
return NO;
}
rootsASCII = kDefaultRootsASCII;
@@ -212,12 +200,10 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
creds = grpc_ssl_credentials_create(rootsASCII.bytes, NULL, NULL);
} else {
grpc_ssl_pem_key_cert_pair key_cert_pair;
- NSData *privateKeyASCII =
- [pemPrivateKey dataUsingEncoding:NSASCIIStringEncoding
- allowLossyConversion:YES];
- NSData *certChainASCII =
- [pemCertChain dataUsingEncoding:NSASCIIStringEncoding
- allowLossyConversion:YES];
+ NSData *privateKeyASCII = [pemPrivateKey dataUsingEncoding:NSASCIIStringEncoding
+ allowLossyConversion:YES];
+ NSData *certChainASCII = [pemCertChain dataUsingEncoding:NSASCIIStringEncoding
+ allowLossyConversion:YES];
key_cert_pair.private_key = privateKeyASCII.bytes;
key_cert_pair.cert_chain = certChainASCII.bytes;
creds = grpc_ssl_credentials_create(rootsASCII.bytes, &key_cert_pair, NULL);
@@ -237,8 +223,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
NSMutableDictionary *args = [NSMutableDictionary dictionary];
// TODO(jcanizales): Add OS and device information (see
- // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#user-agents
- // ).
+ // https://github.com/grpc/grpc/blob/master/doc/PROTOCOL-HTTP2.md#user-agents ).
NSString *userAgent = @"grpc-objc/" GRPC_OBJC_VERSION_STRING;
if (_userAgentPrefix) {
userAgent = [_userAgentPrefix stringByAppendingFormat:@" %@", userAgent];
@@ -252,7 +237,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
if (_responseSizeLimitOverride) {
args[@GRPC_ARG_MAX_RECEIVE_MESSAGE_LENGTH] = _responseSizeLimitOverride;
}
- // Use 10000ms initial backoff time for correct behavior on bad/slow networks
+ // Use 10000ms initial backoff time for correct behavior on bad/slow networks
args[@GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS] = @10000;
return args;
}
@@ -266,15 +251,12 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
GRPCChannel *channel;
@synchronized(self) {
if (_channelCreds == nil) {
- [self setTLSPEMRootCerts:nil
- withPrivateKey:nil
- withCertChain:nil
- error:nil];
+ [self setTLSPEMRootCerts:nil withPrivateKey:nil withCertChain:nil error:nil];
}
#ifdef GRPC_COMPILE_WITH_CRONET
if (useCronet) {
- channel =
- [GRPCChannel secureCronetChannelWithHost:_address channelArgs:args];
+ channel = [GRPCChannel secureCronetChannelWithHost:_address
+ channelArgs:args];
} else
#endif
{
@@ -290,8 +272,7 @@ static GRPCConnectivityMonitor *connectivityMonitor = nil;
}
- (NSString *)hostName {
- // TODO(jcanizales): Default to nil instead of _address when Issue #2635 is
- // clarified.
+ // TODO(jcanizales): Default to nil instead of _address when Issue #2635 is clarified.
return _hostNameOverride ?: _address;
}