📄 downloadmanagerimpl.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: DownloadManagerImpl.java
package org.gudy.azureus2.core3.download.impl;
import com.aelitis.azureus.core.AzureusCoreOperation;
import com.aelitis.azureus.core.AzureusCoreOperationTask;
import com.aelitis.azureus.core.networkmanager.LimitedRateGroup;
import com.aelitis.azureus.core.peermanager.control.PeerControlScheduler;
import com.aelitis.azureus.core.peermanager.control.PeerControlSchedulerFactory;
import com.aelitis.azureus.core.util.CaseSensitiveFileMap;
import com.aelitis.azureus.core.util.CopyOnWriteList;
import java.io.*;
import java.net.URL;
import java.util.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.config.impl.TransferSpeedValidator;
import org.gudy.azureus2.core3.disk.*;
import org.gudy.azureus2.core3.disk.impl.DiskManagerImpl;
import org.gudy.azureus2.core3.download.*;
import org.gudy.azureus2.core3.global.GlobalManager;
import org.gudy.azureus2.core3.global.GlobalManagerStats;
import org.gudy.azureus2.core3.internat.*;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.peer.*;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.tracker.client.*;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.download.DownloadAnnounceResult;
import org.gudy.azureus2.plugins.download.DownloadScrapeResult;
import org.gudy.azureus2.plugins.download.savelocation.SaveLocationChange;
// Referenced classes of package org.gudy.azureus2.core3.download.impl:
// DownloadManagerController, DownloadManagerDefaultPaths, DownloadManagerMoveHandler, DownloadManagerStateImpl,
// DownloadManagerStatsImpl
public class DownloadManagerImpl extends LogRelation
implements DownloadManager
{
protected static class NoStackException extends Exception
{
protected NoStackException(String str)
{
super(str);
}
}
private static final long SCRAPE_DELAY_ERROR_TORRENTS = 0x6ddd00L;
private static final long SCRAPE_DELAY_STOPPED_TORRENTS = 0x36ee80L;
private static final long SCRAPE_INITDELAY_ERROR_TORRENTS = 0x927c0L;
private static final long SCRAPE_INITDELAY_STOPPED_TORRENTS = 0x2bf20L;
private static int upload_when_busy_min_secs;
private static final String CFG_MOVE_COMPLETED_TOP = "Newly Seeding Torrents Get First Priority";
private static final int LDT_STATECHANGED = 1;
private static final int LDT_DOWNLOADCOMPLETE = 2;
private static final int LDT_COMPLETIONCHANGED = 3;
private static final int LDT_POSITIONCHANGED = 4;
private static final int LDT_FILEPRIORITYCHANGED = 5;
private AEMonitor listeners_mon;
private static ListenerManager listeners_aggregator = ListenerManager.createAsyncManager("DM:ListenAggregatorDispatcher", new ListenerManagerDispatcher() {
public void dispatch(Object _listener, int type, Object _value)
{
DownloadManagerListener listener = (DownloadManagerListener)_listener;
Object value[] = (Object[])(Object[])_value;
DownloadManagerImpl dm = (DownloadManagerImpl)value[0];
if (type == 1)
listener.stateChanged(dm, ((Integer)value[1]).intValue());
else
if (type == 2)
listener.downloadComplete(dm);
else
if (type == 3)
listener.completionChanged(dm, ((Boolean)value[1]).booleanValue());
else
if (type == 5)
listener.filePriorityChanged(dm, (DiskManagerFileInfo)value[1]);
else
if (type == 4)
listener.positionChanged(dm, ((Integer)value[1]).intValue(), ((Integer)value[2]).intValue());
}
});
private ListenerManager listeners;
private static final int LDT_TL_ANNOUNCERESULT = 1;
private static final int LDT_TL_SCRAPERESULT = 2;
private ListenerManager tracker_listeners;
private static final int LDT_PE_PEER_ADDED = 1;
private static final int LDT_PE_PEER_REMOVED = 2;
private static final int LDT_PE_PM_ADDED = 5;
private static final int LDT_PE_PM_REMOVED = 6;
private static ListenerManager peer_listeners_aggregator = ListenerManager.createAsyncManager("DM:PeerListenAggregatorDispatcher", new ListenerManagerDispatcher() {
public void dispatch(Object _listener, int type, Object value)
{
DownloadManagerPeerListener listener = (DownloadManagerPeerListener)_listener;
if (type == 1)
listener.peerAdded((PEPeer)value);
else
if (type == 2)
listener.peerRemoved((PEPeer)value);
else
if (type == 5)
listener.peerManagerAdded((PEPeerManager)value);
else
if (type == 6)
listener.peerManagerRemoved((PEPeerManager)value);
}
});
private ListenerManager peer_listeners;
private AEMonitor peer_listeners_mon;
private List current_peers;
private static final int LDT_PE_PIECE_ADDED = 3;
private static final int LDT_PE_PIECE_REMOVED = 4;
private static ListenerManager piece_listeners_aggregator = ListenerManager.createAsyncManager("DM:PieceListenAggregatorDispatcher", new ListenerManagerDispatcher() {
public void dispatch(Object _listener, int type, Object value)
{
DownloadManagerPieceListener listener = (DownloadManagerPieceListener)_listener;
if (type == 3)
listener.pieceAdded((PEPiece)value);
else
if (type == 4)
listener.pieceRemoved((PEPiece)value);
}
});
private ListenerManager piece_listeners;
private AEMonitor piece_listeners_mon;
private List current_pieces;
private DownloadManagerController controller;
private DownloadManagerStatsImpl stats;
protected AEMonitor this_mon;
private boolean persistent;
private boolean assumedComplete;
private int last_informed_state;
private boolean latest_informed_force_start;
private GlobalManager globalManager;
private String torrentFileName;
private boolean open_for_seeding;
private String display_name;
private String internal_name;
private File torrent_save_location;
private int position;
private Object read_torrent_state[];
private DownloadManagerState download_manager_state;
private TOTorrent torrent;
private String torrent_comment;
private String torrent_created_by;
private TRTrackerAnnouncer tracker_client;
private TRTrackerAnnouncerListener tracker_client_listener;
private TRTrackerAnnouncerListener stopping_tracker_client_listener;
private CopyOnWriteList activation_listeners;
private long scrape_random_seed;
private Map data;
private boolean data_already_allocated;
private long creation_time;
private int iSeedingRank;
private boolean az_messaging_enabled;
private boolean dl_identity_obtained;
private byte dl_identity[];
private int dl_identity_hashcode;
private int max_uploads;
private int max_connections;
private int max_connections_when_seeding;
private boolean max_connections_when_seeding_enabled;
private int max_seed_connections;
private int max_uploads_when_seeding;
private boolean max_uploads_when_seeding_enabled;
private int max_upload_when_busy_bps;
private int current_upload_when_busy_bps;
private long last_upload_when_busy_update;
private long last_upload_when_busy_dec_time;
private int crypto_level;
private volatile boolean destroyed;
private File cached_save_location;
private File cached_save_location_result;
public DownloadManagerImpl(GlobalManager _gm, byte _torrent_hash[], String _torrentFileName, String _torrent_save_dir, String _torrent_save_file, int _initialState, boolean _persistent,
boolean _recovered, boolean _open_for_seeding, boolean _has_ever_been_started, List _file_priorities, DownloadManagerInitialisationAdapter _initialisation_adapter)
{
listeners_mon = new AEMonitor("DM:DownloadManager:L");
listeners = ListenerManager.createManager("DM:ListenDispatcher", new ListenerManagerDispatcher() {
final DownloadManagerImpl this$0;
public void dispatch(Object listener, int type, Object value)
{
DownloadManagerImpl.listeners_aggregator.dispatch(listener, type, value);
}
{
this$0 = DownloadManagerImpl.this;
super();
}
});
tracker_listeners = ListenerManager.createManager("DM:TrackerListenDispatcher", new ListenerManagerDispatcher() {
final DownloadManagerImpl this$0;
public void dispatch(Object _listener, int type, Object value)
{
DownloadManagerTrackerListener listener = (DownloadManagerTrackerListener)_listener;
if (type == 1)
listener.announceResult((TRTrackerAnnouncerResponse)value);
else
if (type == 2)
listener.scrapeResult((TRTrackerScraperResponse)value);
}
{
this$0 = DownloadManagerImpl.this;
super();
}
});
peer_listeners = ListenerManager.createManager("DM:PeerListenDispatcher", new ListenerManagerDispatcher() {
final DownloadManagerImpl this$0;
public void dispatch(Object listener, int type, Object value)
{
DownloadManagerImpl.peer_listeners_aggregator.dispatch(listener, type, value);
}
{
this$0 = DownloadManagerImpl.this;
super();
}
});
peer_listeners_mon = new AEMonitor("DM:DownloadManager:PeerL");
current_peers = new ArrayList();
piece_listeners = ListenerManager.createManager("DM:PieceListenDispatcher", new ListenerManagerDispatcher() {
final DownloadManagerImpl this$0;
public void dispatch(Object listener, int type, Object value)
{
DownloadManagerImpl.piece_listeners_aggregator.dispatch(listener, type, value);
}
{
this$0 = DownloadManagerImpl.this;
super();
}
});
piece_listeners_mon = new AEMonitor("DM:DownloadManager:PeiceL");
current_pieces = new ArrayList();
this_mon = new AEMonitor("DM:DownloadManager");
last_informed_state = -1;
display_name = "";
internal_name = "";
position = -1;
tracker_client_listener = new TRTrackerAnnouncerListener() {
final DownloadManagerImpl this$0;
public void receivedTrackerResponse(TRTrackerAnnouncerResponse response)
{
PEPeerManager pm = controller.getPeerManager();
if (pm != null)
pm.processTrackerResponse(response);
tracker_listeners.dispatch(1, response);
}
public void urlChanged(TRTrackerAnnouncer announcer, URL old_url, URL new_url, boolean explicit)
{
if (!explicit)
break MISSING_BLOCK_LABEL_100;
if (!torrent.getPrivate())
break MISSING_BLOCK_LABEL_92;
List peers;
peer_listeners_mon.enter();
peers = new ArrayList(current_peers);
peer_listeners_mon.exit();
break MISSING_BLOCK_LABEL_74;
Exception exception;
exception;
peer_listeners_mon.exit();
throw exception;
(new AEThread(announcer, old_url) {
final List val$peers;
final TRTrackerAnnouncer val$announcer;
final URL val$old_url;
final 9 this$1;
public void runSupport()
{
for (int i = 0; i < peers.size(); i++)
{
PEPeer peer = (PEPeer)peers.get(i);
peer.getManager().removePeer(peer, "Private torrent: tracker changed");
}
try
{
TRTrackerAnnouncer an = TRTrackerAnnouncerFactory.create(torrent, true);
an.cloneFrom(announcer);
an.setTrackerUrl(old_url);
an.stop(false);
an.destroy();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
{
this$1 = 9.this;
peers = list;
announcer = trtrackerannouncer;
old_url = url;
super(x0, x1);
}
}).start();
requestTrackerAnnounce(true);
}
public void urlRefresh()
{
requestTrackerAnnounce(true);
}
{
this$0 = DownloadManagerImpl.this;
super();
}
};
stopping_tracker_client_listener = new TRTrackerAnnouncerListener() {
final DownloadManagerImpl this$0;
public void receivedTrackerResponse(TRTrackerAnnouncerResponse response)
{
if (tracker_client == null)
response.setPeers(new TRTrackerAnnouncerResponsePeer[0]);
tracker_listeners.dispatch(1, response);
}
public void urlChanged(TRTrackerAnnouncer trtrackerannouncer, URL url, URL url1, boolean flag)
{
}
public void urlRefresh()
{
}
{
this$0 = DownloadManagerImpl.this;
super();
}
};
activation_listeners = new CopyOnWriteList();
scrape_random_seed = SystemTime.getCurrentTime();
data_already_allocated = false;
creation_time = SystemTime.getCurrentTime();
az_messaging_enabled = true;
max_uploads = 2;
max_uploads_when_seeding = 2;
crypto_level = 0;
if (_initialState != 0 && _initialState != 70 && _initialState != 75)
Debug.out((new StringBuilder()).append("DownloadManagerImpl: Illegal start state, ").append(_initialState).toString());
persistent = _persistent;
globalManager = _gm;
open_for_seeding = _open_for_seeding;
if (_file_priorities != null)
setData("file_priorities", _file_priorities);
stats = new DownloadManagerStatsImpl(this);
controller = new DownloadManagerController(this);
torrentFileName = _torrentFileName;
for (; _torrent_save_dir.endsWith(File.separator); _torrent_save_dir = _torrent_save_dir.substring(0, _torrent_save_dir.length() - 1));
readTorrent(_torrent_save_dir, _torrent_save_file, _torrent_hash, persistent && !_recovered, _open_for_seeding, _has_ever_been_started, _initialState);
if (torrent != null && _initialisation_adapter != null)
try
{
_initialisation_adapter.initialised(this);
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
}
private void readTorrent(String torrent_save_dir, String torrent_save_file, byte torrent_hash[], boolean new_torrent, boolean for_seeding, boolean has_ever_been_started, int initial_state)
{
display_name = torrentFileName;
internal_name = "";
torrent_comment = "";
torrent_created_by = "";
download_manager_state = DownloadManagerStateImpl.getDownloadState(this, torrentFileName, torrent_hash, initial_state == 70 || initial_state == 75);
readParameters();
DownloadManagerStateAttributeListener attr_listener = new DownloadManagerStateAttributeListener() {
final DownloadManagerImpl this$0;
public void attributeEventOccurred(DownloadManager dm, String attribute_name, int event_type)
{
if (attribute_name.equals("filelinks"))
setFileLinks();
else
if (attribute_name.equals("parameters"))
readParameters();
}
{
this$0 = DownloadManagerImpl.this;
super();
}
};
download_manager_state.addListener(attr_listener, "filelinks", 1);
download_manager_state.addListener(attr_listener, "parameters", 1);
torrent = download_manager_state.getTorrent();
setFileLinks();
if (!dl_identity_obtained)
{
dl_identity = torrent_hash != null ? torrent_hash : torrent.getHash();
dl_identity_hashcode = (new String(dl_identity)).hashCode();
}
if (!Arrays.equals(dl_identity, torrent.getHash()))
{
torrent = null;
torrent_save_location = new File(torrent_save_dir, torrentFileName);
throw new NoStackException("Download identity changed - please remove and re-add the download");
}
read_torrent_state = null;
LocaleUtilDecoder locale_decoder = LocaleTorrentUtil.getTorrentEncoding(torrent);
display_name = FileUtil.convertOSSpecificChars(locale_decoder.decodeString(torrent.getName()), false);
internal_name = ByteFormatter.nicePrint(torrent.getHash(), true);
File save_dir_file = new File(torrent_save_dir);
if (torrent_save_file == null)
{
try
{
if (save_dir_file.exists())
save_dir_file = save_dir_file.getCanonicalFile();
}
catch (Throwable e)
{
Debug.printStackTrace(e);
}
if (torrent.isSimpleTorrent())
{
if (save_dir_file.exists())
{
if (save_dir_file.isDirectory())
{
torrent_save_file = display_name;
} else
{
torrent_save_dir = save_dir_file.getParent().toString();
torrent_save_file = save_dir_file.getName();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -