@@ -15,15 +15,13 @@ interface Logger {
1515}
1616
1717export interface DownloadOptions {
18- timeout ?: number ;
1918 onProgress ?: ( downloaded : number , total : number ) => void ;
2019 maxFileSizeBytes ?: number ; // Maximum allowed file size for downloads (in bytes)
2120}
2221
2322export interface FileClientOptions {
2423 peers ?: string [ ] ; // Gun.js peer URLs
2524 namespace ?: string ; // Gun.js namespace
26- timeout ?: number ; // Download timeout
2725 logger ?: Logger ; // Optional logger for debug output
2826}
2927
@@ -37,7 +35,6 @@ export class FileClient implements IFileClient {
3735 this . options = {
3836 peers : options . peers || [ "http://dig-relay-prod.eba-2cmanxbe.us-east-1.elasticbeanstalk.com/gun" ] ,
3937 namespace : options . namespace || "dig-nat-tools" ,
40- timeout : options . timeout || 30000 ,
4138 } ;
4239
4340 // Create a default logger that only shows warnings and errors if none provided
@@ -311,35 +308,12 @@ export class FileClient implements IFileClient {
311308 return ;
312309 }
313310
314- // Timeout handler with more details
315- const timeoutMs = options . timeout || this . options . timeout ;
316- const timeout = setTimeout ( ( ) => {
317- this . logger . error ( "⏰ WebTorrent download timeout:" , {
318- timeoutMs : timeoutMs ,
319- torrentName : torrent ?. name ,
320- torrentLength : torrent ?. length ,
321- filesCount : torrent ?. files ?. length ,
322- peersCount : torrent ?. numPeers ,
323- downloaded : torrent ?. downloaded ,
324- uploaded : torrent ?. uploaded ,
325- downloadSpeed : torrent ?. downloadSpeed ,
326- progress : torrent ?. progress ,
327- magnetUri : magnetUri . substring ( 0 , 100 ) + '...'
328- } ) ;
329-
330- if ( torrent ) {
331- torrent . destroy ( ) ;
332- }
333- reject ( new Error ( `WebTorrent download timeout after ${ timeoutMs } ms` ) ) ;
334- } , timeoutMs ) ;
335-
336311 torrent . on ( "ready" , ( ) => {
337312 this . logger . debug (
338313 `✅ Torrent ready! File: ${ torrent ! . name } , Size: ${ torrent ! . length } bytes, Files: ${ torrent ! . files . length } `
339314 ) ;
340315
341316 if ( torrent ! . files . length === 0 ) {
342- clearTimeout ( timeout ) ;
343317 torrent ! . destroy ( ) ;
344318 this . logger . error ( "❌ No files in torrent" , {
345319 name : torrent ! . name ,
@@ -352,7 +326,6 @@ export class FileClient implements IFileClient {
352326
353327 // Check file size against maximum allowed size
354328 if ( options . maxFileSizeBytes && torrent ! . length > options . maxFileSizeBytes ) {
355- clearTimeout ( timeout ) ;
356329 torrent ! . destroy ( ) ;
357330 const fileSizeMB = ( torrent ! . length / ( 1024 * 1024 ) ) . toFixed ( 2 ) ;
358331 const maxSizeMB = ( options . maxFileSizeBytes / ( 1024 * 1024 ) ) . toFixed ( 2 ) ;
@@ -376,7 +349,6 @@ export class FileClient implements IFileClient {
376349 } ) ;
377350
378351 stream . on ( "end" , ( ) => {
379- clearTimeout ( timeout ) ;
380352 const buffer = Buffer . concat ( chunks ) ;
381353 this . logger . debug (
382354 `✅ WebTorrent download completed! ${ buffer . length } bytes`
@@ -388,7 +360,6 @@ export class FileClient implements IFileClient {
388360 } ) ;
389361
390362 stream . on ( "error" , ( error : unknown ) => {
391- clearTimeout ( timeout ) ;
392363 torrent ! . destroy ( ) ;
393364 this . logger . error ( "❌ Stream error during download:" , {
394365 ...this . serializeError ( error ) ,
@@ -401,8 +372,7 @@ export class FileClient implements IFileClient {
401372
402373 // Enhanced torrent error handling
403374 torrent . on ( "error" , ( error : unknown ) => {
404- clearTimeout ( timeout ) ;
405- this . logger . error ( `❌ WebTorrent torrent error:` , {
375+ this . logger . debug ( `❌ WebTorrent torrent error:` , {
406376 ...this . serializeError ( error ) ,
407377 magnetUri : magnetUri . substring ( 0 , 100 ) + '...' ,
408378 infoHash : torrent ?. infoHash ,
@@ -413,13 +383,13 @@ export class FileClient implements IFileClient {
413383
414384 // Add additional torrent event listeners for debugging
415385 torrent . on ( "warning" , ( warning : unknown ) => {
416- this . logger . warn ( "⚠️ WebTorrent warning:" , {
386+ this . logger . debug ( "⚠️ WebTorrent warning:" , {
417387 ...this . serializeError ( warning )
418388 } ) ;
419389 } ) ;
420390
421391 torrent . on ( "noPeers" , ( ) => {
422- this . logger . warn ( "⚠️ No peers found for torrent" , {
392+ this . logger . debug ( "⚠️ No peers found for torrent" , {
423393 magnetUri : magnetUri . substring ( 0 , 100 ) + '...' ,
424394 infoHash : torrent ?. infoHash
425395 } ) ;
@@ -492,7 +462,7 @@ export class FileClient implements IFileClient {
492462 url : string ,
493463 options : DownloadOptions = { }
494464 ) : Promise < Buffer > {
495- const { timeout = 30000 , onProgress } = options ;
465+ const { onProgress } = options ;
496466
497467 return new Promise < Buffer > ( ( resolve , reject ) => {
498468 // Parse the URL
@@ -503,7 +473,6 @@ export class FileClient implements IFileClient {
503473
504474 const req = protocol . get (
505475 url ,
506- { timeout } ,
507476 ( res : http . IncomingMessage ) => {
508477 if ( res . statusCode !== 200 ) {
509478 return reject (
@@ -538,11 +507,6 @@ export class FileClient implements IFileClient {
538507 req . on ( "error" , ( err : Error ) => {
539508 reject ( err ) ;
540509 } ) ;
541-
542- req . on ( "timeout" , ( ) => {
543- req . destroy ( ) ;
544- reject ( new Error ( "Download timed out" ) ) ;
545- } ) ;
546510 } ) ;
547511 }
548512
@@ -554,10 +518,8 @@ export class FileClient implements IFileClient {
554518 */
555519 public static async downloadAsStreamStatic (
556520 url : string ,
557- options : DownloadOptions = { }
521+ _options : DownloadOptions = { }
558522 ) : Promise < Readable > {
559- const { timeout = 30000 } = options ;
560-
561523 return new Promise < Readable > ( ( resolve , reject ) => {
562524 // Parse the URL
563525 const parsedUrl = new URL ( url ) ;
@@ -567,7 +529,6 @@ export class FileClient implements IFileClient {
567529
568530 const req = protocol . get (
569531 url ,
570- { timeout } ,
571532 ( res : http . IncomingMessage ) => {
572533 if ( res . statusCode !== 200 ) {
573534 return reject (
@@ -584,11 +545,6 @@ export class FileClient implements IFileClient {
584545 req . on ( "error" , ( err : Error ) => {
585546 reject ( err ) ;
586547 } ) ;
587-
588- req . on ( "timeout" , ( ) => {
589- req . destroy ( ) ;
590- reject ( new Error ( "Download timed out" ) ) ;
591- } ) ;
592548 } ) ;
593549 }
594550
@@ -636,11 +592,6 @@ export class FileClient implements IFileClient {
636592 req . on ( "error" , ( ) => {
637593 resolve ( false ) ;
638594 } ) ;
639-
640- req . on ( "timeout" , ( ) => {
641- req . destroy ( ) ;
642- resolve ( false ) ;
643- } ) ;
644595 } catch {
645596 resolve ( false ) ;
646597 }
0 commit comments