Skip to content

Commit

Permalink
Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
vilicvane committed Dec 14, 2023
1 parent fd02ffb commit 5ddb013
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions src/library/in/tunnel-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,7 @@ export class TunnelServer {
}

Logs.debug(
{
type: 'in',
tunnel: tunnelId,
},
this.getContext(tunnelId),
IN_TUNNEL_WINDOW_SIZE_UPDATED(windowSize),
);
},
Expand All @@ -114,26 +111,15 @@ export class TunnelServer {
session.on('error', error => {
const tunnelId = sessionToTunnelIdMap.get(session);

let context: InLogContext | undefined;

if (tunnelId !== undefined) {
sessionToTunnelIdMap.delete(session);

const tunnel = tunnelMap.get(tunnelId);

if (tunnel) {
context = tunnel.context;
tunnelMap.delete(tunnelId);
}
tunnelMap.delete(tunnelId);
}

Logs.error(
context ?? {
type: 'in',
tunnel: tunnelId,
},
IN_TUNNEL_SERVER_SESSION_ERROR(error),
);
const context = this.getContext(tunnelId);

Logs.error(context, IN_TUNNEL_SERVER_SESSION_ERROR(error));
Logs.debug(context, error);
});
})
.on('stream', (stream, headers) => {
Expand Down Expand Up @@ -411,6 +397,16 @@ export class TunnelServer {
private getNextTunnelId(): TunnelId {
return ++this.lastTunnelIdNumber as TunnelId;
}

private getContext(tunnelId: TunnelId | undefined): InLogContext {
if (tunnelId === undefined) {
return {type: 'in'};
}

const tunnel = this.tunnelMap.get(tunnelId);

return tunnel?.context ?? {type: 'in', tunnel: tunnelId};
}
}

export type TunnelConnection = {
Expand Down

0 comments on commit 5ddb013

Please sign in to comment.