summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorErik Larkö <erik@mullvad.net>2017-09-13 14:26:57 +0200
committerErik Larkö <erik@mullvad.net>2017-09-13 14:26:57 +0200
commit754af96a12716152f2ddb9e56836e29f28720614 (patch)
tree27d9663ea988ef8c779ec8a9646e37d87381dc1e
parent057f46bc30102b48b54775c4f43288c87e8203bb (diff)
parentdf25856fe28e3568e1a9fd2584c59ab8a2808ddd (diff)
downloadmullvadvpn-754af96a12716152f2ddb9e56836e29f28720614.tar.xz
mullvadvpn-754af96a12716152f2ddb9e56836e29f28720614.zip
Merge branch 'set_custom_relay'
-rw-r--r--app/components/Connect.js10
-rw-r--r--app/config.json6
-rw-r--r--app/containers/ConnectPage.js2
-rw-r--r--app/containers/SelectLocationPage.js8
-rw-r--r--app/lib/backend.js12
-rw-r--r--app/lib/ipc-facade.js12
-rw-r--r--app/redux/connection/actions.js9
-rw-r--r--app/redux/connection/reducers.js4
-rw-r--r--test/components/Connect.spec.js2
-rw-r--r--test/connect.spec.js27
-rw-r--r--test/mocks/ipc.js2
11 files changed, 62 insertions, 32 deletions
diff --git a/app/components/Connect.js b/app/components/Connect.js
index 7d6269655a..66696fef64 100644
--- a/app/components/Connect.js
+++ b/app/components/Connect.js
@@ -10,6 +10,7 @@ import ExternalLinkSVG from '../assets/images/icon-extLink.svg';
import type { ServerInfo } from '../lib/backend';
import type { HeaderBarStyle } from './HeaderBar';
import type { ConnectionReduxState } from '../redux/connection/reducers';
+import type { RelayEndpoint } from '../lib/ipc-facade';
export type ConnectProps = {
accountExpiry: string,
@@ -17,7 +18,7 @@ export type ConnectProps = {
preferredServer: string,
onSettings: () => void,
onSelectLocation: () => void,
- onConnect: (address: string) => void,
+ onConnect: (relayEndpoint: RelayEndpoint) => void,
onCopyIP: () => void,
onDisconnect: () => void,
onExternalLink: (type: string) => void,
@@ -301,7 +302,12 @@ export default class Connect extends Component {
const preferredServer = this.props.preferredServer;
const serverInfo = this.props.getServerInfo(preferredServer);
if(serverInfo) {
- this.props.onConnect(serverInfo.address);
+ // TODO: Don't use these hardcoded values
+ this.props.onConnect({
+ host: serverInfo.address,
+ port: 1300,
+ protocol: 'udp',
+ });
}
}
diff --git a/app/config.json b/app/config.json
index d6cd2993f0..fe8d12d84a 100644
--- a/app/config.json
+++ b/app/config.json
@@ -132,8 +132,8 @@
8.541694
]
},
- "uk.mullvad.net": {
- "address": "uk.mullvad.net",
+ "gb.mullvad.net": {
+ "address": "gb.mullvad.net",
"name": "United Kingdom",
"city": "London",
"country": "United Kingdom",
@@ -153,4 +153,4 @@
]
}
}
-} \ No newline at end of file
+}
diff --git a/app/containers/ConnectPage.js b/app/containers/ConnectPage.js
index ceb16054ce..d629e83fc7 100644
--- a/app/containers/ConnectPage.js
+++ b/app/containers/ConnectPage.js
@@ -21,7 +21,7 @@ const mapDispatchToProps = (dispatch, props) => {
return {
onSettings: () => dispatch(push('/settings')),
onSelectLocation: () => dispatch(push('/select-location')),
- onConnect: (addr) => connect(backend, addr),
+ onConnect: (relayEndpoint) => connect(backend, relayEndpoint),
onCopyIP: () => copyIPAddress(),
onDisconnect: () => disconnect(backend),
onExternalLink: (type) => shell.openExternal(links[type]),
diff --git a/app/containers/SelectLocationPage.js b/app/containers/SelectLocationPage.js
index 824274c15c..c11c4b59dd 100644
--- a/app/containers/SelectLocationPage.js
+++ b/app/containers/SelectLocationPage.js
@@ -18,7 +18,13 @@ const mapDispatchToProps = (dispatch, props) => {
// add delay to let the map load
setTimeout(() => {
settings.updateSettings({ preferredServer });
- backend.connect(server.address);
+
+ // TODO: Don't use these hardcoded values
+ backend.connect({
+ host: server.address,
+ port: 1300,
+ protocol: 'udp',
+ });
}, 600);
}
};
diff --git a/app/lib/backend.js b/app/lib/backend.js
index 9567c91fd7..9d451960e4 100644
--- a/app/lib/backend.js
+++ b/app/lib/backend.js
@@ -11,6 +11,7 @@ import { push } from 'react-router-redux';
import type { BackendState } from './ipc-facade';
import type { ConnectionState } from '../redux/connection/reducers';
+import type { RelayEndpoint } from './ipc-facade';
export type EventType = 'connect' | 'connecting' | 'disconnect' | 'login' | 'logging' | 'logout' | 'updatedIp' | 'updatedLocation' | 'updatedReachability';
export type ErrorType = 'NO_CREDIT' | 'NO_INTERNET' | 'INVALID_ACCOUNT';
@@ -129,7 +130,7 @@ export class Backend {
fastestServer(): ServerInfo {
return {
- address: 'uk.mullvad.net',
+ address: 'gb.mullvad.net',
name: 'Fastest',
city: 'London',
country: 'United Kingdom',
@@ -227,17 +228,16 @@ export class Backend {
});
}
- connect(addr: string): Promise<void> {
+ connect(relayEndpoint: RelayEndpoint): Promise<void> {
- this._store.dispatch(connectionActions.connectingTo(addr));
+ this._store.dispatch(connectionActions.connectingTo(relayEndpoint));
-
- return this._ipc.setCountry(addr)
+ return this._ipc.setCustomRelay(relayEndpoint)
.then( () => {
return this._ipc.connect();
})
.catch(e => {
- log.info('Failed connecting to', addr, e);
+ log.info('Failed connecting to', relayEndpoint.host, '-', e.message);
this._store.dispatch(connectionActions.disconnected());
});
}
diff --git a/app/lib/ipc-facade.js b/app/lib/ipc-facade.js
index 063dfd11ae..736d4fc31c 100644
--- a/app/lib/ipc-facade.js
+++ b/app/lib/ipc-facade.js
@@ -25,13 +25,19 @@ export type BackendState = {
state: SecurityState,
target_state: SecurityState,
};
+export type RelayEndpoint = {
+ host: string,
+ port: number,
+ protocol: 'tcp' | 'udp',
+};
+
export interface IpcFacade {
setConnectionString(string): void,
getAccountData(AccountToken): Promise<AccountData>,
getAccount(): Promise<?AccountToken>,
setAccount(accountToken: AccountToken): Promise<void>,
- setCountry(address: string): Promise<void>,
+ setCustomRelay(RelayEndpoint): Promise<void>,
connect(): Promise<void>,
disconnect(): Promise<void>,
getIp(): Promise<Ip>,
@@ -86,8 +92,8 @@ export class RealIpc implements IpcFacade {
return;
}
- setCountry(address: string): Promise<void> {
- return this._ipc.send('set_country', address)
+ setCustomRelay(relayEndpoint: RelayEndpoint): Promise<void> {
+ return this._ipc.send('set_custom_relay', [relayEndpoint])
.then(this._ignoreResponse);
}
diff --git a/app/redux/connection/actions.js b/app/redux/connection/actions.js
index eebc503a18..73a94fcc06 100644
--- a/app/redux/connection/actions.js
+++ b/app/redux/connection/actions.js
@@ -3,11 +3,12 @@
import { clipboard } from 'electron';
import type { Backend } from '../../lib/backend';
+import type { RelayEndpoint } from '../../lib/ipc-facade';
import type { ReduxGetState, ReduxDispatch } from '../store';
import type { Coordinate2d } from '../../types';
-const connect = (backend: Backend, addr: string) => () => backend.connect(addr);
+const connect = (backend: Backend, relay: RelayEndpoint) => () => backend.connect(relay);
const disconnect = (backend: Backend) => () => backend.disconnect();
const copyIPAddress = () => {
return (_dispatch: ReduxDispatch, getState: ReduxGetState) => {
@@ -21,7 +22,7 @@ const copyIPAddress = () => {
type ConnectingAction = {
type: 'CONNECTING',
- serverAddress?: string,
+ relayEndpoint?: RelayEndpoint,
};
type ConnectedAction = {
type: 'CONNECTED',
@@ -62,10 +63,10 @@ export type ConnectionAction = NewPublicIpAction
| OnlineAction
| OfflineAction;
-function connectingTo(serverAddress: string): ConnectingAction {
+function connectingTo(relayEndpoint: RelayEndpoint): ConnectingAction {
return {
type: 'CONNECTING',
- serverAddress: serverAddress,
+ relayEndpoint: relayEndpoint,
};
}
diff --git a/app/redux/connection/reducers.js b/app/redux/connection/reducers.js
index 8f389df159..8adfac594a 100644
--- a/app/redux/connection/reducers.js
+++ b/app/redux/connection/reducers.js
@@ -62,8 +62,8 @@ function onConnecting(state, action) {
status: 'connecting',
};
- if (action.serverAddress) {
- newState.serverAddress = action.serverAddress;
+ if (action.relayEndpoint) {
+ newState.serverAddress = action.relayEndpoint.host;
}
return { ...state, ...newState};
}
diff --git a/test/components/Connect.spec.js b/test/components/Connect.spec.js
index 2a385fed5f..30228fc4c6 100644
--- a/test/components/Connect.spec.js
+++ b/test/components/Connect.spec.js
@@ -94,7 +94,7 @@ describe('components/Connect', () => {
it('invokes the onConnect prop', (done) => {
const component = renderNotConnected({
- onConnect: done,
+ onConnect: () => done(),
});
const connectButton = component.find('.button .button--positive');
diff --git a/test/connect.spec.js b/test/connect.spec.js
index 9ecedb53a1..bb6ac41526 100644
--- a/test/connect.spec.js
+++ b/test/connect.spec.js
@@ -7,13 +7,15 @@ import { IpcChain } from './helpers/IpcChain';
describe('connect', () => {
- it('should invoke set_country and then connect in the backend', (done) => {
+ it('should invoke set_custom_relay and then connect in the backend', (done) => {
const { store, mockIpc, backend } = setupBackendAndStore();
const chain = new IpcChain(mockIpc);
- chain.require('setCountry')
+ chain.require('setCustomRelay')
.withInputValidation(
- (country) => expect(country).to.equal('example.com')
+ (relayEndpoint) => {
+ expect(relayEndpoint).to.equal(arbitraryRelay);
+ },
)
.done();
@@ -22,7 +24,7 @@ describe('connect', () => {
chain.onSuccessOrFailure(done);
- store.dispatch(connectionActions.connect(backend, 'example.com'));
+ store.dispatch(connectionActions.connect(backend, arbitraryRelay));
});
it('should set the connection state to \'disconnected\' on failed attempts', (done) => {
@@ -35,7 +37,7 @@ describe('connect', () => {
expect(store.getState().connection.status).not.to.equal('disconnected');
- store.dispatch(connectionActions.connect(backend, 'example.com'));
+ store.dispatch(connectionActions.connect(backend, arbitraryRelay));
checkNextTick(() => {
@@ -45,13 +47,17 @@ describe('connect', () => {
it('should update the state with the server address', () => {
const { store, backend } = setupBackendAndStore();
- const arbitraryString = 'www.example.com';
+ const relay = {
+ host: 'www.example.com',
+ port: 1,
+ protocol: 'udp',
+ };
- return backend.connect(arbitraryString)
+ return backend.connect(relay)
.then( () => {
const state = store.getState().connection;
expect(state.status).to.equal('connecting');
- expect(state.serverAddress).to.equal(arbitraryString);
+ expect(state.serverAddress).to.equal('www.example.com');
});
});
@@ -81,3 +87,8 @@ describe('connect', () => {
});
});
+const arbitraryRelay = {
+ host: 'www.example.com',
+ port: 1,
+ protocol: 'udp',
+};
diff --git a/test/mocks/ipc.js b/test/mocks/ipc.js
index d28c49e6f6..472811ef4c 100644
--- a/test/mocks/ipc.js
+++ b/test/mocks/ipc.js
@@ -27,7 +27,7 @@ export function newMockIpc() {
setAccount: () => {
return new Promise(r => r());
},
- setCountry: () => {
+ setCustomRelay: () => {
return new Promise(r => r());
},
connect: () => {