summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2018-01-11 15:44:50 +0100
committerLinus Färnstrand <linus@mullvad.net>2018-01-15 16:21:31 +0100
commit928615a5a91ef4a3f52fbd4a6629e86993a1a3aa (patch)
treed76821ad40b0d72f359051945b2d5c415c99fca2
parentfc4178d7e3329fb1fd0014e4ce349a79eafeca51 (diff)
downloadmullvadvpn-928615a5a91ef4a3f52fbd4a6629e86993a1a3aa.tar.xz
mullvadvpn-928615a5a91ef4a3f52fbd4a6629e86993a1a3aa.zip
Adapt frontend to removed ip call and changed location struct
-rw-r--r--app/components/Connect.js2
-rw-r--r--app/lib/backend.js26
-rw-r--r--app/lib/ipc-facade.js32
-rw-r--r--app/redux/connection/actions.js42
-rw-r--r--app/redux/connection/reducers.js15
-rw-r--r--app/redux/settings/reducers.js3
-rw-r--r--test/components/Connect.spec.js12
-rw-r--r--test/components/SelectLocation.spec.js6
-rw-r--r--test/connection-info.spec.js9
-rw-r--r--test/mocks/ipc.js9
10 files changed, 58 insertions, 98 deletions
diff --git a/app/components/Connect.js b/app/components/Connect.js
index fdbe927b77..b0bbc21fac 100644
--- a/app/components/Connect.js
+++ b/app/components/Connect.js
@@ -162,7 +162,7 @@ export default class Connect extends Component {
if(isDisconnected) {
ipComponent = (<span>{ '\u2003' }</span>);
} else {
- ipComponent = (<span>{ this.props.connection.clientIp }</span>);
+ ipComponent = (<span>{ this.props.connection.ip }</span>);
}
}
}
diff --git a/app/lib/backend.js b/app/lib/backend.js
index cd14adb045..9439e09256 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -128,12 +128,6 @@ export class Backend {
}
try {
- await this._fetchPublicIP();
- } catch(e) {
- log.error('Failed to fetch the public IP: ', e.message);
- }
-
- try {
await this._fetchLocation();
} catch(e) {
log.error('Failed to fetch the location: ', e.message);
@@ -359,7 +353,8 @@ export class Backend {
cities: country.cities.map((city) => ({
name: city.name,
code: city.code,
- position: city.position,
+ latitude: city.latitude,
+ longitude: city.longitude,
hasActiveRelays: city.has_active_relays,
}))
}));
@@ -369,18 +364,6 @@ export class Backend {
);
}
- async _fetchPublicIP() {
- await this._ensureAuthenticated();
-
- const publicIp = await this._ipc.getPublicIp();
-
- log.info('Got public IP: ', publicIp);
-
- this._store.dispatch(
- connectionActions.newPublicIp(publicIp)
- );
- }
-
async _fetchLocation() {
await this._ensureAuthenticated();
@@ -389,9 +372,12 @@ export class Backend {
log.info('Got location: ', location);
const locationUpdate = {
+ ip: location.ip,
country: location.country,
city: location.city,
- location: location.position
+ latitude: location.latitude,
+ longitude: location.longitude,
+ mullvadExitIp: location.mullvad_exit_ip,
};
this._store.dispatch(
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js
index b2676193ee..b54cbe5177 100644
--- a/app/lib/ipc-facade.js
+++ b/app/lib/ipc-facade.js
@@ -4,22 +4,24 @@ import JsonRpcWs, { InvalidReply } from './jsonrpc-ws-ipc';
import { object, string, number, boolean, enumeration, arrayOf, oneOf } from 'validated/schema';
import { validate } from 'validated/object';
-import type { Coordinate2d } from '../types';
-
export type AccountData = { expiry: string };
export type AccountToken = string;
export type Ip = string;
export type Location = {
+ ip: Ip,
country: string,
city: string,
- position: Coordinate2d,
+ latitude: number,
+ longitude: number,
+ mullvad_exit_ip: boolean,
};
const LocationSchema = object({
+ ip: string,
country: string,
- country_code: string,
city: string,
- city_code: string,
- position: arrayOf(number),
+ latitude: number,
+ longitude: number,
+ mullvad_exit_ip: boolean,
});
export type SecurityState = 'secured' | 'unsecured';
@@ -121,7 +123,8 @@ export type RelayListCountry = {
export type RelayListCity = {
name: string,
code: string,
- position: [number, number],
+ latitude: number,
+ longitude: number,
has_active_relays: boolean,
};
@@ -132,7 +135,8 @@ const RelayListSchema = object({
cities: arrayOf(object({
name: string,
code: string,
- position: arrayOf(number),
+ latitude: number,
+ longitude: number,
has_active_relays: boolean,
})),
})),
@@ -152,7 +156,6 @@ export interface IpcFacade {
connect(): Promise<void>,
disconnect(): Promise<void>,
shutdown(): Promise<void>,
- getPublicIp(): Promise<Ip>,
getLocation(): Promise<Location>,
getState(): Promise<BackendState>,
registerStateListener((BackendState) => void): void,
@@ -264,17 +267,6 @@ export class RealIpc implements IpcFacade {
.then(this._ignoreResponse);
}
- getPublicIp(): Promise<Ip> {
- return this._ipc.send('get_public_ip')
- .then(raw => {
- if (typeof raw === 'string' && raw) {
- return raw;
- } else {
- throw new InvalidReply(raw, 'Expected a string');
- }
- });
- }
-
getLocation(): Promise<Location> {
return this._ipc.send('get_current_location')
.then(raw => {
diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js
index aef4b85213..fb18777124 100644
--- a/app/redux/connection/actions.js
+++ b/app/redux/connection/actions.js
@@ -4,15 +4,15 @@ import { Clipboard } from 'reactxp';
import type { Backend } from '../../lib/backend';
import type { ReduxThunk } from '../store';
-import type { Coordinate2d } from '../../types';
+import type { Ip } from '../../lib/ipc-facade';
const connect = (backend: Backend): ReduxThunk => () => backend.connect();
const disconnect = (backend: Backend) => () => backend.disconnect();
const copyIPAddress = (): ReduxThunk => {
return (_, getState) => {
- const { connection: { clientIp } } = getState();
- if(clientIp) {
- Clipboard.setText(clientIp);
+ const ip = getState().connection.ip;
+ if(ip) {
+ Clipboard.setText(ip);
}
};
};
@@ -28,20 +28,16 @@ type DisconnectedAction = {
type: 'DISCONNECTED',
};
-type NewPublicIpAction = {
- type: 'NEW_PUBLIC_IP',
- ip: string,
-};
-
-type Location = {
- location: Coordinate2d,
- country: string,
- city: string,
-};
-
type NewLocationAction = {
type: 'NEW_LOCATION',
- newLocation: Location,
+ newLocation: {
+ ip: Ip,
+ country: string,
+ city: string,
+ latitude: number,
+ longitude: number,
+ mullvadExitIp: boolean,
+ },
};
type OnlineAction = {
@@ -52,8 +48,7 @@ type OfflineAction = {
type: 'OFFLINE',
};
-export type ConnectionAction = NewPublicIpAction
- | NewLocationAction
+export type ConnectionAction = NewLocationAction
| ConnectingAction
| ConnectedAction
| DisconnectedAction
@@ -78,14 +73,7 @@ function disconnected(): DisconnectedAction {
};
}
-function newPublicIp(ip: string): NewPublicIpAction {
- return {
- type: 'NEW_PUBLIC_IP',
- ip: ip,
- };
-}
-
-function newLocation(newLoc: Location): NewLocationAction {
+function newLocation(newLoc: $PropertyType<NewLocationAction, 'newLocation'>): NewLocationAction {
return {
type: 'NEW_LOCATION',
newLocation: newLoc,
@@ -105,5 +93,5 @@ function offline(): OfflineAction {
}
-export default { connect, disconnect, copyIPAddress, newPublicIp, newLocation, connecting, connected, disconnected, online, offline };
+export default { connect, disconnect, copyIPAddress, newLocation, connecting, connected, disconnected, online, offline };
diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js
index 52c1d648c1..7eb4c2aaf4 100644
--- a/app/redux/connection/reducers.js
+++ b/app/redux/connection/reducers.js
@@ -1,14 +1,15 @@
// @flow
import type { ReduxAction } from '../store';
-import type { Coordinate2d } from '../../types';
+import type { Ip } from '../../lib/ipc-facade';
export type ConnectionState = 'disconnected' | 'connecting' | 'connected';
export type ConnectionReduxState = {
status: ConnectionState,
isOnline: boolean,
- clientIp: ?string,
- location: ?Coordinate2d,
+ ip: ?Ip,
+ latitude: ?number,
+ longitude: ?number,
country: ?string,
city: ?string,
};
@@ -16,8 +17,9 @@ export type ConnectionReduxState = {
const initialState: ConnectionReduxState = {
status: 'disconnected',
isOnline: true,
- clientIp: null,
- location: null,
+ ip: null,
+ latitude: null,
+ longitude: null,
country: null,
city: null,
};
@@ -29,9 +31,6 @@ export default function(state: ConnectionReduxState = initialState, action: Redu
case 'CONNECTION_CHANGE':
return { ...state, ...action.newData };
- case 'NEW_PUBLIC_IP':
- return { ...state, ...{ clientIp: action.ip }};
-
case 'NEW_LOCATION':
return { ...state, ...action.newLocation };
diff --git a/app/redux/settings/reducers.js b/app/redux/settings/reducers.js
index 59f51c2a66..39005fd486 100644
--- a/app/redux/settings/reducers.js
+++ b/app/redux/settings/reducers.js
@@ -20,7 +20,8 @@ export type RelaySettingsRedux = {|
export type RelayLocationCityRedux = {
name: string,
code: string,
- position: [number, number],
+ latitude: number,
+ longitude: number,
hasActiveRelays: boolean,
};
diff --git a/test/components/Connect.spec.js b/test/components/Connect.spec.js
index ed8c17982a..a14f644045 100644
--- a/test/components/Connect.spec.js
+++ b/test/components/Connect.spec.js
@@ -69,7 +69,7 @@ describe('components/Connect', () => {
status: 'connected',
country: 'Norway',
city: 'Oslo',
- clientIp: '4.3.2.1',
+ ip: '4.3.2.1',
}
});
const countryAndCity = component.find('.connect__status-location');
@@ -87,7 +87,7 @@ describe('components/Connect', () => {
status: 'disconnected',
country: 'Norway',
city: 'Oslo',
- clientIp: '4.3.2.1',
+ ip: '4.3.2.1',
}
});
const countryAndCity = component.find('.connect__status-location');
@@ -157,8 +157,9 @@ const defaultProps: ConnectProps = {
cities: [{
name: 'Malmö',
code: 'mma',
+ latitude: 0,
+ longitude: 0,
hasActiveRelays: true,
- position: [0, 0],
}]
}],
allowLan: false,
@@ -166,8 +167,9 @@ const defaultProps: ConnectProps = {
connection: {
status: 'disconnected',
isOnline: true,
- clientIp: null,
- location: null,
+ ip: null,
+ latitude: null,
+ longitude: null,
country: null,
city: null,
},
diff --git a/test/components/SelectLocation.spec.js b/test/components/SelectLocation.spec.js
index 7ec17ff798..eb72b03c57 100644
--- a/test/components/SelectLocation.spec.js
+++ b/test/components/SelectLocation.spec.js
@@ -24,12 +24,14 @@ describe('components/SelectLocation', () => {
cities: [{
name: 'Malmö',
code: 'mma',
- position: [0, 0],
+ latitude: 0,
+ longitude: 0,
hasActiveRelays: true,
}, {
name: 'Stockholm',
code: 'sto',
- position: [0, 0],
+ latitude: 0,
+ longitude: 0,
hasActiveRelays: true,
}],
}],
diff --git a/test/connection-info.spec.js b/test/connection-info.spec.js
index 76a97a35f7..875825054f 100644
--- a/test/connection-info.spec.js
+++ b/test/connection-info.spec.js
@@ -7,15 +7,6 @@ import connectionActions from '../app/redux/connection/actions';
describe('The connection state', () => {
- it('should contain the latest IP', () => {
- const store = createStore();
-
- store.dispatch(connectionActions.newPublicIp('1.2.3.4'));
- store.dispatch(connectionActions.newPublicIp('5.6.7.8'));
-
- expect(store.getState().connection.clientIp).to.equal('5.6.7.8');
- });
-
it('should contain the latest location', () => {
const store = createStore();
diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js
index fc035f55ed..2ba32ecf2f 100644
--- a/test/mocks/ipc.js
+++ b/test/mocks/ipc.js
@@ -56,14 +56,13 @@ export function newMockIpc() {
shutdown: () => Promise.resolve(),
- getPublicIp: () => Promise.resolve('1.2.3.4'),
-
getLocation: () => Promise.resolve({
+ ip: '',
country: '',
- country_code: '',
city: '',
- city_code: '',
- position: [0, 0],
+ latitude: 0.0,
+ longitude: 0.0,
+ mullvad_exit_ip: false,
}),
getState: () => Promise.resolve({