mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 17:15:03 -07:00
sv2 debug
This commit is contained in:
@@ -174,6 +174,16 @@ describe('StratumV1Service', () => {
|
||||
expect((service as any).detectProtocol(Buffer.from([0x16, 0xaa, 0xbb]))).toBe('v2');
|
||||
});
|
||||
|
||||
it('should not route plaintext PROXY protocol headers to Stratum V2', () => {
|
||||
const firstChunk = Buffer.from('PROXY TCP4 203.0.113.10 192.0.2.10 54321 3333\\r\\n');
|
||||
|
||||
expect((service as any).detectProtocol(firstChunk)).toBeNull();
|
||||
});
|
||||
|
||||
it('should not route malformed plaintext to Stratum V2', () => {
|
||||
expect((service as any).detectProtocol(Buffer.from('mining.subscribe\\n'))).toBeNull();
|
||||
});
|
||||
|
||||
function restoreEnv(key: string, value: string | undefined) {
|
||||
if (value == null) {
|
||||
delete process.env[key];
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user