mirror of
https://github.com/benjamin-wilson/public-pool.git
synced 2026-09-29 09:05:06 -07:00
sv1-sv2 routing
This commit is contained in:
@@ -157,6 +157,15 @@ describe('StratumV1Service', () => {
|
||||
expect((service as any).detectProtocol(firstChunk)).toBe('v1');
|
||||
});
|
||||
|
||||
it('should detect JSON-RPC as Stratum V1 even with non-printable trailing bytes', () => {
|
||||
const firstChunk = Buffer.concat([
|
||||
Buffer.from('{"id": 1, "method": "mining.subscribe", "params": []}\n'),
|
||||
Buffer.from([0x00, 0xff])
|
||||
]);
|
||||
|
||||
expect((service as any).detectProtocol(firstChunk)).toBe('v1');
|
||||
});
|
||||
|
||||
it('should detect binary Noise traffic as Stratum V2', () => {
|
||||
const firstChunk = Buffer.concat([
|
||||
Buffer.from([0x01, 0x02, 0x03, 0x04]),
|
||||
|
||||
@@ -453,6 +453,13 @@ export class StratumV1Service implements OnModuleInit {
|
||||
return false;
|
||||
}
|
||||
|
||||
const jsonPrefix = firstChunk
|
||||
.subarray(firstNonWhitespace, Math.min(firstChunk.length, firstNonWhitespace + 256))
|
||||
.toString('utf8');
|
||||
if (jsonPrefix.includes('"method"') || jsonPrefix.includes('"id"')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const byte of firstChunk) {
|
||||
const isWhitespace = byte === 0x09 || byte === 0x0a || byte === 0x0d;
|
||||
const isPrintableAscii = byte >= 0x20 && byte <= 0x7e;
|
||||
|
||||
Reference in New Issue
Block a user