// prevents someone without the hash from downloading the torrent
try{
byte[] search_key = ((DDBaseKeyImpl)key).getBytes();
Download download = null;
PluginInterface pi = PluginInitializer.getDefaultInterface();
String search_sha1 = pi.getUtilities().getFormatters().encodeBytesToString( search_key );
if ( ta_sha1 == null ){
ta_sha1 = pi.getTorrentManager().getPluginAttribute( "DDBaseTTTorrent::sha1");
}
// gotta look for the sha1(hash)
Download[] downloads = pi.getDownloadManager().getDownloads();
for (int i=0;i<downloads.length;i++){
Download dl = downloads[i];
if ( dl.getTorrent() == null ){
continue;
}
String sha1 = dl.getAttribute( ta_sha1 );
if ( sha1 == null ){
sha1 = pi.getUtilities().getFormatters().encodeBytesToString(
new SHA1Simple().calculateHash( dl.getTorrent().getHash()));
dl.setAttribute( ta_sha1, sha1 );
}
if ( sha1.equals( search_sha1 )){
download = dl;
break;
}
}
if ( download == null ){
synchronized( this ){
if ( external_downloads != null ){
for (int i=0;i<external_downloads.size();i++){
Download dl = (Download)external_downloads.get(i);
if ( dl.getTorrent() == null ){
continue;
}
String sha1 = dl.getAttribute( ta_sha1 );
if ( sha1 == null ){
sha1 = pi.getUtilities().getFormatters().encodeBytesToString(
new SHA1Simple().calculateHash( dl.getTorrent().getHash()));
dl.setAttribute( ta_sha1, sha1 );
}
if ( sha1.equals( search_sha1 )){
download = dl;