Bump bun version in Dockerfile and add fixes for downloads

This commit is contained in:
Peter Stockings
2026-01-01 17:11:38 +11:00
parent e51fb204e0
commit 134c4b36c9
4 changed files with 32 additions and 7 deletions

View File

@@ -1,5 +1,5 @@
# Use the official Bun image # Use the official Bun image
FROM oven/bun:1.1.3 FROM oven/bun:latest
# Set working directory # Set working directory
WORKDIR /app WORKDIR /app

View File

@@ -66,8 +66,8 @@ export class TorrentSession {
this.refillWorkers(); this.refillWorkers();
} }
} }
} catch (e) { } catch (e: any) {
// Tracker error console.error(`[Engine] Tracker ${tracker} failed: ${e?.message || e}`);
} }
}); });
@@ -154,7 +154,7 @@ export class TorrentSession {
} }
for (const worker of this.workers) { 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 // 1. Prioritize ongoing piece reassembly
let foundWork = false; let foundWork = false;

View File

@@ -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 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) => { 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 action = msg.readInt32BE(0);
const receivedTransactionId = msg.slice(4, 8); const receivedTransactionId = msg.slice(4, 8);
if (!transactionId.equals(receivedTransactionId)) return; 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([0, 0, 0, 2]), Buffer.alloc(4), Buffer.alloc(4),
Buffer.from([0xFF, 0xFF, 0xFF, 0xFF]), Buffer.from([0x1B, 0x39]) 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) { } else if (action === 1) {
const peers = []; const peers = [];
for (let i = 20; i + 6 <= msg.length; i += 6) { 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)}`); 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); 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}`);
});
}); });
} }

View File

@@ -103,6 +103,7 @@ export class PeerWorker {
this.peerChoked = true; this.peerChoked = true;
break; break;
case 1: // unchoke case 1: // unchoke
console.log(`[Worker] Unchoked by ${this.host}`);
this.peerChoked = false; this.peerChoked = false;
this.onReady(); // Ready to request blocks now! this.onReady(); // Ready to request blocks now!
break; break;
@@ -166,6 +167,7 @@ export class PeerWorker {
const len = Buffer.alloc(4); const len = Buffer.alloc(4);
len.writeUInt32BE(13); len.writeUInt32BE(13);
this.socket.write(Buffer.concat([len, req])); this.socket.write(Buffer.concat([len, req]));
console.log(`[Worker] Requested block ${index}:${begin} from ${this.host}`);
this.activeRequests++; this.activeRequests++;
this.pendingRequests.add(key); this.pendingRequests.add(key);
} }
@@ -174,4 +176,8 @@ export class PeerWorker {
public hasPiece(index: number) { public hasPiece(index: number) {
return this.peerBitfield?.has(index) ?? false; return this.peerBitfield?.has(index) ?? false;
} }
public isChoked() {
return this.peerChoked;
}
} }