Bump bun version in Dockerfile and add fixes for downloads
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
# Use the official Bun image
|
||||
FROM oven/bun:1.1.3
|
||||
FROM oven/bun:latest
|
||||
|
||||
# Set working directory
|
||||
WORKDIR /app
|
||||
|
||||
@@ -66,8 +66,8 @@ export class TorrentSession {
|
||||
this.refillWorkers();
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
// Tracker error
|
||||
} catch (e: any) {
|
||||
console.error(`[Engine] Tracker ${tracker} failed: ${e?.message || e}`);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -154,7 +154,7 @@ export class TorrentSession {
|
||||
}
|
||||
|
||||
for (const worker of this.workers) {
|
||||
if (worker.getPendingRequests().size >= 5) continue;
|
||||
if (worker.getPendingRequests().size >= 5 || worker.isChoked()) continue;
|
||||
|
||||
// 1. Prioritize ongoing piece reassembly
|
||||
let foundWork = false;
|
||||
|
||||
@@ -31,9 +31,15 @@ export async function getPeersFromUDPTracker(trackerUrl: string, infoHashHex: st
|
||||
|
||||
const connectMsg = Buffer.concat([connectionId, Buffer.from([0, 0, 0, 0]), transactionId]);
|
||||
|
||||
const timeout = setTimeout(() => { client.close(); resolve([]); }, getCONFIG().TRACKER_TIMEOUT);
|
||||
const timeout = setTimeout(() => {
|
||||
console.warn(`[UDP] Tracker ${url.hostname} timed out`);
|
||||
client.close();
|
||||
resolve([]);
|
||||
}, getCONFIG().TRACKER_TIMEOUT);
|
||||
|
||||
client.on("message", (msg) => {
|
||||
// ... existing message handling check
|
||||
// For brevity keeping logic same but assuming success logging could be added here if needed
|
||||
const action = msg.readInt32BE(0);
|
||||
const receivedTransactionId = msg.slice(4, 8);
|
||||
if (!transactionId.equals(receivedTransactionId)) return;
|
||||
@@ -47,17 +53,30 @@ export async function getPeersFromUDPTracker(trackerUrl: string, infoHashHex: st
|
||||
Buffer.from([0, 0, 0, 2]), Buffer.alloc(4), Buffer.alloc(4),
|
||||
Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]), Buffer.from([0x1B, 0x39])
|
||||
]);
|
||||
client.send(announceMsg, parseInt(url.port), url.hostname);
|
||||
client.send(announceMsg, parseInt(url.port), url.hostname, (err) => {
|
||||
if (err) console.error(`[UDP] Announce send error to ${url.hostname}:`, err);
|
||||
});
|
||||
} else if (action === 1) {
|
||||
const peers = [];
|
||||
for (let i = 20; i + 6 <= msg.length; i += 6) {
|
||||
peers.push(`${msg[i]}.${msg[i + 1]}.${msg[i + 2]}.${msg[i + 3]}:${msg.readUInt16BE(i + 4)}`);
|
||||
}
|
||||
console.log(`[UDP] Tracker ${url.hostname} returned ${peers.length} peers`);
|
||||
clearTimeout(timeout); client.close(); resolve(peers);
|
||||
}
|
||||
});
|
||||
|
||||
client.send(connectMsg, parseInt(url.port), url.hostname, () => {});
|
||||
client.on('error', (err) => {
|
||||
console.error(`[UDP] Socket error for ${url.hostname}:`, err);
|
||||
clearTimeout(timeout);
|
||||
resolve([]);
|
||||
});
|
||||
|
||||
// Explicitly handle DNS errors during send
|
||||
client.send(connectMsg, parseInt(url.port), url.hostname, (err) => {
|
||||
if (err) console.error(`[UDP] Connect send error to ${url.hostname}:`, err);
|
||||
else console.log(`[UDP] Sent connect to ${url.hostname}`);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ export class PeerWorker {
|
||||
this.peerChoked = true;
|
||||
break;
|
||||
case 1: // unchoke
|
||||
console.log(`[Worker] Unchoked by ${this.host}`);
|
||||
this.peerChoked = false;
|
||||
this.onReady(); // Ready to request blocks now!
|
||||
break;
|
||||
@@ -166,6 +167,7 @@ export class PeerWorker {
|
||||
const len = Buffer.alloc(4);
|
||||
len.writeUInt32BE(13);
|
||||
this.socket.write(Buffer.concat([len, req]));
|
||||
console.log(`[Worker] Requested block ${index}:${begin} from ${this.host}`);
|
||||
this.activeRequests++;
|
||||
this.pendingRequests.add(key);
|
||||
}
|
||||
@@ -174,4 +176,8 @@ export class PeerWorker {
|
||||
public hasPiece(index: number) {
|
||||
return this.peerBitfield?.has(index) ?? false;
|
||||
}
|
||||
|
||||
public isChoked() {
|
||||
return this.peerChoked;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user