diff options
| author | Erik Larkö <erik@mullvad.net> | 2017-09-12 13:33:46 +0200 |
|---|---|---|
| committer | Erik Larkö <erik@mullvad.net> | 2017-09-12 13:46:04 +0200 |
| commit | 4ed0102b38aa29bee9b0a876ec48c48d715f644e (patch) | |
| tree | 4c3334ed98f97b2c83c9b49f448c790810a5f835 /app | |
| parent | d541f4ee98182faa6c4e52727c948612b4d7ad53 (diff) | |
| download | mullvadvpn-4ed0102b38aa29bee9b0a876ec48c48d715f644e.tar.xz mullvadvpn-4ed0102b38aa29bee9b0a876ec48c48d715f644e.zip | |
Move the hardcoded relay endpoint data to the Connect component
Diffstat (limited to 'app')
| -rw-r--r-- | app/components/Connect.js | 10 | ||||
| -rw-r--r-- | app/containers/ConnectPage.js | 2 | ||||
| -rw-r--r-- | app/containers/SelectLocationPage.js | 8 | ||||
| -rw-r--r-- | app/lib/backend.js | 10 | ||||
| -rw-r--r-- | app/lib/ipc-facade.js | 16 | ||||
| -rw-r--r-- | app/redux/connection/actions.js | 9 | ||||
| -rw-r--r-- | app/redux/connection/reducers.js | 4 |
7 files changed, 37 insertions, 22 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/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 9d1fb21d35..b17b163a85 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'; @@ -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)); - // TODO: Don't hardcode these values - return this._ipc.setCustomRelay(addr, 1300, 'udp') + 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 0a9ceebf65..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>, - setCustomRelay(host: string, port: number, protocol: 'udp' | 'tcp'): Promise<void>, + setCustomRelay(RelayEndpoint): Promise<void>, connect(): Promise<void>, disconnect(): Promise<void>, getIp(): Promise<Ip>, @@ -86,12 +92,8 @@ export class RealIpc implements IpcFacade { return; } - setCustomRelay(host: string, port: number, protocol: 'udp' | 'tcp'): Promise<void> { - return this._ipc.send('set_custom_relay', { - host, - port, - protocol, - }) + 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}; } |
