sv2 debug

This commit is contained in:
Ben
2026-06-05 23:41:22 -04:00
parent 2a37cb1f06
commit 3d6c8b3134
3 changed files with 72 additions and 1 deletions
+19
View File
@@ -428,6 +428,13 @@ export class StratumV1Service implements OnModuleInit {
return null;
}
// Plaintext that is not JSON-RPC is not a valid SV2 Noise Act 1. This
// catches PROXY-protocol lines, SSH banners, and malformed SV1 clients
// before they get misrouted into the SV2 decrypt path.
if (this.looksLikePlaintext(firstChunk)) {
return null;
}
return 'v2';
}
@@ -473,6 +480,18 @@ export class StratumV1Service implements OnModuleInit {
|| prefix.startsWith('OPTIONS ');
}
private looksLikePlaintext(firstChunk: Buffer): boolean {
for (const byte of firstChunk) {
const isWhitespace = byte === 0x09 || byte === 0x0a || byte === 0x0d;
const isPrintableAscii = byte >= 0x20 && byte <= 0x7e;
if (!isWhitespace && !isPrintableAscii) {
return false;
}
}
return true;
}
private getPositiveIntegerEnv(key: string, fallback: number) {
const configured = parseInt(process.env[key], 10);
if (Number.isFinite(configured) && configured > 0) {