use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class TrackerView method removeTrackerPeerSources.
private static void removeTrackerPeerSources(List<TrackerPeerSource> list) {
int numLeft = list.size();
if (numLeft == 0) {
return;
}
TrackerPeerSource toRemove = list.get(0);
if (toRemove == null) {
return;
}
MessageBoxShell mb = new MessageBoxShell(MessageText.getString("message.confirm.delete.title"), MessageText.getString("message.confirm.delete.text", new String[] { toRemove.getName() }), new String[] { MessageText.getString("Button.yes"), MessageText.getString("Button.no") }, 1);
if (numLeft > 1) {
String sDeleteAll = MessageText.getString("v3.deleteContent.applyToAll", new String[] { "" + numLeft });
mb.addCheckBox("!" + sDeleteAll + "!", Parameter.MODE_BEGINNER, false);
}
mb.setRememberOnlyIfButton(0);
mb.setRemember("removeTracker", false, MessageText.getString("MessageBoxWindow.nomoreprompting"));
mb.open(result -> {
if (result == -1) {
// cancel
return;
}
boolean remove = result == 0;
boolean doAll = mb.getCheckBoxEnabled();
if (doAll) {
if (remove) {
for (TrackerPeerSource tps : list) {
if (tps.canDelete()) {
tps.delete();
}
}
}
} else {
if (remove) {
toRemove.delete();
}
// Loop with remaining tags to be removed
list.remove(0);
removeTrackerPeerSources(list);
}
});
}
use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class TrackerView method defaultSelected.
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
TrackerPeerSource source = (TrackerPeerSource) rows[0].getDataSource();
showInAllTrackers(source);
}
}
use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class TrackerView method refreshToolBarItems.
@Override
public void refreshToolBarItems(Map<String, Long> list) {
if (tv == null || !tv.isVisible()) {
return;
}
boolean canEnable = false;
Object[] datasources = tv.getSelectedDataSources().toArray();
for (Object object : datasources) {
if (object instanceof TrackerPeerSource) {
TrackerPeerSource tps = (TrackerPeerSource) object;
if (tps.canDelete()) {
canEnable = true;
break;
}
}
}
list.put("remove", canEnable ? UIToolBarItem.STATE_ENABLED : 0);
}
use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class TrackerView method fillMenu.
@Override
public void fillMenu(String sColumnName, Menu menu) {
if (tv == null) {
return;
}
final Object[] sources = tv.getSelectedDataSources().toArray();
List<TrackerPeerSource> found_trackers = new ArrayList<>();
boolean found_dht_tracker = false;
boolean update_ok = false;
boolean delete_ok = false;
for (Object o : sources) {
TrackerPeerSource ps = (TrackerPeerSource) o;
if (ps.getType() == TrackerPeerSource.TP_TRACKER) {
found_trackers.add(ps);
}
if (ps.getType() == TrackerPeerSource.TP_DHT) {
found_dht_tracker = true;
}
int state = ps.getStatus();
if ((state == TrackerPeerSource.ST_ONLINE || state == TrackerPeerSource.ST_QUEUED || state == TrackerPeerSource.ST_ERROR) && !ps.isUpdating() && ps.canManuallyUpdate()) {
update_ok = true;
}
if (ps.canDelete()) {
delete_ok = true;
}
}
boolean needs_sep = false;
boolean found_tracker = !found_trackers.isEmpty();
if (found_tracker || found_dht_tracker) {
final MenuItem update_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(update_item, "GeneralView.label.trackerurlupdate");
update_item.setEnabled(update_ok);
update_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
@Override
public void run(TableRowCore row) {
for (Object o : sources) {
TrackerPeerSource ps = (TrackerPeerSource) o;
if (ps.canManuallyUpdate()) {
ps.manualUpdate();
}
}
}
});
if (found_tracker) {
final MenuItem edit_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(edit_item, "MyTorrentsView.menu.editTracker");
edit_item.addListener(SWT.Selection, new TableSelectedRowsListener(tv) {
@Override
public boolean run(TableRowCore[] rows) {
final TOTorrent torrent = manager.getTorrent();
if (torrent != null) {
Utils.execSWTThread(new Runnable() {
@Override
public void run() {
List<List<String>> group = TorrentUtils.announceGroupsToList(torrent);
new MultiTrackerEditor(null, null, group, new TrackerEditorListener() {
@Override
public void trackersChanged(String str, String str2, List<List<String>> _group) {
TorrentUtils.listToAnnounceGroups(_group, torrent);
try {
TorrentUtils.writeToFile(torrent);
} catch (Throwable e2) {
Debug.printStackTrace(e2);
}
TRTrackerAnnouncer tc = manager.getTrackerClient();
if (tc != null) {
tc.resetTrackerUrl(true);
}
}
}, true, true);
}
});
}
return (true);
}
});
String tracker_key = null;
if (sources.length == 1) {
URL url = ((TrackerPeerSource) sources[0]).getURL();
if (url != null) {
tracker_key = BuddyPluginUtils.getTrackerChatKey(url.toExternalForm());
}
}
MenuBuildUtils.addChatMenu(menu, "menu.discuss.tracker", tracker_key);
TOTorrent torrent = manager.getTorrent();
edit_item.setEnabled(torrent != null && !TorrentUtils.isReallyPrivate(torrent));
}
if (found_trackers.size() == 1) {
TrackerPeerSource tps = found_trackers.get(0);
if (tps.getURL() != null) {
final MenuItem allt_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(allt_item, "menu.show.in.all.trackers");
allt_item.addListener(SWT.Selection, (ev) -> {
showInAllTrackers(tps);
});
}
}
needs_sep = true;
}
if (delete_ok) {
final MenuItem delete_item = new MenuItem(menu, SWT.PUSH);
Messages.setLanguageText(delete_item, "Button.remove");
Utils.setMenuItemImage(delete_item, "delete");
delete_item.addListener(SWT.Selection, event -> removeTrackerPeerSources(sources));
needs_sep = true;
}
if (needs_sep) {
new MenuItem(menu, SWT.SEPARATOR);
}
}
use of com.biglybt.core.tracker.TrackerPeerSource in project BiglyBT by BiglySoftware.
the class DownloadImpl method getAggregatedScrapeResultSupport.
private DownloadScrapeResult getAggregatedScrapeResultSupport() {
List<TRTrackerScraperResponse> responses = download_manager.getGoodTrackerScrapeResponses();
int best_peers = -1;
int best_seeds = -1;
int best_time = -1;
TRTrackerScraperResponse best_resp = null;
if (responses != null) {
for (TRTrackerScraperResponse response : responses) {
int peers = response.getPeers();
int seeds = response.getSeeds();
if (peers > best_peers || (peers == best_peers && seeds > best_seeds)) {
best_peers = peers;
best_seeds = seeds;
best_resp = response;
}
}
}
if (best_peers == -1) {
try {
TrackerPeerSource our_dht = null;
List<TrackerPeerSource> peer_sources = download_manager.getTrackerPeerSources();
for (TrackerPeerSource ps : peer_sources) {
if (ps.getType() == TrackerPeerSource.TP_DHT) {
our_dht = ps;
break;
}
}
peer_listeners_mon.enter();
if (announce_response_map != null) {
int total_seeds = 0;
int total_peers = 0;
int latest_time = 0;
int num = 0;
if (our_dht != null && our_dht.getStatus() == TrackerPeerSource.ST_ONLINE) {
total_seeds = our_dht.getSeedCount();
total_peers = our_dht.getLeecherCount();
latest_time = our_dht.getLastUpdate();
num = 1;
}
for (int[] entry : announce_response_map.values()) {
num++;
int seeds = entry[0];
int peers = entry[1];
int time = entry[3];
total_seeds += seeds;
total_peers += peers;
if (time > latest_time) {
latest_time = time;
}
}
if (total_peers >= 0) {
best_peers = Math.max(1, total_peers / num);
best_seeds = total_seeds / num;
if (total_seeds > 0 && best_seeds == 0) {
best_seeds = 1;
}
best_time = latest_time;
best_resp = null;
}
}
} finally {
peer_listeners_mon.exit();
}
}
if (best_peers >= 0) {
// System.out.println( download_manager.getDisplayName() + ": " + best_peers + "/" + best_seeds + "/" + best_resp );
last_aggregate_scrape.update(best_resp, best_seeds, best_peers, best_time);
return (last_aggregate_scrape);
} else {
return (getLastScrapeResult());
}
}
Aggregations