Skip to content

Commit

Permalink
Revert "debug: adding debug outputs for connections"
Browse files Browse the repository at this point in the history
This reverts commit 02f48823ea1e480ac61c5d14178f468cd461acf1.
  • Loading branch information
tegefaulkes committed Oct 26, 2022
1 parent fb07925 commit b381e29
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 45 deletions.
5 changes: 0 additions & 5 deletions src/bin/CommandPolykey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ class CommandPolykey extends commander.Command {
// Set the logger according to the verbosity
this.logger.setLevel(binUtils.verboseToLogLevel(opts.verbose));
// Set the logger formatter according to the format
this.logger.handlers.forEach((handler) =>
handler.setFormatter(
formatting.format`${formatting.date}:${formatting.level}:${formatting.key}:${formatting.msg}`,
),
);
if (opts.format === 'json') {
this.logger.handlers.forEach((handler) =>
handler.setFormatter(formatting.jsonFormatter),
Expand Down
20 changes: 2 additions & 18 deletions src/network/ConnectionForward.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class ConnectionForward extends Connection {
data: Buffer,
remoteInfo: { address: string; port: number },
) => {
this.logger.info(`forward Connection received message: ${data}`);
// Ignore messages not intended for this target
if (remoteInfo.address !== this.host || remoteInfo.port !== this.port) {
return;
Expand All @@ -60,9 +59,6 @@ class ConnectionForward extends Connection {
this.startKeepAliveTimeout();
}
if (msg.type === 'ping') {
this.logger.info(
`FG -- Forward received ping, responding with pong and resolving readyP`,
);
this.resolveReadyP();
// Respond with ready message
await this.send(networkUtils.pongBuffer);
Expand All @@ -79,7 +75,7 @@ class ConnectionForward extends Connection {
* Handler is removed and not executed when `end` is initiated here
*/
protected handleEnd = async () => {
this.logger.info('Receives tlsSocket ending');
this.logger.debug('Receives tlsSocket ending');
if (this.utpConn.destroyed) {
this.tlsSocket.destroy();
this.logger.debug('Destroyed tlsSocket');
Expand All @@ -98,7 +94,6 @@ class ConnectionForward extends Connection {
* If already stopped, then this does nothing
*/
protected handleClose = async () => {
this.logger.info(`TLS Close`);
await this.stop();
};

Expand Down Expand Up @@ -130,7 +125,6 @@ class ConnectionForward extends Connection {
// Promise for abortion and timeout
const { p: abortedP, resolveP: resolveAbortedP } = promise<void>();
if (ctx.signal.aborted) {
this.logger.info(`Forward was aborted with: ${ctx.signal.reason}`);
// This is for arbitrary abortion reason provided by the caller
// Re-throw the default timeout error as a network timeout error
if (
Expand All @@ -145,17 +139,14 @@ class ConnectionForward extends Connection {
this.resolveReadyP = resolveReadyP;
this.utpSocket.on('message', this.handleMessage);
const handleStartError = (e) => {
this.logger.info(`TLS error connection ${e}`);
rejectErrorP(e);
};
// Normal sockets defaults to `allowHalfOpen: false`
// But UTP defaults to `allowHalfOpen: true`
// Setting `allowHalfOpen: false` on UTP is buggy and cannot be used
this.logger.info(`Starting UTP connection to ${this.host}:${this.port}`);
this.utpConn = this.utpSocket.connect(this.port, this.host, {
allowHalfOpen: true,
});
this.logger.info('Starting TLS connection');
this.tlsSocket = tls.connect(
{
key: Buffer.from(this.tlsConfig.keyPrivatePem, 'ascii'),
Expand All @@ -173,22 +164,16 @@ class ConnectionForward extends Connection {
let punchInterval;
try {
// Send punch signal
this.logger.info(`Forward starting pings to ${this.host}:${this.port}`);
this.logger.info(`C -- Forward sending ping`);
await this.send(networkUtils.pingBuffer);
punchInterval = setInterval(async () => {
this.logger.info(`C -- Forward sending ping`);
await this.send(networkUtils.pingBuffer);
}, this.punchIntervalTime);
this.logger.info(`forward racing ready and secure with error and abort`);
await Promise.race([
Promise.all([readyP, secureConnectP]),
errorP,
abortedP,
]);
this.logger.info(`forward race succeeded`);
} catch (e) {
this.logger.error(`race threw error ${e}`);
// Clean up partial start
// TLSSocket isn't established yet, so it is destroyed
if (!this.tlsSocket.destroyed) {
Expand All @@ -205,7 +190,6 @@ class ConnectionForward extends Connection {
this.tlsSocket.on('error', this.handleError);
this.tlsSocket.off('error', handleStartError);
if (ctx.signal.aborted) {
this.logger.info(`Forward was aborted with: ${ctx.signal.reason}`);
// Clean up partial start
// TLSSocket isn't established yet, so it is destroyed
if (!this.tlsSocket.destroyed) {
Expand All @@ -229,7 +213,7 @@ class ConnectionForward extends Connection {
// Clean up partial start
this.utpSocket.off('message', this.handleMessage);
// TLSSocket is established, and is ended gracefully
this.logger.info('Sends tlsSocket ending');
this.logger.debug('Sends tlsSocket ending');
// Graceful exit has its own end handler
this.tlsSocket.removeAllListeners('end');
await this.endGracefully(this.tlsSocket);
Expand Down
22 changes: 1 addition & 21 deletions src/network/ConnectionReverse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class ConnectionReverse extends Connection {
data: Buffer,
remoteInfo: { address: string; port: number },
) => {
this.logger.info(`reverse Connection received message: ${data}`);
// Ignore messages not intended for this target
if (remoteInfo.address !== this.host || remoteInfo.port !== this.port) {
return;
Expand All @@ -60,10 +59,8 @@ class ConnectionReverse extends Connection {
this.startKeepAliveTimeout();
}
if (msg.type === 'ping') {
this.logger.info(`E -- Reverse received ping, responding with pong`);
await this.send(networkUtils.pongBuffer);
} else if (msg.type === 'pong') {
this.logger.info(`H -- Reverse received pong, resolving ready`);
this.resolveReadyP();
}
};
Expand All @@ -78,7 +75,7 @@ class ConnectionReverse extends Connection {
* Handler is removed and not executed when `end` is initiated here
*/
protected handleEnd = async () => {
this.logger.info('Receives serverSocket ending');
this.logger.debug('Receives serverSocket ending');
this.logger.debug('Responds serverSocket ending');
this.serverSocket.end();
this.serverSocket.destroy();
Expand All @@ -92,7 +89,6 @@ class ConnectionReverse extends Connection {
* If already stopped, then this does nothing
*/
protected handleClose = async () => {
this.logger.info('reverse socket closing');
await this.stop();
};

Expand Down Expand Up @@ -126,7 +122,6 @@ class ConnectionReverse extends Connection {
// Promise for abortion and timeout
const { p: abortedP, resolveP: resolveAbortedP } = promise<void>();
if (ctx.signal.aborted) {
this.logger.info(`Reverse was aborted with: ${ctx.signal.reason}`);
// This is for arbitrary abortion reason provided by the caller
// Re-throw the default timeout error as a network timeout error
if (
Expand All @@ -140,9 +135,6 @@ class ConnectionReverse extends Connection {
}
this.resolveReadyP = resolveReadyP;
this.utpSocket.on('message', this.handleMessage);
this.logger.info(
`reverse creating socket to ${this.serverHost}:${this.serverPort}`,
);
this.serverSocket = net.connect(this.serverPort, this.serverHost, () => {
const proxyAddressInfo = this.serverSocket.address() as AddressInfo;
this.proxyHost = proxyAddressInfo.address as Host;
Expand All @@ -154,32 +146,21 @@ class ConnectionReverse extends Connection {
resolveSocketP();
});
const handleStartError = (e) => {
this.logger.info(`reverse error ${e}`);
rejectErrorP(e);
};
this.serverSocket.once('error', handleStartError);
this.serverSocket.on('end', this.handleEnd);
this.serverSocket.on('close', this.handleClose);
let punchInterval;
try {
this.logger.info('Reverse racing socket, error and abort stage 1');
await Promise.race([socketP, errorP, abortedP]);
this.logger.info(
'B -- Connection Reverse has connected to the GRPC Agent server',
);
// Send punch & ready signal
this.logger.info(`Reverse starting pinging to ${this.host}:${this.port}`);
this.logger.info('D -- Reverse sending ping');
await this.send(networkUtils.pingBuffer);
punchInterval = setInterval(async () => {
this.logger.info('D -- Reverse sending ping');
await this.send(networkUtils.pingBuffer);
}, this.punchIntervalTime);
this.logger.info('Reverse racing ready, error and abort stage 2');
await Promise.race([readyP, errorP, abortedP]);
this.logger.info('Racing completed');
} catch (e) {
this.logger.info(`racing error ${e}`);
// Clean up partial start
// Socket isn't established yet, so it is destroyed
this.serverSocket.destroy();
Expand All @@ -193,7 +174,6 @@ class ConnectionReverse extends Connection {
this.serverSocket.on('error', this.handleError);
this.serverSocket.off('error', handleStartError);
if (ctx.signal.aborted) {
this.logger.info(`reverse aborted`);
// Clean up partial start
// Socket isn't established yet, so it is destroyed
this.serverSocket.destroy();
Expand Down
1 change: 0 additions & 1 deletion src/network/Proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,6 @@ class Proxy {
await clientSocketWrite(
'HTTP/1.1 200 Connection Established\r\n' + '\r\n',
);
this.logger.info(`A -- GRPC client connected to Proxy TCP server`);
this.logger.info(`Handled CONNECT to ${proxyAddress}`);
});
};
Expand Down

0 comments on commit b381e29

Please sign in to comment.