Search in sources :

Example 6 with TRTrackerScraperResponse

use of com.biglybt.core.tracker.client.TRTrackerScraperResponse in project BiglyBT by BiglySoftware.

the class ScrapeInfoView method setTracker.

private void setTracker() {
    if (cScrapeInfoView == null || cScrapeInfoView.isDisposed()) {
        return;
    }
    Display display = cScrapeInfoView.getDisplay();
    String status = manager.getTrackerStatus();
    int time = manager.getTrackerTime();
    TRTrackerAnnouncer trackerClient = manager.getTrackerClient();
    if (trackerClient != null) {
        tracker_status.setText(trackerClient.getStatusString());
        time = trackerClient.getTimeUntilNextUpdate();
    } else {
        tracker_status.setText(status);
    }
    if (time < 0) {
        trackerUpdateIn.setText(MessageText.getString("GeneralView.label.updatein.querying"));
    } else {
        trackerUpdateIn.setText(TimeFormatter.formatColon(time));
    }
    boolean update_state;
    String trackerURL = null;
    if (trackerClient != null) {
        URL temp = trackerClient.getTrackerURL();
        if (temp != null) {
            trackerURL = temp.toString();
        }
    }
    if (trackerURL == null) {
        TOTorrent torrent = manager.getTorrent();
        if (torrent != null) {
            trackerURL = torrent.getAnnounceURL().toString();
        }
    }
    if (trackerURL != null) {
        trackerUrlValue.setText(trackerURL);
        if ((trackerURL.startsWith("http://") || trackerURL.startsWith("https://"))) {
            trackerUrlValue.setForeground(Colors.blue);
            trackerUrlValue.setCursor(display.getSystemCursor(SWT.CURSOR_HAND));
            Messages.setLanguageText(trackerUrlValue.getWidget(), "GeneralView.label.trackerurlopen.tooltip", true);
        } else {
            trackerUrlValue.setForeground(null);
            trackerUrlValue.setCursor(null);
            Messages.setLanguageText(trackerUrlValue.getWidget(), null);
            trackerUrlValue.setToolTipText(null);
        }
    }
    if (trackerClient != null) {
        update_state = ((SystemTime.getCurrentTime() / 1000 - trackerClient.getLastUpdateTime() >= TRTrackerAnnouncer.REFRESH_MINIMUM_SECS));
    } else {
        TRTrackerScraperResponse sr = manager.getTrackerScrapeResponse();
        if (sr == null) {
            update_state = true;
        } else {
            update_state = ((SystemTime.getCurrentTime() - sr.getScrapeStartTime() >= TRTrackerScraper.REFRESH_MINIMUM_SECS * 1000));
        }
    }
    if (updateButton.getEnabled() != update_state) {
        updateButton.setEnabled(update_state);
    }
    cScrapeInfoView.layout();
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) URL(java.net.URL)

Example 7 with TRTrackerScraperResponse

use of com.biglybt.core.tracker.client.TRTrackerScraperResponse in project BiglyBT by BiglySoftware.

the class TorrentInfoView method initialize.

private void initialize(Composite composite) {
    this.parent = composite;
    if (download_manager == null) {
        return;
    }
    // I don't want to waste my time :) [tux]
    if (sc != null && !sc.isDisposed()) {
        sc.dispose();
    }
    sc = new ScrolledComposite(composite, SWT.V_SCROLL | SWT.H_SCROLL);
    sc.getVerticalBar().setIncrement(16);
    sc.setExpandHorizontal(true);
    sc.setExpandVertical(true);
    GridData gridData = new GridData(GridData.FILL, GridData.FILL, true, true, 1, 1);
    Utils.setLayoutData(sc, gridData);
    outer_panel = sc;
    Composite panel = new Composite(sc, SWT.NULL);
    sc.setContent(panel);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 1;
    panel.setLayout(layout);
    // int userMode = COConfigurationManager.getIntParameter("User Mode");
    // header
    Composite cHeader = new Composite(panel, SWT.BORDER);
    GridLayout configLayout = new GridLayout();
    configLayout.marginHeight = 3;
    configLayout.marginWidth = 0;
    cHeader.setLayout(configLayout);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    Utils.setLayoutData(cHeader, gridData);
    Display d = panel.getDisplay();
    cHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
    cHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
    Label lHeader = new Label(cHeader, SWT.NULL);
    lHeader.setBackground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION));
    lHeader.setForeground(Colors.getSystemColor(d, SWT.COLOR_LIST_SELECTION_TEXT));
    FontData[] fontData = lHeader.getFont().getFontData();
    fontData[0].setStyle(SWT.BOLD);
    int fontHeight = (int) (fontData[0].getHeight() * 1.2);
    fontData[0].setHeight(fontHeight);
    headerFont = new Font(d, fontData);
    lHeader.setFont(headerFont);
    lHeader.setText(" " + MessageText.getString("authenticator.torrent") + " : " + download_manager.getDisplayName().replaceAll("&", "&&"));
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER);
    Utils.setLayoutData(lHeader, gridData);
    Composite gTorrentInfo = new Composite(panel, SWT.NULL);
    gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL);
    Utils.setLayoutData(gTorrentInfo, gridData);
    layout = new GridLayout();
    layout.numColumns = 2;
    gTorrentInfo.setLayout(layout);
    // torrent encoding
    Label label = new Label(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    label.setText(MessageText.getString("TorrentInfoView.torrent.encoding") + ": ");
    TOTorrent torrent = download_manager.getTorrent();
    BufferedLabel blabel = new BufferedLabel(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(blabel, gridData);
    blabel.setText(torrent == null ? "" : LocaleTorrentUtil.getCurrentTorrentEncoding(torrent));
    // trackers
    label = new Label(gTorrentInfo, SWT.NULL);
    gridData = new GridData();
    Utils.setLayoutData(label, gridData);
    label.setText(MessageText.getString("label.tracker") + ": ");
    String trackers = "";
    if (torrent != null) {
        TOTorrentAnnounceURLGroup group = torrent.getAnnounceURLGroup();
        TOTorrentAnnounceURLSet[] sets = group.getAnnounceURLSets();
        List<String> tracker_list = new ArrayList<>();
        URL url = torrent.getAnnounceURL();
        tracker_list.add(url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort())));
        for (int i = 0; i < sets.length; i++) {
            TOTorrentAnnounceURLSet set = sets[i];
            URL[] urls = set.getAnnounceURLs();
            for (int j = 0; j < urls.length; j++) {
                url = urls[j];
                String str = url.getHost() + (url.getPort() == -1 ? "" : (":" + url.getPort()));
                if (!tracker_list.contains(str)) {
                    tracker_list.add(str);
                }
            }
        }
        TRTrackerAnnouncer announcer = download_manager.getTrackerClient();
        URL active_url = null;
        if (announcer != null) {
            active_url = announcer.getTrackerURL();
        } else {
            TRTrackerScraperResponse scrape = download_manager.getTrackerScrapeResponse();
            if (scrape != null) {
                active_url = scrape.getURL();
            }
        }
        if (active_url == null) {
            active_url = torrent.getAnnounceURL();
        }
        trackers = active_url.getHost() + (active_url.getPort() == -1 ? "" : (":" + active_url.getPort()));
        tracker_list.remove(trackers);
        if (tracker_list.size() > 0) {
            trackers += " (";
            for (int i = 0; i < tracker_list.size(); i++) {
                trackers += (i == 0 ? "" : ", ") + tracker_list.get(i);
            }
            trackers += ")";
        }
    }
    blabel = new BufferedLabel(gTorrentInfo, SWT.WRAP);
    Utils.setLayoutData(blabel, Utils.getWrappableLabelGridData(1, GridData.FILL_HORIZONTAL));
    blabel.setText(trackers);
    // columns
    Group gColumns = new Group(panel, SWT.NULL);
    Messages.setLanguageText(gColumns, "TorrentInfoView.columns");
    gridData = new GridData(GridData.FILL_BOTH);
    Utils.setLayoutData(gColumns, gridData);
    layout = new GridLayout();
    layout.numColumns = 4;
    gColumns.setLayout(layout);
    Map<String, FakeTableCell> usable_cols = new HashMap<>();
    TableColumnManager col_man = TableColumnManager.getInstance();
    TableColumnCore[][] cols_sets = { col_man.getAllTableColumnCoreAsArray(DownloadTypeIncomplete.class, TableManager.TABLE_MYTORRENTS_INCOMPLETE), col_man.getAllTableColumnCoreAsArray(DownloadTypeComplete.class, TableManager.TABLE_MYTORRENTS_COMPLETE) };
    for (int i = 0; i < cols_sets.length; i++) {
        TableColumnCore[] cols = cols_sets[i];
        for (int j = 0; j < cols.length; j++) {
            TableColumnCore col = cols[j];
            String id = col.getName();
            if (usable_cols.containsKey(id)) {
                continue;
            }
            FakeTableCell fakeTableCell = null;
            try {
                fakeTableCell = new FakeTableCell(col, download_manager);
                fakeTableCell.setOrentation(SWT.LEFT);
                fakeTableCell.setWrapText(false);
                col.invokeCellAddedListeners(fakeTableCell);
                // One refresh to see if it throws up
                fakeTableCell.refresh();
                usable_cols.put(id, fakeTableCell);
            } catch (Throwable t) {
                // System.out.println("not usable col: " + id + " - " + Debug.getCompressedStackTrace());
                try {
                    if (fakeTableCell != null) {
                        fakeTableCell.dispose();
                    }
                } catch (Throwable t2) {
                // ignore;
                }
            }
        }
    }
    Collection<FakeTableCell> values = usable_cols.values();
    cells = new FakeTableCell[values.size()];
    values.toArray(cells);
    Arrays.sort(cells, new Comparator<FakeTableCell>() {

        @Override
        public int compare(FakeTableCell o1, FakeTableCell o2) {
            TableColumnCore c1 = (TableColumnCore) o1.getTableColumn();
            TableColumnCore c2 = (TableColumnCore) o2.getTableColumn();
            String key1 = MessageText.getString(c1.getTitleLanguageKey());
            String key2 = MessageText.getString(c2.getTitleLanguageKey());
            return key1.compareToIgnoreCase(key2);
        }
    });
    for (int i = 0; i < cells.length; i++) {
        final FakeTableCell cell = cells[i];
        label = new Label(gColumns, SWT.NULL);
        gridData = new GridData();
        if (i % 2 == 1) {
            gridData.horizontalIndent = 16;
        }
        Utils.setLayoutData(label, gridData);
        String key = ((TableColumnCore) cell.getTableColumn()).getTitleLanguageKey();
        label.setText(MessageText.getString(key) + ": ");
        label.setToolTipText(MessageText.getString(key + ".info", ""));
        final Composite c = new Composite(gColumns, SWT.DOUBLE_BUFFERED);
        gridData = new GridData(GridData.FILL_HORIZONTAL);
        gridData.heightHint = 16;
        Utils.setLayoutData(c, gridData);
        cell.setControl(c);
        cell.invalidate();
        cell.refresh();
        c.addListener(SWT.MouseHover, new Listener() {

            @Override
            public void handleEvent(Event event) {
                Object toolTip = cell.getToolTip();
                if (toolTip instanceof String) {
                    String s = (String) toolTip;
                    c.setToolTipText(s);
                }
            }
        });
    }
    refresh();
    sc.setMinSize(panel.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Also used : TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) UIPluginViewToolBarListener(com.biglybt.pif.ui.UIPluginViewToolBarListener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) BufferedLabel(com.biglybt.ui.swt.components.BufferedLabel) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) FakeTableCell(com.biglybt.ui.swt.views.table.impl.FakeTableCell) Font(org.eclipse.swt.graphics.Font) TOTorrentAnnounceURLGroup(com.biglybt.core.torrent.TOTorrentAnnounceURLGroup) URL(java.net.URL) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager) GridLayout(org.eclipse.swt.layout.GridLayout) TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) FontData(org.eclipse.swt.graphics.FontData) DownloadTypeComplete(com.biglybt.pif.download.DownloadTypeComplete) TRTrackerAnnouncer(com.biglybt.core.tracker.client.TRTrackerAnnouncer) TOTorrent(com.biglybt.core.torrent.TOTorrent) GridData(org.eclipse.swt.layout.GridData) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) DownloadTypeIncomplete(com.biglybt.pif.download.DownloadTypeIncomplete) TOTorrentAnnounceURLSet(com.biglybt.core.torrent.TOTorrentAnnounceURLSet)

Example 8 with TRTrackerScraperResponse

use of com.biglybt.core.tracker.client.TRTrackerScraperResponse in project BiglyBT by BiglySoftware.

the class TrackerCellUtils method getTooltipText.

public static String getTooltipText(TableCell cell, DownloadManager dm, boolean show_errors) {
    if (dm == null || cell == null)
        return null;
    if (show_errors) {
        if (dm.isTrackerError()) {
            return (null);
        }
    }
    String sToolTip = null;
    TRTrackerScraperResponse response = dm.getTrackerScrapeResponse();
    if (response instanceof TRTrackerBTScraperResponseImpl && response.getStatus() == TRTrackerScraperResponse.ST_ONLINE) {
        String sPrefix = ((TRTrackerBTScraperResponseImpl) response).getTrackerStatus().getSupportsMultipeHashScrapes() ? "" : "No";
        sToolTip = MessageText.getString("Tracker.tooltip." + sPrefix + "MultiSupport");
    }
    return sToolTip;
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) TRTrackerBTScraperResponseImpl(com.biglybt.core.tracker.client.impl.bt.TRTrackerBTScraperResponseImpl)

Example 9 with TRTrackerScraperResponse

use of com.biglybt.core.tracker.client.TRTrackerScraperResponse in project BiglyBT by BiglySoftware.

the class CompletedItem method refresh.

@Override
public void refresh(TableCell cell) {
    DownloadManager dm = (DownloadManager) cell.getDataSource();
    if (dm == null)
        return;
    TRTrackerScraperResponse resp = dm.getTrackerScrapeResponse();
    if (resp == null)
        return;
    int completed = resp.getCompleted();
    if (cell.setSortValue(completed) || !cell.isValid())
        cell.setText(completed == -1 ? "?" : Integer.toString(completed));
}
Also used : TRTrackerScraperResponse(com.biglybt.core.tracker.client.TRTrackerScraperResponse) DownloadManager(com.biglybt.core.download.DownloadManager)

Example 10 with TRTrackerScraperResponse

use of com.biglybt.core.tracker.client.TRTrackerScraperResponse 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

TRTrackerScraperResponse (com.biglybt.core.tracker.client.TRTrackerScraperResponse)11 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 TRTrackerAnnouncer (com.biglybt.core.tracker.client.TRTrackerAnnouncer)3 DownloadManager (com.biglybt.core.download.DownloadManager)2 TRTrackerBTScraperResponseImpl (com.biglybt.core.tracker.client.impl.bt.TRTrackerBTScraperResponseImpl)2 URL (java.net.URL)2 DecimalFormat (java.text.DecimalFormat)2 DiskManager (com.biglybt.core.disk.DiskManager)1 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)1 DownloadManagerStats (com.biglybt.core.download.DownloadManagerStats)1 PEPeerManager (com.biglybt.core.peer.PEPeerManager)1 TOTorrentAnnounceURLGroup (com.biglybt.core.torrent.TOTorrentAnnounceURLGroup)1 TOTorrentAnnounceURLSet (com.biglybt.core.torrent.TOTorrentAnnounceURLSet)1 TrackerPeerSource (com.biglybt.core.tracker.TrackerPeerSource)1 DownloadTypeComplete (com.biglybt.pif.download.DownloadTypeComplete)1 DownloadTypeIncomplete (com.biglybt.pif.download.DownloadTypeIncomplete)1 UIPluginViewToolBarListener (com.biglybt.pif.ui.UIPluginViewToolBarListener)1 TableColumnCore (com.biglybt.ui.common.table.TableColumnCore)1 TableColumnManager (com.biglybt.ui.common.table.impl.TableColumnManager)1 BufferedLabel (com.biglybt.ui.swt.components.BufferedLabel)1