Display actual IP address on onion path dialog

pull/1631/head
Lucas Phang 4 years ago
parent 2f3dbb5be4
commit ae393d6344

@ -1,7 +1,10 @@
import React, { useState } from 'react'; import React, { useState, useEffect } from 'react';
import { SessionButton, SessionButtonColor, SessionButtonType } from './session/SessionButton'; import { SessionButton, SessionButtonColor, SessionButtonType } from './session/SessionButton';
import { SessionModal } from './session/SessionModal'; import { SessionModal } from './session/SessionModal';
import { DefaultTheme } from 'styled-components'; import { DefaultTheme } from 'styled-components';
import { getPathNodesIPAddresses } from '../session/onions/onionSend';
import { useInterval } from '../hooks/useInterval';
import electron from 'electron'; import electron from 'electron';
const { shell } = electron; const { shell } = electron;
@ -46,33 +49,61 @@ const OnionPath = (props: { nodes: IPathNode[] }) => {
export const OnionStatusDialog = (props: Props) => { export const OnionStatusDialog = (props: Props) => {
const { theme, onClose } = props; const { theme, onClose } = props;
const openFAQPage = () => { const [onionPathAddresses, setOnionPathAddresses] = useState<string[]>([])
console.log("Opening FAQ Page") const [pathNodes, setPathNodes] = useState<IPathNode[]>([])
shell.openExternal('https://getsession.org/faq/#onion-routing');
const getOnionPathAddresses = () => {
const onionPathAddresses = getPathNodesIPAddresses();
console.log("Current Onion Path - ", onionPathAddresses);
setOnionPathAddresses(onionPathAddresses)
} }
const nodes: IPathNode[] = [ const buildOnionPath = () => {
// Default path values
let path = [
{ {
label: 'You' label: 'You'
}, },
{ {
ip: '100', ip: 'Connecting...',
label: 'Entry Node' label: 'Entry Node'
}, },
{ {
ip: '100', ip: 'Connecting...',
label: 'Service Node' label: 'Service Node'
}, },
{ {
ip: '100', ip: 'Connecting...',
label: 'Service Node' label: 'Service Node'
}, },
{ {
ip: '100',
label: 'Destination' label: 'Destination'
}, },
] ]
// if there is a onion path, update the addresses
if (onionPathAddresses.length) {
onionPathAddresses.forEach((ipAddress, index) => {
const pathIndex = index + 1;
path[pathIndex].ip = ipAddress;
})
}
setPathNodes(path);
}
useInterval(() => {
getOnionPathAddresses()
}, 1000)
useEffect(() => {
buildOnionPath()
}, [onionPathAddresses])
const openFAQPage = () => {
console.log("Opening FAQ Page")
shell.openExternal('https://getsession.org/faq/#onion-routing');
}
return ( return (
<SessionModal <SessionModal
title={window.i18n('onionPathIndicatorTitle')} title={window.i18n('onionPathIndicatorTitle')}
@ -84,7 +115,7 @@ export const OnionStatusDialog = (props: Props) => {
<p>{window.i18n('onionPathIndicatorDescription')}</p> <p>{window.i18n('onionPathIndicatorDescription')}</p>
</div> </div>
<OnionPath nodes={nodes} /> <OnionPath nodes={pathNodes} />
<SessionButton <SessionButton
text={window.i18n('learnMore')} text={window.i18n('learnMore')}

@ -109,6 +109,10 @@ export class OnionPaths {
return this.onionPaths.length !== 0 && this.onionPaths[0].path.length !== 0; return this.onionPaths.length !== 0 && this.onionPaths[0].path.length !== 0;
} }
public getOnionPathNoRebuild() {
return this.onionPaths ? this.onionPaths[0].path : [];
}
public markPathAsBad(path: Array<Snode>) { public markPathAsBad(path: Array<Snode>) {
// TODO: we might want to remove the nodes from the // TODO: we might want to remove the nodes from the
// node pool (but we don't know which node on the path // node pool (but we don't know which node on the path

@ -129,7 +129,19 @@ export const getOnionPathStatus = () => {
window.log.error(`getOnionPathStatus Error ${e.code} ${e.message}`); window.log.error(`getOnionPathStatus Error ${e.code} ${e.message}`);
} }
return hasOnionPath; return hasOnionPath;
};
export const getPathNodesIPAddresses = () => {
let pathNodes: Array<Snode> = [];
let displayNode: Array<string> = []
try {
pathNodes = OnionPaths.getInstance().getOnionPathNoRebuild();
displayNode = pathNodes.map(node => node.ip);
} catch (e) {
window.log.error(`getPathNodesIPAddresses Error ${e.code} ${e.message}`);
} }
return displayNode;
};
const initOptionsWithDefaults = (options: OnionFetchBasicOptions) => { const initOptionsWithDefaults = (options: OnionFetchBasicOptions) => {
const defaultFetchBasicOptions = { const defaultFetchBasicOptions = {

Loading…
Cancel
Save