pobrn / mktorrent

A simple command line utility to create BitTorrent metainfo files
Other
472 stars 73 forks source link

Add flag to enable easier cross-seeding #48

Closed rmsacks closed 4 years ago

rmsacks commented 4 years ago

I don't know if this is within the scope of the project, but it is something that I've found to be very useful and I think others may find it useful, too.

I recently ran into a problem when I wanted to cross seed the same files with two different torrents. Since the both torrent files used the same piece size and were operating on the same files, the generated info hashes were identical and my torrent client refused to add the second torrent. This flag prevents that from happening by adding a random entry like this to the info section of the torrent file:

x_cross_seed42:mktorrent-EAB9AF9C87121A01849725228398D350e

The only effect this entry should have is ensuring that the computed info hashes for two torrent files are different even if they have the same files and piece size. It should be ignored otherwise. This behavior can also be found in other popular programs such as ruTorrent and pyrocore.

FranciscoPombal commented 4 years ago

@rmsacks

I would change the option description to something like add a randomly-generated source string embedded in infohash., to make it clearer that this option is similar to -s. After all, the use case for this option is almost the same as -s, except you don't exactly care to manually specify what the source string should be.

Rudde commented 4 years ago

@rmsacks Can you move this to be written before the pieces are written?

rmsacks commented 4 years ago

@rmsacks Can you move this to be written before the pieces are written?

Done and rebased on master.

FranciscoPombal commented 4 years ago

Sorry for not pointing this out earlier, but why define CROSS_SEED_RAND_LENGTH to be a certain value if the length of the "interesting" string is actually going to be that vale times an arbitrary constant (2 in this case)? Seems a little counter-intuitive.

The "interesting" for loop could have then been re-written as:

fprintf(f, "12:x_cross_seed%zu:mktorrent-", strlen("mktorrent-") + CROSS_SEED_RAND_LENGTH);
for (int i = 0; i < CROSS_SEED_RAND_LENGTH / 2; ++i) {
    unsigned char rand_byte = random();
    fputc("0123456789ABCDEF"[rand_byte >> 4], f);
    fputc("0123456789ABCDEF"[rand_byte & 0x0F], f);
}

which also gets rid of the "magic" + 10.

uno20001 commented 4 years ago

CROSS_SEED_RAND_LENGTH is the number of random bytes, so I think it makes sense.

FranciscoPombal commented 4 years ago

@uno20001

ah, so the string is supposed to encode bytes in hex? Then it does make sense.

uno20001 commented 4 years ago

Yes.