use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class ExternalSeedPlugin method removePeer.
protected void removePeer(ExternalSeedPeer peer) {
Download download = peer.getDownload();
try {
download_mon.enter();
List existing_peers = (List) download_map.get(download);
if (existing_peers != null) {
if (existing_peers.remove(peer)) {
log(download.getName() + " removed seed " + peer.getName());
}
}
} finally {
download_mon.exit();
}
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class ExternalSeedReaderImpl method readyToActivate.
protected boolean readyToActivate(PeerManager peer_manager, Peer peer, long time_since_start) {
boolean early_days = time_since_start < INITIAL_DELAY;
try {
Download download = peer_manager.getDownload();
// first respect failure count
int fail_count = getFailureCount();
if (fail_count > 0) {
int delay = reconnect_delay;
for (int i = 1; i < fail_count; i++) {
delay += delay;
if (delay > 30 * 60 * 1000) {
break;
}
}
long now = getSystemTime();
long last_fail = getLastFailTime();
if (last_fail < now && now - last_fail < delay) {
return (false);
}
}
if (ws_valid_until > 0 && getSystemTime() > ws_valid_until) {
return (false);
}
if (download.getState() != Download.ST_DOWNLOADING) {
return (false);
}
if (download.isComplete()) {
return (false);
}
if (!PluginCoreUtils.unwrap(download).getDownloadState().isNetworkEnabled(host_net)) {
return (false);
}
if (PluginCoreUtils.unwrap(torrent).getEffectiveTorrentType() == TOTorrent.TT_V2) {
// don't activate if we are missing any piece hashes (safe hack for the mo)
byte[][] pieces = torrent.getPieces();
for (byte[] piece : pieces) {
if (piece == null) {
return (false);
}
}
}
if (transient_seed) {
// kick any existing peers that are running too slowly if the download appears
// to be stalled
Peer[] existing_peers = peer_manager.getPeers(getIP());
int existing_peer_count = existing_peers.length;
int global_limit = TransferSpeedValidator.getGlobalDownloadRateLimitBytesPerSecond();
if (global_limit > 0) {
// if we have a global limit in force and we are near it then no point in
// activating
int current_down = plugin.getGlobalDownloadRateBytesPerSec();
if (global_limit - current_down < 5 * 1024) {
return (false);
}
}
int download_limit = peer_manager.getDownloadRateLimitBytesPerSecond();
if (global_limit > 0 && global_limit < download_limit) {
download_limit = global_limit;
}
if ((download_limit == 0 || download_limit > STALLED_DOWNLOAD_SPEED + 5 * 1024) && peer_manager.getStats().getDownloadAverage() < STALLED_DOWNLOAD_SPEED) {
for (int i = 0; i < existing_peers.length; i++) {
Peer existing_peer = existing_peers[i];
if (existing_peer instanceof ExternalSeedPeer) {
continue;
}
PeerStats stats = existing_peer.getStats();
if (stats.getTimeSinceConnectionEstablished() > INITIAL_DELAY) {
if (stats.getDownloadAverage() < STALLED_PEER_SPEED) {
existing_peer.close("Replacing slow peer with web-seed", false, false);
existing_peer_count--;
}
}
}
}
if (existing_peer_count == 0) {
if (peer_manager.getPendingPeers(getIP()).length == 0) {
log(getName() + ": activating as transient seed and nothing blocking it");
return (true);
}
}
}
if (!use_avail_to_activate) {
log(getName() + ": activating as availability-based activation disabled");
return (true);
}
if (ws_fast_activate || !early_days) {
if (ws_min_availability > 0) {
float availability = download.getStats().getAvailability();
if (availability < ws_min_availability) {
log(getName() + ": activating as availability is poor (<" + ws_min_availability + ")");
return (true);
}
}
int min_speed = ws_min_download_speed > 0 ? ws_min_download_speed : min_download_speed_default;
if (min_speed > 0) {
if (peer_manager.getStats().getDownloadAverage() < min_speed) {
log(getName() + ": activating as speed is slow (<" + DisplayFormatters.formatByteCountToKiBEtcPerSec(min_speed) + ")");
return (true);
}
}
}
// if we have an announce result and there are no seeds, or it failed then go for it
DownloadAnnounceResult ar = download.getLastAnnounceResult();
if (ar != null) {
if (ar.getResponseType() == DownloadAnnounceResult.RT_ERROR) {
log(getName() + ": activating as tracker unavailable");
return (true);
}
if (ar.getSeedCount() == 0) {
log(getName() + ": activating as no seeds");
return (true);
}
}
} catch (Throwable e) {
Debug.printStackTrace(e);
}
return (false);
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class NetworkAdminSpeedTesterBTImpl method startUp.
protected static void startUp() {
PluginInterface plugin = PluginInitializer.getDefaultInterface();
com.biglybt.pif.download.DownloadManager dm = plugin.getDownloadManager();
Download[] downloads = dm.getDownloads();
if (downloads != null) {
int num = downloads.length;
for (int i = 0; i < num; i++) {
Download download = downloads[i];
if (download.getBooleanAttribute(speedTestAttrib)) {
try {
if (download.getState() != Download.ST_STOPPED) {
try {
download.stop();
} catch (Throwable e) {
Debug.out(e);
}
}
download.remove(true, true);
} catch (Throwable e) {
Debug.out("Had " + e.getMessage() + " while trying to remove " + downloads[i].getName());
}
}
}
}
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class DataSourceUtils method getTorrent.
public static TOTorrent getTorrent(Object ds) {
if (ds instanceof TOTorrent) {
return (TOTorrent) ds;
}
if (ds instanceof DownloadManager) {
TOTorrent torrent = ((DownloadManager) ds).getTorrent();
if (torrent != null) {
return torrent;
}
}
if (ds instanceof ActivitiesEntry) {
TOTorrent torrent = ((ActivitiesEntry) ds).getTorrent();
if (torrent == null) {
// getDM will check hash as well
DownloadManager dm = getDM(ds);
if (dm != null) {
torrent = dm.getTorrent();
}
}
return torrent;
}
if (ds instanceof TranscodeFile) {
TranscodeFile tf = (TranscodeFile) ds;
try {
DiskManagerFileInfo file = tf.getSourceFile();
if (file != null) {
Download download = file.getDownload();
if (download != null) {
Torrent torrent = download.getTorrent();
if (torrent != null) {
return PluginCoreUtils.unwrap(torrent);
}
}
}
} catch (Throwable e) {
}
}
if (ds instanceof TranscodeJob) {
TranscodeJob tj = (TranscodeJob) ds;
try {
DiskManagerFileInfo file = tj.getFile();
if (file != null) {
Download download = tj.getFile().getDownload();
if (download != null) {
Torrent torrent = download.getTorrent();
if (torrent != null) {
return PluginCoreUtils.unwrap(torrent);
}
}
}
} catch (DownloadException e) {
}
}
if (ds instanceof ISelectedContent) {
return ((ISelectedContent) ds).getTorrent();
}
if (ds instanceof String) {
String hash = (String) ds;
try {
GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
DownloadManager dm = gm.getDownloadManager(new HashWrapper(Base32.decode(hash)));
if (dm != null) {
return dm.getTorrent();
}
} catch (Exception e) {
// ignore
}
}
DownloadManager dm = getDM(ds);
if (dm != null) {
return dm.getTorrent();
}
return null;
}
use of com.biglybt.pif.download.Download in project BiglyBT by BiglySoftware.
the class DeviceManagerUI method setupTranscodeMenus.
private void setupTranscodeMenus() {
if (DISABLED_TRANSCODING) {
return;
}
// top level menus
final String[] tables = { TableManager.TABLE_MYTORRENTS_INCOMPLETE, TableManager.TABLE_MYTORRENTS_INCOMPLETE_BIG, TableManager.TABLE_MYTORRENTS_COMPLETE, TableManager.TABLE_MYTORRENTS_COMPLETE_BIG, TableManager.TABLE_TORRENT_FILES, TableManager.TABLE_MYTORRENTS_UNOPENED, TableManager.TABLE_MYTORRENTS_UNOPENED_BIG, TableManager.TABLE_MYTORRENTS_ALL_BIG, TableManager.TABLE_MYTORRENTS_ALL_SMALL };
TableManager table_manager = plugin_interface.getUIManager().getTableManager();
MenuItemFillListener menu_fill_listener = new MenuItemFillListener() {
@Override
public void menuWillBeShown(MenuItem menu, Object _target) {
final TableRow[] target;
if (_target instanceof TableRow) {
target = new TableRow[] { (TableRow) _target };
} else {
target = (TableRow[]) _target;
}
boolean enabled = target.length > 0;
for (TableRow row : target) {
Object obj = row.getDataSource();
if (obj instanceof Download) {
Download download = (Download) obj;
if (download.getState() == Download.ST_ERROR) {
enabled = false;
}
} else if (obj instanceof DiskManagerFileInfo) {
DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
try {
if (file.getIndex() < 0 || file.getDownload().getState() == Download.ST_ERROR) {
enabled = false;
}
} catch (Throwable e) {
enabled = false;
}
}
}
menu.setEnabled(enabled);
menu.removeAllChildItems();
if (enabled) {
Device[] devices = device_manager.getDevices();
int devices_added = 0;
for (Device device : devices) {
if (device.isHidden()) {
continue;
}
if (device instanceof TranscodeTarget) {
devices_added++;
final TranscodeTarget renderer = (TranscodeTarget) device;
TranscodeProfile[] profiles = renderer.getTranscodeProfiles();
TableContextMenuItem device_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem((TableContextMenuItem) menu, "!" + device.getName() + (profiles.length == 0 ? " (No Profiles)" : "") + "!");
device_item.setStyle(MenuItem.STYLE_MENU);
if (profiles.length == 0) {
device_item.setEnabled(false);
} else {
Arrays.sort(profiles, new Comparator<TranscodeProfile>() {
@Override
public int compare(TranscodeProfile o1, TranscodeProfile o2) {
int i1 = o1.getIconIndex();
int i2 = o2.getIconIndex();
if (i1 == i2) {
return o1.getName().compareToIgnoreCase(o2.getName());
} else {
return (i1 - i2);
}
}
});
for (final TranscodeProfile profile : profiles) {
TableContextMenuItem profile_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem(device_item, "!" + profile.getName() + "!");
profile_item.addMultiListener(new MenuItemListener() {
@Override
public void selected(MenuItem menu, Object x) {
for (TableRow row : target) {
Object obj = row.getDataSource();
try {
if (obj instanceof Download) {
Download download = (Download) obj;
addDownload(renderer, profile, -1, download);
} else {
DiskManagerFileInfo file = (DiskManagerFileInfo) obj;
addFile(renderer, profile, -1, file);
}
} catch (Throwable e) {
Debug.out(e);
}
}
}
});
}
}
}
}
if (devices_added == 0) {
TableContextMenuItem device_item = plugin_interface.getUIManager().getTableManager().addContextMenuItem((TableContextMenuItem) menu, "!(No Devices)!");
device_item.setEnabled(false);
}
}
}
};
// instead of forcing a loop like this
for (String table : tables) {
TableContextMenuItem menu = table_manager.addContextMenuItem(table, "devices.contextmenu.xcode");
menu.setStyle(TableContextMenuItem.STYLE_MENU);
menu.setHeaderCategory(MenuItem.HEADER_CONTENT);
menu.addFillListener(menu_fill_listener);
menu.setDisposeWithUIDetach(UIInstance.UIT_SWT);
}
}
Aggregations