Class TorrentBuilder
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic final class -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final create_flags_tThis flag only affects v1-only torrents, and is only relevant together with the v1_only_flag.static final create_flags_tThis will include the file modification time as part of the torrent.static final create_flags_tIf this flag is set, files that are symlinks get a symlink attribute set on them and their data will not be included in the torrent.static final create_flags_tDo not generate v2 metadata or enforce v2 alignment and padding rules this is mainly for tests, not recommended for production use.static final create_flags_tDo not generate v1 metadata. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddCollection(String value) Add collections of similar torrents.addCollections(List<String> value) This adds a DHT node to the torrent.This adds a DHT node to the torrent.addSimilarTorrent(Sha1Hash value) Add similar torrents (by info-hash).addSimilarTorrents(List<Sha1Hash> value) addTracker(Pair<String, Integer> value) Adds a tracker to the torrent.addTracker(String url) Adds a tracker on tier 0 to the torrent.addTracker(String url, int tier) Adds a tracker to the torrent.addTrackers(List<Pair<String, Integer>> value) Adds a list of trackers to the torrent.addUrlSeed(String value) This adds a URL seed to the torrent.addUrlSeeds(List<String> value) This adds a list of url seeds to the torrent.intalignment(int value) Used when pad files are enabled.comment()The comment for the torrent.Sets the comment for the torrent.longThe "creation time" field.creationDate(long timestamp) Set the "creation time" field.creator()The creator of the torrent.Sets the creator of the torrent.flags()create_flags_t is a type alias that simplifies the usage of the bitfield_flag structure for a specific case within the libtorrent namespace.flags(create_flags_t value) Specifies options for the torrent creation.generate()This function will generate a result with the .torrent file as a bencoded tree.booleanTorrents with the private flag set ask clients to not use any other sources than the tracker for peers, and to not advertise itself publicly, apart from the tracker.listener()listener(TorrentBuilder.Listener value) nodes()Lists specified DHT nodes in the torrent (added with addNodes(List<Pair<String, Integer>>)).path()Sets the path by the specified fileintThe ``piece_size`` is the size of each piece in bytes.pieceSize(int value) The size of each piece in bytes.setPrivate(boolean value) Sets the private flag of the torrent.trackers()urlSeeds()
-
Field Details
-
MODIFICATION_TIME
This will include the file modification time as part of the torrent. This is not enabled by default, as it might cause problems when you create a torrent from separate files with the same content, hoping to yield the same info-hash. If the files have different modification times, with this option enabled, you would get different info-hashes for the files. -
SYMLINKS
If this flag is set, files that are symlinks get a symlink attribute set on them and their data will not be included in the torrent. This is useful if you need to reconstruct a file hierarchy which contains symlinks. -
V2_ONLY
Do not generate v1 metadata. The resulting torrent will only be usable by clients which support v2. This requires setting all v2 hashes, with set_hash2() before calling generate(). Setting v1 hashes (with set_hash()) is an error with this flag set. -
V1_ONLY
Do not generate v2 metadata or enforce v2 alignment and padding rules this is mainly for tests, not recommended for production use. This requires setting all v1 hashes, with set_hash(), before calling generate(). Setting v2 hashes (with set_hash2()) is an error with this flag set. -
CANONICAL_FILES
This flag only affects v1-only torrents, and is only relevant together with the v1_only_flag. This flag will force the same file order and padding as a v2 (or hybrid) torrent would have. It has the effect of ordering files and inserting pad files to align them with piece boundaries.
-
-
Constructor Details
-
TorrentBuilder
public TorrentBuilder()
-
-
Method Details
-
path
-
path
Sets the path by the specified file -
pieceSize
public int pieceSize()The ``piece_size`` is the size of each piece in bytes. It must be a power of 2 and a minimum of 16 kiB. If a piece size of 0 is specified, a piece_size will be set automatically. -
pieceSize
The size of each piece in bytes. It must be a multiple of 16 kiB. If a piece size of 0 is specified, apieceSizewill be calculated such that the torrent file is roughly 40 kB. -
flags
create_flags_t is a type alias that simplifies the usage of the bitfield_flag structure for a specific case within the libtorrent namespace.The bitfield_flag structure in the provided code is a utility for managing flags in a bitfield, which is essentially a data structure that compactly stores bits.
create_flags_t is a type alias for bitfield_flag<std::uint32_t, create_flags_tag>, specifically designed to handle creation flags in libtorrent.
It provides a compact, efficient way to manage binary flags using bitwise operations, with the additional type safety provided by the create_flags_tag.
-
flags
Specifies options for the torrent creation. It can be any combination of the flags defined bycreate_flags_t -
alignment
public int alignment() -
alignment
Used when pad files are enabled. This is the size eligible files are aligned to. The default is -1, which means the piece size of the torrent. -
comment
The comment for the torrent. The comment in a torrent file is optional. -
comment
Sets the comment for the torrent. The comment in a torrent file is optional. -
creator
The creator of the torrent. This is optional. -
creator
Sets the creator of the torrent. This is optional. -
creationDate
public long creationDate()The "creation time" field. Defaults to the system clock at the time of construction. The timestamp is specified in seconds, posix time. If the creation date is set to 0, the "creation date" field will be omitted from the generated torrent. -
creationDate
Set the "creation time" field. Defaults to the system clock at the time of construction. The timestamp is specified in seconds, posix time. If the creation date is set to 0, the "creation date" field will be omitted from the generated torrent. -
urlSeeds
-
addUrlSeeds
This adds a list of url seeds to the torrent. You can have any number of url seeds. For a single file torrent, this should be an HTTP url, pointing to a file with identical content as the file of the torrent. For a multi-file torrent, it should point to a directory containing a directory with the same name as this torrent, and all the files of the torrent in it. -
addUrlSeed
This adds a URL seed to the torrent. You can have any number of url seeds. For a single file torrent, this should be an HTTP url, pointing to a file with identical content as the file of the torrent. For a multi-file torrent, it should point to a directory containing a directory with the same name as this torrent, and all the files of the torrent in it. -
nodes
-
addNodes
This adds a DHT node to the torrent. This especially useful if you're creating a tracker less torrent. It can be used by clients to bootstrap their DHT node from. The node is a hostname and a port number where there is a DHT node running. You can have any number of DHT nodes in a torrent. -
addNode
This adds a DHT node to the torrent. This especially useful if you're creating a tracker less torrent. It can be used by clients to bootstrap their DHT node from. The node is a hostname and a port number where there is a DHT node running. You can have any number of DHT nodes in a torrent. -
trackers
-
addTrackers
Adds a list of trackers to the torrent.- See Also:
-
addTracker
Adds a tracker to the torrent. This is not strictly required, but most torrents use a tracker as their main source of peers. The url should be a http:// or udp:// url to a machine running a bittorrent tracker that accepts announces for this torrent's info-hash. The tier is the fallback priority of the tracker. All trackers with tier 0 are tried first (in any order). If all fail, trackers with tier 1 are tried. If all of those fail, trackers with tier 2 are tried, and so on. -
addTracker
Adds a tracker to the torrent. This is not strictly required, but most torrents use a tracker as their main source of peers. The url should be a http:// or udp:// url to a machine running a bittorrent tracker that accepts announces for this torrent's info-hash. The tier is the fallback priority of the tracker. All trackers with tier 0 are tried first (in any order). If all fail, trackers with tier 1 are tried. If all of those fail, trackers with tier 2 are tried, and so on. -
addTracker
Adds a tracker on tier 0 to the torrent. -
isPrivate
public boolean isPrivate()Torrents with the private flag set ask clients to not use any other sources than the tracker for peers, and to not advertise itself publicly, apart from the tracker. -
setPrivate
Sets the private flag of the torrent.Torrents with the private flag set ask clients to not use any other sources than the tracker for peers, and to not advertise itself publicly, apart from the tracker.
-
similarTorrents
-
addSimilarTorrents
- See Also:
-
addSimilarTorrent
Add similar torrents (by info-hash).Similar torrents are expected to share some files with this torrent. Torrents sharing a collection name with this torrent are also expected to share files with this torrent. A torrent may have more than one collection and more than one similar torrents. For more information, see BEP 38.
BEP 38: ...
-
collections
-
addCollections
-
addCollection
Add collections of similar torrents.Similar torrents are expected to share some files with this torrent. Torrents sharing a collection name with this torrent are also expected to share files with this torrent. A torrent may have more than one collection and more than one similar torrents. For more information, see BEP 38.
BEP 38: ...
-
listener
-
listener
-
generate
This function will generate a result with the .torrent file as a bencoded tree.- Throws:
IOException
-