Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unable to reuse init parameters #987

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
44 changes: 34 additions & 10 deletions src/controllers/status.ts
Expand Up @@ -190,15 +190,26 @@ export class StatusController {
}

// Get original keys
const originalKeyStore = this.webClientService.salty.keyStore;
const originalPeerPermanentKeyBytes = this.webClientService.salty.peerPermanentKeyBytes;
let close: boolean | string = false;
let originalKeyStore: saltyrtc.KeyStore;
let originalPeerPermanentKeyBytes: Uint8Array;
try {
originalKeyStore = this.webClientService.salty.keyStore;
originalPeerPermanentKeyBytes = this.webClientService.salty.peerPermanentKeyBytes;
} catch (error) {
this.log.warn('Unable to get original keys, redirecting', error);
close = 'welcome';
}

// Soft reconnect: Does not reset the loaded data
// Soft reconnect: Does not reset the loaded data (unless the keys could not be retrived)
this.webClientService.stop({
reason: DisconnectReason.SessionStopped,
send: true,
close: false,
close: close,
});
if (close !== false) {
return;
}
this.webClientService.init({
keyStore: originalKeyStore,
peerTrustedKey: originalPeerPermanentKeyBytes,
Expand Down Expand Up @@ -239,19 +250,32 @@ export class StatusController {
this.log.info(`Connection lost (iOS). Reconnect attempt #${++this.stateService.attempt}`);

// Get original keys
const originalKeyStore = this.webClientService.salty.keyStore;
const originalPeerPermanentKeyBytes = this.webClientService.salty.peerPermanentKeyBytes;
let close: boolean | string = false;
let originalKeyStore: saltyrtc.KeyStore;
let originalPeerPermanentKeyBytes: Uint8Array;
try {
originalKeyStore = this.webClientService.salty.keyStore;
originalPeerPermanentKeyBytes = this.webClientService.salty.peerPermanentKeyBytes;
} catch (error) {
this.log.warn('Unable to get original keys, redirecting', error);
close = 'welcome';
}

// Delay connecting a bit to wait for old websocket to close
// TODO: Make this more robust and hopefully faster
const startTimeout = 500;
// Soft reconnect: Does not reset the loaded data (unless the keys could not be retrived)
this.log.debug('Stopping old connection');
this.webClientService.stop({
reason: DisconnectReason.SessionStopped,
send: true,
close: false,
close: close,
connectionBuildupState: 'push',
});
if (close !== false) {
return;
}

// Delay reconnecting a bit to wait for old websocket to close
// TODO: Make this more robust and hopefully faster
const startTimeout = 500;

// Only send a push...
const push = ((): { send: boolean, reason?: string } => {
Expand Down
12 changes: 0 additions & 12 deletions src/services/webclient.ts
Expand Up @@ -1287,18 +1287,6 @@ export class WebClientService {
* Stop the webclient service.
*
* This is a forced stop, meaning that all connections are being closed.
*
* @reason The disconnect reason.
* @send will send a disconnect message to the remote peer containing the
* disconnect reason if set to `true`.
* @close will close the session (meaning all cached data will be
* invalidated) if set to `true`. Note that the session will always be
* closed in case `reason` indicates that the session is to be deleted,
* has been replaced, a protocol error occurred or in case `redirect` has
* been set to `true`.
* @redirect will redirect to the welcome page if set to `true`.
* @connectionBuildupState: The connection buildup state the state service
* will be reset to.
*/
public stop(args: threema.WebClientServiceStopArguments): void {
if (args.close === true) {
Expand Down