📄 downloadmanagercontroller.java
字号:
}
});
}
protected void initializeDiskManagerSupport(int initialising_state, DiskManagerListener listener)
{
this_mon.enter();
int entry_state = getState();
if (entry_state == 0 || entry_state == 70 || entry_state == 75 || entry_state == 100)
break MISSING_BLOCK_LABEL_94;
Debug.out((new StringBuilder()).append("DownloadManagerController::initializeDiskManager: Illegal initialize state, ").append(entry_state).toString());
setFailed((new StringBuilder()).append("Inconsistent download state: initSupport, state = ").append(entry_state).toString());
this_mon.exit();
download_manager.informStateChanged();
return;
DiskManager old_dm = getDiskManager();
if (old_dm != null)
{
Debug.out("DownloadManagerController::initializeDiskManager: disk manager is not null");
old_dm.stop(false);
setDiskManager(null, null);
}
errorDetail = "";
setState(initialising_state, false);
DiskManager dm = DiskManagerFactory.create(download_manager.getTorrent(), download_manager);
setDiskManager(dm, listener);
this_mon.exit();
download_manager.informStateChanged();
break MISSING_BLOCK_LABEL_195;
Exception exception;
exception;
this_mon.exit();
download_manager.informStateChanged();
throw exception;
}
public boolean canForceRecheck()
{
int state = getState();
return state == 70 || state == 75 || state == 100 && getDiskManager() == null;
}
public void forceRecheck(ForceRecheckListener l)
{
this_mon.enter();
if (getDiskManager() == null && canForceRecheck())
break MISSING_BLOCK_LABEL_34;
Debug.out("DownloadManagerController::forceRecheck: illegal entry state");
this_mon.exit();
return;
int start_state = getState();
download_manager.getDownloadState().clearResumeData();
boolean wasForceStarted = force_start;
force_start = true;
download_manager.setDataAlreadyAllocated(false);
initializeDiskManagerSupport(30, new forceRecheckDiskManagerListener(wasForceStarted, start_state, l));
this_mon.exit();
break MISSING_BLOCK_LABEL_108;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public void setPieceCheckingEnabled(boolean enabled)
{
piece_checking_enabled = enabled;
DiskManager dm = getDiskManager();
if (dm != null)
dm.setPieceCheckingEnabled(enabled);
}
public void stopIt(int _stateAfterStopping, boolean remove_torrent, boolean remove_data)
{
boolean closing;
int stateAfterStopping;
long current_up = stats.getDataSendRate();
if (current_up != 0L)
data_send_rate_at_close = current_up;
closing = _stateAfterStopping == 71;
if (closing)
_stateAfterStopping = 70;
stateAfterStopping = _stateAfterStopping;
int state;
this_mon.enter();
state = getState();
if (state != 70 && (state != 100 || getDiskManager() != null))
break MISSING_BLOCK_LABEL_123;
if (remove_data)
download_manager.deleteDataFiles();
if (remove_torrent)
download_manager.deleteTorrentFile();
setState(_stateAfterStopping, false);
this_mon.exit();
download_manager.informStateChanged();
return;
if (state == 65)
{
this_mon.exit();
download_manager.informStateChanged();
return;
}
final AESemaphore nd_sem;
setSubState(_stateAfterStopping);
setState(65, false);
nd_sem = new AESemaphore("DM:DownloadManager.NDTR");
NonDaemonTaskRunner.runAsync(new NonDaemonTask() {
final AESemaphore val$nd_sem;
final DownloadManagerController this$0;
public Object run()
{
nd_sem.reserve();
return null;
}
public String getName()
{
return (new StringBuilder()).append("Stopping '").append(getDisplayName()).append("'").toString();
}
{
this$0 = DownloadManagerController.this;
nd_sem = aesemaphore;
super();
}
});
if (peer_manager != null)
{
peer_manager.stopAll();
stats.saveSessionTotals();
}
download_manager.informStopped(peer_manager, stateAfterStopping == 75);
peer_manager = null;
DiskManager dm = getDiskManager();
if (dm != null)
{
dm.stop(closing);
stats.setCompleted(stats.getCompleted());
stats.setDownloadCompleted(stats.getDownloadCompleted(true));
if (!download_manager.getAssumedComplete())
download_manager.getDownloadState().save();
setDiskManager(null, null);
}
force_start = false;
if (remove_data)
download_manager.deleteDataFiles();
if (remove_torrent)
download_manager.deleteTorrentFile();
if (getState() == 65)
setState(stateAfterStopping, true);
break MISSING_BLOCK_LABEL_404;
Exception exception;
exception;
force_start = false;
if (remove_data)
download_manager.deleteDataFiles();
if (remove_torrent)
download_manager.deleteTorrentFile();
if (getState() == 65)
setState(stateAfterStopping, true);
throw exception;
nd_sem.release();
break MISSING_BLOCK_LABEL_422;
Exception exception1;
exception1;
nd_sem.release();
throw exception1;
this_mon.exit();
download_manager.informStateChanged();
break MISSING_BLOCK_LABEL_482;
Throwable e;
e;
Debug.printStackTrace(e);
this_mon.exit();
download_manager.informStateChanged();
break MISSING_BLOCK_LABEL_482;
Exception exception2;
exception2;
this_mon.exit();
download_manager.informStateChanged();
throw exception2;
}
protected void setStateWaiting()
{
setState(0, true);
}
public void setStateFinishing()
{
setState(55, true);
}
public void setStateDownloading()
{
if (getState() == 60)
setState(50, true);
else
if (getState() != 50)
Logger.log(new LogEvent(this, LogIDs.CORE, 1, "Trying to set state to downloading when state is not seeding"));
}
public void setStateSeeding(boolean never_downloaded)
{
setStateFinishing();
download_manager.downloadEnded(never_downloaded);
setState(60, true);
}
public boolean isStateSeeding()
{
return getState() == 60;
}
protected void setStateQueued()
{
setState(75, true);
}
public int getState()
{
if (state_set_by_method != 10)
return state_set_by_method;
DiskManager dm = getDiskManager();
if (dm == null)
return 10;
int diskManagerState = dm.getState();
if (diskManagerState == 1)
return 10;
if (diskManagerState == 2)
return 20;
if (diskManagerState == 3)
return 30;
if (diskManagerState == 4)
return 40;
return diskManagerState != 10 ? 100 : 100;
}
protected int getSubState()
{
if (state_set_by_method == 65)
return substate;
else
return getState();
}
private void setSubState(int ss)
{
substate = ss;
}
private void setState(int _state, boolean _inform_changed)
{
boolean call_filesExist = false;
state_mon.enter();
int old_state = state_set_by_method;
if (old_state != _state)
{
state_set_by_method = _state;
if (state_set_by_method != 75)
{
activation_bloom = null;
if (state_set_by_method == 70)
activation_count = 0;
}
if (state_set_by_method != 75 && state_set_by_method == 100)
{
TOTorrent torrent = download_manager.getTorrent();
if (torrent != null && !torrent.isSimpleTorrent())
{
File save_dir_file = download_manager.getAbsoluteSaveLocation();
if (save_dir_file != null && save_dir_file.exists() && save_dir_file.isDirectory())
TorrentUtils.recursiveEmptyDirDelete(save_dir_file, false);
}
}
}
state_mon.exit();
break MISSING_BLOCK_LABEL_157;
Exception exception;
exception;
state_mon.exit();
throw exception;
if (call_filesExist)
filesExist(true);
if (_inform_changed)
download_manager.informStateChanged();
return;
}
public void restartDownload(boolean forceRecheck)
{
boolean was_force_start = isForceStart();
stopIt(70, false, false);
if (forceRecheck)
download_manager.getDownloadState().clearResumeData();
download_manager.initialize();
if (was_force_start)
setForceStart(true);
}
protected void destroy()
{
if (peer_manager_registration != null)
{
peer_manager_registration.unregister();
peer_manager_registration = null;
}
fileFacadeSet.destroyFileInfo();
}
public boolean isPeerSourceEnabled(String peer_source)
{
return download_manager.getDownloadState().isPeerSourceEnabled(peer_source);
}
public byte[][] getSecrets()
{
TOTorrent torrent = download_manager.getTorrent();
byte secret1[] = torrent.getHash();
byte secret2[] = getSecret2(torrent);
return (new byte[][] {
secret1, secret2
});
Throwable e;
e;
Debug.printStackTrace(e);
return (new byte[][] {
secret1
});
Throwable e;
e;
Debug.printStackTrace(e);
return new byte[0][];
}
public byte[][] getSecrets(int crypto_level)
{
TOTorrent torrent = download_manager.getTorrent();
byte secret[];
if (crypto_level == 1)
secret = torrent.getHash();
else
secret = getSecret2(torrent);
return (new byte[][] {
secret
});
Throwable e;
e;
Debug.printStackTrace(e);
return new byte[0][];
}
protected byte[] getSecret2(TOTorrent torrent)
throws TOTorrentException
{
Map secrets_map = download_manager.getDownloadState().getMapAttribute("secrets");
if (secrets_map == null)
secrets_map = new HashMap();
else
secrets_map = new LightHashMap(secrets_map);
if (secrets_map.size() == 0)
{
secrets_map.put("p1", torrent.getPieces()[0]);
download_manager.getDownloadState().setMapAttribute("secrets", secrets_map);
}
return (byte[])(byte[])secrets_map.get("p1");
}
public boolean manualRoute(NetworkConnection connection)
{
return false;
}
public long getRandomSeed()
{
return download_manager.getDownloadState().getLongParameter("rand");
}
public void addRateLimiter(LimitedRateGroup group, boolean upload)
{
PEPeerManager pm;
this_mon.enter();
ArrayList new_limiters = new ArrayList(external_rate_limiters_cow != null ? external_rate_limiters_cow.size() + 1 : 1);
if (external_rate_limiters_cow != null)
new_limiters.addAll(external_rate_limiters_cow);
new_limiters.add(((Object) (new Object[] {
group, new Boolean(upload)
})));
external_rate_limiters_cow = new_limiters;
pm = peer_manager;
this_mon.exit();
break MISSING_BLOCK_LABEL_113;
Exception exception;
exception;
this_mon.exit();
throw exception;
if (pm != null)
pm.addRateLimiter(group, upload);
return;
}
public void removeRateLimiter(LimitedRateGroup group, boolean upload)
{
PEPeerManager pm;
this_mon.enter();
if (external_rate_limiters_cow != null)
{
ArrayList new_limiters = new ArrayList(external_rate_limiters_cow.size() - 1);
for (int i = 0; i < external_rate_limiters_cow.size(); i++)
{
Object entry[] = (Object[])(Object[])external_rate_limiters_cow.get(i);
if (entry[0] != group)
new_limiters.add(((Object) (entry)));
}
if (new_limiters.size() == 0)
external_rate_limiters_cow = null;
else
external_rate_limiters_cow = new_limiters;
}
pm = peer_manager;
this_mon.exit();
break MISSING_BLOCK_LABEL_141;
Exception exception;
exception;
this_mon.exit();
throw exception;
if (pm != null)
pm.removeRateLimiter(group, upload);
return;
}
public void enqueueReadRequest(PEPeer peer, DiskManagerReadRequest request, DiskManagerReadRequestListener listener)
{
getDiskManager().enqueueReadRequest(request, listener);
}
public boolean activateRequest(InetSocketAddress address)
{
if (getState() == 75)
{
BloomFilter bloom = activation_bloom;
if (bloom == null)
activation_bloom = bloom = BloomFilterFactory.createAddRemove4Bit(64);
byte address_bytes[] = address.getAddress().getAddress();
int hit_count = bloom.add(address_bytes);
if (hit_count > 5)
{
Logger.log(new LogEvent(this, LogIDs.CORE, 1, (new StringBuilder()).append("Activate request for ").append(getDisplayName()).append(" from ").append(address).append(" denied as too many recently received").toString()));
return false;
}
Logger.log(new LogEvent(this, LogIDs.CORE, (new StringBuilder()).append("Activate request for ").append(getDisplayName()).append(" from ").append(address).toString()));
long now = SystemTime.getCurrentTime();
if (now < activation_bloom_create_time || now - activation_bloom_create_time > 0x927c0L)
{
activation_bloom = BloomFilterFactory.createAddRemove4Bit(64);
activation_bloom_create_time = now;
}
activation_count = bloom.getEntryCount();
activation_count_time = now;
return download_manager.activateRequest(activation_count);
} else
{
return false;
}
}
public void deactivateRequest(InetSocketAddress address)
{
BloomFilter bloom = activation_bloom;
if (bloom != null)
{
byte address_bytes[] = address.getAddress().getAddress();
int count = bloom.count(address_bytes);
for (int i = 0; i < count; i++)
bloom.remove(address_bytes);
activation_count = bloom.getEntryCount();
}
}
public int getActivationCount()
{
long now = SystemTime.getCurrentTime();
if (now < activation_count_time)
activation_count_time = now;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -