Skip to content

Commit

Permalink
Add streamSSLLevel to MQTTSessionManager
Browse files Browse the repository at this point in the history
  • Loading branch information
jcavar committed Feb 16, 2018
1 parent ee06e91 commit 0451e0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions MQTTClient/MQTTClient/MQTTSessionManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ typedef NS_ENUM(int, MQTTSessionManagerState) {
event, it will attempt to reconnect to the broker. The time in between connection attempts is doubled each time, until it remains at maxRetryInterval.
Defaults to 64 seconds.
* @param connectInForeground Whether or not to connect the MQTTSession when the app enters the foreground, and disconnect when it becomes inactive. When NO, the caller is responsible for calling -connectTo: and -disconnect. Defaults to YES.
* @param streamSSLLevel an NSString containing the security level for read and write streams
* For list of possible values see:
* https://developer.apple.com/documentation/corefoundation/cfstream/cfstream_socket_security_level_constants
* Please also note that kCFStreamSocketSecurityLevelTLSv1_2 is not in a list
* and cannot be used as constant, but you can use it as a string value
* defaults to kCFStreamSocketSecurityLevelNegotiatedSSL
* @param queue Queue for MQTTSession.
* @return the initialized MQTTSessionManager object
*/
Expand All @@ -165,6 +171,7 @@ typedef NS_ENUM(int, MQTTSessionManagerState) {
maxSize:(NSUInteger)maxSize
maxConnectionRetryInterval:(NSTimeInterval)maxRetryInterval
connectInForeground:(BOOL)connectInForeground
streamSSLLevel:(NSString *)streamSSLLevel
queue:(dispatch_queue_t)queue NS_DESIGNATED_INITIALIZER;

/** Connects to the MQTT broker and stores the parameters for subsequent reconnects
Expand Down
15 changes: 9 additions & 6 deletions MQTTClient/MQTTClient/MQTTSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ @interface MQTTSessionManager()
@property (nonatomic) NSUInteger maxWindowSize;
@property (nonatomic) NSUInteger maxSize;
@property (nonatomic) NSUInteger maxMessages;
@property (strong, nonatomic) NSString *streamSSLLevel;

@property (strong, nonatomic) NSDictionary<NSString *, NSNumber *> *internalSubscriptions;
@property (strong, nonatomic) NSDictionary<NSString *, NSNumber *> *effectiveSubscriptions;
Expand All @@ -68,6 +69,7 @@ - (instancetype)init {
maxSize:MQTT_MAX_SIZE
maxConnectionRetryInterval:RECONNECT_TIMER_MAX_DEFAULT
connectInForeground:YES
streamSSLLevel:kCFStreamSocketSecurityLevelNegotiatedSSL
queue:dispatch_get_main_queue()];
return self;
}
Expand All @@ -78,9 +80,10 @@ - (MQTTSessionManager *)initWithPersistence:(BOOL)persistent
maxSize:(NSUInteger)maxSize
maxConnectionRetryInterval:(NSTimeInterval)maxRetryInterval
connectInForeground:(BOOL)connectInForeground
streamSSLLevel:(NSString *)streamSSLLevel
queue:(dispatch_queue_t)queue {
self = [super init];

self.streamSSLLevel = streamSSLLevel;
self.queue = queue;
[self updateState:MQTTSessionManagerStateStarting];
self.internalSubscriptions = [[NSMutableDictionary alloc] init];
Expand Down Expand Up @@ -172,19 +175,19 @@ - (void)connectTo:(NSString *)host
willQoS:willQos
willRetainFlag:willRetainFlag
protocolLevel:protocolLevel
queue:self.queue
queue:self.queue
securityPolicy:securityPolicy
certificates:certificates];

self.session.streamSSLLevel = self.streamSSLLevel;
MQTTCoreDataPersistence *persistence = [[MQTTCoreDataPersistence alloc] init];

persistence.persistent = self.persistent;
persistence.maxWindowSize = self.maxWindowSize;
persistence.maxSize = self.maxSize;
persistence.maxMessages = self.maxMessages;

self.session.persistence = persistence;

self.session.delegate = self;
self.reconnectFlag = FALSE;
}
Expand Down

0 comments on commit 0451e0b

Please sign in to comment.