Package com.biglybt.core.util
Class TorrentUtils
java.lang.Object
com.biglybt.core.util.TorrentUtils
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
private static class
static interface
static interface
static interface
static interface
static class
private static class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static AtomicLong
private static boolean
private static final List<byte[]>
private static final Set<HashWrapper>
private static final AsyncDispatcher
private static boolean
private static final int
private static final Map<String,
TorrentUtils.DNSTXTEntry> private static int
private static final ThreadPool
(package private) static final DNSUtils.DNSUtilsIntf
(package private) static final Map
static final long
private static final String
private static final String
private static final long
private static final int
private static boolean
private static CopyOnWriteList<TorrentUtils.PotentialTorrentDeletionListener>
private static Map<DownloadManager,
Integer> private static Map<TorrentUtils.PotentialTorrentDeletionListener,
DownloadManager[]> private static final ThreadLocal<Map<String,
Object>> private static final CopyOnWriteList<TorrentUtils.torrentAttributeListener>
private static final String
private static final String
static final String
static final String
static final String
static final String
static final String
private static final String
private static final String
private static final String
static final String
static final String
private static final String
private static final String
private static final String
private static final String
private static final String
private static final String
(package private) static final Map
(package private) static final AtomicLong
(package private) static long
static final int
static final int
static final int
(package private) static final CopyOnWriteList<TorrentUtils.TorrentAnnounceURLChangeListener>
(package private) static final HashSet
private static final boolean
private static final Pattern
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addCreatedTorrent
(TOTorrent torrent) static void
static void
static void
static boolean
announceGroupsContainsURL
(TOTorrent torrent, String url) static void
announceGroupsInsertFirst
(TOTorrent torrent, String first_url) static void
announceGroupsInsertFirst
(TOTorrent torrent, URL first_url) static void
announceGroupsInsertFirst
(TOTorrent torrent, URL[] first_urls) static void
announceGroupsInsertLast
(TOTorrent torrent, URL[] first_urls) static void
announceGroupsSetFirst
(TOTorrent torrent, String first_url) announceGroupsToList
(TOTorrent torrent) static String
announceGroupsToText
(TOTorrent torrent) static String
announceGroupsToText
(List<List<String>> group) announceTextToGroups
(String text) applyAllDNSMods
(URL url) private static URL
applyDNSMods
(URL url) private static TOTorrentAnnounceURLGroup
applyDNSMods
(URL announce_url, TOTorrentAnnounceURLGroup group) static boolean
static boolean
canMergeAnnounceURLs
(TOTorrent new_torrent, TOTorrent dest_torrent) private static void
static void
clearTorrentFileName
(TOTorrent torrent) static TOTorrent
cloneTorrent
(TOTorrent torrent) static void
copyToFile
(TOTorrent torrent, File file) static File
copyTorrentFileToSaveDir
(File f, boolean persistent) Copy a file to the Torrent Save Directory, taking into account all the user config options related to that.static void
static void
static TOTorrent
static TOTorrent
static void
endTorrentDelete
(DownloadManager[] dms) static String
expandTrackerLists
(List<List<String>> groups) private static void
fireAttributeListener
(TOTorrent torrent, String attribute, Object value) static long
private static Map
getAzureusPrivateProperties
(TOTorrent torrent) private static Map
getAzureusProperties
(TOTorrent torrent) private static String
getContentMapString
(TOTorrent torrent, String key) static URL
static URL
getDecentralisedURL
(byte[] hash) static URL
getDecentralisedURL
(TOTorrent torrent) static boolean
getDHTBackupEnabled
(TOTorrent torrent) static String
getDisplayName
(TOTorrent torrent) private static TorrentUtils.DNSTXTEntry
getDNSTXTEntry
(String host, boolean force_update, List<String> already_got_records) static TorrentUtils.DNSTXTEntry
getDNSTXTEntry
(URL url) static DownloadManager
Get the DownloadManager related to a torrent's hashBytesstatic boolean
static boolean
static byte[]
getHashForDisplay
(TOTorrent torrent) static Map
getHashTreeState
(TOTorrent torrent) getIgnoreSetSupport
(boolean force) getInitialLinkage
(TOTorrent torrent) getInitialMetadata
(DownloadManager dm, boolean include_dn) getInitialMetadata
(TOTorrent torrent) getInitialTags
(TOTorrent torrent) static String
getLocalisedName
(TOTorrent torrent) getMergedTrackers
(DownloadManager[] dms) getMergedTrackers
(List<TOTorrent> torrents) getMergedTrackersFromGroups
(List<List<List<String>>> all_trackers) static long
getNetworkCache
(TOTorrent torrent) static String
getObtainedFrom
(TOTorrent torrent) static byte[]
getOriginalHash
(TOTorrent torrent) static Map
getPeerCache
(TOTorrent torrent) static Map
getPluginMapProperty
(TOTorrent torrent, String name) static String
getPluginStringProperty
(TOTorrent torrent, String name) static boolean
getPrivate
(TOTorrent torrent) getSkipExtensionsSetSupport
(boolean force) static boolean[]
getSkipFiles
(TOTorrent torrent) getSkipFileSetSupport
(boolean force) getTagCache
(TOTorrent torrent) static Object
getTLS()
get tls for cloning onto another threadstatic String
static TOTorrent
static HashWrapper
static String
getTorrentFileName
(TOTorrent torrent) static String
getTorrentFileName
(TOTorrent torrent, boolean is_mandatory) getUniqueTrackerHosts
(TOTorrent torrent) getUniqueTrackerHosts
(TOTorrent torrent, boolean include_port) static Map
getV2RootHashCache
(TOTorrent torrent) static boolean
isCreatedTorrent
(TOTorrent torrent) static boolean
isDecentralised
(TOTorrent torrent) static boolean
isDecentralised
(String host) static boolean
isDecentralised
(URL url) static boolean
isDHTBackupRequested
(TOTorrent torrent) static boolean
isFeaturedContent
(TOTorrent torrent) static boolean
isReallyPrivate
(TOTorrent torrent) static boolean
static boolean
isTorrentFile
(String filename) Runs a file through a series of test to verify if it is a torrent.static boolean
isTrackerAddress
(TOTorrent torrent, InetSocketAddress isa) static void
listToAnnounceGroups
(List<List<String>> groups, TOTorrent torrent) static TOTorrentAnnounceURLSet[]
listToAnnounceSets
(List<List<String>> groups, TOTorrent torrent) This method DOES NOT MODIFY THE TORRENTstatic void
static boolean
mergeAnnounceURLs
(TOTorrent new_torrent, TOTorrent dest_torrent) static boolean
static String
nicePrintTorrentHash
(TOTorrent torrent) A nice string of a Torrent's hashstatic String
nicePrintTorrentHash
(TOTorrent torrent, boolean tight) A nice string of a Torrent's hashstatic boolean
propagateExportability
(TOTorrent source, File dest) static TorrentUtils.ExtendedTorrent
readDelegateFromFile
(File file, boolean force_initial_discard) If you set "create_delegate" to true then you must understand that this results is piece hashes being discarded and then re-read from the torrent file if needed Therefore, if you delete the original torrent file you're going to get errors if you access the pieces after this (and they've been discarded)static TOTorrent
static TOTorrent
readFromFile
(File file, boolean create_delegate) static TOTorrent
readFromFile
(File file, boolean create_delegate, boolean force_initial_discard) static void
Deletes the given dir and all dirs underneath if empty.static void
recursiveEmptyDirDelete
(File f, boolean log_warnings) Same as #recursiveEmptyDirDelete(File), except allows disabling of logging of any warningsstatic void
registerMapFluff
(String[] fluff) Register keys that are used for heavyweight maps that should be discarded when the torrent is not in use Make sure these keys are only ever used for Map objects!removeAnnounceURLs
(List<List<String>> base_urls, List<List<String>> remove_urls, boolean use_prefix_match) removeAnnounceURLs2
(List<List<String>> base_urls, List<String> remove_urls, boolean use_prefix_match) static void
removeCreatedTorrent
(TOTorrent torrent) static void
static void
static void
static boolean
replaceAnnounceURL
(TOTorrent torrent, URL old_url, URL new_url) static void
runTorrentDelete
(DownloadManager[] dms, Runnable target) static void
setDecentralised
(TOTorrent torrent) static void
setDHTBackupEnabled
(TOTorrent torrent, boolean enabled) static void
setDHTBackupRequested
(TOTorrent torrent, boolean requested) static void
setDisplayName
(TOTorrent torrent, String str) static void
static void
setHashTreeState
(TOTorrent torrent, Map state) static void
setInitialMetadata
(DownloadManager dm, Map<String, Object> metadata, boolean include_dn) static void
setInitialMetadata
(TOTorrent torrent, Map<String, Object> metadata) static void
setInitialTags
(TOTorrent torrent, List<String> tags) static void
setMemoryOnly
(TOTorrent torrent, boolean mem_only) static void
setNetworkCache
(TOTorrent torrent, List<String> networks) static void
setObtainedFrom
(TOTorrent torrent, String str) static void
setObtainedFrom
(File file, String str) static void
setOriginalHash
(TOTorrent torrent, byte[] hash) static void
setPeerCache
(TOTorrent torrent, Map pc) static void
setPeerCacheValid
(TOTorrent torrent) static void
setPluginMapProperty
(TOTorrent torrent, String name, Map value) static void
setPluginStringProperty
(TOTorrent torrent, String name, String value) static void
setPrivate
(TOTorrent torrent, boolean _private) static void
setResumeDataCompletelyValid
(DownloadManagerState download_manager_state) static void
setResumeDataTotallyIncomplete
(DownloadManagerState download_manager_state) static void
setTagCache
(TOTorrent torrent, List<String> tags) static void
static void
setTLSDescription
(String desc) static void
setTLSTorrentHash
(HashWrapper hash) static void
static void
setV2RootHashCache
(TOTorrent torrent, Map cache) static boolean
shouldDeleteTorrentFileAfterAdd
(File f, boolean persistent) static void
static void
Disables DNS Handling, but doesn't save it to the configstatic void
writeToFile
(TOTorrent torrent) static void
writeToFile
(TOTorrent torrent, boolean force_backup) static void
writeToFile
(TOTorrent torrent, File file, boolean force_backup)
-
Field Details
-
MAX_TORRENT_FILE_SIZE
public static final long MAX_TORRENT_FILE_SIZE- See Also:
-
NO_VALID_URL_URL
- See Also:
-
TORRENT_FLAG_LOW_NOISE
public static final int TORRENT_FLAG_LOW_NOISE- See Also:
-
TORRENT_FLAG_METADATA_TORRENT
public static final int TORRENT_FLAG_METADATA_TORRENT- See Also:
-
TORRENT_FLAG_DISABLE_RCM
public static final int TORRENT_FLAG_DISABLE_RCM- See Also:
-
TORRENT_AZ_PROP_DHT_BACKUP_ENABLE
- See Also:
-
TORRENT_AZ_PROP_DHT_BACKUP_REQUESTED
- See Also:
-
TORRENT_AZ_PROP_TORRENT_FLAGS
- See Also:
-
TORRENT_AZ_PROP_PLUGINS
- See Also:
-
TORRENT_AZ_PROP_OBTAINED_FROM
- See Also:
-
TORRENT_AZ_PROP_DISPLAY_NAME
- See Also:
-
TORRENT_AZ_PROP_NETWORK_CACHE
- See Also:
-
TORRENT_AZ_PROP_TAG_CACHE
- See Also:
-
TORRENT_AZ_PROP_INITIAL_TAGS
- See Also:
-
TORRENT_AZ_PROP_INITIAL_METADATA
- See Also:
-
TORRENT_AZ_PROP_PEER_CACHE
- See Also:
-
TORRENT_AZ_PROP_PEER_CACHE_VALID
- See Also:
-
TORRENT_AZ_PROP_INITIAL_LINKAGE
- See Also:
-
TORRENT_AZ_PROP_INITIAL_LINKAGE2
- See Also:
-
TORRENT_AZ_PROP_ORIGINAL_HASH
- See Also:
-
TORRENT_AZ_PROP_HASHTREE_STATE
- See Also:
-
TORRENT_AZ_PROP_HYBRID_HASH_V2
- See Also:
-
TORRENT_AZ_PROP_V2_ROOT_HASH_CACHE
- See Also:
-
MEM_ONLY_TORRENT_PATH
- See Also:
-
PC_MARKER
private static final long PC_MARKER -
created_torrents
-
created_torrents_set
-
tls
-
ignore_files_set
-
skip_extensions_set
-
skip_file_set
-
bSaveTorrentBackup
private static boolean bSaveTorrentBackup -
torrent_attribute_listeners
private static final CopyOnWriteList<TorrentUtils.torrentAttributeListener> torrent_attribute_listeners -
torrent_url_changed_listeners
static final CopyOnWriteList<TorrentUtils.TorrentAnnounceURLChangeListener> torrent_url_changed_listeners -
dispatcher
-
DNS_HANDLING_ENABLE
private static boolean DNS_HANDLING_ENABLE -
TRACE_DNS
private static final boolean TRACE_DNS- See Also:
-
DNS_HISTORY_TIMEOUT
private static final int DNS_HISTORY_TIMEOUT- See Also:
-
dns_mapping
-
dns_mapping_seq_count
private static volatile int dns_mapping_seq_count -
dns_threads
-
dns_utils
-
priority_file_exts
-
priority_file_exts_ignore_case
private static volatile boolean priority_file_exts_ignore_case -
torrent_delete_level
-
torrent_delete_time
static long torrent_delete_time -
announce_group_uid_next
-
PIECE_HASH_TIMEOUT
private static final int PIECE_HASH_TIMEOUT- See Also:
-
torrent_delegates
-
torrentFluffKeyset
-
fluffThombstone
-
txt_pattern
-
ptd_listeners
-
ptd_map
-
ptdl_last
-
tracker_hosts
-
tracker_addresses
-
-
Constructor Details
-
TorrentUtils
public TorrentUtils()
-
-
Method Details
-
getAnnounceGroupUID
public static long getAnnounceGroupUID() -
readFromFile
- Throws:
TOTorrentException
-
readDelegateFromFile
public static TorrentUtils.ExtendedTorrent readDelegateFromFile(File file, boolean force_initial_discard) throws TOTorrentException If you set "create_delegate" to true then you must understand that this results is piece hashes being discarded and then re-read from the torrent file if needed Therefore, if you delete the original torrent file you're going to get errors if you access the pieces after this (and they've been discarded)- Parameters:
file
-create_delegate
-force_initial_discard
- - use to get rid of pieces immediately- Returns:
- Throws:
TOTorrentException
-
readFromFile
public static TOTorrent readFromFile(File file, boolean create_delegate, boolean force_initial_discard) throws TOTorrentException - Throws:
TOTorrentException
-
readFromBEncodedInputStream
- Throws:
TOTorrentException
-
cloneTorrent
- Throws:
TOTorrentException
-
setMemoryOnly
-
writeToFile
- Throws:
TOTorrentException
-
writeToFile
- Throws:
TOTorrentException
-
writeToFile
public static void writeToFile(TOTorrent torrent, File file, boolean force_backup) throws TOTorrentException - Throws:
TOTorrentException
-
getTorrentFileName
- Throws:
TOTorrentException
-
getTorrentFileName
public static String getTorrentFileName(TOTorrent torrent, boolean is_mandatory) throws TOTorrentException - Throws:
TOTorrentException
-
clearTorrentFileName
-
copyToFile
- Throws:
TOTorrentException
-
delete
- Throws:
TOTorrentException
-
delete
-
move
-
exceptionToText
-
getUniqueTrackerHosts
-
getUniqueTrackerHosts
-
announceGroupsToText
-
announceGroupsToText
-
announceTextToGroups
-
announceGroupsToList
-
expandTrackerLists
-
getMergedTrackers
-
getMergedTrackers
-
getMergedTrackersFromGroups
-
listToAnnounceSets
public static TOTorrentAnnounceURLSet[] listToAnnounceSets(List<List<String>> groups, TOTorrent torrent) This method DOES NOT MODIFY THE TORRENT- Parameters:
groups
-torrent
-- Returns:
-
listToAnnounceGroups
-
announceGroupsInsertFirst
-
announceGroupsInsertFirst
-
announceGroupsInsertFirst
-
announceGroupsInsertLast
-
announceGroupsSetFirst
-
announceGroupsContainsURL
-
canMergeAnnounceURLs
-
mergeAnnounceURLs
-
mergeAnnounceURLs
-
removeAnnounceURLs
-
removeAnnounceURLs2
-
getClone
-
areIdentical
-
replaceAnnounceURL
-
setResumeDataTotallyIncomplete
-
setResumeDataCompletelyValid
-
getLocalisedName
-
setTLSTorrentHash
-
getTLSTorrentHash
-
getTLSTorrent
-
setTLSDescription
-
getTLSDescription
-
getTLS
get tls for cloning onto another thread- Returns:
-
setTLS
-
getDecentralisedEmptyURL
-
getDecentralisedURL
-
getDecentralisedURL
-
setDecentralised
-
isDecentralised
-
isDecentralised
-
isDecentralised
-
getAzureusProperties
-
getAzureusPrivateProperties
-
getContentMapString
-
isFeaturedContent
-
setObtainedFrom
-
setObtainedFrom
-
getObtainedFrom
-
setDisplayName
-
getDisplayName
-
setNetworkCache
-
getNetworkCache
-
setTagCache
-
getTagCache
-
setInitialTags
-
getInitialTags
-
setInitialMetadata
-
getInitialMetadata
-
getInitialMetadata
-
setInitialMetadata
public static void setInitialMetadata(DownloadManager dm, Map<String, Object> metadata, boolean include_dn) -
setOriginalHash
-
getOriginalHash
-
setHashTreeState
-
getHashTreeState
-
setV2RootHashCache
-
getV2RootHashCache
-
getHashForDisplay
-
setPeerCache
-
setPeerCacheValid
-
getPeerCache
-
setFlag
-
getFlag
-
getInitialLinkage
-
setPluginStringProperty
-
getPluginStringProperty
-
setPluginMapProperty
-
getPluginMapProperty
-
setDHTBackupEnabled
-
getDHTBackupEnabled
-
isDHTBackupRequested
-
setDHTBackupRequested
-
isReallyPrivate
-
getPrivate
-
setPrivate
-
getSkipExtensionsSet
-
getSkipExtensionsSetSupport
-
getSkipFileSet
-
getSkipFileSetSupport
-
getSkipFiles
- Parameters:
torrent
-- Returns:
- null if no files skipped otherwise entry for each file in torrent
-
getIgnoreSet
-
getIgnoreSetSupport
-
registerMapFluff
Register keys that are used for heavyweight maps that should be discarded when the torrent is not in use Make sure these keys are only ever used for Map objects! -
copyTorrentFileToSaveDir
Copy a file to the Torrent Save Directory, taking into account all the user config options related to that.Also makes the directory if it doesn't exist.
- Parameters:
f
- File to copypersistent
- Whether the torrent is persistent- Returns:
- File after it's been copied (may be the same as f)
- Throws:
IOException
-
shouldDeleteTorrentFileAfterAdd
-
getDownloadManager
Get the DownloadManager related to a torrent's hashBytes- Parameters:
hashBytes
-- Returns:
-
recursiveEmptyDirDelete
Deletes the given dir and all dirs underneath if empty. Don't delete default save path or completed files directory, however, allow deletion of their empty subdirectories Files defined to be ignored for the sake of torrent creation are automatically deleted For example, by default this includes thumbs.db -
recursiveEmptyDirDelete
Same as #recursiveEmptyDirDelete(File), except allows disabling of logging of any warnings- Parameters:
f
- Dir to deletelog_warnings
- Whether to log warning
-
nicePrintTorrentHash
A nice string of a Torrent's hash- Parameters:
torrent
- Torrent to format hash of- Returns:
- Hash string in a nice format
-
nicePrintTorrentHash
A nice string of a Torrent's hash- Parameters:
torrent
- Torrent to format hash oftight
- No spaces between groups of numbers- Returns:
- Hash string in a nice format
-
isTorrentFile
Runs a file through a series of test to verify if it is a torrent.- Parameters:
filename
- File to test- Returns:
- true - file is a valid torrent file
- Throws:
FileNotFoundException
IOException
-
addCreatedTorrent
-
removeCreatedTorrent
-
isCreatedTorrent
-
download
- Throws:
IOException
-
download
- Throws:
IOException
-
fireAttributeListener
-
addTorrentAttributeListener
-
removeTorrentAttributeListener
-
addTorrentURLChangeListener
public static void addTorrentURLChangeListener(TorrentUtils.TorrentAnnounceURLChangeListener listener) -
removeTorrentURLChangeListener
public static void removeTorrentURLChangeListener(TorrentUtils.TorrentAnnounceURLChangeListener listener) -
getDNSTXTEntry
-
checkDNSTimeouts
private static void checkDNSTimeouts() -
getDNSTXTEntry
private static TorrentUtils.DNSTXTEntry getDNSTXTEntry(String host, boolean force_update, List<String> already_got_records) -
applyDNSMods
-
applyAllDNSMods
-
applyDNSMods
private static TOTorrentAnnounceURLGroup applyDNSMods(URL announce_url, TOTorrentAnnounceURLGroup group) -
startTorrentDelete
-
endTorrentDelete
-
runTorrentDelete
-
addPotentialTorrentDeletionListener
public static void addPotentialTorrentDeletionListener(TorrentUtils.PotentialTorrentDeletionListener l) -
removePotentialTorrentDeletionListener
public static void removePotentialTorrentDeletionListener(TorrentUtils.PotentialTorrentDeletionListener l) -
isTorrentDeleting
public static boolean isTorrentDeleting() -
setTorrentDeleted
public static void setTorrentDeleted() -
getMillisecondsSinceLastTorrentDelete
public static long getMillisecondsSinceLastTorrentDelete() -
propagateExportability
-
temporarilyDisableDNSHandling
public static void temporarilyDisableDNSHandling()Disables DNS Handling, but doesn't save it to the config -
isTrackerAddress
-
getFilePriorityExtensions
-
getFilePriorityExtensionsIgnoreCase
public static boolean getFilePriorityExtensionsIgnoreCase() -
main
-