Search in sources :

Example 76 with PEPeer

use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.

the class PeersGraphicView method render.

private void render(DownloadManager manager, ManagerData data, PEPeer[] sortedPeers, Point panelSize, Point panelOffset) {
    data.peer_hit_map.clear();
    int min_dim = Math.min(panelSize.x, panelSize.y);
    if (min_dim <= 100) {
        OWN_SIZE = OWN_SIZE_MIN;
    } else if (min_dim >= 400) {
        OWN_SIZE = OWN_SIZE_DEFAULT;
    } else {
        int s_diff = OWN_SIZE_MAX - OWN_SIZE_MIN;
        float rat = (min_dim - 100.0f) / (400 - 100);
        OWN_SIZE = OWN_SIZE_MIN + (int) (s_diff * rat);
    }
    int x0 = panelSize.x / 2;
    int y0 = panelSize.y / 2;
    int a = x0 - 20;
    int b = y0 - 20;
    if (a < 10 || b < 10) {
        GC gcPanel = new GC(panel);
        gcPanel.setBackground(Colors.white);
        gcPanel.fillRectangle(panelOffset.x, panelOffset.y, panelSize.x, panelSize.y);
        gcPanel.dispose();
        return;
    }
    if (data.oldSize == null || !data.oldSize.equals(panelSize)) {
        data.oldSize = panelSize;
        perimeter = 0;
        for (int i = 0; i < NB_ANGLES; i++) {
            rs[i] = Math.sqrt(1 / (deltaYXs[i] * deltaYXs[i] / (a * a) + deltaYYs[i] * deltaYYs[i] / (b * b)));
            perimeter += rs[i];
        }
    }
    Image buffer = new Image(display, panelSize.x, panelSize.y);
    GC gcBuffer = new GC(buffer);
    gcBuffer.setBackground(Colors.white);
    gcBuffer.setForeground(Colors.blue);
    gcBuffer.fillRectangle(0, 0, panelSize.x, panelSize.y);
    try {
        gcBuffer.setTextAntialias(SWT.ON);
        gcBuffer.setAntialias(SWT.ON);
    } catch (Exception e) {
    }
    gcBuffer.setBackground(Colors.blues[Colors.BLUES_MIDLIGHT]);
    int nbPeers = sortedPeers.length;
    int iAngle = 0;
    double currentPerimeter = 0;
    // double angle;
    double r;
    for (int i = 0; i < nbPeers; i++) {
        PEPeer peer = sortedPeers[i];
        do {
            // angle = angles[iAngle];
            r = rs[iAngle];
            currentPerimeter += r;
            if (iAngle + 1 < NB_ANGLES)
                iAngle++;
        } while (currentPerimeter < i * perimeter / nbPeers);
        // angle = (4 * i - nbPeers) * Math.PI  / (2 * nbPeers) - Math.PI / 2;
        int[] triangle = new int[6];
        int percent_received = peer.getPercentDoneOfCurrentIncomingRequest();
        int percent_sent = peer.getPercentDoneOfCurrentOutgoingRequest();
        // set up base line state
        boolean drawLine = false;
        if (!peer.isChokingMe() || percent_received >= 0) {
            gcBuffer.setForeground(Colors.blues[1]);
            drawLine = true;
        }
        if (!peer.isChokedByMe() || percent_sent >= 0) {
            gcBuffer.setForeground(Colors.blues[3]);
            drawLine = true;
        }
        if (!peer.isChokingMe() && peer.isUnchokeOverride() && peer.isInteresting()) {
            gcBuffer.setForeground(Colors.green);
            drawLine = true;
        }
        if (peer.isChokedByMe() && percent_sent >= 0) {
            gcBuffer.setForeground(Colors.green);
            drawLine = true;
        }
        if (drawLine) {
            int x1 = x0 + (int) (r * deltaYXs[iAngle]);
            int y1 = y0 + (int) (r * deltaYYs[iAngle]);
            gcBuffer.drawLine(x0, y0, x1, y1);
        }
        if (percent_received >= 0) {
            gcBuffer.setBackground(Colors.blues[Colors.BLUES_MIDDARK]);
            double r1 = r - r * percent_received / 100;
            triangle[0] = (int) (x0 + (r1 - 10) * deltaYXs[iAngle] + 0.5);
            triangle[1] = (int) (y0 + (r1 - 10) * deltaYYs[iAngle] + 0.5);
            triangle[2] = (int) (x0 + deltaXXs[iAngle] * 4 + (r1) * deltaYXs[iAngle] + 0.5);
            triangle[3] = (int) (y0 + deltaXYs[iAngle] * 4 + (r1) * deltaYYs[iAngle] + 0.5);
            triangle[4] = (int) (x0 - deltaXXs[iAngle] * 4 + (r1) * deltaYXs[iAngle] + 0.5);
            triangle[5] = (int) (y0 - deltaXYs[iAngle] * 4 + (r1) * deltaYYs[iAngle] + 0.5);
            gcBuffer.fillPolygon(triangle);
        }
        if (percent_sent >= 0) {
            gcBuffer.setBackground(Colors.blues[Colors.BLUES_MIDLIGHT]);
            double r1 = r * percent_sent / 100;
            triangle[0] = (int) (x0 + r1 * deltaYXs[iAngle] + 0.5);
            triangle[1] = (int) (y0 + r1 * deltaYYs[iAngle] + 0.5);
            triangle[2] = (int) (x0 + deltaXXs[iAngle] * 4 + (r1 - 10) * deltaYXs[iAngle] + 0.5);
            triangle[3] = (int) (y0 + deltaXYs[iAngle] * 4 + (r1 - 10) * deltaYYs[iAngle] + 0.5);
            triangle[4] = (int) (x0 - deltaXXs[iAngle] * 4 + (r1 - 10) * deltaYXs[iAngle] + 0.5);
            triangle[5] = (int) (y0 - deltaXYs[iAngle] * 4 + (r1 - 10) * deltaYYs[iAngle] + 0.5);
            gcBuffer.fillPolygon(triangle);
        }
        int x1 = x0 + (int) (r * deltaYXs[iAngle]);
        int y1 = y0 + (int) (r * deltaYYs[iAngle]);
        gcBuffer.setBackground(Colors.blues[Colors.BLUES_MIDDARK]);
        if (peer.isSnubbed()) {
            gcBuffer.setBackground(Colors.grey);
        }
        /*int PS = (int) (PEER_SIZE);
        if (deltaXY == 0) {
          PS = (int) (PEER_SIZE * 2);
        } else {
          if (deltaYY > 0) {
            PS = (int) (PEER_SIZE / deltaXY);
          }
        }*/
        // PieUtils.drawPie(gcBuffer,(x1 - PS / 2),y1 - PS / 2,PS,PS,peer.getPercentDoneInThousandNotation() / 10);
        int peer_x = x1 - PEER_SIZE / 2;
        int peer_y = y1 - PEER_SIZE / 2;
        data.peer_hit_map.put(peer, new int[] { peer_x + panelOffset.x, peer_y + panelOffset.y });
        Image flag = ImageRepository.getCountryFlag(peer, false);
        if (flag != null) {
            PieUtils.drawPie(gcBuffer, flag, peer_x, peer_y, PEER_SIZE, PEER_SIZE, peer.getPercentDoneInThousandNotation() / 10, true);
        } else {
            PieUtils.drawPie(gcBuffer, peer_x, peer_y, PEER_SIZE, PEER_SIZE, peer.getPercentDoneInThousandNotation() / 10);
        }
    // gcBuffer.drawText(peer.getIp() , x1 + 8 , y1 , true);
    }
    gcBuffer.setBackground(Colors.blues[Colors.BLUES_MIDDARK]);
    data.me_hit_x = x0 - OWN_SIZE / 2;
    data.me_hit_y = y0 - OWN_SIZE / 2;
    PieUtils.drawPie(gcBuffer, data.me_hit_x, data.me_hit_y, OWN_SIZE, OWN_SIZE, manager.getStats().getCompleted() / 10);
    if (my_flag != null) {
        PieUtils.drawPie(gcBuffer, my_flag, data.me_hit_x, data.me_hit_y, OWN_SIZE, OWN_SIZE, manager.getStats().getCompleted() / 10, false);
    }
    data.me_hit_x += panelOffset.x;
    data.me_hit_y += panelOffset.y;
    gcBuffer.dispose();
    GC gcPanel = new GC(panel);
    gcPanel.drawImage(buffer, panelOffset.x, panelOffset.y);
    gcPanel.dispose();
    buffer.dispose();
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) GC(org.eclipse.swt.graphics.GC) Image(org.eclipse.swt.graphics.Image) Point(org.eclipse.swt.graphics.Point)

Example 77 with PEPeer

use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.

the class PeersViewBase method addPeersMenu.

protected static boolean addPeersMenu(final DownloadManager man, String column_name, Menu menu) {
    new MenuItem(menu, SWT.SEPARATOR);
    MenuItem copy_me_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(copy_me_item, "menu.copy.my.peer");
    copy_me_item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            String str = getMyPeerDetails();
            if (str.isEmpty()) {
                str = "<no usable peers>";
            }
            ClipboardCopy.copyToClipBoard(str);
        }
    });
    if (man == null) {
        return (true);
    }
    PEPeerManager pm = man.getPeerManager();
    if (pm == null) {
        return (true);
    }
    if (TorrentUtils.isReallyPrivate(man.getTorrent())) {
        return (true);
    }
    MenuItem copy_all_peers = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(copy_all_peers, "menu.copy.all.peers");
    copy_all_peers.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            List<PEPeer> peers = pm.getPeers();
            String str = getMyPeerDetails();
            for (PEPeer peer : peers) {
                int port = peer.getTCPListenPort();
                if (port > 0) {
                    String address = peer.getIp() + ":" + port;
                    str += (str.isEmpty() ? "" : ",") + address;
                }
            }
            if (str.isEmpty()) {
                str = "<no usable peers>";
            }
            ClipboardCopy.copyToClipBoard(str);
        }
    });
    MenuItem add_peers_item = new MenuItem(menu, SWT.PUSH);
    Messages.setLanguageText(add_peers_item, "menu.add.peers");
    add_peers_item.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event event) {
            SimpleTextEntryWindow entryWindow = new SimpleTextEntryWindow("dialog.add.peers.title", "dialog.add.peers.msg");
            String def = COConfigurationManager.getStringParameter("add.peers.default", "");
            entryWindow.setPreenteredText(String.valueOf(def), false);
            entryWindow.prompt(new UIInputReceiverListener() {

                @Override
                public void UIInputReceiverClosed(UIInputReceiver entryWindow) {
                    if (!entryWindow.hasSubmittedInput()) {
                        return;
                    }
                    String sReturn = entryWindow.getSubmittedInput();
                    if (sReturn == null) {
                        return;
                    }
                    COConfigurationManager.setParameter("add.peers.default", sReturn);
                    PEPeerManager pm = man.getPeerManager();
                    if (pm == null) {
                        return;
                    }
                    String[] bits = sReturn.split(",");
                    for (String bit : bits) {
                        bit = bit.trim();
                        int pos = bit.lastIndexOf(':');
                        if (pos != -1) {
                            String host = bit.substring(0, pos).trim();
                            String port = bit.substring(pos + 1).trim();
                            try {
                                int i_port = Integer.parseInt(port);
                                pm.addPeer(host, i_port, 0, NetworkManager.getCryptoRequired(NetworkManager.CRYPTO_OVERRIDE_NONE), null);
                            } catch (Throwable e) {
                            }
                        } else {
                            pm.addPeer(bit, 6881, 0, NetworkManager.getCryptoRequired(NetworkManager.CRYPTO_OVERRIDE_NONE), null);
                        }
                    }
                }
            });
        }
    });
    return (true);
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) SelectionListener(org.eclipse.swt.events.SelectionListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) Listener(org.eclipse.swt.widgets.Listener) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener) TableSelectionListener(com.biglybt.ui.common.table.TableSelectionListener) UIManagerListener(com.biglybt.pif.ui.UIManagerListener) TableLifeCycleListener(com.biglybt.ui.common.table.TableLifeCycleListener) MenuItem(org.eclipse.swt.widgets.MenuItem) SimpleTextEntryWindow(com.biglybt.ui.swt.SimpleTextEntryWindow) UIInputReceiver(com.biglybt.pif.ui.UIInputReceiver) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager) ArrayList(java.util.ArrayList) List(java.util.List) UIInputReceiverListener(com.biglybt.pif.ui.UIInputReceiverListener)

Example 78 with PEPeer

use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.

the class PeersViewBase method initYourTableView.

protected TableViewSWT<PEPeer> initYourTableView(String table_id, boolean enable_tabs) {
    if (table_id == TableManager.TABLE_TORRENT_PEERS) {
        tv = TableViewFactory.createTableViewSWT(Peer.class, TableManager.TABLE_TORRENT_PEERS, getPropertiesPrefix(), basicItems, "pieces", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    } else {
        TableColumnCore[] items = PeersView.getBasicColumnItems(TableManager.TABLE_ALL_PEERS);
        TableColumnCore[] basicItems = new TableColumnCore[items.length + 1];
        System.arraycopy(items, 0, basicItems, 0, items.length);
        basicItems[items.length] = new DownloadNameItem(TableManager.TABLE_ALL_PEERS);
        TableColumnManager tcManager = TableColumnManager.getInstance();
        tcManager.setDefaultColumnNames(TableManager.TABLE_ALL_PEERS, basicItems);
        tv = TableViewFactory.createTableViewSWT(Peer.class, TableManager.TABLE_ALL_PEERS, getPropertiesPrefix(), basicItems, "connected_time", SWT.MULTI | SWT.FULL_SELECTION | SWT.VIRTUAL);
    }
    tv.setRowDefaultHeightEM(1);
    tv.setEnableTabViews(enable_tabs, true, null);
    UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT();
    if (uiFunctions != null) {
        UISWTInstance pluginUI = uiFunctions.getUISWTInstance();
        registerPluginViews(table_id, pluginUI);
    }
    tv.addLifeCycleListener(this);
    tv.addMenuFillListener(this);
    tv.addSelectionListener(this, false);
    return tv;
}
Also used : Peer(com.biglybt.pif.peers.Peer) PEPeer(com.biglybt.core.peer.PEPeer) DownloadNameItem(com.biglybt.ui.swt.views.tableitems.peers.DownloadNameItem) UIFunctionsSWT(com.biglybt.ui.swt.UIFunctionsSWT) TableColumnCore(com.biglybt.ui.common.table.TableColumnCore) UISWTInstance(com.biglybt.ui.swt.pif.UISWTInstance) TableColumnManager(com.biglybt.ui.common.table.impl.TableColumnManager)

Example 79 with PEPeer

use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.

the class PieceGraphView method buildImage.

private void buildImage() {
    if (canvas == null || canvas.isDisposed()) {
        return;
    }
    // canvas.setBackground(ColorCache.getColor(canvas.getDisplay(), "#1b1b1b"));
    Rectangle bounds = canvas.getClientArea();
    if (bounds.isEmpty()) {
        return;
    }
    if (dlm == null) {
        canvas.redraw();
        return;
    }
    PEPeerManager pm = dlm.getPeerManager();
    DiskManager dm = dlm.getDiskManager();
    if (pm == null || dm == null) {
        canvas.redraw();
        return;
    }
    final DiskManagerPiece[] dm_pieces = dm.getPieces();
    if (dm_pieces == null || dm_pieces.length == 0) {
        canvas.redraw();
        return;
    }
    int numPieces = dm_pieces.length;
    if (imgHaveAll == null || imgHaveAll.isDisposed()) {
        imgHaveAll = new Image(canvas.getDisplay(), BLOCK_SIZE, BLOCK_SIZE);
        GC gc = new GC(imgHaveAll);
        try {
            try {
                gc.setAntialias(SWT.ON);
            } catch (Exception e) {
            // ignore
            }
            gc.setBackground(canvas.getBackground());
            gc.fillRectangle(imgHaveAll.getBounds());
            gc.setBackground(blockColors[BLOCKCOLOR_HAVEALL]);
            gc.fillRoundRectangle(1, 1, BLOCK_FILLSIZE, BLOCK_FILLSIZE, BLOCK_FILLSIZE, BLOCK_FILLSIZE);
        } finally {
            gc.dispose();
        }
    }
    if (imgNoHave == null || imgNoHave.isDisposed()) {
        imgNoHave = new Image(canvas.getDisplay(), BLOCK_SIZE, BLOCK_SIZE);
        GC gc = new GC(imgNoHave);
        try {
            try {
                gc.setAntialias(SWT.ON);
            } catch (Exception e) {
            // ignore
            }
            gc.setBackground(canvas.getBackground());
            gc.fillRectangle(imgNoHave.getBounds());
            gc.setBackground(blockColors[BLOCKCOLOR_NOHAVE]);
            gc.fillRoundRectangle(1, 1, BLOCK_FILLSIZE, BLOCK_FILLSIZE, BLOCK_FILLSIZE, BLOCK_FILLSIZE);
        } finally {
            gc.dispose();
        }
    }
    boolean clearImage = img == null || img.isDisposed() || img.getBounds().width != bounds.width || img.getBounds().height != bounds.height;
    if (clearImage) {
        if (img != null && !img.isDisposed()) {
            img.dispose();
        }
        // System.out.println("clear " + img);
        img = new Image(canvas.getDisplay(), bounds.width, bounds.height);
        squareCache = null;
    }
    PEPiece[] currentDLPieces = dlm.getCurrentPieces();
    Arrays.sort(currentDLPieces, compFindPEPiece);
    // find upload pieces
    ArrayList currentULPieces = new ArrayList();
    ArrayList futureULPieces = new ArrayList();
    PEPeer[] peers = (PEPeer[]) pm.getPeers().toArray(new PEPeer[0]);
    for (int i = 0; i < peers.length; i++) {
        PEPeer peer = peers[i];
        int[] peerRequestedPieces = peer.getIncomingRequestedPieceNumbers();
        if (peerRequestedPieces != null && peerRequestedPieces.length > 0) {
            currentULPieces.add(new Long(peerRequestedPieces[0]));
            for (int j = 1; j < peerRequestedPieces.length; j++) {
                futureULPieces.add(new Long(peerRequestedPieces[j]));
            }
        }
        // we'll have duplicates
        Collections.sort(currentULPieces);
        Collections.sort(futureULPieces);
    }
    int iNumCols = bounds.width / BLOCK_SIZE;
    int iNumRows = bounds.height / BLOCK_SIZE;
    int numSquares = onePiecePerBlock ? numPieces : iNumCols * iNumRows;
    double numPiecesPerSquare = numPieces / (double) numSquares;
    if (squareCache == null || squareCache.length != numSquares) {
        squareCache = new double[numSquares];
        Arrays.fill(squareCache, -1);
    }
    int[] availability = pm.getAvailability();
    int numRedraws = 0;
    GC gc = new GC(img);
    try {
        int iRow = 0;
        if (clearImage) {
            gc.setBackground(canvas.getBackground());
            gc.fillRectangle(bounds);
        }
        try {
            gc.setAdvanced(true);
            gc.setAntialias(SWT.ON);
            gc.setInterpolation(SWT.HIGH);
        } catch (Exception e) {
        // ignore
        }
        int iCol = 0;
        for (int squareNo = 0; squareNo < numSquares; squareNo++) {
            if (iCol >= iNumCols) {
                iCol = 0;
                iRow++;
            }
            int startNo = (int) (squareNo * numPiecesPerSquare);
            int count = (int) ((squareNo + 1) * numPiecesPerSquare) - startNo;
            if (count == 0) {
                count = 1;
            }
            // if (count > 1) System.out.println("!!! " + startNo);
            // System.out.println(startNo + ";" + count);
            double pctDone = getPercentDone(startNo, count, dm_pieces);
            // System.out.print(pctDone + ";");
            int colorIndex;
            int iXPos = iCol * BLOCK_SIZE;
            int iYPos = iRow * BLOCK_SIZE;
            if (pctDone == 1) {
                if (squareCache[squareNo] != pctDone) {
                    squareCache[squareNo] = pctDone;
                    gc.drawImage(imgHaveAll, iXPos, iYPos);
                    if (!clearImage) {
                        numRedraws++;
                        canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
                    }
                }
            } else if (pctDone == 0) {
                if (squareCache[squareNo] != pctDone) {
                    squareCache[squareNo] = pctDone;
                    gc.drawImage(imgNoHave, iXPos, iYPos);
                    if (!clearImage) {
                        numRedraws++;
                        canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
                    }
                }
            } else {
                // !done
                boolean isDownloading = false;
                for (int i = startNo; i < startNo + count; i++) {
                    if (Arrays.binarySearch(currentDLPieces, new Long(i), compFindPEPiece) >= 0) {
                        isDownloading = true;
                        break;
                    }
                }
                double val = pctDone + (isDownloading ? 0 : 1);
                if (squareCache[squareNo] != val) {
                    squareCache[squareNo] = val;
                    gc.drawImage(imgNoHave, iXPos, iYPos);
                    int size = (int) (BLOCK_FILLSIZE * pctDone);
                    if (size == 0) {
                        size = 1;
                    }
                    int q = (int) ((BLOCK_FILLSIZE - size) / 2.0 + 0.5) + 1;
                    colorIndex = isDownloading ? BLOCKCOLOR_DOWNLOADING : BLOCKCOLOR_HAVESOME;
                    gc.setBackground(blockColors[colorIndex]);
                    gc.fillOval(iXPos + q, iYPos + q, size, size);
                    // gc.fillRoundRectangle(iXPos + q, iYPos + q, size, size, size, size);
                    if (!clearImage) {
                        numRedraws++;
                        canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
                    }
                }
            }
            for (int i = startNo; i < startNo + count; i++) {
                if (Collections.binarySearch(currentULPieces, new Long(i)) >= 0) {
                    colorIndex = BLOCKCOLOR_UPLOADING;
                    int size = BLOCK_FILLSIZE + 1;
                    gc.setForeground(blockColors[colorIndex]);
                    gc.drawRoundRectangle(iXPos, iYPos, size, size, size, size);
                    if (!clearImage) {
                        numRedraws++;
                        canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
                    }
                    squareCache[squareNo] = -1;
                    break;
                } else if (Collections.binarySearch(futureULPieces, new Long(i)) >= 0) {
                    colorIndex = BLOCKCOLOR_UPLOADING;
                    int size = BLOCK_FILLSIZE + 1;
                    gc.setForeground(blockColors[colorIndex]);
                    gc.setLineStyle(SWT.LINE_DOT);
                    gc.drawRoundRectangle(iXPos, iYPos, size, size, size, size);
                    if (!clearImage) {
                        numRedraws++;
                        canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
                    }
                    gc.setLineStyle(SWT.LINE_SOLID);
                    squareCache[squareNo] = -1;
                    break;
                }
            }
            if (availability != null) {
                boolean hasNoAvail = false;
                for (int i = startNo; i < startNo + count; i++) {
                    if (availability[i] == 0) {
                        hasNoAvail = true;
                        squareCache[squareNo] = -1;
                        break;
                    }
                }
                if (hasNoAvail) {
                    gc.setForeground(blockColors[BLOCKCOLOR_NOAVAIL]);
                    gc.drawRectangle(iXPos, iYPos, BLOCK_FILLSIZE + 1, BLOCK_FILLSIZE + 1);
                    if (!clearImage) {
                        numRedraws++;
                        canvas.redraw(iXPos, iYPos, BLOCK_SIZE, BLOCK_SIZE, false);
                    }
                }
            }
            iCol++;
        }
    // System.out.println("redraws " + numRedraws);
    } catch (Exception e) {
        Debug.out(e);
    } finally {
        gc.dispose();
    }
// canvas.redraw();
}
Also used : PEPeer(com.biglybt.core.peer.PEPeer) DiskManager(com.biglybt.core.disk.DiskManager) PEPiece(com.biglybt.core.peer.PEPiece) PEPeerManager(com.biglybt.core.peer.PEPeerManager) DiskManagerPiece(com.biglybt.core.disk.DiskManagerPiece)

Example 80 with PEPeer

use of com.biglybt.core.peer.PEPeer in project BiglyBT by BiglySoftware.

the class PrivacyView method updatePeersEtc.

private void updatePeersEtc(final DownloadManager dm) {
    final PEPeerManager pm;
    if (dm != null) {
        pm = dm.getPeerManager();
    } else {
        pm = null;
    }
    Utils.execSWTThread(new AERunnable() {

        @Override
        public void runSupport() {
            if (peer_info == null || peer_info.isDisposed()) {
                return;
            }
            if (pm == null) {
                peer_info.setText(dm == null ? "" : MessageText.getString("privacy.view.dl.not.running"));
            } else {
                AEProxySelector proxy_selector = AEProxySelectorFactory.getSelector();
                Proxy proxy = proxy_selector.getActiveProxy();
                boolean socks_bad_incoming = false;
                List<PEPeer> peers = pm.getPeers();
                String[] all_nets = AENetworkClassifier.AT_NETWORKS;
                int[] counts = new int[all_nets.length];
                int incoming = 0;
                int outgoing = 0;
                int outgoing_connected = 0;
                for (PEPeer peer : peers) {
                    String net = PeerUtils.getNetwork(peer);
                    for (int i = 0; i < all_nets.length; i++) {
                        if (all_nets[i] == net) {
                            counts[i]++;
                            break;
                        }
                    }
                    boolean is_incoming = peer.isIncoming();
                    if (is_incoming) {
                        incoming++;
                    } else {
                        outgoing++;
                        if (peer.getPeerState() == PEPeer.TRANSFERING) {
                            outgoing_connected++;
                        }
                    }
                    if (proxy != null) {
                        if (is_incoming) {
                            if (!peer.isLANLocal()) {
                                try {
                                    if (InetAddress.getByAddress(HostNameToIPResolver.hostAddressToBytes(peer.getIp())).isLoopbackAddress()) {
                                        continue;
                                    }
                                } catch (Throwable e) {
                                }
                                socks_bad_incoming = true;
                                break;
                            }
                        }
                    }
                }
                String str = "";
                for (int i = 0; i < all_nets.length; i++) {
                    int num = counts[i];
                    if (num > 0) {
                        str += (str.length() == 0 ? "" : ", ") + all_nets[i] + "=" + num;
                    }
                }
                if (str.length() == 0) {
                    str = MessageText.getString("privacy.view.no.peers");
                } else {
                    str += ", " + MessageText.getString("label.incoming") + "=" + incoming + ", " + MessageText.getString("label.outgoing") + "=" + outgoing_connected + "/" + outgoing;
                }
                if (socks_bad_incoming) {
                    str += " (" + MessageText.getString("privacy.view.non.local.peer") + ")";
                }
                peer_info.setText(str);
            }
            updateVPNSocks();
        }
    });
}
Also used : AERunnable(com.biglybt.core.util.AERunnable) Proxy(java.net.Proxy) PEPeer(com.biglybt.core.peer.PEPeer) AEProxySelector(com.biglybt.core.proxy.AEProxySelector) PEPeerManager(com.biglybt.core.peer.PEPeerManager) List(java.util.List)

Aggregations

PEPeer (com.biglybt.core.peer.PEPeer)84 PEPeerManager (com.biglybt.core.peer.PEPeerManager)18 DownloadManager (com.biglybt.core.download.DownloadManager)11 ArrayList (java.util.ArrayList)11 DiskManagerFileInfo (com.biglybt.core.disk.DiskManagerFileInfo)5 AERunnable (com.biglybt.core.util.AERunnable)5 PEPiece (com.biglybt.core.peer.PEPiece)4 List (java.util.List)4 Image (org.eclipse.swt.graphics.Image)4 DiskManager (com.biglybt.core.disk.DiskManager)3 GlobalManager (com.biglybt.core.global.GlobalManager)3 PEPeerStats (com.biglybt.core.peer.PEPeerStats)3 PEPeerTransport (com.biglybt.core.peer.impl.PEPeerTransport)3 TOTorrent (com.biglybt.core.torrent.TOTorrent)3 Point (org.eclipse.swt.graphics.Point)3 DiskManagerPiece (com.biglybt.core.disk.DiskManagerPiece)2 DownloadManagerPeerListener (com.biglybt.core.download.DownloadManagerPeerListener)2 PiecePicker (com.biglybt.core.peermanager.piecepicker.PiecePicker)2 BitFlags (com.biglybt.core.peermanager.piecepicker.util.BitFlags)2 Tag (com.biglybt.core.tag.Tag)2