📄 ddbasetttorrent.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: DDBaseTTTorrent.java
package org.gudy.azureus2.pluginsimpl.local.ddb;
import com.aelitis.azureus.core.AzureusCore;
import com.aelitis.azureus.plugins.dht.DHTPluginContact;
import com.aelitis.azureus.plugins.dht.DHTPluginProgressListener;
import java.util.*;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import org.gudy.azureus2.core3.logging.LogAlert;
import org.gudy.azureus2.core3.logging.Logger;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.PluginInterface;
import org.gudy.azureus2.plugins.PluginManager;
import org.gudy.azureus2.plugins.ddb.*;
import org.gudy.azureus2.plugins.download.Download;
import org.gudy.azureus2.plugins.download.DownloadManager;
import org.gudy.azureus2.plugins.torrent.*;
import org.gudy.azureus2.plugins.utils.Formatters;
import org.gudy.azureus2.plugins.utils.Utilities;
// Referenced classes of package org.gudy.azureus2.pluginsimpl.local.ddb:
// DDBaseContactImpl, DDBaseHelpers, DDBaseImpl, DDBaseKeyImpl,
// DDBaseValueImpl
public class DDBaseTTTorrent
implements DistributedDatabaseTransferType, DistributedDatabaseTransferHandler
{
private static final boolean TRACE = false;
private static final byte CRYPTO_VERSION = 1;
private AzureusCore azureus_core;
private DDBaseImpl ddb;
private TorrentAttribute ta_sha1;
private boolean crypto_tested;
private boolean crypto_available;
private List external_downloads;
private Map data_cache;
protected DDBaseTTTorrent(AzureusCore _azureus_core, DDBaseImpl _ddb)
{
data_cache = new LinkedHashMap(5, 0.75F, true) {
final DDBaseTTTorrent this$0;
protected boolean removeEldestEntry(java.util.Map.Entry eldest)
{
return size() > 5;
}
{
this$0 = DDBaseTTTorrent.this;
super(x0, x1, x2);
}
};
azureus_core = _azureus_core;
ddb = _ddb;
}
public void addDownload(Download download)
{
synchronized (this)
{
if (external_downloads == null)
external_downloads = new ArrayList();
external_downloads.add(download);
}
}
public void removeDownload(Download download)
{
synchronized (this)
{
if (external_downloads != null)
external_downloads.remove(download);
if (external_downloads.size() == 0)
external_downloads = null;
}
}
public DistributedDatabaseValue read(DistributedDatabaseContact contact, DistributedDatabaseTransferType type, DistributedDatabaseKey key)
throws DistributedDatabaseException
{
Download download;
String originator;
byte search_key[] = ((DDBaseKeyImpl)key).getBytes();
download = null;
PluginInterface pi = azureus_core.getPluginManager().getDefaultPluginInterface();
String search_sha1 = pi.getUtilities().getFormatters().encodeBytesToString(search_key);
if (ta_sha1 == null)
ta_sha1 = pi.getTorrentManager().getPluginAttribute("DDBaseTTTorrent::sha1");
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))
continue;
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))
continue;
download = dl;
break;
}
}
}
originator = contact.getName();
if (download != null)
break MISSING_BLOCK_LABEL_462;
String msg = (new StringBuilder()).append("TorrentDownload: request from ").append(originator).append(" for '").append(pi.getUtilities().getFormatters().encodeBytesToString(search_key)).append("' not found").toString();
ddb.log(msg);
return null;
Torrent torrent;
torrent = download.getTorrent();
if (!torrent.isPrivate())
break MISSING_BLOCK_LABEL_535;
Debug.out("Attempt to download private torrent");
ddb.log((new StringBuilder()).append("TorrentDownload: request from ").append(originator).append(" for '").append(download.getName()).append("' denied as it is private").toString());
return null;
String msg = (new StringBuilder()).append("TorrentDownload: request from ").append(originator).append(" for '").append(download.getName()).append("' OK").toString();
ddb.log(msg);
HashWrapper hw = new HashWrapper(torrent.getHash());
Map map = data_cache;
JVM INSTR monitorenter ;
Object data[];
data = (Object[])(Object[])data_cache.get(hw);
if (data == null)
break MISSING_BLOCK_LABEL_669;
data[1] = new Long(SystemTime.getCurrentTime());
return ddb.createValue((byte[])(byte[])data[0]);
map;
JVM INSTR monitorexit ;
goto _L1
Exception exception1;
exception1;
throw exception1;
_L1:
byte data[];
torrent = torrent.removeAdditionalProperties();
torrent.setDecentralisedBackupRequested(true);
data = torrent.writeToBEncodedData();
data = encrypt(torrent.getHash(), data);
if (data == null)
return null;
synchronized (data_cache)
{
if (data_cache.size() == 0)
{
final TimerEventPeriodic pe[] = {
null
};
pe[0] = SimpleTimer.addPeriodicEvent("DDBTorrent:timeout", 30000L, new TimerEventPerformer() {
final TimerEventPeriodic val$pe[];
final DDBaseTTTorrent this$0;
public void perform(TimerEvent event)
{
long now = SystemTime.getCurrentTime();
synchronized (data_cache)
{
Iterator it = data_cache.values().iterator();
do
{
if (!it.hasNext())
break;
long time = ((Long)((Object[])(Object[])it.next())[1]).longValue();
if (now < time || now - time > 0x1d4c0L)
it.remove();
} while (true);
if (data_cache.size() == 0)
pe[0].cancel();
}
}
{
this$0 = DDBaseTTTorrent.this;
pe = atimereventperiodic;
super();
}
});
}
data_cache.put(hw, ((Object) (new Object[] {
data, new Long(SystemTime.getCurrentTime())
})));
}
return ddb.createValue(data);
Throwable e;
e;
throw new DistributedDatabaseException("Torrent write fails", e);
}
public void write(DistributedDatabaseContact contact, DistributedDatabaseTransferType type, DistributedDatabaseKey key, DistributedDatabaseValue value)
throws DistributedDatabaseException
{
throw new DistributedDatabaseException("not supported");
}
protected DistributedDatabaseValue read(DDBaseContactImpl contact, final DistributedDatabaseProgressListener listener, DistributedDatabaseTransferType type, DistributedDatabaseKey key, long timeout)
throws DistributedDatabaseException
{
byte torrent_hash[] = ((DDBaseKeyImpl)key).getBytes();
byte lookup_key[] = (new SHA1Simple()).calculateHash(torrent_hash);
byte data[] = contact.getContact().read(new DHTPluginProgressListener() {
final DistributedDatabaseProgressListener val$listener;
final DDBaseTTTorrent this$0;
public void reportSize(long size)
{
listener.reportSize(size);
}
public void reportActivity(String str)
{
listener.reportActivity(str);
}
public void reportCompleteness(int percent)
{
listener.reportCompleteness(percent);
}
{
this$0 = DDBaseTTTorrent.this;
listener = distributeddatabaseprogresslistener;
super();
}
}, DDBaseHelpers.getKey(type.getClass()).getHash(), lookup_key, timeout);
if (data == null)
return null;
data = decrypt(torrent_hash, data);
if (data == null)
return null;
else
return new DDBaseValueImpl(contact, data, SystemTime.getCurrentTime(), -1L);
}
protected byte[] encrypt(byte hash[], byte data[])
{
if (!testCrypto())
return null;
byte enc[] = doCrypt(1, hash, data, 0);
if (enc == null)
{
byte res[] = new byte[data.length + 2];
res[0] = 1;
res[1] = 0;
System.arraycopy(data, 0, res, 2, data.length);
return res;
} else
{
byte res[] = new byte[enc.length + 2];
res[0] = 1;
res[1] = 1;
System.arraycopy(enc, 0, res, 2, enc.length);
return res;
}
}
protected byte[] decrypt(byte hash[], byte data[])
{
if (!testCrypto())
return null;
if (data[0] != 1)
{
Debug.out("Invalid crypto version received");
return data;
}
if (data[1] == 0)
{
byte res[] = new byte[data.length - 2];
System.arraycopy(data, 2, res, 0, res.length);
return res;
} else
{
byte res[] = doCrypt(2, hash, data, 2);
return res;
}
}
protected byte[] doCrypt(int mode, byte hash[], byte data[], int data_offset)
{
Cipher cipher;
byte key_data[] = new byte[24];
System.arraycopy(hash, 0, key_data, 0, hash.length);
javax.crypto.SecretKey tdes_key = new SecretKeySpec(key_data, "DESede");
cipher = Cipher.getInstance("DESede");
cipher.init(mode, tdes_key);
return cipher.doFinal(data, data_offset, data.length - data_offset);
Throwable e;
e;
Debug.out(e);
return null;
}
protected boolean testCrypto()
{
if (!crypto_tested)
{
crypto_tested = true;
try
{
Cipher.getInstance("DESede");
crypto_available = true;
}
catch (Throwable e)
{
Logger.log(new LogAlert(false, "Unable to initialise cryptographic framework for magnet-based torrent downloads, please re-install Java", e));
}
}
return crypto_available;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -