diff --git a/src/com/turn/ttorrent/common/Torrent.java b/src/com/turn/ttorrent/common/Torrent.java index 1318fdc77..818e5e09c 100644 --- a/src/com/turn/ttorrent/common/Torrent.java +++ b/src/com/turn/ttorrent/common/Torrent.java @@ -115,6 +115,8 @@ public String getName() { return this.name; } + /** Return the hash of the B-encoded meta-info structure of this torrent. + */ public byte[] getInfoHash() { return this.info_hash; } @@ -139,6 +141,8 @@ public byte[] getEncoded() { return this.encoded; } + /** Return the announce URL used by this torrent. + */ public String getAnnounceUrl() { return this.announceUrl; } @@ -173,6 +177,19 @@ public static String toHexString(String input) { } } + /** Create a {@link Torrent} object for a file. + * + *
+ * Hash the given file (by filename) to create the {@link Torrent} object + * representing the Torrent metainfo about this file, needed for announcing + * and/or sharing said file. + *
+ * + * @param source The file name. + * @param announce The announce URL that will be used for this torrent. + * @param createdBy The creator's name, or any string identifying the + * torrent's creator. + */ public static Torrent create(File source, String announce, String createdBy) throws NoSuchAlgorithmException, IOException { logger.info("Creating torrent for " + source.getName() + "..."); @@ -195,6 +212,20 @@ public static Torrent create(File source, String announce, String createdBy) return new Torrent(baos.toByteArray()); } + /** Return the concatenation of the SHA-1 hashes of a file's pieces. + * + *+ * Hashes the given file piece by piece using the default Torrent piece + * length (see {@link #PIECE_LENGTH}) and returns the concatenation of + * these hashes, as a string. + *
+ * + *+ * This is used for creating Torrent meta-info structures from a file. + *
+ * + * @param source The file to hash. + */ private static String hashPieces(File source) throws NoSuchAlgorithmException, IOException { MessageDigest md = MessageDigest.getInstance("SHA-1"); diff --git a/src/com/turn/ttorrent/tracker/Tracker.java b/src/com/turn/ttorrent/tracker/Tracker.java index bf57085b5..cc2c273f3 100644 --- a/src/com/turn/ttorrent/tracker/Tracker.java +++ b/src/com/turn/ttorrent/tracker/Tracker.java @@ -55,7 +55,7 @@ public class Tracker { /** The in-memory repository of torrents tracked. */ private ConcurrentMap