1 /* 2 * 3 * Copyright 2015 gRPC authors. 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 */ 18 19 #import <Foundation/Foundation.h> 20 21 #import <grpc/impl/codegen/compression_types.h> 22 23 NS_ASSUME_NONNULL_BEGIN 24 25 @class GRPCCompletionQueue; 26 struct grpc_call; 27 struct grpc_channel_credentials; 28 29 @interface GRPCHost : NSObject 30 31 + (void)flushChannelCache; 32 + (void)resetAllHostSettings; 33 34 @property(nonatomic, readonly) NSString *address; 35 @property(nonatomic, copy, nullable) NSString *userAgentPrefix; 36 @property(nonatomic, nullable) struct grpc_channel_credentials *channelCreds; 37 @property(nonatomic) grpc_compression_algorithm compressAlgorithm; 38 @property(nonatomic) int keepaliveInterval; 39 @property(nonatomic) int keepaliveTimeout; 40 @property(nonatomic) id logContext; 41 @property(nonatomic) BOOL retryEnabled; 42 43 @property(nonatomic) unsigned int minConnectTimeout; 44 @property(nonatomic) unsigned int initialConnectBackoff; 45 @property(nonatomic) unsigned int maxConnectBackoff; 46 47 /** The following properties should only be modified for testing: */ 48 49 @property(nonatomic, getter=isSecure) BOOL secure; 50 51 @property(nonatomic, copy, nullable) NSString *hostNameOverride; 52 53 /** The default response size limit is 4MB. Set this to override that default. */ 54 @property(nonatomic, strong, nullable) NSNumber *responseSizeLimitOverride; 55 56 - (nullable instancetype)init NS_UNAVAILABLE; 57 /** Host objects initialized with the same address are the same. */ 58 + (nullable instancetype)hostWithAddress:(NSString *)address; 59 - (nullable instancetype)initWithAddress:(NSString *)address NS_DESIGNATED_INITIALIZER; 60 - (BOOL)setTLSPEMRootCerts:(nullable NSString *)pemRootCerts 61 withPrivateKey:(nullable NSString *)pemPrivateKey 62 withCertChain:(nullable NSString *)pemCertChain 63 error:(NSError **)errorPtr; 64 65 /** Create a grpc_call object to the provided path on this host. */ 66 - (nullable struct grpc_call *)unmanagedCallWithPath:(NSString *)path 67 serverName:(NSString *)serverName 68 timeout:(NSTimeInterval)timeout 69 completionQueue:(GRPCCompletionQueue *)queue; 70 71 // TODO: There's a race when a new RPC is coming through just as an existing one is getting 72 // notified that there's no connectivity. If connectivity comes back at that moment, the new RPC 73 // will have its channel destroyed by the other RPC, and will never get notified of a problem, so 74 // it'll hang (the C layer logs a timeout, with exponential back off). One solution could be to pass 75 // the GRPCChannel to the GRPCCall, renaming this as "disconnectChannel:channel", which would only 76 // act on that specific channel. 77 - (void)disconnect; 78 @end 79 80 NS_ASSUME_NONNULL_END 81