chihaya / chihaya

A customizable, multi-protocol BitTorrent Tracker
https://chihaya.io
Other
1.43k stars 190 forks source link

IncrementTorrentSnatches not working correctly? #127

Closed Yuuki2012 closed 8 years ago

Yuuki2012 commented 8 years ago

As the title says, it doesn't work? I'm trying to scrape but it's ALWAYS returning 0 ( Example: https://yuuki-chan.xyz/scraper/ )

mrd0ll4r commented 8 years ago

What exactly are you doing before scraping? And what is the format for the scrape you posted? How do you get the data? (API or real scrape?)

Yuuki2012 commented 8 years ago

I'm using the http://website.tld:6881/scrape?info_hash=HASH_GOES_HERE the API isn't working for me either, or I have no idea how that works.\

it's written in PHP, I'm using https://github.com/johannes85/PHP-Torrent-Scraper

mrd0ll4r commented 8 years ago

I cannot reproduce your issue, but I've found a another one. Anyways, this is what I've done:

  1. hit http://<tracker>/announce?info_hash=0000000000000000&peer_id=0000000000000000&port=20222&left=1&downloaded=0&uploaded=0 - this adds you to the leechers for that torrent
  2. hit http://<tracker>/announce?info_hash=0000000000000000&peer_id=0000000000000000&port=20222&left=0&downloaded=0&uploaded=0&event=completed - this removes you from the leechers, adds you to the seeders and should increment the snatches by one
  3. hit http:///scrape?info_hash=0000000000000000 - you'll get something like

    d5:filesd16:0000000000000000d8:completei1e10:incompletei0e10:downloadedi2eeee

Notice how downloaded is 2? That should be 1 AFAIK

The bug is in tracker/announce.go:200 - we use the &*val construct to get the torrent for the announce, but it seems like that doesn't work properly (and we increment the snatches on the original torrent (without synchronization!)). It works if you comment that line out. This is also a problem of our spaghetti-like code to create the announce object to work with. We're working to redesign the internals, so that should probably be fixed as well.

@jzelinskie please re-test if you have time/fix in your local branch - We should add a test for that somewhere, but I don't think a PR makes sense right now?

jzelinskie commented 8 years ago

It looks like something in the Go runtime changed and the *&var trick no longer makes a copy! See http://play.golang.org/p/PEC7sJ9lLm

I'd be willing to accept a PR to change the uses of *&var to a real copy. But this is a pretty big deal. I'm going to push my refactor branch soon, so that we can accelerate that work. Thanks for waiting patiently for my sharing of that code @mrd0ll4r.

pushrax commented 8 years ago

When did that happen... that's good to know. This still works though: http://play.golang.org/p/B5yDABUUcW

jzelinskie commented 8 years ago

This should be fixed in f70be949118a1ed9136224b3a618d95362b24d65. Let me know that it works and I'll close the issue.

Also, the API uses the URL-Encoded version of the infohash. This is likely the reason why you can't find the swarm.

Yuuki2012 commented 8 years ago

@mrd0ll4r I tried those urls, seems to work, but shouldn't the torrent clients tell the tracker it's completed downloading? (I'm using qBittorrent and libTorrent (ruTorrent)), but neither of them return to the tracker that they've finished downloading.

mrd0ll4r commented 8 years ago

@jzelinskie fixed it for me, thx :)

@Yuuki2012 they should indeed. I'll test it with libTorrent...

Yuuki2012 commented 8 years ago

@mrd0ll4r did you figure anything out?

mrd0ll4r commented 8 years ago

I don't have a second machine to seed from right now, so I can't test it too well - I did test it for a public torrent where I just added an instance of chihaya to the list of trackers (as the primary tracker, actually). libTorrent did interact with it, but didn't report a download. I had the debug log on, so I saw all requests made to chihaya, and none contained event=completed.

Can you maybe check how this works with a torrent marked "private"? As I said, I can't test that right now because I can't seed.

Anyways, the original issue looks fixed to me, and regardless of the outcome of these tests, chihaya (now) behaves as expected :)

Yuuki2012 commented 8 years ago

@mrd0ll4r https://yuuki-chan.xyz/torrents.php < as you can see the download counter works here, it's not marked as private torrent tho, but I think it's a client problem, that not all clients pass "event=completed" to the tracker.

mrd0ll4r commented 8 years ago

@Yuuki2012 yes, I got the same impression. Thanks for reporting the issue :)

@jzelinskie fixed, close?

jzelinskie commented 8 years ago

This should be fixed. Let me know if it isn't and I'll reopen.