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:
committed by
Facebook GitHub Bot
parent
6359c82be1
commit
1390bf4a33
@@ -125,10 +125,15 @@ class ServerController extends EventEmitter implements ServerEventsListener {
|
|||||||
this.initialized = this.certificateProvider
|
this.initialized = this.certificateProvider
|
||||||
.loadSecureServerConfig()
|
.loadSecureServerConfig()
|
||||||
.then((options) => {
|
.then((options) => {
|
||||||
|
console.log('[conn] secure server listening at port: ', secure);
|
||||||
this.secureServer = createServer(secure, this, options);
|
this.secureServer = createServer(secure, this, options);
|
||||||
if (GK.get('flipper_websocket_server')) {
|
if (GK.get('flipper_websocket_server')) {
|
||||||
const {secure: altSecure} =
|
const {secure: altSecure} =
|
||||||
this.store.getState().application.altServerPorts;
|
this.store.getState().application.altServerPorts;
|
||||||
|
console.log(
|
||||||
|
'[conn] secure server (ws) listening at port: ',
|
||||||
|
altSecure,
|
||||||
|
);
|
||||||
this.altSecureServer = createServer(
|
this.altSecureServer = createServer(
|
||||||
altSecure,
|
altSecure,
|
||||||
this,
|
this,
|
||||||
@@ -138,10 +143,15 @@ class ServerController extends EventEmitter implements ServerEventsListener {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
console.log('[conn] insecure server listening at port: ', insecure);
|
||||||
this.insecureServer = createServer(insecure, this);
|
this.insecureServer = createServer(insecure, this);
|
||||||
if (GK.get('flipper_websocket_server')) {
|
if (GK.get('flipper_websocket_server')) {
|
||||||
const {insecure: altInsecure} =
|
const {insecure: altInsecure} =
|
||||||
this.store.getState().application.altServerPorts;
|
this.store.getState().application.altServerPorts;
|
||||||
|
console.log(
|
||||||
|
'[conn] insecure server (ws) listening at port: ',
|
||||||
|
altInsecure,
|
||||||
|
);
|
||||||
this.altInsecureServer = createServer(
|
this.altInsecureServer = createServer(
|
||||||
altInsecure,
|
altInsecure,
|
||||||
this,
|
this,
|
||||||
|
|||||||
@@ -101,7 +101,9 @@ using WrapperPlugin = facebook::flipper::FlipperCppWrapperPlugin;
|
|||||||
sonarThread.getEventBase(),
|
sonarThread.getEventBase(),
|
||||||
connectionThread.getEventBase(),
|
connectionThread.getEventBase(),
|
||||||
[SKEnvironmentVariables getInsecurePort],
|
[SKEnvironmentVariables getInsecurePort],
|
||||||
[SKEnvironmentVariables getSecurePort]});
|
[SKEnvironmentVariables getSecurePort],
|
||||||
|
[SKEnvironmentVariables getAltInsecurePort],
|
||||||
|
[SKEnvironmentVariables getAltSecurePort]});
|
||||||
_cppClient = facebook::flipper::FlipperClient::instance();
|
_cppClient = facebook::flipper::FlipperClient::instance();
|
||||||
|
|
||||||
// To switch to a websocket provider, uncomment the line below.
|
// To switch to a websocket provider, uncomment the line below.
|
||||||
|
|||||||
@@ -14,6 +14,8 @@
|
|||||||
@interface SKEnvironmentVariables : NSObject
|
@interface SKEnvironmentVariables : NSObject
|
||||||
+ (int)getInsecurePort;
|
+ (int)getInsecurePort;
|
||||||
+ (int)getSecurePort;
|
+ (int)getSecurePort;
|
||||||
|
+ (int)getAltInsecurePort;
|
||||||
|
+ (int)getAltSecurePort;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
static int const DEFAULT_INSECURE_PORT = 8089;
|
static int const DEFAULT_INSECURE_PORT = 8089;
|
||||||
static int const DEFAULT_SECURE_PORT = 8088;
|
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
|
@implementation SKEnvironmentVariables
|
||||||
|
|
||||||
+ (int)getInsecurePort {
|
+ (int)getInsecurePort {
|
||||||
@@ -26,6 +29,18 @@ static int const DEFAULT_SECURE_PORT = 8088;
|
|||||||
atIndex:1
|
atIndex:1
|
||||||
withDefault:DEFAULT_SECURE_PORT];
|
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
|
+ (int)extractIntFromPropValue:(NSString*)propValue
|
||||||
atIndex:(int)index
|
atIndex:(int)index
|
||||||
withDefault:(int)fallback {
|
withDefault:(int)fallback {
|
||||||
@@ -45,6 +60,17 @@ static int const DEFAULT_SECURE_PORT = 8088;
|
|||||||
|
|
||||||
return value;
|
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
|
@end
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ struct FlipperInitConfig {
|
|||||||
|
|
||||||
int insecurePort = 8089;
|
int insecurePort = 8089;
|
||||||
int securePort = 8088;
|
int securePort = 8088;
|
||||||
|
int altInsecurePort = 9089;
|
||||||
|
int altSecurePort = 9088;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace flipper
|
} // namespace flipper
|
||||||
|
|||||||
Reference in New Issue
Block a user