Skip to content

Commit

Permalink
Add some missing code comments and a typo fix
Browse files Browse the repository at this point in the history
Signed-off-by: Maxime Petazzoni <[email protected]>
  • Loading branch information
Maxime Petazzoni committed Jul 19, 2011
1 parent f26ab02 commit d852ed0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions src/com/turn/ttorrent/common/Torrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -139,6 +141,8 @@ public byte[] getEncoded() {
return this.encoded;
}

/** Return the announce URL used by this torrent.
*/
public String getAnnounceUrl() {
return this.announceUrl;
}
Expand Down Expand Up @@ -173,6 +177,19 @@ public static String toHexString(String input) {
}
}

/** Create a {@link Torrent} object for a file.
*
* <p>
* 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.
* </p>
*
* @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() + "...");
Expand All @@ -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.
*
* <p>
* 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.
* </p>
*
* <p>
* This is used for creating Torrent meta-info structures from a file.
* </p>
*
* @param source The file to hash.
*/
private static String hashPieces(File source)
throws NoSuchAlgorithmException, IOException {
MessageDigest md = MessageDigest.getInstance("SHA-1");
Expand Down
2 changes: 1 addition & 1 deletion src/com/turn/ttorrent/tracker/Tracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class Tracker {
/** The in-memory repository of torrents tracked. */
private ConcurrentMap<String, TrackedTorrent> torrents;

/** Create a new BitTorrent tracket on the default port.
/** Create a new BitTorrent tracker on the default port.
*
* @param address The address to bind to.
* @param version A version string served in the HTTP headers
Expand Down

0 comments on commit d852ed0

Please sign in to comment.