Skip to content

Commit

Permalink
Always loudly log intercepted connections that fail to reach the proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
pimterry committed Nov 14, 2023
1 parent 90ebd19 commit 6eec741
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions native-connect-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ if (!connectFn) { // Should always be set, but just in case
: PROXY_HOST_IPv4_BYTES
);

if (isIntercepted) return;
if (isIntercepted) {
this.intercepted = true;
return;
}

if (!shouldBeIntercepted) {
// Not intercecpted, sent to unrecognized port - probably not HTTP(S)
Expand Down Expand Up @@ -88,22 +91,33 @@ if (!connectFn) { // Should always be set, but just in case
// Skip 4 bytes: 2 family, 2 port
addrPtr.add(4).writeByteArray(PROXY_HOST_IPv4_BYTES);
}
this.intercepted = true;
} else if (DEBUG_MODE) {
console.log(`Ignoring ${sockType} connection`);
this.ignored = true;
}

// N.b. we ignore all non-TCP connections: both UDP and Unix streams
},
onLeave: function (result) {
if (!DEBUG_MODE || this.ignored) return;
if (!this.intercepted) return; // Don't log about connections we don't touch.
const wasSuccessful = result.toInt32() === 0;

if (wasSuccessful && !DEBUG_MODE) return;

const fd = this.sockFd;
const sockType = Socket.type(fd);
const address = Socket.peerAddress(fd);
console.debug(
`Connected ${sockType} fd ${fd} to ${JSON.stringify(address)} (${result.toInt32()})`
);

if (wasSuccessful) {
console.debug(
`Connected ${sockType} fd ${fd} to ${JSON.stringify(address)} (${result.toInt32()})`
);
} else {
console.error(
`\n !!! --- Intercepted ${sockType} connection ${fd} failed when redirected to proxy ${PROXY_HOST}:${PROXY_PORT} --- !!!\n` +
` Is your proxy configured correctly?\n`
);
}
}
});

Expand Down

0 comments on commit 6eec741

Please sign in to comment.