📄 trtrackerbtannouncerimpl.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: TRTrackerBTAnnouncerImpl.java
package org.gudy.azureus2.core3.tracker.client.impl.bt;
import com.aelitis.azureus.core.dht.netcoords.DHTNetworkPositionManager;
import com.aelitis.azureus.core.networkmanager.admin.NetworkAdmin;
import com.aelitis.azureus.core.networkmanager.admin.NetworkAdminASN;
import com.aelitis.azureus.core.networkmanager.impl.udp.UDPNetworkManager;
import com.aelitis.azureus.core.peermanager.utils.PeerClassifier;
import com.aelitis.net.udp.uc.*;
import java.io.*;
import java.net.*;
import java.util.*;
import java.util.zip.GZIPInputStream;
import javax.net.ssl.*;
import org.gudy.azureus2.core3.config.COConfigurationManager;
import org.gudy.azureus2.core3.config.ParameterListener;
import org.gudy.azureus2.core3.internat.MessageText;
import org.gudy.azureus2.core3.logging.*;
import org.gudy.azureus2.core3.security.SESecurityManager;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.tracker.client.*;
import org.gudy.azureus2.core3.tracker.client.impl.*;
import org.gudy.azureus2.core3.tracker.protocol.PRHelpers;
import org.gudy.azureus2.core3.tracker.protocol.udp.*;
import org.gudy.azureus2.core3.tracker.util.TRTrackerUtils;
import org.gudy.azureus2.core3.util.*;
import org.gudy.azureus2.plugins.clientid.ClientIDException;
import org.gudy.azureus2.plugins.download.DownloadAnnounceResult;
import org.gudy.azureus2.plugins.download.DownloadAnnounceResultPeer;
import org.gudy.azureus2.pluginsimpl.local.clientid.ClientIDManagerImpl;
public class TRTrackerBTAnnouncerImpl extends TRTrackerAnnouncerImpl
{
private static final int OVERRIDE_PERIOD = 10000;
protected static Timer tracker_timer = new Timer("Tracker Timer", 32);
public static String UDP_REALM = "UDP Tracker";
private static AEMonitor class_mon = new AEMonitor("TRTrackerBTAnnouncer:class");
private static Map tracker_report_map = new HashMap();
private TOTorrent torrent;
private TimerEvent current_timer_event;
private TimerEventPerformer timer_event_action;
protected int tracker_state;
private String tracker_status_str;
private TRTrackerAnnouncerResponseImpl last_response;
private long last_update_time_secs;
private long current_time_to_wait_secs;
private boolean manual_control;
private long min_interval;
private static int userMinInterval = 0;
private static int userMaxNumwant = 100;
private static boolean udpAnnounceEnabled = true;
private int failure_added_time;
private long failure_time_last_updated;
private boolean stopped;
private boolean stopped_for_queue;
private boolean completed;
private boolean complete_reported;
private boolean update_in_progress;
private long rd_last_override;
private int rd_override_percentage;
private long min_interval_override;
private List trackerUrlLists;
private URL lastUsedUrl;
private URL lastAZTrackerCheckedURL;
private HashWrapper torrent_hash;
private String last_tracker_message;
private String info_hash;
private byte tracker_peer_id[];
private String tracker_peer_id_str;
private byte data_peer_id[];
private String key_id;
private static final int key_id_length = 8;
private int key_udp;
private int announceCount;
private int announceFailCount;
private byte autoUDPprobeEvery;
private String tracker_id;
private String ip_override;
private String peer_networks[];
private TRTrackerAnnouncerDataProvider announce_data_provider;
protected AEMonitor this_mon;
private boolean az_tracker;
private boolean destroyed;
static final String chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
public static String createKeyID()
{
String key_id = "";
for (int i = 0; i < 8; i++)
{
int pos = (int)(Math.random() * (double)"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".length());
key_id = (new StringBuilder()).append(key_id).append("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789".charAt(pos)).toString();
}
return key_id;
}
public TRTrackerBTAnnouncerImpl(TOTorrent _torrent, String _peer_networks[], boolean _manual)
throws TRTrackerAnnouncerException
{
UnsupportedEncodingException e;
super(_torrent);
tracker_state = 1;
tracker_status_str = "";
last_response = null;
min_interval = 0L;
failure_added_time = 0;
failure_time_last_updated = 0L;
complete_reported = false;
update_in_progress = false;
rd_last_override = 0L;
rd_override_percentage = 100;
min_interval_override = 0L;
info_hash = "info_hash=";
tracker_peer_id_str = "&peer_id=";
key_id = "";
autoUDPprobeEvery = 1;
tracker_id = "";
this_mon = new AEMonitor("TRTrackerBTAnnouncer");
torrent = _torrent;
peer_networks = _peer_networks;
manual_control = _manual;
constructTrackerUrlLists(true);
try
{
tracker_peer_id = ClientIDManagerImpl.getSingleton().generatePeerID(torrent, true);
if (COConfigurationManager.getBooleanParameter("Tracker Separate Peer IDs"))
data_peer_id = ClientIDManagerImpl.getSingleton().generatePeerID(torrent, false);
else
data_peer_id = tracker_peer_id;
}
// Misplaced declaration of an exception variable
catch (UnsupportedEncodingException e)
{
throw new TRTrackerAnnouncerException("TRTrackerAnnouncer: Peer ID generation fails", e);
}
key_id = createKeyID();
key_udp = (int)(Math.random() * 4294967295D);
torrent_hash = _torrent.getHashWrapper();
new StringBuilder();
this;
JVM INSTR dup_x1 ;
info_hash;
append();
URLEncoder.encode(new String(torrent_hash.getBytes(), "ISO-8859-1"), "ISO-8859-1").replaceAll("\\+", "%20");
append();
toString();
info_hash;
new StringBuilder();
this;
JVM INSTR dup_x1 ;
tracker_peer_id_str;
append();
URLEncoder.encode(new String(tracker_peer_id, "ISO-8859-1"), "ISO-8859-1").replaceAll("\\+", "%20");
append();
toString();
tracker_peer_id_str;
break MISSING_BLOCK_LABEL_389;
e;
Logger.log(new LogEvent(torrent, LOGID, "URL encode fails", e));
throw new TRTrackerAnnouncerException("TRTrackerAnnouncer: URL encode fails");
e;
Logger.log(new LogEvent(torrent, LOGID, "Torrent hash retrieval fails", e));
throw new TRTrackerAnnouncerException("TRTrackerAnnouncer: URL encode fails");
timer_event_action = new TimerEventPerformer() {
final TRTrackerBTAnnouncerImpl this$0;
public void perform(TimerEvent this_event)
{
long secs_to_wait;
if (manual_control)
{
requestUpdateSupport();
return;
}
secs_to_wait = getErrorRetryInterval();
secs_to_wait = requestUpdateSupport();
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, TRTrackerAnnouncerImpl.LOGID, (new StringBuilder()).append("Next tracker announce (unadjusted) will be in ").append(secs_to_wait).append("s").toString()));
break MISSING_BLOCK_LABEL_342;
local;
current_time_to_wait_secs = secs_to_wait;
if (tracker_state == 4)
break MISSING_BLOCK_LABEL_340;
long target_time;
this_mon.enter();
if (this_event.isCancelled())
break MISSING_BLOCK_LABEL_312;
secs_to_wait = getAdjustedSecsToWait();
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, TRTrackerAnnouncerImpl.LOGID, (new StringBuilder()).append("Next tracker announce (adjusted) will be in ").append(secs_to_wait).append("s").toString()));
target_time = SystemTime.getCurrentTime() + secs_to_wait * 1000L;
if (current_timer_event == null || current_timer_event.isCancelled())
break MISSING_BLOCK_LABEL_285;
if (current_timer_event != this_event && current_timer_event.getWhen() < target_time)
{
this_mon.exit();
return;
}
current_timer_event.cancel();
if (!destroyed)
current_timer_event = TRTrackerBTAnnouncerImpl.tracker_timer.addEvent(target_time, this);
this_mon.exit();
break MISSING_BLOCK_LABEL_340;
Exception exception1;
exception1;
this_mon.exit();
throw exception1;
JVM INSTR ret 5;
}
{
this$0 = TRTrackerBTAnnouncerImpl.this;
super();
}
};
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, (new StringBuilder()).append("Tracker Announcer Created using url : ").append(trackerURLListToString()).toString()));
return;
}
public void cloneFrom(TRTrackerAnnouncer _other)
{
if (_other instanceof TRTrackerBTAnnouncerImpl)
{
TRTrackerBTAnnouncerImpl other = (TRTrackerBTAnnouncerImpl)_other;
data_peer_id = other.data_peer_id;
tracker_peer_id = other.tracker_peer_id;
tracker_peer_id_str = other.tracker_peer_id_str;
tracker_id = other.tracker_id;
key_id = other.key_id;
key_udp = other.key_udp;
announce_data_provider = other.announce_data_provider;
} else
{
Debug.out("Incompatible type");
}
}
protected long getAdjustedSecsToWait()
{
long secs_to_wait = current_time_to_wait_secs;
if (last_response != null && last_response.getStatus() != 2)
{
if (last_response.getStatus() == 1)
{
if (failure_added_time < 900)
failure_added_time = 900;
secs_to_wait = getErrorRetryInterval();
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, "MIN INTERVAL CALC: tracker reported error, adjusting to error retry interval"));
} else
{
secs_to_wait = getErrorRetryInterval();
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, "MIN INTERVAL CALC: tracker seems to be offline, adjusting to error retry interval"));
}
} else
{
if (rd_override_percentage == 0)
{
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, "MIN INTERVAL CALC: override, perc = 0"));
return 60L;
}
if (rd_override_percentage != 100)
{
secs_to_wait = (secs_to_wait * (long)rd_override_percentage) / 100L;
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, (new StringBuilder()).append("MIN INTERVAL CALC: override, perc = ").append(rd_override_percentage).toString()));
}
if (secs_to_wait < 60L)
secs_to_wait = 60L;
if (min_interval != 0L && secs_to_wait < min_interval)
{
float percentage = (float)min_interval / (float)current_time_to_wait_secs;
int added_secs = (int)((float)(min_interval - secs_to_wait) * percentage);
secs_to_wait += added_secs;
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, (new StringBuilder()).append("MIN INTERVAL CALC: min_interval=").append(min_interval).append(", interval=").append(current_time_to_wait_secs).append(", orig=").append(current_time_to_wait_secs).append(", new=").append(secs_to_wait).append(", added=").append(added_secs).append(", perc=").append(percentage).toString()));
}
}
return secs_to_wait;
}
public int getStatus()
{
return tracker_state;
}
public String getStatusString()
{
return tracker_status_str;
}
public void setRefreshDelayOverrides(int percentage)
{
long now;
if (percentage > 100)
percentage = 100;
else
if (percentage < 0)
percentage = 0;
now = SystemTime.getCurrentTime();
boolean override_allowed = rd_last_override > 0L && now - rd_last_override > 10000L;
if (now < rd_last_override)
override_allowed = true;
if (!override_allowed || rd_override_percentage == percentage)
break MISSING_BLOCK_LABEL_265;
this_mon.enter();
rd_last_override = now;
rd_override_percentage = percentage;
if (current_timer_event != null && !current_timer_event.isCancelled())
{
long start = current_timer_event.getCreatedTime();
long expiry = current_timer_event.getWhen();
long secs_to_wait = getAdjustedSecsToWait();
long target_time = start + secs_to_wait * 1000L;
if (target_time != expiry)
{
current_timer_event.cancel();
if (!destroyed)
{
if (Logger.isEnabled())
Logger.log(new LogEvent(torrent, LOGID, (new StringBuilder()).append("Changed next tracker announce to ").append(secs_to_wait).append("s via ").append(Debug.getStackTrace(true, false, 0, 3)).toString()));
current_timer_event = tracker_timer.addEvent(start, target_time, timer_event_action);
}
}
}
this_mon.exit();
break MISSING_BLOCK_LABEL_265;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public int getTimeUntilNextUpdate()
{
int i;
this_mon.enter();
if (current_timer_event != null)
break MISSING_BLOCK_LABEL_28;
i = getErrorRetryInterval();
this_mon.exit();
return i;
int j;
int rem = (int)((current_timer_event.getWhen() - SystemTime.getCurrentTime()) / 1000L);
j = rem;
this_mon.exit();
return j;
Exception exception;
exception;
this_mon.exit();
throw exception;
}
public int getLastUpdateTime()
{
return (int)last_update_time_secs;
}
public void update(boolean force)
{
long now = SystemTime.getCurrentTime() / 1000L;
if (now < last_update_time_secs)
force = true;
long effective_min = min_interval_override <= 0L ? 60L : min_interval_override;
if (manual_control || force || now - last_update_time_secs >= effective_min)
requestUpdate();
}
public void complete(boolean already_reported)
{
complete_reported = complete_reported || already_reported;
completed = true;
requestUpdate();
}
public void stop(boolean for_queue)
{
stopped = true;
stopped_for_queue = for_queue;
requestUpdate();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -