Define alt ports for web socket connections

Summary:
The changes below add the notion of alternative ports to Flipper.

These alternative ports are meant to and will be used to connect via WebSocket instead of RSocket. The name does not suggest that as to make as generic as possible so that they can be reused for different purposes in the future.

Reviewed By: passy

Differential Revision: D30898874

fbshipit-source-id: 5eed8c61b41b502c859192aaac59c284b7b36228
This commit is contained in:
Lorenzo Blasa
2021-09-15 07:58:45 -07:00
committed by Facebook GitHub Bot
parent 6359c82be1
commit 1390bf4a33
5 changed files with 43 additions and 1 deletions

View File

@@ -12,6 +12,9 @@
static int const DEFAULT_INSECURE_PORT = 8089;
static int const DEFAULT_SECURE_PORT = 8088;
static int const DEFAULT_ALT_INSECURE_PORT = 9089;
static int const DEFAULT_ALT_SECURE_PORT = 9088;
@implementation SKEnvironmentVariables
+ (int)getInsecurePort {
@@ -26,6 +29,18 @@ static int const DEFAULT_SECURE_PORT = 8088;
atIndex:1
withDefault:DEFAULT_SECURE_PORT];
}
+ (int)getAltInsecurePort {
NSString* envVar = [self getFlipperAltPortsVariable];
return [self extractIntFromPropValue:envVar
atIndex:0
withDefault:DEFAULT_ALT_INSECURE_PORT];
}
+ (int)getAltSecurePort {
NSString* envVar = [self getFlipperAltPortsVariable];
return [self extractIntFromPropValue:envVar
atIndex:1
withDefault:DEFAULT_ALT_SECURE_PORT];
}
+ (int)extractIntFromPropValue:(NSString*)propValue
atIndex:(int)index
withDefault:(int)fallback {
@@ -45,6 +60,17 @@ static int const DEFAULT_SECURE_PORT = 8088;
return value;
}
+ (NSString*)getFlipperAltPortsVariable {
// Try to retrieve from environment first.
NSString* value = NSProcessInfo.processInfo.environment[@"FLIPPER_ALT_PORTS"];
// If empty, check defaults instead.
if ([value length] == 0) {
value = [[NSUserDefaults standardUserDefaults]
stringForKey:@"com.facebook.flipper.ports.alt"];
}
return value;
}
@end
#endif