Search in sources :

Example 11 with TrackerPeerSource

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);
        }
    });
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource) MessageBoxShell(com.biglybt.ui.swt.shells.MessageBoxShell)

Example 12 with TrackerPeerSource

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);
    }
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource)

Example 13 with TrackerPeerSource

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);
}
Also used : TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource)

Example 14 with TrackerPeerSource

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);
    }
}
Also used : TrackerEditorListener(com.biglybt.ui.swt.maketorrent.TrackerEditorListener) TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource) ArrayList(java.util.ArrayList) TableSelectedRowsListener(com.biglybt.ui.swt.views.table.TableSelectedRowsListener) MenuItem(org.eclipse.swt.widgets.MenuItem) MultiTrackerEditor(com.biglybt.ui.swt.maketorrent.MultiTrackerEditor) URL(java.net.URL) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) AERunnable(com.biglybt.core.util.AERunnable) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with TrackerPeerSource

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());
    }
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) TrackerPeerSource(com.biglybt.core.tracker.TrackerPeerSource)

Aggregations

TrackerPeerSource (com.biglybt.core.tracker.TrackerPeerSource)22 URL (java.net.URL)3 TrackerPeerSourceAdapter (com.biglybt.core.tracker.TrackerPeerSourceAdapter)2 TRTrackerScraperResponse (com.biglybt.core.tracker.client.TRTrackerScraperResponse)2 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)1 AERunnable (com.biglybt.core.util.AERunnable)1 PluginInterface (com.biglybt.pif.PluginInterface)1 Download (com.biglybt.pif.download.Download)1 DownloadImpl (com.biglybt.pifimpl.local.download.DownloadImpl)1 DHTPluginContact (com.biglybt.plugin.dht.DHTPluginContact)1 DHTPluginOperationListener (com.biglybt.plugin.dht.DHTPluginOperationListener)1 DHTPluginValue (com.biglybt.plugin.dht.DHTPluginValue)1 ExternalSeedPlugin (com.biglybt.plugin.extseed.ExternalSeedPlugin)1 SelectedContent (com.biglybt.ui.selectedcontent.SelectedContent)1 MultiTrackerEditor (com.biglybt.ui.swt.maketorrent.MultiTrackerEditor)1 TrackerEditorListener (com.biglybt.ui.swt.maketorrent.TrackerEditorListener)1 MessageBoxShell (com.biglybt.ui.swt.shells.MessageBoxShell)1 TableSelectedRowsListener (com.biglybt.ui.swt.views.table.TableSelectedRowsListener)1 InetSocketAddress (java.net.InetSocketAddress)1