use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class TagDownloadWithState method setRateLimit.
private void setRateLimit(DownloadManager manager, boolean added) {
synchronized (rate_lock) {
if (added) {
if (manager.getUserData(rate_lock) == null) {
manager.setUserData(rate_lock, "");
manager.addPeerListener(peer_listener, true);
manager.addRateLimiter(upload_limiter, true);
manager.addRateLimiter(download_limiter, false);
}
} else {
if (manager.getUserData(rate_lock) != null) {
manager.setUserData(rate_lock, null);
manager.removeRateLimiter(upload_limiter, true);
manager.removeRateLimiter(download_limiter, false);
manager.removePeerListener(peer_listener);
PEPeerManager pm = manager.getPeerManager();
if (pm != null) {
List<PEPeer> peers = pm.getPeers();
if (upload_rate_limit < 0 || download_rate_limit < 0) {
for (PEPeer peer : peers) {
if (upload_rate_limit < 0) {
peer.setUploadDisabled(peer_listener, false);
}
if (download_rate_limit < 0) {
peer.setDownloadDisabled(peer_listener, false);
}
}
}
}
}
}
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class AEProxySelectorSWTImpl method updateStatus.
private void updateStatus() {
if (!is_visible) {
return;
}
Image icon;
String tip_key;
Proxy active_proxy = proxy_selector.getActiveProxy();
long now = SystemTime.getMonotonousTime();
if (active_proxy == null) {
icon = icon_grey;
tip_key = "label.inactive";
} else {
long last_con = proxy_selector.getLastConnectionTime();
long last_fail = proxy_selector.getLastFailTime();
long con_ago = now - last_con;
long fail_ago = now - last_fail;
if (last_fail < 0) {
icon = icon_green;
tip_key = "PeerManager.status.ok";
} else {
if (fail_ago > 60 * 1000) {
if (con_ago < fail_ago) {
icon = icon_green;
tip_key = "PeerManager.status.ok";
} else {
icon = icon_grey;
tip_key = "PeersView.state.pending";
}
} else {
icon = icon_yellow;
tip_key = "label.con_prob";
}
}
}
if (flag_incoming) {
boolean bad_incoming = false;
if (now - last_bad_peer_update > 15 * 1000) {
last_bad_peer_update = now;
List<DownloadManager> dms = core.getGlobalManager().getDownloadManagers();
for (DownloadManager dm : dms) {
PEPeerManager pm = dm.getPeerManager();
if (pm != null) {
if (pm.getNbRemoteTCPConnections() + pm.getNbRemoteUDPConnections() + pm.getNbRemoteUTPConnections() > 0) {
List<PEPeer> peers = pm.getPeers();
for (PEPeer peer : peers) {
if (peer.isIncoming()) {
if (!peer.isLANLocal()) {
try {
if (InetAddress.getByAddress(HostNameToIPResolver.hostAddressToBytes(peer.getIp())).isLoopbackAddress()) {
continue;
}
} catch (Throwable e) {
}
bad_incoming = true;
break;
}
}
}
}
}
if (bad_incoming) {
break;
}
}
} else if (last_icon == icon_red) {
bad_incoming = true;
}
if (bad_incoming) {
icon = icon_red;
tip_key = "proxy.socks.bad.incoming";
}
}
if (last_icon != icon) {
final Image f_icon = icon;
final String f_key = tip_key;
Utils.execSWTThread(new AERunnable() {
@Override
public void runSupport() {
last_icon = f_icon;
status.setImage(f_icon);
status.setTooltipText(MessageText.getString("proxy.socks.ui.icon.tip", new String[] { MessageText.getString(f_key) }));
}
});
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class LightWeightSeed method activate.
protected synchronized void activate(String reason_str, byte activation_reason) {
log("Activate: " + activation_reason + "/" + reason_str);
if (activation_state != ACT_NONE) {
return;
}
try {
disk_manager = new LWSDiskManager(this, data_location);
disk_manager.start();
if (disk_manager.getState() != DiskManager.READY) {
log("Start of '" + getString() + "' failed, disk manager failed = " + disk_manager.getErrorMessage());
} else {
peer_manager = PEPeerManagerFactory.create(announcer.getPeerId(), new LWSPeerManagerAdapter(this, peer_manager_registration), disk_manager);
peer_manager.addListener(new PEPeerManagerListenerAdapter() {
@Override
public void peerAdded(final PEPeerManager manager, final PEPeer peer) {
last_activity_time = SystemTime.getMonotonousTime();
}
@Override
public void peerRemoved(PEPeerManager manager, PEPeer peer) {
last_activity_time = SystemTime.getMonotonousTime();
}
});
peer_manager.start();
announcer.update(true);
activation_state = activation_reason;
last_activity_time = SystemTime.getMonotonousTime();
}
} catch (Throwable e) {
log("Activation of '" + getString() + "' failed", e);
} finally {
if (activation_state != ACT_NONE) {
} else {
deactivate();
}
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class PEPieceImpl method checkRequests.
/**
* This will scan each block looking for requested blocks. For each one, it'll verify
* if the PEPeer for it still exists and is still willing and able to upload data.
* If not, it'll unmark the block as requested.
* @return int of how many were cleared (0 to nbBlocks)
*/
/*
public int checkRequests()
{
if (getTimeSinceLastActivity() <30 *1000)
return 0;
int cleared =0;
boolean nullPeer =false;
for (int i =0; i <nbBlocks; i++)
{
if (!downloaded[i] &&!dmPiece.isWritten(i))
{
final String requester =requested[i];
final PEPeerTransport pt;
if (requester !=null)
{
pt =manager.getTransportFromAddress(requester);
if (pt !=null)
{
pt.setSnubbed(true);
if (!pt.isDownloadPossible())
{
clearRequested(i);
cleared++;
}
} else
{
nullPeer =true;
clearRequested(i);
cleared++;
}
}
}
}
if (cleared >0)
{
dmPiece.clearRequested();
if (Logger.isEnabled())
Logger.log(new LogEvent(dmPiece.getManager().getTorrent(), LOGID, LogEvent.LT_WARNING,
"checkRequests(): piece #" +getPieceNumber()+" cleared " +cleared +" requests."
+ (nullPeer ?" Null peer was detected." :"")));
}
return cleared;
}
*/
/*
* Parg: replaced above commented out checking with one that verifies that the
* requests still exist. As piece-picker activity and peer disconnect logic is multi-threaded
* and full of holes, this is a stop-gap measure to prevent a piece from being left with
* requests that no longer exist
*/
public void checkRequests() {
if (getTimeSinceLastActivity() < 30 * 1000) {
return;
}
int cleared = 0;
PEPeerManager manager = piecePicker.getPeerManager();
for (int i = 0; i < nbBlocks; i++) {
if (!downloaded[i] && !dmPiece.isWritten(i)) {
final String requester = requested[i];
if (requester != null) {
if (!manager.requestExists(requester, getPieceNumber(), i * DiskManager.BLOCK_SIZE, getBlockSize(i))) {
clearRequested(i);
cleared++;
}
}
}
}
if (cleared > 0) {
if (Logger.isEnabled())
Logger.log(new LogEvent(dmPiece.getManager().getTorrent(), LOGID, LogEvent.LT_WARNING, "checkRequests(): piece #" + getPieceNumber() + " cleared " + cleared + " requests"));
} else {
if (fully_requested && getNbUnrequested() > 0) {
if (Logger.isEnabled())
Logger.log(new LogEvent(dmPiece.getManager().getTorrent(), LOGID, LogEvent.LT_WARNING, "checkRequests(): piece #" + getPieceNumber() + " reset fully requested"));
fully_requested = false;
}
}
}
use of com.biglybt.core.peer.PEPeerManager in project BiglyBT by BiglySoftware.
the class PluginCoreUtils method convert.
public static Object convert(Object datasource, boolean toCore) {
if (datasource instanceof Object[]) {
Object[] array = (Object[]) datasource;
Object[] newArray = new Object[array.length];
for (int i = 0; i < array.length; i++) {
Object o = array[i];
newArray[i] = convert(o, toCore);
}
return newArray;
}
try {
if (toCore) {
if (datasource instanceof com.biglybt.core.download.DownloadManager) {
return datasource;
}
if (datasource instanceof DownloadImpl) {
return ((DownloadImpl) datasource).getDownload();
}
if (datasource instanceof com.biglybt.core.disk.DiskManager) {
return datasource;
}
if (datasource instanceof DiskManagerImpl) {
return ((DiskManagerImpl) datasource).getDiskmanager();
}
if (datasource instanceof PEPeerManager) {
return datasource;
}
if (datasource instanceof PeerManagerImpl) {
return ((PeerManagerImpl) datasource).getDelegate();
}
if (datasource instanceof PEPeer) {
return datasource;
}
if (datasource instanceof PeerImpl) {
return ((PeerImpl) datasource).getPEPeer();
}
if (datasource instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
return datasource;
}
if (datasource instanceof com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) {
return ((com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) datasource).getCore();
}
if (datasource instanceof TRHostTorrent) {
return datasource;
}
if (datasource instanceof TrackerTorrentImpl) {
((TrackerTorrentImpl) datasource).getHostTorrent();
}
} else {
// to PI
if (datasource instanceof com.biglybt.core.download.DownloadManager) {
return wrap((com.biglybt.core.download.DownloadManager) datasource);
}
if (datasource instanceof DownloadImpl) {
return datasource;
}
if (datasource instanceof com.biglybt.core.disk.DiskManager) {
return wrap((com.biglybt.core.disk.DiskManager) datasource);
}
if (datasource instanceof DiskManagerImpl) {
return datasource;
}
if (datasource instanceof PEPeerManager) {
return wrap((PEPeerManager) datasource);
}
if (datasource instanceof PeerManagerImpl) {
return datasource;
}
if (datasource instanceof PEPeer) {
return PeerManagerImpl.getPeerForPEPeer((PEPeer) datasource);
}
if (datasource instanceof Peer) {
return datasource;
}
if (datasource instanceof com.biglybt.core.disk.DiskManagerFileInfo) {
DiskManagerFileInfo fileInfo = (com.biglybt.core.disk.DiskManagerFileInfo) datasource;
if (fileInfo != null) {
try {
DownloadManager dm = fileInfo.getDownloadManager();
return new com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl(dm == null ? null : DownloadManagerImpl.getDownloadStatic(dm), fileInfo);
} catch (DownloadException e) {
/* Ignore */
}
}
}
if (datasource instanceof com.biglybt.pifimpl.local.disk.DiskManagerFileInfoImpl) {
return datasource;
}
if (datasource instanceof TRHostTorrent) {
TRHostTorrent item = (TRHostTorrent) datasource;
return new TrackerTorrentImpl(item);
}
if (datasource instanceof TrackerTorrentImpl) {
return datasource;
}
}
} catch (Throwable t) {
Debug.out(t);
}
return datasource;
}
Aggregations