torrent hash

Ask for help and report issues not specific to either the Mac OS X or GTK+ versions of Transmission
Post Reply
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

torrent hash

Post by deadeyes »

Hi all,

I am using Transmssion-daemon as a back-end for a webbased multi-user interface.

However I have some issues when 2 users want to add the same torrent.
Transmission-rpc gives a message that this is a duplicate torrent.

In a database I link the torrent hash with a user id.

My idea for fixing this is adding another row with the same hash and the other user id.
What I need for this is how transmission-daemon comes to the transfer hash.
On what basis is it calculated?
If you have another way of fixing this that would be welcome as well!

Thanks in advance!
blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: torrent hash

Post by blacke4dawn »

Transfer hash? As far as I know about transfer hashes are the ones used for each individual block, so it sounds like you want the torrent hash which is the ID of the torrent itself. I don't know how they are created but the daemon gets it from the torrent file itself (can it use magnet links yet?). If you really want to know how the hash is calculated then I guess the technical documentation for the torrent protocol/files is where to get it.

Not sure how your webinterface is constructed but it seems the best way to handle that is to just capture that specific error and add it to the other user, which seems to be what you are already thinking of.
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: torrent hash

Post by deadeyes »

blacke4dawn wrote:Transfer hash? As far as I know about transfer hashes are the ones used for each individual block, so it sounds like you want the torrent hash which is the ID of the torrent itself. I don't know how they are created but the daemon gets it from the torrent file itself (can it use magnet links yet?). If you really want to know how the hash is calculated then I guess the technical documentation for the torrent protocol/files is where to get it.

Not sure how your webinterface is constructed but it seems the best way to handle that is to just capture that specific error and add it to the other user, which seems to be what you are already thinking of.
Edited:

Well, after I have captured that error I still need the torrent hash(not the ID, I am talking about the hash, for example: ee7f0023adfd861de3ce97259dfefa2bdbf2193d).

I don't think this has anything to do with magnet links. In the end magnet links just retrieve a torrent file.

OK, I'll wait a few days if other people know if I can easily calculate/retrieve the torrent hash.
blacke4dawn
Posts: 552
Joined: Sun Dec 13, 2009 10:44 pm

Re: torrent hash

Post by blacke4dawn »

As I said, I don't know how the webinterface it's constructed or even what language it's built in, but try looking for a "package" that can manipulate torrent files and it's very likely you can get it that way. Thinking about it now this seems to be slightly better to extract the hash from the file and checking the database for it before sending it to Transmission.

As for magnet links, as far as I gathered from it technically it doesn't retrieve a file per say, just the same info that is contained within a torrent file.
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: torrent hash

Post by deadeyes »

blacke4dawn wrote:As I said, I don't know how the webinterface it's constructed or even what language it's built in, but try looking for a "package" that can manipulate torrent files and it's very likely you can get it that way. Thinking about it now this seems to be slightly better to extract the hash from the file and checking the database for it before sending it to Transmission.

As for magnet links, as far as I gathered from it technically it doesn't retrieve a file per say, just the same info that is contained within a torrent file.
Thinking about it now this seems to be slightly better to extract the hash from the file and checking the database for it before sending it to Transmission.
That is actually what I am planning to do. :)

This is how the hash is calculated(it is not just in the torrent file):

Code: Select all

info_hash
    The 20 byte sha1 hash of the bencoded form of the info value from the metainfo file. Note that this is a substring of the metainfo file. This value will almost certainly have to be escaped.
I would like to not require any extra packages for just doing such a thing.
So I'll try to find out how I can bencode myself in php.
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: torrent hash

Post by deadeyes »

I found these related urls
http://wiki.theory.org/BitTorrentSpecification
http://wiki.theory.org/Decoding_encodin ... a_with_PHP (uses $retval["isDct"] in array, which does not work for Bencoding again :s)
http://paste.lisp.org/display/17178
http://www.phpclasses.org/browse/file/16612.html

I did some minor modifications and this is what I finally used (it has code for both bdecode and bencode):
http://pastebin.com/DXx3PhaN

First it reads the torrent file.
Then the data gets Bdecoded
Then only the 'info' part is taken
This part is Bencoded
From this bencoded part we take the SHA1 sum.
someone_else
Posts: 1
Joined: Thu Jan 19, 2012 4:35 am

Re: torrent hash

Post by someone_else »

Same situation and the same troubles.
A piece of idea about solution:
(Let the user A have downloaded torrent with CONCRETE_HASH previously)
1) Instead of ignoring user B's attempt to re-add torrent with CONCRETE_HASH,
we can just make hardlinks from user A files to user B directory
2) If there is any new tracker_URL in user B .torrent metafile, we should add it into active torrent with CONCRETE_HASH.
Unfortunately, Transmission response doesn't contain any information about hash, we have to calculate it using .torrent file, bencode functions and sha1()
deadeyes
Posts: 20
Joined: Wed Jun 16, 2010 7:02 am

Re: torrent hash

Post by deadeyes »

Hi and thanks for replying on my thread.

I didn't found any information on CONCRETE_HASH. Were can I find this and what does it means(tried googling it but with no result)?

What I am planning to do is just writing the url that the user used and put that in the db. As soon as a second user tries to download this he gets an entry added so it shows up in his list.
If the same user adds a torrent, it will be searched for in the db.
Now there is one difference between magnet and real torrent links. For real links I am thinking about adding both the link, and a hash of the downloaded file.
After the download is finished I will ran a directory traversal for that download and create hardlinks.
fguillen
Posts: 1
Joined: Sun Feb 10, 2013 1:01 pm

Re: torrent hash

Post by fguillen »

I think this should be solved in the Transmission response. Transmission should response with the "hashString" of the duplicated torrent: https://trac.transmissionbt.com/ticket/4682
Post Reply