Spaces:
Sleeping
Sleeping
PERDYPTO commited on
Delete server.js
Browse files
server.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
| 1 |
-
const http = require('http');
|
| 2 |
-
const net = require('net');
|
| 3 |
-
const WebSocket = require('ws');
|
| 4 |
-
|
| 5 |
-
// Hugging Face strictly listens on internal traffic port 7860
|
| 6 |
-
const PORT = 7860;
|
| 7 |
-
const POOL_HOST = 'heavyhash.mine.zpool.ca';
|
| 8 |
-
const POOL_PORT = 5136; // Port for Zpool's HeavyHash algorithm
|
| 9 |
-
|
| 10 |
-
const server = http.createServer((req, res) => {
|
| 11 |
-
res.writeHead(200, { 'Content-Type': 'text/plain' });
|
| 12 |
-
res.end('Proxy active and broadcasting safely.\n');
|
| 13 |
-
});
|
| 14 |
-
|
| 15 |
-
const wss = new WebSocket.Server({ server });
|
| 16 |
-
|
| 17 |
-
wss.on('connection', (ws) => {
|
| 18 |
-
console.log('Browser linked to cloud array. Spawning TCP socket to Zpool...');
|
| 19 |
-
|
| 20 |
-
// Open an direct TCP socket socket layer to the Zpool server architecture
|
| 21 |
-
const stratumSocket = new net.Socket();
|
| 22 |
-
|
| 23 |
-
stratumSocket.connect(POOL_PORT, POOL_HOST, () => {
|
| 24 |
-
console.log(`TCP Handshake complete with: ${POOL_HOST}:${POOL_PORT}`);
|
| 25 |
-
});
|
| 26 |
-
|
| 27 |
-
// Forward messages arriving from your Cloudflare Pages WebGPU script to Zpool
|
| 28 |
-
ws.on('message', (message) => {
|
| 29 |
-
try {
|
| 30 |
-
const dataStr = message.toString();
|
| 31 |
-
console.log(`[Browser -> Pool]: ${dataStr.trim()}`);
|
| 32 |
-
stratumSocket.write(dataStr + '\n');
|
| 33 |
-
} catch (err) {
|
| 34 |
-
console.error('Error handling WebSocket message frame:', err);
|
| 35 |
-
}
|
| 36 |
-
});
|
| 37 |
-
|
| 38 |
-
// Forward block jobs and share confirmations returning from Zpool to your browser
|
| 39 |
-
let buffer = '';
|
| 40 |
-
stratumSocket.on('data', (data) => {
|
| 41 |
-
buffer += data.toString();
|
| 42 |
-
const lines = buffer.split('\n');
|
| 43 |
-
buffer = lines.pop(); // Retain incomplete data fragments in buffer stream
|
| 44 |
-
|
| 45 |
-
for (const line of lines) {
|
| 46 |
-
if (line.trim()) {
|
| 47 |
-
console.log(`[Pool -> Browser]: ${line.trim()}`);
|
| 48 |
-
if (ws.readyState === WebSocket.OPEN) {
|
| 49 |
-
ws.send(line);
|
| 50 |
-
}
|
| 51 |
-
}
|
| 52 |
-
}
|
| 53 |
-
});
|
| 54 |
-
|
| 55 |
-
// Error handling safeguards
|
| 56 |
-
ws.on('close', () => {
|
| 57 |
-
console.log('Browser closed tab instance. Destroying pool socket pipeline.');
|
| 58 |
-
stratumSocket.destroy();
|
| 59 |
-
});
|
| 60 |
-
|
| 61 |
-
stratumSocket.on('close', () => {
|
| 62 |
-
console.log('Zpool stream connection dropped. Disconnecting client WebSocket.');
|
| 63 |
-
ws.close();
|
| 64 |
-
});
|
| 65 |
-
|
| 66 |
-
ws.on('error', (err) => console.error('WS Error:', err));
|
| 67 |
-
stratumSocket.on('error', (err) => console.error('TCP Socket Error:', err));
|
| 68 |
-
});
|
| 69 |
-
|
| 70 |
-
server.listen(PORT, '0.0.0.0', () => {
|
| 71 |
-
console.log(`Server executing compute bridge protocols on port ${PORT}`);
|
| 72 |
-
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|