Skip to content
This repository has been archived by the owner on May 22, 2020. It is now read-only.

Commit

Permalink
RUN-3034 Realms do not fully isolate under multi runtime (#121)
Browse files Browse the repository at this point in the history
  • Loading branch information
HarsimranSingh authored Jul 31, 2017
1 parent 7c8dad2 commit 476f4da
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const srcFiles = ['src/**/*.js', 'index.js', 'Gruntfile.js'];

//optional dependencies that we ship.
const optionalDependencies = [
'js-adapter/**',
'node-adapter/**',
'runtime-p2p/**'
];

Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ import {

import {
default as connectionManager,
meshEnabled
meshEnabled,
isMeshEnabled
} from './src/browser/connection_manager';

import * as log from './src/browser/log';
Expand Down Expand Up @@ -138,7 +139,7 @@ portDiscovery.on('runtime/launched', (portInfo) => {
log.writeToLog('info', `Port discovery message received ${JSON.stringify(portInfo)}`);

//TODO: Include REALM in the determination.
if (meshEnabled && portInfo.port !== myPortInfo.port) {
if (meshEnabled && portInfo.port !== myPortInfo.port && isMeshEnabled(portInfo.options)) {

connectionManager.connectToRuntime(`${myPortInfo.version}:${myPortInfo.port}`, portInfo).then((runtimePeer) => {
//one connected we broadcast our port discovery message.
Expand Down
40 changes: 18 additions & 22 deletions src/browser/connection_manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Please contact OpenFin Inc. at sales@openfin.co to obtain a Commercial License.
declare let process: any;
import { EventEmitter } from 'events';
import { Identity } from './api_protocol/transport_strategy/api_transport_base';
import { ArgMap, PortInfo } from './port_discovery';

// npm modules
// (none)
Expand All @@ -21,16 +22,13 @@ import { Identity } from './api_protocol/transport_strategy/api_transport_base';
const coreState = require('./core_state');
import * as log from './log';


//TODO: pre-release flag, this will go away once we release multi runtime.
const multiRuntimeCommandLineFlag = 'enable-multi-runtime';
const enableMeshCommandLineFlag = 'enable-mesh';
const securityRealmFlag = 'security-realm';

//TODO: pre-release flag, this will go away once we release multi runtime
const multiRuntimeEnabled = coreState.argo[multiRuntimeCommandLineFlag];
const enableMesh = coreState.argo[enableMeshCommandLineFlag];
const securityRealm = coreState.argo[securityRealmFlag];

let connectionManager: any;
let meshEnabled = false;

Expand All @@ -46,14 +44,6 @@ function startConnectionManager() {
}
}

//TODO: pre-release flag, this will go away once we release multi runtime
if (multiRuntimeEnabled) {

if (!securityRealm || enableMesh) {
startConnectionManager();
}
}

function buildNoopConnectionManager() {
connectionManager = new EventEmitter();
connectionManager.connectToRuntime = () => {
Expand All @@ -71,6 +61,21 @@ function buildNoopConnectionManager() {
connectionManager.connections = [];
}

function isMeshEnabled(args: ArgMap) {
let enabled = false;
const enableMesh = args[enableMeshCommandLineFlag];
const securityRealm = args[securityRealmFlag];

if (!securityRealm || enableMesh) {
enabled = true;
}

return enabled;
}

if (multiRuntimeEnabled && isMeshEnabled(coreState.argo)) {
startConnectionManager();
}

/*
Note that these should match the definitions found here:
Expand All @@ -90,15 +95,6 @@ interface IdentityAddress {
identity: Identity;
}

interface PortInfo {
version: any;
sslPort: number;
port: number;
requestedVersion?: string;
securityRealm?: string;
runtimeInformationChannel?: string;
}

interface ConnectionManager extends EventEmitter {
connections: Array<PeerRuntime>;
connectToRuntime: (uuid: string, portInfo: PortInfo) => Promise<PeerRuntime>;
Expand All @@ -107,4 +103,4 @@ interface ConnectionManager extends EventEmitter {


export default connectionManager as ConnectionManager;
export { meshEnabled, PeerRuntime };
export { meshEnabled, PeerRuntime, isMeshEnabled };
8 changes: 5 additions & 3 deletions src/browser/port_discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface PortInfo {
version: any;
sslPort: number;
port: number;
options: ArgMap;
requestedVersion?: string;
securityRealm?: string;
runtimeInformationChannel: string;
Expand Down Expand Up @@ -61,10 +62,11 @@ export class PortDiscovery extends EventEmitter {
version: <string>ver.openfin,
// tslint:enable
sslPort: -1,
port: port,
port,
options: args,
requestedVersion: versionKeyword,
securityRealm: securityRealm,
runtimeInformationChannel: runtimeInformationChannel
securityRealm,
runtimeInformationChannel
};

return portDiscoveryPayload;
Expand Down

0 comments on commit 476f4da

Please sign in to comment.