theobarrague / fake-bittorrent-client

A Node.js BitTorrent API implementation for testing or cheating on trackers
MIT License
1 stars 0 forks source link

Allow a configurable timeout on http/https requests #1

Closed draeder closed 3 years ago

draeder commented 3 years ago

I was looking for a way to test bittorrent servers, and this is exactly what I needed! Thank you for your work!

It would be nice to be able set a timeout / req.destroy() for dead tracker servers to avoid waiting long times for the regular http/https timeout. I tried reviewing your code to add it myself, but I couldn't entirely figure out how to go about it.

theobarrague commented 3 years ago

Yeah for sure, i will quickly review code and provide a solution :)

draeder commented 3 years ago

Awesome, thank you! It would also be nice if you publish any of the changes to NPM. I see there are difference between what is here on GitHub and what is on NPM...

theobarrague commented 3 years ago

Check if the new update satisfy your requirements. I checked by adding some network delay to my network card, not in real conditions but it should works.

In code you can do :

const client = new FakeBitTorrentClient(
  'http://www.xxx.zzz/announce',
  'xxx_hash_xxx',
  { timeout: 1500 }
);

Or use the command line like this : fake-bittorrent-client --tracker 'http://www.xxx.zzz/announce' --hash 'xxx_hash_xxx' --download 33554432 --timeout 1500

draeder commented 3 years ago

Thanks for the updated code! Now, I better understand how you're making your requests with the http/https modules and may be able to suggest some additional features with a PR.

It looks like it's working for the most part. What I'm doing is building a package that uses fake-bittorrent-tracker to test the list of trackers from trackerslist. First I simply ping them and remove dead hosts. Next I use fake-bittorrent-tracker as designed to upload/download a fake torrent to the remaining hosts. I can see that the timeout is working for the majority of remaining trackers in my list.

But for some of the trackers, the timeout doesn't seem to work. This might be due to lower level networking failures, like SSL failures when trying to open the socket, or general socket failures. Here is one example where fake-bittorrent-client took well over 30 seconds to finally timeout, even with the updated code and the timeout set to 1500ms:

http://tracker4.itzmx.com:2710/announce Upload Failed Error: connect ETIMEDOUT 212.1.226.176:2710
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1137:16) {
  errno: -60,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '212.1.226.176',
  port: 2710
}
Error : Error: connect ETIMEDOUT 212.1.226.176:2710
http://tracker4.itzmx.com:2710/announce Download Failed Error: connect ETIMEDOUT 212.1.226.176:2710
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1137:16) {
  errno: -60,
  code: 'ETIMEDOUT',
  syscall: 'connect',
  address: '212.1.226.176',
  port: 2710
}
Error : Error: connect ETIMEDOUT 212.1.226.176:2710

That particular tracker URL seems to have a variety of problems, sometimes it 404s, sometimes it has a socket reset, and other times the timeout above; so it's a good URL to test with.

I'll see what else I can learn about the issue and see if I can contribute to the project.

One other thing to note is that req.abort() is depreciated. req.destroy() is the way forward based on the documentation. Though, req.abort() seems to work for now in your code.

theobarrague commented 3 years ago

I followed a Stack Overflow solution, there are surely other mistakes in the code.

I'll investigate your problem probably this week.

I am opening a new issue specific for this problem.

Thanks for your return!