From ae393d63444688b4f0bc4c77a48b1329236b9a22 Mon Sep 17 00:00:00 2001 From: Lucas Phang Date: Fri, 14 May 2021 16:31:23 +1000 Subject: [PATCH] Display actual IP address on onion path dialog --- ts/components/OnionStatusDialog.tsx | 81 ++++++++++++++++++++--------- ts/session/onions/index.ts | 6 ++- ts/session/onions/onionSend.ts | 16 +++++- 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/ts/components/OnionStatusDialog.tsx b/ts/components/OnionStatusDialog.tsx index 9d423ca18..4f50c7ce5 100644 --- a/ts/components/OnionStatusDialog.tsx +++ b/ts/components/OnionStatusDialog.tsx @@ -1,7 +1,10 @@ -import React, { useState } from 'react'; +import React, { useState, useEffect } from 'react'; import { SessionButton, SessionButtonColor, SessionButtonType } from './session/SessionButton'; import { SessionModal } from './session/SessionModal'; import { DefaultTheme } from 'styled-components'; +import { getPathNodesIPAddresses } from '../session/onions/onionSend'; +import { useInterval } from '../hooks/useInterval'; + import electron from 'electron'; const { shell } = electron; @@ -46,33 +49,61 @@ const OnionPath = (props: { nodes: IPathNode[] }) => { export const OnionStatusDialog = (props: Props) => { const { theme, onClose } = props; + const [onionPathAddresses, setOnionPathAddresses] = useState([]) + const [pathNodes, setPathNodes] = useState([]) + + const getOnionPathAddresses = () => { + const onionPathAddresses = getPathNodesIPAddresses(); + console.log("Current Onion Path - ", onionPathAddresses); + setOnionPathAddresses(onionPathAddresses) + } + + const buildOnionPath = () => { + // Default path values + let path = [ + { + label: 'You' + }, + { + ip: 'Connecting...', + label: 'Entry Node' + }, + { + ip: 'Connecting...', + label: 'Service Node' + }, + { + ip: 'Connecting...', + label: 'Service Node' + }, + { + 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'); } - - const nodes: IPathNode[] = [ - { - label: 'You' - }, - { - ip: '100', - label: 'Entry Node' - }, - { - ip: '100', - label: 'Service Node' - }, - { - ip: '100', - label: 'Service Node' - }, - { - ip: '100', - label: 'Destination' - }, - ] - + return ( {

{window.i18n('onionPathIndicatorDescription')}

- + ) { // TODO: we might want to remove the nodes from the // node pool (but we don't know which node on the path diff --git a/ts/session/onions/onionSend.ts b/ts/session/onions/onionSend.ts index 18a672ee2..5fdc558f8 100644 --- a/ts/session/onions/onionSend.ts +++ b/ts/session/onions/onionSend.ts @@ -124,12 +124,24 @@ export const getOnionPathForSending = async (requestNumber: number) => { export const getOnionPathStatus = () => { let hasOnionPath: boolean = false; try { - hasOnionPath = OnionPaths.getInstance().hasOnionPath(); + hasOnionPath = OnionPaths.getInstance().hasOnionPath(); } catch (e) { window.log.error(`getOnionPathStatus Error ${e.code} ${e.message}`); } return hasOnionPath; -} +}; + +export const getPathNodesIPAddresses = () => { + let pathNodes: Array = []; + let displayNode: Array = [] + 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 defaultFetchBasicOptions = {