diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-12-26 11:10:15 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2018-01-03 11:57:35 +0100 |
| commit | 21b53d23243336c6939d898897d605685efbada3 (patch) | |
| tree | 68df18757e605e17aa1c6d20f0a185b5953d6a87 | |
| parent | 7028023e6a53b2644a4029acf45b0e9d2bf2ecc1 (diff) | |
| download | mullvadvpn-21b53d23243336c6939d898897d605685efbada3.tar.xz mullvadvpn-21b53d23243336c6939d898897d605685efbada3.zip | |
Add getAllowLan and setAllowLan RPC calls
| -rw-r--r-- | app/lib/ipc-facade.js | 32 | ||||
| -rw-r--r-- | test/mocks/ipc.js | 10 |
2 files changed, 31 insertions, 11 deletions
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js index 567a6ab8f1..b2676193ee 100644 --- a/app/lib/ipc-facade.js +++ b/app/lib/ipc-facade.js @@ -142,11 +142,13 @@ const RelayListSchema = object({ export interface IpcFacade { setConnectionString(string): void, getAccountData(AccountToken): Promise<AccountData>, + getRelayLocations(): Promise<RelayList>, getAccount(): Promise<?AccountToken>, setAccount(accountToken: ?AccountToken): Promise<void>, updateRelaySettings(RelaySettingsUpdate): Promise<void>, getRelaySettings(): Promise<RelaySettings>, - getRelayLocations(): Promise<RelayList>, + setAllowLan(boolean): Promise<void>, + getAllowLan(): Promise<boolean>, connect(): Promise<void>, disconnect(): Promise<void>, shutdown(): Promise<void>, @@ -186,6 +188,16 @@ export class RealIpc implements IpcFacade { }); } + async getRelayLocations(): Promise<RelayList> { + const raw = await this._ipc.send('get_relay_locations'); + try { + const validated: any = validate(RelayListSchema, raw); + return (validated: RelayList); + } catch (e) { + throw new InvalidReply(raw, e); + } + } + getAccount(): Promise<?AccountToken> { return this._ipc.send('get_account') .then( raw => { @@ -223,13 +235,17 @@ export class RealIpc implements IpcFacade { }); } - async getRelayLocations(): Promise<RelayList> { - const raw = await this._ipc.send('get_relay_locations'); - try { - const validated: any = validate(RelayListSchema, raw); - return (validated: RelayList); - } catch (e) { - throw new InvalidReply(raw, e); + setAllowLan(allowLan: boolean): Promise<void> { + return this._ipc.send('set_allow_lan', [allowLan]) + .then(this._ignoreResponse); + } + + async getAllowLan(): Promise<boolean> { + const raw = await this._ipc.send('get_allow_lan'); + if(typeof(raw) === 'boolean') { + return raw; + } else { + throw new InvalidReply(raw, 'Expected a boolean'); } } diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js index ede4bd37b7..fc035f55ed 100644 --- a/test/mocks/ipc.js +++ b/test/mocks/ipc.js @@ -24,6 +24,10 @@ export function newMockIpc() { expiry: '', }), + getRelayLocations: () => Promise.resolve({ + countries: [], + }), + getAccount: () => Promise.resolve('1111'), setAccount: () => Promise.resolve(), @@ -42,9 +46,9 @@ export function newMockIpc() { }, }), - getRelayLocations: () => Promise.resolve({ - countries: [], - }), + setAllowLan: (_allowLan: boolean) => Promise.resolve(), + + getAllowLan: () => Promise.resolve(true), connect: () => Promise.resolve(), |
