I need some sort of command line util that will talk to a tracker or BitTorrent client and dump back info it gets. I am guessing I just need a wrapper around postrequest (see below) but my py skills aren't up to it yet.
Why? here is the story.
http://www.edubuntu.org/EdubuntuTesting says "Get the latest daily CD..." so off I go to http://cdimage.ubuntu.com/edubuntu/daily/current/ where I find http://cdimage.ubuntu.com/edubuntu/daily/current/breezy-install-i386.iso.torrent and fire it up.
10 min later and I still see "connecting to peers (0.0%)".
Not only am I not getting it, but who knows how many others aren't getting it either. This makes me sad, so I decide to do something to help.
I could just click on http://cdimage.ubuntu.com/edubuntu/daily/current/breezy-install-i386.iso but that won't help the Ubuntu guys with there BT troubles.
I can make some guesses at what the problem is, but I would like a more scientific method way. some steps that I can use to A) determine what the problem really is, and B) show someone else so that there isn't any guessing going on.
I could also hit http://btfaq.com/natcheck.pl and see: "Unable to connect. This likely means you need to adjust your port forwarding configuration, or there is no client running on that port." But that also won't help the Ubuntu guys. But it is an example of the kind of thing I am looking for, only I want to point it at other IP's not my own.
This is where I am stuck. If you have anything to offer at this point, great! offer away. (remember, my goal is to figure out how to debug BT problems, not get the file.) If not, then keep reading.
There is a BT command that will display the key data in a .torrent:
$ btshowmetainfo breezy-install-i386.iso.torrent btshowmetainfo 20021207 - decode BitTorrent metainfo files
metainfo file.: breezy-install-i386.iso.torrent info hash.....: e0f9f66ab7a85ca00305bce087ecb21516d9afc6 file name.....: breezy-install-i386.iso file size.....: 674230272 (1285 * 524288 + 520192) announce url..: http://torrent.ubuntu.com:6969/announce
From this I can get the URL of the tracker: http://torrent.ubuntu.com:6969/announce
I can put that in a browser or use crul to get back a simple string: $ curl http://torrent.ubuntu.com:6969/announce you sent me garbage - no info hash
That doesn't help much. So hack the /announce off and you get a big status page showing all the .torrents the tracker is servicing: http://torrent.ubuntu.com:6969
Ok, that is a help - it shows that for the file I want: e0f9f66ab7a85ca00305bce087ecb21516d9afc6 breezy-install-i386.iso 642MiB There are 2 complete's (aka seeds) so I should be able to get data.
But 60 min has gone by, and I am still at "connecting to peers (0.0%)" so there is still a problem: Assuming the page is correct and there really are two completes, my client isn't getting data from them.
Why not? My guess is they are behind a firewall. But I don't want to guess. and I don't want to rely on the GUI clients when trying to describe what is going on. I want something I can cut/paste into an email.
The few things I think I need for the current problem:
1) btquerytracker
--tracker http://trackerurl
--trackerstatus Is the tracker there, really a bt tracker, if so, display the version and anything else it has to offer.
--torrent file.torrent
--torrentstatus Display whatever the tracker has to offer about this .torrent, like the peerlist (the IP:port of the peers)
--peer IP:port
--peerstatus Display whatever the tracker has to offer about this peer.
2) btquerypeer
--peer IP:port
--peerstatus Is the peer there, version, and whatever the peer has to offer about itself.
--getpiece n - request the peer send you a piece of data. (Not that we really want the data, but it will confirm that it can send data. user better redirect this somewhere, and so status better go out on stderr.)
So, someone want to take a stab? You will at least get my appreciation, and I would think I am not the only one that wants something like this.
Here is the key bit of py code that I think is the heart of what I need.
carl (AT) cware1:/usr/lib/python2 DOT 4/site-packages/BitTorrent$ vi Rerequester.py ...
def postrequest(self, data): try: r = bdecode(data) check_peers(r) if r.has_key('failure reason'): self.errorfunc('rejected by tracker - ' + r['failure reason']) else: if r.has_key('warning message'): self.errorfunc('warning from tracker - ' + r['warning message']) self.announce_interval = r.get('interval', self.announce_interval) self.interval = r.get('min interval', self.interval) self.trackerid = r.get('tracker id', self.trackerid) self.last = r.get('last') p = r['peers'] peers = [] if type(p) == type(''): for x in xrange(0, len(p), 6): ip = '.'.join([str(ord(i)) for i in p[x:x+4]]) port = (ord(p[x+4]) << 8) | ord(p[x+5]) peers.append((ip, port, None)) else: for x in p: peers.append((x['ip'], x['port'], x.get('peer id'))) ps = len(peers) + self.howmany() if ps < self.maxpeers: if self.doneflag.isSet(): if r.get('num peers', 1000) - r.get('done peers', 0) > ps * 1.2: self.last = None else: if r.get('num peers', 1000) > ps * 1.2: self.last = None for x in peers: self.connect((x[0], x[1]), x[2]) except ValueError, e: if data != '': self.errorfunc('bad data from tracker - ' + str(e))
CarlKarsten
©2005 Carl Karsten |