From 8ac48d806294863900ccaf5b381d02cd9b37a76d Mon Sep 17 00:00:00 2001 From: "bartosz.chyra" Date: Wed, 3 Feb 2021 16:04:43 +0100 Subject: [PATCH 1/3] double tor is removed --- src/main/main.js | 19 +++++++++++-------- src/renderer/store/handlers/contacts.ts | 1 + src/renderer/store/handlers/identity.ts | 6 ++---- src/renderer/store/handlers/messages.ts | 1 + src/renderer/store/handlers/users.ts | 6 +++--- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/main/main.js b/src/main/main.js index d9604f298..d4b086277 100644 --- a/src/main/main.js +++ b/src/main/main.js @@ -253,14 +253,17 @@ app.on('ready', async () => { mainWindow.webContents.on('did-finish-load', async () => { mainWindow.webContents.send('ping') try { - // Spawn and kill tor to generate onionAddress - console.log('spawning tor for onion address') - torProcess = await spawnTor() - createServer(mainWindow) - mainWindow.webContents.send('onionAddress', getOnionAddress()) - torProcess.kill() - torProcess = null - console.log('killed tor process') + if (!torProcess) { + + // Spawn and kill tor to generate onionAddress + console.log('spawning tor for onion address') + torProcess = await spawnTor() + createServer(mainWindow) + mainWindow.webContents.send('onionAddress', getOnionAddress()) + // torProcess.kill() + // torProcess = null + // console.log('killed tor process') + } } catch (error) { console.log(error) } diff --git a/src/renderer/store/handlers/contacts.ts b/src/renderer/store/handlers/contacts.ts index f9007476b..3e7941901 100644 --- a/src/renderer/store/handlers/contacts.ts +++ b/src/renderer/store/handlers/contacts.ts @@ -223,6 +223,7 @@ export const connectWsContacts = (key?: string) => async (dispatch, getState) => const user = users[contact.key] if (user?.onionAddress) { console.log("trying to connect inside contacts loop") + console.log(user?.onionAddress) contactsToConnect.push({ key: contact.key, onionAddress: user?.onionAddress }) } } diff --git a/src/renderer/store/handlers/identity.ts b/src/renderer/store/handlers/identity.ts index c21068700..988f91592 100644 --- a/src/renderer/store/handlers/identity.ts +++ b/src/renderer/store/handlers/identity.ts @@ -408,7 +408,7 @@ export const setIdentityEpic = identityToSet => async (dispatch, getState) => { await dispatch(fetchBalance()) await dispatch(fetchFreeUtxos()) await dispatch(messagesHandlers.epics.fetchMessages()) - await dispatch(appHandlers.epics.initializeUseTor()) + // await dispatch(appHandlers.epics.initializeUseTor()) const usernameStatus = electronStore.get('registrationStatus.status') const nickname = electronStore.get('registrationStatus.nickname') console.log(usernameStatus) @@ -429,10 +429,8 @@ export const setIdentityEpic = identityToSet => async (dispatch, getState) => { } dispatch(setLoadingMessage('')) dispatch(setLoading(false)) - setTimeout(() => { dispatch(contactsHandlers.epics.connectWsContacts()) - }, 5000) - if (electronStore.get('isMigrating')) { + if (electronStore.get('isMigrating')) { dispatch(modalsHandlers.actionCreators.openModal('migrationModal')()) } } diff --git a/src/renderer/store/handlers/messages.ts b/src/renderer/store/handlers/messages.ts index b256509c1..3de56942d 100644 --- a/src/renderer/store/handlers/messages.ts +++ b/src/renderer/store/handlers/messages.ts @@ -620,6 +620,7 @@ export const handleWebsocketMessage = data => async (dispatch, getState) => { console.log('Contact exist') if (!contact.connected) { console.log('Contact is not connected, initializing connection') + console.log(publicKey) //dispatch(contactsHandlers.actions.setContactConnected({ connected: true, key: publicKey })) dispatch(contactsHandlers.epics.connectWsContacts(publicKey)) } diff --git a/src/renderer/store/handlers/users.ts b/src/renderer/store/handlers/users.ts index 778bab93c..ed9088753 100644 --- a/src/renderer/store/handlers/users.ts +++ b/src/renderer/store/handlers/users.ts @@ -252,9 +252,9 @@ export const createOrUpdateUser = payload => async (dispatch, getState) => { status: 'IN_PROGRESS' }) - ipcRenderer.send('spawnTor') - electronStore.set('useTor', true) - dispatch(appHandlers.actions.setUseTor(true)) + // ipcRenderer.send('spawnTor') + // electronStore.set('useTor', true) + // dispatch(appHandlers.actions.setUseTor(true)) dispatch(checkRegistrationConfirmations({ firstRun: true })) dispatch( notificationsHandlers.actions.enqueueSnackbar( From 17bc31b0c054c74ad6134267ef13844b3f862e36 Mon Sep 17 00:00:00 2001 From: "bartosz.chyra" Date: Thu, 4 Feb 2021 13:13:49 +0100 Subject: [PATCH 2/3] fixed double tor process --- src/main/main.js | 3 +++ src/renderer/index.js | 8 +++++++- src/renderer/store/handlers/identity.ts | 9 ++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/main.js b/src/main/main.js index d4b086277..741d0a3f5 100644 --- a/src/main/main.js +++ b/src/main/main.js @@ -287,10 +287,13 @@ app.on('ready', async () => { console.log('spawning tor for application') torProcess = await spawnTor() electronStore.set('isTorActive', true) + mainWindow.webContents.send('connectWsContacts') } }) ipcMain.on('killTor', async (event, arg) => { + console.log('starting killing tor') if (torProcess !== null) { + console.log('tor killing proccessing') torProcess.kill() torProcess = null electronStore.set('isTorActive', false) diff --git a/src/renderer/index.js b/src/renderer/index.js index d00b45eb8..deb7d3426 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -15,8 +15,9 @@ import messagesHandlers from './store/handlers/messages' import nodeSelectors from './store/selectors/node' import coordinatorSelectors from './store/selectors/coordinator' import identityHandlers from './store/handlers/identity' -import { errorNotification, successNotification } from './store/handlers/utils' +import contactsHandlers from './store/handlers/contacts' +import { errorNotification, successNotification } from './store/handlers/utils' import notificationsHandlers from './store/handlers/notifications' import appSelectors from './store/selectors/app' @@ -66,6 +67,11 @@ ipcRenderer.on('wsMessage', (_, data) => { store.dispatch(messagesHandlers.epics.handleWebsocketMessage(data)) }) +ipcRenderer.on('connectWsContacts', (event, msg) => { + console.log('connecting ws contacts') + store.dispatch(contactsHandlers.epics.connectWsContacts()) +}) + ipcRenderer.on('askForUsingDefaultBlockchainLocation', event => { store.dispatch(appHandlers.epics.askForBlockchainLocation()) }) diff --git a/src/renderer/store/handlers/identity.ts b/src/renderer/store/handlers/identity.ts index 988f91592..7b1b14de0 100644 --- a/src/renderer/store/handlers/identity.ts +++ b/src/renderer/store/handlers/identity.ts @@ -4,7 +4,7 @@ import { createAction, handleActions } from 'redux-actions' import secp256k1 from 'secp256k1' import { randomBytes } from 'crypto' import { DateTime } from 'luxon' -import { remote } from 'electron' +import { ipcRenderer, remote } from 'electron' import client from '../../zcash' import channels from '../../zcash/channels' @@ -408,8 +408,11 @@ export const setIdentityEpic = identityToSet => async (dispatch, getState) => { await dispatch(fetchBalance()) await dispatch(fetchFreeUtxos()) await dispatch(messagesHandlers.epics.fetchMessages()) - // await dispatch(appHandlers.epics.initializeUseTor()) - const usernameStatus = electronStore.get('registrationStatus.status') + if (!useTor) { + ipcRenderer.send('killTor') + // await dispatch(appHandlers.epics.initializeUseTor()) + } + const usernameStatus = electronStore.get('registrationStatus.status') const nickname = electronStore.get('registrationStatus.nickname') console.log(usernameStatus) if (nickname && usernameStatus !== 'SUCCESS') { From 29982c6a42bcb278139465eadf8566f2aa1bde42 Mon Sep 17 00:00:00 2001 From: "bartosz.chyra" Date: Thu, 4 Feb 2021 13:18:25 +0100 Subject: [PATCH 3/3] increased ws connection timeout --- src/main/websockets/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/websockets/client.js b/src/main/websockets/client.js index c0c814c5b..9e16a3381 100644 --- a/src/main/websockets/client.js +++ b/src/main/websockets/client.js @@ -32,7 +32,7 @@ new Promise((resolve, reject) => { const id = setTimeout(() => { // eslint-disable-next-line reject('timeout') - }, 20000) + }, 35000) socket.on('unexpected-response', err => { console.log(err) })