Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/socket/tunnelbroker.js
- This file was added.
// @flow | |||||
import WebSocket from 'ws'; | |||||
import { type TBKeyserverConnectionInitializationMessage } from 'lib/types/tunnelbroker-messages.js'; | |||||
import sleep from 'lib/utils/sleep.js'; | |||||
import { fetchOlmAccount } from '../updaters/olm-account-updater.js'; | |||||
import type { IdentityInfo } from '../user/identity.js'; | |||||
async function createAndMaintainTunnelbrokerWebsocket( | |||||
identityInfo: IdentityInfo, | |||||
) { | |||||
const accountInfo = await fetchOlmAccount('content'); | |||||
const deviceId = JSON.parse(accountInfo.account.identity_keys()).curve25519; | |||||
ashoat: My feedback from the last review appears to have been ignored:
{F695889}
Remember – a… | |||||
jonUnsubmitted Done Inline Actionsmissed this one. jon: missed this one. | |||||
openTunnelbrokerConnection( | |||||
deviceId, | |||||
identityInfo.userId, | |||||
identityInfo.accessToken, | |||||
); | |||||
} | |||||
function openTunnelbrokerConnection( | |||||
deviceID: string, | |||||
userID: string, | |||||
accessToken: string, | |||||
) { | |||||
try { | |||||
const tunnelbrokerSocket = new WebSocket('ws://127.0.0.1:51001'); | |||||
tunnelbrokerSocket.on('open', () => { | |||||
const message: TBKeyserverConnectionInitializationMessage = { | |||||
type: 'sessionRequest', | |||||
accessToken, | |||||
deviceId: deviceID, | |||||
deviceType: 'keyserver', | |||||
userId: deviceID, | |||||
}; | |||||
tunnelbrokerSocket.send(JSON.stringify(message)); | |||||
console.info('Connection to Tunnelbroker established'); | |||||
}); | |||||
tunnelbrokerSocket.on('close', async () => { | |||||
console.warn('Connection to Tunnelbroker closed'); | |||||
await sleep(1000); | |||||
console.info('Attempting to re-establish Tunnelbroker connection'); | |||||
openTunnelbrokerConnection(deviceID, userID, accessToken); | |||||
}); | |||||
tunnelbrokerSocket.on('error', (error: Error) => { | |||||
console.error('Tunnelbroker socket error: ' + error.message); | |||||
}); | |||||
} catch { | |||||
console.log('Failed to open connection with Tunnelbroker'); | |||||
} | |||||
} | |||||
export { createAndMaintainTunnelbrokerWebsocket }; |
My feedback from the last review appears to have been ignored:
{F695889}
Remember – a reviewer should never have to repeat feedback. This is a common issue for you... please review feedback carefully before updating a diff. Go line by line for each comment you received, and make sure you addressed it 100%. It shouldn't ever be necessary for me to repeat feedback to you.