diff --git a/mobile/library/objective-c/BUILD b/mobile/library/objective-c/BUILD index fb4f6ad9275c..deacdbdfa9e1 100644 --- a/mobile/library/objective-c/BUILD +++ b/mobile/library/objective-c/BUILD @@ -7,18 +7,30 @@ exports_files([ objc_library( name = "envoy_engine_objc_lib", srcs = [ + "EnvoyAliases.h", + "EnvoyConfiguration.h", "EnvoyConfiguration.m", "EnvoyEngineImpl.m", + "EnvoyEventTracker.h", "EnvoyEventTracker.m", + "EnvoyHTTPCallbacks.h", "EnvoyHTTPCallbacks.m", + "EnvoyHTTPFilter.h", "EnvoyHTTPFilter.m", "EnvoyHTTPFilterCallbacksImpl.h", "EnvoyHTTPFilterCallbacksImpl.m", + "EnvoyHTTPFilterFactory.h", "EnvoyHTTPFilterFactory.m", + "EnvoyHTTPStream.h", "EnvoyHTTPStreamImpl.m", + "EnvoyKeyValueStore.h", + "EnvoyLogger.h", "EnvoyLogger.m", + "EnvoyNativeFilterConfig.h", "EnvoyNativeFilterConfig.m", + "EnvoyNetworkMonitor.h", "EnvoyNetworkMonitor.m", + "EnvoyStringAccessor.h", "EnvoyStringAccessor.m", ], hdrs = [ diff --git a/mobile/library/objective-c/EnvoyAliases.h b/mobile/library/objective-c/EnvoyAliases.h new file mode 100644 index 000000000000..22d49a138d11 --- /dev/null +++ b/mobile/library/objective-c/EnvoyAliases.h @@ -0,0 +1,25 @@ +#import + +#import "library/common/types/c_types.h" + +NS_ASSUME_NONNULL_BEGIN + +/// Return codes for Engine interface. @see /library/common/types/c_types.h +extern const int kEnvoySuccess; +extern const int kEnvoyFailure; + +/// A set of headers that may be passed to/from an Envoy stream. +typedef NSDictionary *> EnvoyHeaders; + +typedef NSDictionary EnvoyTags; + +/// A set of key-value pairs describing an event. +typedef NSDictionary EnvoyEvent; + +/// Contains internal HTTP stream metrics, context, and other details. +typedef envoy_stream_intel EnvoyStreamIntel; + +// Contains one time HTTP stream metrics, context, and other details. +typedef envoy_final_stream_intel EnvoyFinalStreamIntel; + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyConfiguration.h b/mobile/library/objective-c/EnvoyConfiguration.h new file mode 100644 index 000000000000..46bf01f21882 --- /dev/null +++ b/mobile/library/objective-c/EnvoyConfiguration.h @@ -0,0 +1,101 @@ +#import + +@class EnvoyHTTPFilterFactory; +@class EnvoyNativeFilterConfig; +@class EnvoyStringAccessor; +@protocol EnvoyKeyValueStore; + +NS_ASSUME_NONNULL_BEGIN + +/// Typed configuration that may be used for starting Envoy. +@interface EnvoyConfiguration : NSObject + +@property (nonatomic, assign) BOOL adminInterfaceEnabled; +@property (nonatomic, strong, nullable) NSString *grpcStatsDomain; +@property (nonatomic, assign) UInt32 connectTimeoutSeconds; +@property (nonatomic, assign) UInt32 dnsFailureRefreshSecondsBase; +@property (nonatomic, assign) UInt32 dnsFailureRefreshSecondsMax; +@property (nonatomic, assign) UInt32 dnsQueryTimeoutSeconds; +@property (nonatomic, assign) UInt32 dnsMinRefreshSeconds; +@property (nonatomic, strong) NSString *dnsPreresolveHostnames; +@property (nonatomic, assign) UInt32 dnsRefreshSeconds; +@property (nonatomic, assign) BOOL enableHappyEyeballs; +@property (nonatomic, assign) BOOL enableGzip; +@property (nonatomic, assign) BOOL enableBrotli; +@property (nonatomic, assign) BOOL enableInterfaceBinding; +@property (nonatomic, assign) BOOL enableDrainPostDnsRefresh; +@property (nonatomic, assign) BOOL enforceTrustChainVerification; +@property (nonatomic, assign) BOOL enablePlatformCertificateValidation; +@property (nonatomic, assign) UInt32 h2ConnectionKeepaliveIdleIntervalMilliseconds; +@property (nonatomic, assign) UInt32 h2ConnectionKeepaliveTimeoutSeconds; +@property (nonatomic, assign) BOOL h2ExtendKeepaliveTimeout; +@property (nonatomic, assign) UInt32 maxConnectionsPerHost; +@property (nonatomic, assign) UInt32 statsFlushSeconds; +@property (nonatomic, assign) UInt32 streamIdleTimeoutSeconds; +@property (nonatomic, assign) UInt32 perTryIdleTimeoutSeconds; +@property (nonatomic, strong) NSString *appVersion; +@property (nonatomic, strong) NSString *appId; +@property (nonatomic, strong) NSString *virtualClusters; +@property (nonatomic, strong) NSString *directResponseMatchers; +@property (nonatomic, strong) NSString *directResponses; +@property (nonatomic, strong) NSArray *nativeFilterChain; +@property (nonatomic, strong) NSArray *httpPlatformFilterFactories; +@property (nonatomic, strong) NSDictionary *stringAccessors; +@property (nonatomic, strong) NSDictionary> *keyValueStores; +@property (nonatomic, strong) NSArray *statsSinks; + +/** + Create a new instance of the configuration. + */ +- (instancetype)initWithAdminInterfaceEnabled:(BOOL)adminInterfaceEnabled + GrpcStatsDomain:(nullable NSString *)grpcStatsDomain + connectTimeoutSeconds:(UInt32)connectTimeoutSeconds + dnsRefreshSeconds:(UInt32)dnsRefreshSeconds + dnsFailureRefreshSecondsBase:(UInt32)dnsFailureRefreshSecondsBase + dnsFailureRefreshSecondsMax:(UInt32)dnsFailureRefreshSecondsMax + dnsQueryTimeoutSeconds:(UInt32)dnsQueryTimeoutSeconds + dnsMinRefreshSeconds:(UInt32)dnsMinRefreshSeconds + dnsPreresolveHostnames:(NSString *)dnsPreresolveHostnames + enableHappyEyeballs:(BOOL)enableHappyEyeballs + enableGzip:(BOOL)enableGzip + enableBrotli:(BOOL)enableBrotli + enableInterfaceBinding:(BOOL)enableInterfaceBinding + enableDrainPostDnsRefresh:(BOOL)enableDrainPostDnsRefresh + enforceTrustChainVerification:(BOOL)enforceTrustChainVerification + enablePlatformCertificateValidation:(BOOL)enablePlatformCertificateValidation + h2ConnectionKeepaliveIdleIntervalMilliseconds: + (UInt32)h2ConnectionKeepaliveIdleIntervalMilliseconds + h2ConnectionKeepaliveTimeoutSeconds:(UInt32)h2ConnectionKeepaliveTimeoutSeconds + h2ExtendKeepaliveTimeout:(BOOL)h2ExtendKeepaliveTimeout + maxConnectionsPerHost:(UInt32)maxConnectionsPerHost + statsFlushSeconds:(UInt32)statsFlushSeconds + streamIdleTimeoutSeconds:(UInt32)streamIdleTimeoutSeconds + perTryIdleTimeoutSeconds:(UInt32)perTryIdleTimeoutSeconds + appVersion:(NSString *)appVersion + appId:(NSString *)appId + virtualClusters:(NSString *)virtualClusters + directResponseMatchers:(NSString *)directResponseMatchers + directResponses:(NSString *)directResponses + nativeFilterChain: + (NSArray *)nativeFilterChain + platformFilterChain: + (NSArray *)httpPlatformFilterFactories + stringAccessors: + (NSDictionary *) + stringAccessors + keyValueStores: + (NSDictionary> *) + keyValueStores + statsSinks:(NSArray *)statsSinks; + +/** + Resolves the provided configuration template using properties on this configuration. + + @param templateYAML The template configuration to resolve. + @return The resolved template. Nil if the template fails to fully resolve. + */ +- (nullable NSString *)resolveTemplate:(NSString *)templateYAML; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyEngine.h b/mobile/library/objective-c/EnvoyEngine.h index f063f0c57cc8..22b66ce9d87e 100644 --- a/mobile/library/objective-c/EnvoyEngine.h +++ b/mobile/library/objective-c/EnvoyEngine.h @@ -1,457 +1,24 @@ #import +#import "library/objective-c/EnvoyAliases.h" +#import "library/objective-c/EnvoyConfiguration.h" +#import "library/objective-c/EnvoyEventTracker.h" +#import "library/objective-c/EnvoyHTTPCallbacks.h" +#import "library/objective-c/EnvoyHTTPFilter.h" +#import "library/objective-c/EnvoyHTTPFilterFactory.h" +#import "library/objective-c/EnvoyHTTPStream.h" +#import "library/objective-c/EnvoyKeyValueStore.h" +#import "library/objective-c/EnvoyLogger.h" +#import "library/objective-c/EnvoyNativeFilterConfig.h" +#import "library/objective-c/EnvoyNetworkMonitor.h" +#import "library/objective-c/EnvoyStringAccessor.h" + #import "library/common/types/c_types.h" NS_ASSUME_NONNULL_BEGIN -#pragma mark - Aliases - -/// A set of headers that may be passed to/from an Envoy stream. -typedef NSDictionary *> EnvoyHeaders; - -typedef NSDictionary EnvoyTags; - -/// A set of key-value pairs describing an event. -typedef NSDictionary EnvoyEvent; - -/// Contains internal HTTP stream metrics, context, and other details. -typedef envoy_stream_intel EnvoyStreamIntel; - -// Contains one time HTTP stream metrics, context, and other details. -typedef envoy_final_stream_intel EnvoyFinalStreamIntel; - -#pragma mark - EnvoyHTTPCallbacks - -/// Interface that can handle callbacks from an HTTP stream. -@interface EnvoyHTTPCallbacks : NSObject - -/** - * Dispatch queue provided to handle callbacks. - */ -@property (nonatomic, assign) dispatch_queue_t dispatchQueue; - -// Formatting for block properties is inconsistent and not configurable. -// clang-format off - -/** - * Called when all headers get received on the async HTTP stream. - * @param headers the headers received. - * @param endStream whether the response is headers-only. - * @param streamIntel internal HTTP stream metrics, context, and other details. - */ -@property (nonatomic, copy) void (^onHeaders)( - EnvoyHeaders *headers, BOOL endStream, EnvoyStreamIntel streamIntel); - -/** - * Called when a data frame gets received on the async HTTP stream. - * This callback can be invoked multiple times if the data gets streamed. - * @param data the data received. - * @param endStream whether the data is the last data frame. - * @param streamIntel internal HTTP stream metrics, context, and other details. - */ -@property (nonatomic, copy) void (^onData)( - NSData *data, BOOL endStream, EnvoyStreamIntel streamIntel); - -/** - * Called when all trailers get received on the async HTTP stream. - * Note that end stream is implied when on_trailers is called. - * @param trailers the trailers received. - * @param streamIntel internal HTTP stream metrics, context, and other details. - */ -@property (nonatomic, copy) void (^onTrailers)( - EnvoyHeaders *trailers, EnvoyStreamIntel streamIntel); - -/** - * Called to signal there is buffer space available for continued request body upload. - * - * This is only ever called when the library is in explicit flow control mode. When enabled, - * the issuer should wait for this callback after calling sendData, before making another call - * to sendData. - * @param streamIntel internal HTTP stream metrics, context, and other details. - */ -@property (nonatomic, copy) void (^onSendWindowAvailable)(EnvoyStreamIntel streamIntel); - -/** - * Called when the async HTTP stream has an error. - * @param streamIntel internal HTTP stream metrics, context, and other details. - * @param finalStreamIntel one time HTTP stream metrics, context, and other details. - */ -@property (nonatomic, copy) void (^onError)( - uint64_t errorCode, NSString *message, int32_t attemptCount, EnvoyStreamIntel streamIntel, - EnvoyFinalStreamIntel finalStreamIntel); - -/** - * Called when the async HTTP stream is canceled. - * Note this callback will ALWAYS be fired if a stream is canceled, even if the request and/or - * response is already complete. It will fire no more than once, and no other callbacks for the - * stream will be issued afterwards. - * @param streamIntel internal HTTP stream metrics, context, and other details. - * @param finalStreamIntel one time HTTP stream metrics, context, and other details. - */ -@property (nonatomic, copy) void (^onCancel)( - EnvoyStreamIntel streamIntel, EnvoyFinalStreamIntel finalStreamIntel); - -/** - * Final call made when an HTTP stream is closed gracefully. - * Note this may already be inferred from a prior callback with endStream=TRUE, and this only needs - * to be handled if information from finalStreamIntel is desired. - * @param streamIntel internal HTTP stream metrics, context, and other details. - * @param finalStreamIntel one time HTTP stream metrics, context, and other details. - */ -@property (nonatomic, copy) void (^onComplete)( - EnvoyStreamIntel streamIntel, EnvoyFinalStreamIntel finalStreamIntel); - -// clang-format on -@end - -#pragma mark - EnvoyHTTPFilter - -/// Return codes for on-headers filter invocations. @see envoy/http/filter.h -extern const int kEnvoyFilterHeadersStatusContinue; -extern const int kEnvoyFilterHeadersStatusStopIteration; -extern const int kEnvoyFilterHeadersStatusStopAllIterationAndBuffer; - -/// Return codes for on-data filter invocations. @see envoy/http/filter.h -extern const int kEnvoyFilterDataStatusContinue; -extern const int kEnvoyFilterDataStatusStopIterationAndBuffer; -extern const int kEnvoyFilterDataStatusStopIterationNoBuffer; -extern const int kEnvoyFilterDataStatusResumeIteration; - -/// Return codes for on-trailers filter invocations. @see envoy/http/filter.h -extern const int kEnvoyFilterTrailersStatusContinue; -extern const int kEnvoyFilterTrailersStatusStopIteration; -extern const int kEnvoyFilterTrailersStatusResumeIteration; - -/// Return codes for on-resume filter invocations. These are unique to platform filters, -/// and used exclusively after an asynchronous request to resume iteration via callbacks. -extern const int kEnvoyFilterResumeStatusStopIteration; -extern const int kEnvoyFilterResumeStatusResumeIteration; - -/// Callbacks for asynchronous interaction with the filter. -@protocol EnvoyHTTPFilterCallbacks - -/// Resume filter iteration asynchronously. This will result in an on-resume invocation of the -/// filter. -- (void)resumeIteration; - -/// Reset the underlying stream idle timeout to its configured threshold. This may be useful if -/// a filter stops iteration for an extended period of time, since ordinarily timeouts will still -/// apply. This may be called periodically to continue to indicate "activity" on the stream. -- (void)resetIdleTimer; - -@end - -@interface EnvoyHTTPFilter : NSObject - -// Formatting for block properties is inconsistent and not configurable. -// clang-format off - -/// Returns tuple of: -/// 0 - NSNumber *,filter status -/// 1 - EnvoyHeaders *, forward headers -@property (nonatomic, copy) NSArray * (^onRequestHeaders)( - EnvoyHeaders *headers, BOOL endStream, EnvoyStreamIntel streamIntel); - -/// Returns tuple of: -/// 0 - NSNumber *,filter status -/// 1 - NSData *, forward data -/// 2 - EnvoyHeaders *, optional pending headers -@property (nonatomic, copy) NSArray * (^onRequestData)( - NSData *data, BOOL endStream, EnvoyStreamIntel streamIntel); - -/// Returns tuple of: -/// 0 - NSNumber *,filter status -/// 1 - EnvoyHeaders *, forward trailers -/// 2 - EnvoyHeaders *, optional pending headers -/// 3 - NSData *, optional pending data -@property (nonatomic, copy) NSArray * (^onRequestTrailers)( - EnvoyHeaders *trailers, EnvoyStreamIntel streamIntel); - -/// Returns tuple of: -/// 0 - NSNumber *,filter status -/// 1 - EnvoyHeaders *, forward headers -@property (nonatomic, copy) NSArray * (^onResponseHeaders)( - EnvoyHeaders *headers, BOOL endStream, EnvoyStreamIntel streamIntel); - -/// Returns tuple of: -/// 0 - NSNumber *,filter status -/// 1 - NSData *, forward data -/// 2 - EnvoyHeaders *, optional pending headers -@property (nonatomic, copy) NSArray * (^onResponseData)( - NSData *data, BOOL endStream, EnvoyStreamIntel streamIntel); - -/// Returns tuple of: -/// 0 - NSNumber *,filter status -/// 1 - EnvoyHeaders *, forward trailers -/// 2 - EnvoyHeaders *, optional pending headers -/// 3 - NSData *, optional pending data -@property (nonatomic, copy)NSArray * (^onResponseTrailers)( - EnvoyHeaders *trailers, EnvoyStreamIntel streamIntel); - -@property (nonatomic, copy) void (^onCancel)( - EnvoyStreamIntel streamIntel, EnvoyFinalStreamIntel finalStreamIntel); - -@property (nonatomic, copy) void (^onError)( - uint64_t errorCode, NSString *message, int32_t attemptCount, EnvoyStreamIntel streamIntel, - EnvoyFinalStreamIntel finalStreamIntel); - -@property (nonatomic, copy) void (^onComplete)( - EnvoyStreamIntel streamIntel, EnvoyFinalStreamIntel finalStreamIntel); - -@property (nonatomic, copy) void (^setRequestFilterCallbacks)( - id callbacks); - -/// Returns tuple of: -/// 0 - NSNumber *,filter status -/// 1 - EnvoyHeaders *, optional pending headers -/// 2 - NSData *, optional pending data -/// 3 - EnvoyHeaders *, optional pending trailers -@property (nonatomic, copy) NSArray * (^onResumeRequest)( - EnvoyHeaders *_Nullable headers, NSData *_Nullable data, EnvoyHeaders *_Nullable trailers, - BOOL endStream, EnvoyStreamIntel streamIntel); - -@property (nonatomic, copy) void (^setResponseFilterCallbacks)( - id callbacks); - -/// Returns tuple of: -/// 0 - NSNumber *,filter status -/// 1 - EnvoyHeaders *, optional pending headers -/// 2 - NSData *, optional pending data -/// 3 - EnvoyHeaders *, optional pending trailers -@property (nonatomic, copy) NSArray * (^onResumeResponse)( - EnvoyHeaders *_Nullable headers, NSData *_Nullable data, EnvoyHeaders *_Nullable trailers, - BOOL endStream, EnvoyStreamIntel streamIntel); - -// clang-format on -@end - -#pragma mark - EnvoyHTTPFilterFactory - -@interface EnvoyHTTPFilterFactory : NSObject - -@property (nonatomic, strong) NSString *filterName; - -@property (nonatomic, copy) EnvoyHTTPFilter * (^create)(); - -@end - -#pragma mark - EnvoyHTTPStream - -@protocol EnvoyHTTPStream - -/** - Open an underlying HTTP stream. - - @param handle Underlying handle of the HTTP stream owned by an Envoy engine. - @param engine Underlying handle of the Envoy engine. - @param callbacks The callbacks for the stream. - @param explicitFlowControl Whether explicit flow control will be enabled for this stream. - */ -- (instancetype)initWithHandle:(intptr_t)handle - engine:(intptr_t)engineHandle - callbacks:(EnvoyHTTPCallbacks *)callbacks - explicitFlowControl:(BOOL)explicitFlowControl; - -/** - Send headers over the provided stream. - - @param headers Headers to send over the stream. - @param close True if the stream should be closed after sending. - */ -- (void)sendHeaders:(EnvoyHeaders *)headers close:(BOOL)close; - -/** - Read data from the response stream. Returns immediately. - Has no effect if explicit flow control is not enabled. - - @param byteCount Maximum number of bytes that may be be passed by the next data callback. - */ -- (void)readData:(size_t)byteCount; - -/** - Send data over the provided stream. - - @param data Data to send over the stream. - @param close True if the stream should be closed after sending. - */ -- (void)sendData:(NSData *)data close:(BOOL)close; - -/** - Send trailers over the provided stream. - - @param trailers Trailers to send over the stream. - */ -- (void)sendTrailers:(EnvoyHeaders *)trailers; - -/** - Cancel the stream. This functions as an interrupt, and aborts further callbacks and handling of the - stream. - - @return Success unless the stream has already been canceled. - */ -- (int)cancel; - -/** - Clean up the stream after it's closed (by completion, cancellation, or error). - */ -- (void)cleanUp; - -@end - -#pragma mark - EnvoyHTTPStreamImpl - -// Concrete implementation of the `EnvoyHTTPStream` protocol. -@interface EnvoyHTTPStreamImpl : NSObject - -@end - -#pragma mark - EnvoyStringAccessor - -@interface EnvoyStringAccessor : NSObject - -@property (nonatomic, copy) NSString * (^getEnvoyString)(); - -- (instancetype)initWithBlock:(NSString * (^)())block; - -@end - -#pragma mark - EnvoyKeyValueStore - -@protocol EnvoyKeyValueStore - -/// Read a value from the key value store implementation. -- (NSString *_Nullable)readValueForKey:(NSString *)key; - -/// Save a value to the key value store implementation. -- (void)saveValue:(NSString *)value toKey:(NSString *)key; - -/// Remove a value from the key value store implementation. -- (void)removeKey:(NSString *)key; - -@end - -#pragma mark - EnvoyNativeFilterConfig - -@interface EnvoyNativeFilterConfig : NSObject - -@property (nonatomic, strong) NSString *name; -@property (nonatomic, strong) NSString *typedConfig; - -- (instancetype)initWithName:(NSString *)name typedConfig:(NSString *)typedConfig; - -@end - -#pragma mark - EnvoyConfiguration - -/// Typed configuration that may be used for starting Envoy. -@interface EnvoyConfiguration : NSObject - -@property (nonatomic, assign) BOOL adminInterfaceEnabled; -@property (nonatomic, strong, nullable) NSString *grpcStatsDomain; -@property (nonatomic, assign) UInt32 connectTimeoutSeconds; -@property (nonatomic, assign) UInt32 dnsFailureRefreshSecondsBase; -@property (nonatomic, assign) UInt32 dnsFailureRefreshSecondsMax; -@property (nonatomic, assign) UInt32 dnsQueryTimeoutSeconds; -@property (nonatomic, assign) UInt32 dnsMinRefreshSeconds; -@property (nonatomic, strong) NSString *dnsPreresolveHostnames; -@property (nonatomic, assign) UInt32 dnsRefreshSeconds; -@property (nonatomic, assign) BOOL enableHappyEyeballs; -@property (nonatomic, assign) BOOL enableGzip; -@property (nonatomic, assign) BOOL enableBrotli; -@property (nonatomic, assign) BOOL enableInterfaceBinding; -@property (nonatomic, assign) BOOL enableDrainPostDnsRefresh; -@property (nonatomic, assign) BOOL enforceTrustChainVerification; -@property (nonatomic, assign) BOOL enablePlatformCertificateValidation; -@property (nonatomic, assign) UInt32 h2ConnectionKeepaliveIdleIntervalMilliseconds; -@property (nonatomic, assign) UInt32 h2ConnectionKeepaliveTimeoutSeconds; -@property (nonatomic, assign) BOOL h2ExtendKeepaliveTimeout; -@property (nonatomic, assign) UInt32 maxConnectionsPerHost; -@property (nonatomic, assign) UInt32 statsFlushSeconds; -@property (nonatomic, assign) UInt32 streamIdleTimeoutSeconds; -@property (nonatomic, assign) UInt32 perTryIdleTimeoutSeconds; -@property (nonatomic, strong) NSString *appVersion; -@property (nonatomic, strong) NSString *appId; -@property (nonatomic, strong) NSString *virtualClusters; -@property (nonatomic, strong) NSString *directResponseMatchers; -@property (nonatomic, strong) NSString *directResponses; -@property (nonatomic, strong) NSArray *nativeFilterChain; -@property (nonatomic, strong) NSArray *httpPlatformFilterFactories; -@property (nonatomic, strong) NSDictionary *stringAccessors; -@property (nonatomic, strong) NSDictionary> *keyValueStores; -@property (nonatomic, strong) NSArray *statsSinks; - -/** - Create a new instance of the configuration. - */ -- (instancetype)initWithAdminInterfaceEnabled:(BOOL)adminInterfaceEnabled - GrpcStatsDomain:(nullable NSString *)grpcStatsDomain - connectTimeoutSeconds:(UInt32)connectTimeoutSeconds - dnsRefreshSeconds:(UInt32)dnsRefreshSeconds - dnsFailureRefreshSecondsBase:(UInt32)dnsFailureRefreshSecondsBase - dnsFailureRefreshSecondsMax:(UInt32)dnsFailureRefreshSecondsMax - dnsQueryTimeoutSeconds:(UInt32)dnsQueryTimeoutSeconds - dnsMinRefreshSeconds:(UInt32)dnsMinRefreshSeconds - dnsPreresolveHostnames:(NSString *)dnsPreresolveHostnames - enableHappyEyeballs:(BOOL)enableHappyEyeballs - enableGzip:(BOOL)enableGzip - enableBrotli:(BOOL)enableBrotli - enableInterfaceBinding:(BOOL)enableInterfaceBinding - enableDrainPostDnsRefresh:(BOOL)enableDrainPostDnsRefresh - enforceTrustChainVerification:(BOOL)enforceTrustChainVerification - enablePlatformCertificateValidation:(BOOL)enablePlatformCertificateValidation - h2ConnectionKeepaliveIdleIntervalMilliseconds: - (UInt32)h2ConnectionKeepaliveIdleIntervalMilliseconds - h2ConnectionKeepaliveTimeoutSeconds:(UInt32)h2ConnectionKeepaliveTimeoutSeconds - h2ExtendKeepaliveTimeout:(BOOL)h2ExtendKeepaliveTimeout - maxConnectionsPerHost:(UInt32)maxConnectionsPerHost - statsFlushSeconds:(UInt32)statsFlushSeconds - streamIdleTimeoutSeconds:(UInt32)streamIdleTimeoutSeconds - perTryIdleTimeoutSeconds:(UInt32)perTryIdleTimeoutSeconds - appVersion:(NSString *)appVersion - appId:(NSString *)appId - virtualClusters:(NSString *)virtualClusters - directResponseMatchers:(NSString *)directResponseMatchers - directResponses:(NSString *)directResponses - nativeFilterChain: - (NSArray *)nativeFilterChain - platformFilterChain: - (NSArray *)httpPlatformFilterFactories - stringAccessors: - (NSDictionary *) - stringAccessors - keyValueStores: - (NSDictionary> *) - keyValueStores - statsSinks:(NSArray *)statsSinks; - -/** - Resolves the provided configuration template using properties on this configuration. - - @param templateYAML The template configuration to resolve. - @return The resolved template. Nil if the template fails to fully resolve. - */ -- (nullable NSString *)resolveTemplate:(NSString *)templateYAML; - -@end - -#pragma mark - EnvoyEventTracker - -// Tracking events interface - -@interface EnvoyEventTracker : NSObject - -@property (nonatomic, copy, nonnull) void (^track)(EnvoyEvent *); - -- (instancetype)initWithEventTrackingClosure:(nonnull void (^)(EnvoyEvent *))track; - -@end - #pragma mark - EnvoyEngine -/// Return codes for Engine interface. @see /library/common/types/c_types.h -extern const int kEnvoySuccess; -extern const int kEnvoyFailure; - /// Wrapper layer for calling into Envoy's C/++ API. @protocol EnvoyEngine @@ -569,20 +136,6 @@ extern const int kEnvoyFailure; @end -#pragma mark - EnvoyLogger - -// Logging interface. -@interface EnvoyLogger : NSObject - -@property (nonatomic, copy) void (^log)(NSString *); - -/** - Create a new instance of the logger. - */ -- (instancetype)initWithLogClosure:(void (^)(NSString *))log; - -@end - #pragma mark - EnvoyEngineImpl // Concrete implementation of the `EnvoyEngine` interface. @@ -592,26 +145,4 @@ extern const int kEnvoyFailure; @end -#pragma mark - EnvoyNetworkMonitor - -// Monitors network changes in order to update Envoy network cluster preferences. -@interface EnvoyNetworkMonitor : NSObject - -/** - Create a new instance of the network monitor. - */ -- (instancetype)initWithEngine:(envoy_engine_t)engineHandle; - -// Start monitoring reachability using `SCNetworkReachability`, updating the -// preferred Envoy network cluster on changes. -// This is typically called by `EnvoyEngine` automatically on startup. -- (void)startReachability; - -// Start monitoring reachability using `NWPathMonitor`, updating the -// preferred Envoy network cluster on changes. -// This is typically called by `EnvoyEngine` automatically on startup. -- (void)startPathMonitor; - -@end - NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyEventTracker.h b/mobile/library/objective-c/EnvoyEventTracker.h new file mode 100644 index 000000000000..1c884d34cab2 --- /dev/null +++ b/mobile/library/objective-c/EnvoyEventTracker.h @@ -0,0 +1,15 @@ +#import + +#import "library/objective-c/EnvoyAliases.h" + +NS_ASSUME_NONNULL_BEGIN + +@interface EnvoyEventTracker : NSObject + +@property (nonatomic, copy) void (^track)(EnvoyEvent *); + +- (instancetype)initWithEventTrackingClosure:(void (^)(EnvoyEvent *))track; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyEventTracker.m b/mobile/library/objective-c/EnvoyEventTracker.m index 5e4f8680a2fb..d9925925414a 100644 --- a/mobile/library/objective-c/EnvoyEventTracker.m +++ b/mobile/library/objective-c/EnvoyEventTracker.m @@ -2,7 +2,7 @@ @implementation EnvoyEventTracker -- (instancetype)initWithEventTrackingClosure:(nonnull void (^)(EnvoyEvent *))track { +- (instancetype)initWithEventTrackingClosure:(void (^)(EnvoyEvent *))track { self = [super init]; if (!self) { return nil; diff --git a/mobile/library/objective-c/EnvoyHTTPCallbacks.h b/mobile/library/objective-c/EnvoyHTTPCallbacks.h new file mode 100644 index 000000000000..3ade8d060649 --- /dev/null +++ b/mobile/library/objective-c/EnvoyHTTPCallbacks.h @@ -0,0 +1,87 @@ +#import + +#import "library/objective-c/EnvoyAliases.h" + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark - EnvoyHTTPCallbacks + +/// Interface that can handle callbacks from an HTTP stream. +@interface EnvoyHTTPCallbacks : NSObject + +/** + * Dispatch queue provided to handle callbacks. + */ +@property (nonatomic, assign) dispatch_queue_t dispatchQueue; + +/** + * Called when all headers get received on the async HTTP stream. + * @param headers the headers received. + * @param endStream whether the response is headers-only. + * @param streamIntel internal HTTP stream metrics, context, and other details. + */ +@property (nonatomic, copy) void (^onHeaders) + (EnvoyHeaders *headers, BOOL endStream, EnvoyStreamIntel streamIntel); + +/** + * Called when a data frame gets received on the async HTTP stream. + * This callback can be invoked multiple times if the data gets streamed. + * @param data the data received. + * @param endStream whether the data is the last data frame. + * @param streamIntel internal HTTP stream metrics, context, and other details. + */ +@property (nonatomic, copy) void (^onData) + (NSData *data, BOOL endStream, EnvoyStreamIntel streamIntel); + +/** + * Called when all trailers get received on the async HTTP stream. + * Note that end stream is implied when on_trailers is called. + * @param trailers the trailers received. + * @param streamIntel internal HTTP stream metrics, context, and other details. + */ +@property (nonatomic, copy) void (^onTrailers)(EnvoyHeaders *trailers, EnvoyStreamIntel streamIntel) + ; + +/** + * Called to signal there is buffer space available for continued request body upload. + * + * This is only ever called when the library is in explicit flow control mode. When enabled, + * the issuer should wait for this callback after calling sendData, before making another call + * to sendData. + * @param streamIntel internal HTTP stream metrics, context, and other details. + */ +@property (nonatomic, copy) void (^onSendWindowAvailable)(EnvoyStreamIntel streamIntel); + +/** + * Called when the async HTTP stream has an error. + * @param streamIntel internal HTTP stream metrics, context, and other details. + * @param finalStreamIntel one time HTTP stream metrics, context, and other details. + */ +@property (nonatomic, copy) void (^onError) + (uint64_t errorCode, NSString *message, int32_t attemptCount, EnvoyStreamIntel streamIntel, + EnvoyFinalStreamIntel finalStreamIntel); + +/** + * Called when the async HTTP stream is canceled. + * Note this callback will ALWAYS be fired if a stream is canceled, even if the request and/or + * response is already complete. It will fire no more than once, and no other callbacks for the + * stream will be issued afterwards. + * @param streamIntel internal HTTP stream metrics, context, and other details. + * @param finalStreamIntel one time HTTP stream metrics, context, and other details. + */ +@property (nonatomic, copy) void (^onCancel) + (EnvoyStreamIntel streamIntel, EnvoyFinalStreamIntel finalStreamIntel); + +/** + * Final call made when an HTTP stream is closed gracefully. + * Note this may already be inferred from a prior callback with endStream=TRUE, and this only needs + * to be handled if information from finalStreamIntel is desired. + * @param streamIntel internal HTTP stream metrics, context, and other details. + * @param finalStreamIntel one time HTTP stream metrics, context, and other details. + */ +@property (nonatomic, copy) void (^onComplete) + (EnvoyStreamIntel streamIntel, EnvoyFinalStreamIntel finalStreamIntel); + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyHTTPFilter.h b/mobile/library/objective-c/EnvoyHTTPFilter.h new file mode 100644 index 000000000000..a6bce99e8eee --- /dev/null +++ b/mobile/library/objective-c/EnvoyHTTPFilter.h @@ -0,0 +1,124 @@ +#import + +#import "library/objective-c/EnvoyAliases.h" + +#import "library/common/types/c_types.h" + +NS_ASSUME_NONNULL_BEGIN + +/// Return codes for on-headers filter invocations. @see envoy/http/filter.h +extern const int kEnvoyFilterHeadersStatusContinue; +extern const int kEnvoyFilterHeadersStatusStopIteration; +extern const int kEnvoyFilterHeadersStatusStopAllIterationAndBuffer; + +/// Return codes for on-data filter invocations. @see envoy/http/filter.h +extern const int kEnvoyFilterDataStatusContinue; +extern const int kEnvoyFilterDataStatusStopIterationAndBuffer; +extern const int kEnvoyFilterDataStatusStopIterationNoBuffer; +extern const int kEnvoyFilterDataStatusResumeIteration; + +/// Return codes for on-trailers filter invocations. @see envoy/http/filter.h +extern const int kEnvoyFilterTrailersStatusContinue; +extern const int kEnvoyFilterTrailersStatusStopIteration; +extern const int kEnvoyFilterTrailersStatusResumeIteration; + +/// Return codes for on-resume filter invocations. These are unique to platform filters, +/// and used exclusively after an asynchronous request to resume iteration via callbacks. +extern const int kEnvoyFilterResumeStatusStopIteration; +extern const int kEnvoyFilterResumeStatusResumeIteration; + +/// Callbacks for asynchronous interaction with the filter. +@protocol EnvoyHTTPFilterCallbacks + +/// Resume filter iteration asynchronously. This will result in an on-resume invocation of the +/// filter. +- (void)resumeIteration; + +/// Reset the underlying stream idle timeout to its configured threshold. This may be useful if +/// a filter stops iteration for an extended period of time, since ordinarily timeouts will still +/// apply. This may be called periodically to continue to indicate "activity" on the stream. +- (void)resetIdleTimer; + +@end + +@interface EnvoyHTTPFilter : NSObject + +/// Returns tuple of: +/// 0 - NSNumber *,filter status +/// 1 - EnvoyHeaders *, forward headers +@property (nonatomic, copy) NSArray * (^onRequestHeaders) + (EnvoyHeaders *headers, BOOL endStream, EnvoyStreamIntel streamIntel); + +/// Returns tuple of: +/// 0 - NSNumber *,filter status +/// 1 - NSData *, forward data +/// 2 - EnvoyHeaders *, optional pending headers +@property (nonatomic, copy) NSArray * (^onRequestData) + (NSData *data, BOOL endStream, EnvoyStreamIntel streamIntel); + +/// Returns tuple of: +/// 0 - NSNumber *,filter status +/// 1 - EnvoyHeaders *, forward trailers +/// 2 - EnvoyHeaders *, optional pending headers +/// 3 - NSData *, optional pending data +@property (nonatomic, copy) NSArray * (^onRequestTrailers) + (EnvoyHeaders *trailers, EnvoyStreamIntel streamIntel); + +/// Returns tuple of: +/// 0 - NSNumber *,filter status +/// 1 - EnvoyHeaders *, forward headers +@property (nonatomic, copy) NSArray * (^onResponseHeaders) + (EnvoyHeaders *headers, BOOL endStream, EnvoyStreamIntel streamIntel); + +/// Returns tuple of: +/// 0 - NSNumber *,filter status +/// 1 - NSData *, forward data +/// 2 - EnvoyHeaders *, optional pending headers +@property (nonatomic, copy) NSArray * (^onResponseData) + (NSData *data, BOOL endStream, EnvoyStreamIntel streamIntel); + +/// Returns tuple of: +/// 0 - NSNumber *,filter status +/// 1 - EnvoyHeaders *, forward trailers +/// 2 - EnvoyHeaders *, optional pending headers +/// 3 - NSData *, optional pending data +@property (nonatomic, copy) NSArray * (^onResponseTrailers) + (EnvoyHeaders *trailers, EnvoyStreamIntel streamIntel); + +@property (nonatomic, copy) void (^onCancel) + (EnvoyStreamIntel streamIntel, EnvoyFinalStreamIntel finalStreamIntel); + +@property (nonatomic, copy) void (^onError) + (uint64_t errorCode, NSString *message, int32_t attemptCount, EnvoyStreamIntel streamIntel, + EnvoyFinalStreamIntel finalStreamIntel); + +@property (nonatomic, copy) void (^onComplete) + (EnvoyStreamIntel streamIntel, EnvoyFinalStreamIntel finalStreamIntel); + +@property (nonatomic, copy) void (^setRequestFilterCallbacks) + (id callbacks); + +/// Returns tuple of: +/// 0 - NSNumber *,filter status +/// 1 - EnvoyHeaders *, optional pending headers +/// 2 - NSData *, optional pending data +/// 3 - EnvoyHeaders *, optional pending trailers +@property (nonatomic, copy) NSArray * (^onResumeRequest) + (EnvoyHeaders *_Nullable headers, NSData *_Nullable data, EnvoyHeaders *_Nullable trailers, + BOOL endStream, EnvoyStreamIntel streamIntel); + +@property (nonatomic, copy) void (^setResponseFilterCallbacks) + (id callbacks); + +/// Returns tuple of: +/// 0 - NSNumber *,filter status +/// 1 - EnvoyHeaders *, optional pending headers +/// 2 - NSData *, optional pending data +/// 3 - EnvoyHeaders *, optional pending trailers +@property (nonatomic, copy) NSArray * (^onResumeResponse) + (EnvoyHeaders *_Nullable headers, NSData *_Nullable data, EnvoyHeaders *_Nullable trailers, + BOOL endStream, EnvoyStreamIntel streamIntel); + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyHTTPFilterFactory.h b/mobile/library/objective-c/EnvoyHTTPFilterFactory.h new file mode 100644 index 000000000000..25b7509e1737 --- /dev/null +++ b/mobile/library/objective-c/EnvoyHTTPFilterFactory.h @@ -0,0 +1,15 @@ +#import + +@class EnvoyHTTPFilter; + +NS_ASSUME_NONNULL_BEGIN + +@interface EnvoyHTTPFilterFactory : NSObject + +@property (nonatomic, strong) NSString *filterName; + +@property (nonatomic, copy) EnvoyHTTPFilter * (^create)(); + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyHTTPStream.h b/mobile/library/objective-c/EnvoyHTTPStream.h new file mode 100644 index 000000000000..c2a425618c47 --- /dev/null +++ b/mobile/library/objective-c/EnvoyHTTPStream.h @@ -0,0 +1,79 @@ +#import + +#import "library/objective-c/EnvoyAliases.h" + +#import "library/common/types/c_types.h" + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark - EnvoyHTTPStream + +@protocol EnvoyHTTPStream + +/** + Open an underlying HTTP stream. + + @param handle Underlying handle of the HTTP stream owned by an Envoy engine. + @param engine Underlying handle of the Envoy engine. + @param callbacks The callbacks for the stream. + @param explicitFlowControl Whether explicit flow control will be enabled for this stream. + */ +- (instancetype)initWithHandle:(intptr_t)handle + engine:(intptr_t)engineHandle + callbacks:(EnvoyHTTPCallbacks *)callbacks + explicitFlowControl:(BOOL)explicitFlowControl; + +/** + Send headers over the provided stream. + + @param headers Headers to send over the stream. + @param close True if the stream should be closed after sending. + */ +- (void)sendHeaders:(EnvoyHeaders *)headers close:(BOOL)close; + +/** + Read data from the response stream. Returns immediately. + Has no effect if explicit flow control is not enabled. + + @param byteCount Maximum number of bytes that may be be passed by the next data callback. + */ +- (void)readData:(size_t)byteCount; + +/** + Send data over the provided stream. + + @param data Data to send over the stream. + @param close True if the stream should be closed after sending. + */ +- (void)sendData:(NSData *)data close:(BOOL)close; + +/** + Send trailers over the provided stream. + + @param trailers Trailers to send over the stream. + */ +- (void)sendTrailers:(EnvoyHeaders *)trailers; + +/** + Cancel the stream. This functions as an interrupt, and aborts further callbacks and handling of the + stream. + + @return Success unless the stream has already been canceled. + */ +- (int)cancel; + +/** + Clean up the stream after it's closed (by completion, cancellation, or error). + */ +- (void)cleanUp; + +@end + +#pragma mark - EnvoyHTTPStreamImpl + +// Concrete implementation of the `EnvoyHTTPStream` protocol. +@interface EnvoyHTTPStreamImpl : NSObject + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyKeyValueStore.h b/mobile/library/objective-c/EnvoyKeyValueStore.h new file mode 100644 index 000000000000..745fb353ced3 --- /dev/null +++ b/mobile/library/objective-c/EnvoyKeyValueStore.h @@ -0,0 +1,18 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@protocol EnvoyKeyValueStore + +/// Read a value from the key value store implementation. +- (NSString *_Nullable)readValueForKey:(NSString *)key; + +/// Save a value to the key value store implementation. +- (void)saveValue:(NSString *)value toKey:(NSString *)key; + +/// Remove a value from the key value store implementation. +- (void)removeKey:(NSString *)key; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyLogger.h b/mobile/library/objective-c/EnvoyLogger.h new file mode 100644 index 000000000000..8c630f5efc4d --- /dev/null +++ b/mobile/library/objective-c/EnvoyLogger.h @@ -0,0 +1,17 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +// Logging interface. +@interface EnvoyLogger : NSObject + +@property (nonatomic, copy) void (^log)(NSString *); + +/** + Create a new instance of the logger. + */ +- (instancetype)initWithLogClosure:(void (^)(NSString *))log; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyNativeFilterConfig.h b/mobile/library/objective-c/EnvoyNativeFilterConfig.h new file mode 100644 index 000000000000..2f38ecee4619 --- /dev/null +++ b/mobile/library/objective-c/EnvoyNativeFilterConfig.h @@ -0,0 +1,14 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface EnvoyNativeFilterConfig : NSObject + +@property (nonatomic, strong) NSString *name; +@property (nonatomic, strong) NSString *typedConfig; + +- (instancetype)initWithName:(NSString *)name typedConfig:(NSString *)typedConfig; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyNetworkMonitor.h b/mobile/library/objective-c/EnvoyNetworkMonitor.h new file mode 100644 index 000000000000..e09d3807964d --- /dev/null +++ b/mobile/library/objective-c/EnvoyNetworkMonitor.h @@ -0,0 +1,27 @@ +#import + +#import "library/common/types/c_types.h" + +NS_ASSUME_NONNULL_BEGIN + +// Monitors network changes in order to update Envoy network cluster preferences. +@interface EnvoyNetworkMonitor : NSObject + +/** + Create a new instance of the network monitor. + */ +- (instancetype)initWithEngine:(envoy_engine_t)engineHandle; + +// Start monitoring reachability using `SCNetworkReachability`, updating the +// preferred Envoy network cluster on changes. +// This is typically called by `EnvoyEngine` automatically on startup. +- (void)startReachability; + +// Start monitoring reachability using `NWPathMonitor`, updating the +// preferred Envoy network cluster on changes. +// This is typically called by `EnvoyEngine` automatically on startup. +- (void)startPathMonitor; + +@end + +NS_ASSUME_NONNULL_END diff --git a/mobile/library/objective-c/EnvoyStringAccessor.h b/mobile/library/objective-c/EnvoyStringAccessor.h new file mode 100644 index 000000000000..117c85dc8583 --- /dev/null +++ b/mobile/library/objective-c/EnvoyStringAccessor.h @@ -0,0 +1,13 @@ +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface EnvoyStringAccessor : NSObject + +@property (nonatomic, copy) NSString * (^getEnvoyString)(); + +- (instancetype)initWithBlock:(NSString * (^)())block; + +@end + +NS_ASSUME_NONNULL_END