Skip to content

Commit

Permalink
Use human-readable names for websockets
Browse files Browse the repository at this point in the history
Co-authored-by: Fedor Indutny <79877362+indutny-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and indutny-signal committed Dec 1, 2021
1 parent bec88d5 commit 57daf07
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
6 changes: 5 additions & 1 deletion ts/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,11 @@ export async function startApp(): Promise<void> {
}

// This one should always be last - it could restart the app
if (window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5')) {
if (
window.isBeforeVersion(lastVersion, 'v1.15.0-beta.5') ||
(window.isAfterVersion(lastVersion, 'v5.24.0-alpha') &&
window.isBeforeVersion(lastVersion, 'v5.25.0'))
) {
await deleteAllLogs();
window.restart();
return;
Expand Down
1 change: 1 addition & 0 deletions ts/textsecure/CDSSocketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export class CDSSocketManager {
const url = `${this.options.url}/discovery/${publicKeyHex}/${codeHashHex}`;

return connectWebSocket<CDSSocket>({
name: 'CDSSocket',
url,
version,
proxyAgent: this.proxyAgent,
Expand Down
6 changes: 6 additions & 0 deletions ts/textsecure/SocketManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export class SocketManager extends EventListener {
this.setStatus(SocketStatus.CONNECTING);

const process = this.connectResource({
name: 'authenticated',
path: '/v1/websocket/',
query: { login: username, password },
resourceOptions: {
Expand Down Expand Up @@ -253,6 +254,7 @@ export class SocketManager extends EventListener {
handler: IRequestHandler
): Promise<WebSocketResource> {
return this.connectResource({
name: 'provisioning',
path: '/v1/websocket/provisioning/',
resourceOptions: {
handleRequest: (req: IncomingWebSocketRequest): void => {
Expand Down Expand Up @@ -426,6 +428,7 @@ export class SocketManager extends EventListener {
log.info('SocketManager: connecting unauthenticated socket');

const process = this.connectResource({
name: 'unauthenticated',
path: '/v1/websocket/',
resourceOptions: {
keepalive: { path: '/v1/keepalive' },
Expand Down Expand Up @@ -464,10 +467,12 @@ export class SocketManager extends EventListener {
}

private connectResource({
name,
path,
resourceOptions,
query = {},
}: {
name: string;
path: string;
resourceOptions: WebSocketResourceOptions;
query?: Record<string, string>;
Expand All @@ -481,6 +486,7 @@ export class SocketManager extends EventListener {
const url = `${this.options.url}${path}?${qs.encode(queryWithDefaults)}`;

return connectWebSocket({
name,
url,
certificateAuthority: this.options.certificateAuthority,
version: this.options.version,
Expand Down
8 changes: 5 additions & 3 deletions ts/textsecure/WebSocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export type IResource = {
};

export type ConnectOptionsType<Resource extends IResource> = Readonly<{
name: string;
url: string;
certificateAuthority: string;
version: string;
Expand All @@ -32,6 +33,7 @@ export type ConnectOptionsType<Resource extends IResource> = Readonly<{
}>;

export function connect<Resource extends IResource>({
name,
url,
certificateAuthority,
version,
Expand Down Expand Up @@ -109,14 +111,14 @@ export function connect<Resource extends IResource>({
});

return new AbortableProcess<Resource>(
`WebSocket.connect(${url})`,
`WebSocket.connect(${name})`,
{
abort() {
if (resource) {
log.warn(`WebSocket: closing socket ${url}`);
log.warn(`WebSocket: closing socket ${name}`);
resource.close(3000, 'aborted');
} else {
log.warn(`WebSocket: aborting connection ${url}`);
log.warn(`WebSocket: aborting connection ${name}`);
Timers.clearTimeout(timer);
client.abort();
}
Expand Down

0 comments on commit 57daf07

Please sign in to comment.