diff options
| author | Andrej Mihajlov <and@mullvad.net> | 2017-12-12 12:51:03 +0100 |
|---|---|---|
| committer | Andrej Mihajlov <and@mullvad.net> | 2017-12-19 10:32:24 +0100 |
| commit | 668ddcd44533f2d8e80f373e0bcd2d9d257e6ed3 (patch) | |
| tree | c6c146e869e7c8897342dcc6dd87f72974daf5f2 | |
| parent | 383a48638198accef99e987cd3297283ed25398b (diff) | |
| download | mullvadvpn-668ddcd44533f2d8e80f373e0bcd2d9d257e6ed3.tar.xz mullvadvpn-668ddcd44533f2d8e80f373e0bcd2d9d257e6ed3.zip | |
Add IPC method to fetch relay locations
| -rw-r--r-- | app/lib/ipc-facade.js | 39 | ||||
| -rw-r--r-- | test/mocks/ipc.js | 4 |
2 files changed, 43 insertions, 0 deletions
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js index a4cf9bdc9f..2fa4212622 100644 --- a/app/lib/ipc-facade.js +++ b/app/lib/ipc-facade.js @@ -108,6 +108,34 @@ const RelaySettingsSchema = oneOf( }) ); +export type RelayList = { + countries: Array<RelayListCountry>, +}; + +export type RelayListCountry = { + name: string, + code: string, + cities: Array<RelayListCity>, +}; + +export type RelayListCity = { + name: string, + code: string, + position: [Number, Number], +}; + +const RelayListSchema = object({ + countries: arrayOf(object({ + name: string, + code: string, + cities: arrayOf(object({ + name: string, + code: string, + position: arrayOf(number), + })), + })), +}); + export interface IpcFacade { setConnectionString(string): void, @@ -116,6 +144,7 @@ export interface IpcFacade { setAccount(accountToken: ?AccountToken): Promise<void>, updateRelaySettings(RelaySettingsUpdate): Promise<void>, getRelaySettings(): Promise<RelaySettings>, + getRelayLocations(): Promise<RelayList>, connect(): Promise<void>, disconnect(): Promise<void>, shutdown(): Promise<void>, @@ -192,6 +221,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); + } + } + connect(): Promise<void> { return this._ipc.send('connect') .then(this._ignoreResponse); diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js index 59655c03ab..ede4bd37b7 100644 --- a/test/mocks/ipc.js +++ b/test/mocks/ipc.js @@ -42,6 +42,10 @@ export function newMockIpc() { }, }), + getRelayLocations: () => Promise.resolve({ + countries: [], + }), + connect: () => Promise.resolve(), disconnect: () => Promise.resolve(), |
