Search in sources :

Example 6 with HashWrapper

use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.

the class DHTDBMapping method remove.

protected DHTDBValueImpl remove(DHTTransportContact originator) {
    // local remove
    HashWrapper originator_id = new HashWrapper(originator.getID());
    DHTDBValueImpl res = removeDirectValue(originator_id);
    return (res);
}
Also used : HashWrapper(com.biglybt.core.util.HashWrapper)

Example 7 with HashWrapper

use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.

the class DHTDBMapping method get.

protected DHTDBValueImpl[] get(DHTTransportContact by_who, int max, short flags) {
    if ((flags & DHT.FLAG_STATS) != 0) {
        if (adapter_key != null) {
            try {
                ByteArrayOutputStream baos = new ByteArrayOutputStream(64);
                DataOutputStream dos = new DataOutputStream(baos);
                adapter_key.serialiseStats(dos);
                dos.close();
                return (new DHTDBValueImpl[] { new DHTDBValueImpl(SystemTime.getCurrentTime(), baos.toByteArray(), 0, db.getLocalContact(), db.getLocalContact(), true, DHT.FLAG_STATS, 0, DHT.REP_FACT_DEFAULT) });
            } catch (Throwable e) {
                Debug.printStackTrace(e);
            }
        }
        return (new DHTDBValueImpl[0]);
    }
    List<DHTDBValueImpl> res = new ArrayList<>();
    Set<HashWrapper> duplicate_check = new HashSet<>();
    Map<HashWrapper, DHTDBValueImpl>[] maps = new Map[] { direct_originator_map_may_be_null, indirect_originator_value_map };
    for (int i = 0; i < maps.length; i++) {
        Map<HashWrapper, DHTDBValueImpl> map = maps[i];
        if (map == null) {
            continue;
        }
        List<HashWrapper> keys_used = new ArrayList<>();
        Iterator<Map.Entry<HashWrapper, DHTDBValueImpl>> it = map.entrySet().iterator();
        while (it.hasNext() && (max == 0 || res.size() < max)) {
            Map.Entry<HashWrapper, DHTDBValueImpl> entry = it.next();
            HashWrapper entry_key = entry.getKey();
            DHTDBValueImpl entry_value = entry.getValue();
            HashWrapper x = new HashWrapper(entry_value.getValue());
            if (duplicate_check.contains(x)) {
                continue;
            }
            duplicate_check.add(x);
            if (entry_value.getValue().length > 0) {
                res.add(entry_value);
                keys_used.add(entry_key);
            }
        }
        for (int j = 0; j < keys_used.size(); j++) {
            map.get(keys_used.get(j));
        }
    }
    informRead(by_who);
    DHTDBValueImpl[] v = new DHTDBValueImpl[res.size()];
    res.toArray(v);
    return (v);
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) HashWrapper(com.biglybt.core.util.HashWrapper)

Example 8 with HashWrapper

use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.

the class DHTDBMapping method getAllValues.

protected List<DHTDBValueImpl> getAllValues(DHTTransportContact originator) {
    List<DHTDBValueImpl> res = new ArrayList<>();
    Set<HashWrapper> duplicate_check = new HashSet<>();
    Map<HashWrapper, DHTDBValueImpl>[] maps = new Map[] { direct_originator_map_may_be_null, indirect_originator_value_map };
    for (int i = 0; i < maps.length; i++) {
        Map<HashWrapper, DHTDBValueImpl> map = maps[i];
        if (map == null) {
            continue;
        }
        Iterator<Map.Entry<HashWrapper, DHTDBValueImpl>> it = map.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<HashWrapper, DHTDBValueImpl> entry = it.next();
            DHTDBValueImpl entry_value = entry.getValue();
            HashWrapper x = new HashWrapper(entry_value.getValue());
            if (duplicate_check.contains(x)) {
                continue;
            }
            duplicate_check.add(x);
            if (entry_value.getValue().length > 0) {
                res.add(entry_value);
            }
        }
    }
    return (res);
}
Also used : HashWrapper(com.biglybt.core.util.HashWrapper)

Example 9 with HashWrapper

use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.

the class PiecesViewBase method fillMenu.

@Override
public void fillMenu(String sColumnName, Menu menu) {
    final List<Object> selected = tv.getSelectedDataSources();
    if (selected.size() == 0) {
        return;
    }
    List<PEPeerManager> pms = getPeerManagers();
    if (pms.isEmpty()) {
        return;
    }
    boolean has_undone = false;
    boolean has_unforced = false;
    boolean all_uploading = true;
    IdentityHashSet<DownloadManager> download_managers = new IdentityHashSet<>();
    GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
    for (Object obj : selected) {
        PEPiece piece = (PEPiece) obj;
        PEPeerManager pm = piece.getManager();
        if (pm != null && gm != null) {
            DownloadManager dm = gm.getDownloadManager(new HashWrapper(pm.getHash()));
            if (dm != null) {
                download_managers.add(dm);
            }
        }
        if (!(piece instanceof PEPieceUploading)) {
            all_uploading = false;
            if (!piece.getDMPiece().isDone()) {
                has_undone = true;
                if (piece.getPiecePicker().isForcePiece(piece.getPieceNumber())) {
                    has_unforced = true;
                }
            }
        }
    }
    if (download_managers.size() > 0) {
        MenuItem itemDetails = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(itemDetails, "PeersView.menu.showdownload");
        Utils.setMenuItemImage(itemDetails, "details");
        itemDetails.addListener(SWT.Selection, new Listener() {

            @Override
            public void handleEvent(Event event) {
                UIFunctions uiFunctions = UIFunctionsManager.getUIFunctions();
                if (uiFunctions != null) {
                    for (DownloadManager dm : download_managers) {
                        uiFunctions.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
                    }
                }
            }
        });
        new MenuItem(menu, SWT.SEPARATOR);
    }
    if (all_uploading) {
        if (selected.size() > 0) {
            PEPieceUploading piece = (PEPieceUploading) selected.get(0);
            CopyOnWriteSet<String> uploaders = piece.getUploadPeers();
            PEPeer peer = null;
            if (uploaders.size() == 1) {
                String ip = uploaders.iterator().next();
                List<PEPeer> peers = piece.getManager().getPeers(ip);
                if (peers.size() == 1) {
                    peer = peers.get(0);
                }
            }
            if (mdi != null && mdi.getEntry(PeersView.MSGID_PREFIX) != null) {
                MenuItem show_peer = new MenuItem(menu, SWT.PUSH);
                Messages.setLanguageText(show_peer, "menu.show.peer");
                final PEPeer f_peer = peer;
                show_peer.addSelectionListener(new SelectionAdapter() {

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        if (mdi != null) {
                            MdiEntrySWT entry = mdi.getEntry(PeersView.MSGID_PREFIX);
                            if (entry != null) {
                                UISWTViewEventListener listener = entry.getEventListener();
                                if (listener instanceof PeersView) {
                                    ((PeersView) listener).selectPeer(f_peer);
                                    mdi.showEntryByID(PeersView.MSGID_PREFIX);
                                }
                            }
                        }
                    }
                });
                show_peer.setEnabled(peer != null);
            }
        }
    } else {
        final MenuItem force_piece = new MenuItem(menu, SWT.CHECK);
        Messages.setLanguageText(force_piece, "label.force.piece");
        force_piece.setEnabled(has_undone);
        if (has_undone) {
            force_piece.setSelection(has_unforced);
            force_piece.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent e) {
                    boolean forced = force_piece.getSelection();
                    for (Object obj : selected) {
                        PEPiece piece = (PEPiece) obj;
                        if (!piece.getDMPiece().isDone()) {
                            piece.getPiecePicker().setForcePiece(piece.getPieceNumber(), forced);
                        }
                    }
                }
            });
        }
        final MenuItem cancel_reqs_piece = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(cancel_reqs_piece, "label.rerequest.blocks");
        cancel_reqs_piece.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                for (Object obj : selected) {
                    PEPiece piece = (PEPiece) obj;
                    for (int i = 0; i < piece.getNbBlocks(); i++) {
                        if (piece.isRequested(i)) {
                            piece.clearRequested(i);
                        }
                    }
                }
            }
        });
        final MenuItem reset_piece = new MenuItem(menu, SWT.PUSH);
        Messages.setLanguageText(reset_piece, "label.reset.piece");
        reset_piece.addSelectionListener(new SelectionAdapter() {

            @Override
            public void widgetSelected(SelectionEvent e) {
                for (Object obj : selected) {
                    PEPiece piece = (PEPiece) obj;
                    piece.reset();
                }
            }
        });
        new MenuItem(menu, SWT.SEPARATOR);
    }
}
Also used : IdentityHashSet(com.biglybt.core.util.IdentityHashSet) PEPeer(com.biglybt.core.peer.PEPeer) ParameterListener(com.biglybt.core.config.ParameterListener) TableViewSWTMenuFillListener(com.biglybt.ui.swt.views.table.TableViewSWTMenuFillListener) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) Listener(org.eclipse.swt.widgets.Listener) UISWTViewCoreEventListener(com.biglybt.ui.swt.pifimpl.UISWTViewCoreEventListener) DownloadManager(com.biglybt.core.download.DownloadManager) GlobalManager(com.biglybt.core.global.GlobalManager) UIFunctions(com.biglybt.ui.UIFunctions) SelectionEvent(org.eclipse.swt.events.SelectionEvent) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) MdiEntrySWT(com.biglybt.ui.swt.mdi.MdiEntrySWT) UISWTViewEventListener(com.biglybt.ui.swt.pif.UISWTViewEventListener) PEPiece(com.biglybt.core.peer.PEPiece) HashWrapper(com.biglybt.core.util.HashWrapper) Event(org.eclipse.swt.widgets.Event) UISWTViewEvent(com.biglybt.ui.swt.pif.UISWTViewEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) PEPeerManager(com.biglybt.core.peer.PEPeerManager)

Example 10 with HashWrapper

use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.

the class PiecesViewBase method defaultSelected.

@Override
public void defaultSelected(TableRowCore[] rows, int keyMask, int origin) {
    // Show piece in PieceInfoView
    // Show subtab if we have one
    TableViewSWT_TabsCommon tabsCommon = tv.getTabsCommon();
    if (tabsCommon != null) {
        MultipleDocumentInterfaceSWT mdi = tabsCommon.getMDI();
        if (mdi != null) {
            mdi.showEntryByID(PieceInfoView.MSGID_PREFIX);
            return;
        }
    }
    if (rows.length != 1) {
        return;
    }
    // Show in sister tab
    if (mdi != null && mdi.getEntry(PieceInfoView.MSGID_PREFIX) != null) {
        mdi.showEntryByID(PieceInfoView.MSGID_PREFIX, rows[0].getDataSource());
    } else {
        UIFunctions uif = UIFunctionsManager.getUIFunctions();
        if (uif != null) {
            GlobalManager gm = CoreFactory.getSingleton().getGlobalManager();
            PEPeerManager pm = ((PEPiece) rows[0].getDataSource()).getManager();
            DownloadManager dm = pm == null ? null : gm.getDownloadManager(new HashWrapper(pm.getHash()));
            if (dm != null) {
                uif.getMDI().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_TORRENT_DETAILS, dm);
            }
        }
    }
}
Also used : TableViewSWT_TabsCommon(com.biglybt.ui.swt.views.table.impl.TableViewSWT_TabsCommon) PEPiece(com.biglybt.core.peer.PEPiece) GlobalManager(com.biglybt.core.global.GlobalManager) HashWrapper(com.biglybt.core.util.HashWrapper) UIFunctions(com.biglybt.ui.UIFunctions) MultipleDocumentInterfaceSWT(com.biglybt.ui.swt.mdi.MultipleDocumentInterfaceSWT) PEPeerManager(com.biglybt.core.peer.PEPeerManager) DownloadManager(com.biglybt.core.download.DownloadManager)

Aggregations

HashWrapper (com.biglybt.core.util.HashWrapper)17 DownloadManager (com.biglybt.core.download.DownloadManager)5 GlobalManager (com.biglybt.core.global.GlobalManager)4 DHTTransportContact (com.biglybt.core.dht.transport.DHTTransportContact)2 PEPeerManager (com.biglybt.core.peer.PEPeerManager)2 PEPiece (com.biglybt.core.peer.PEPiece)2 UIFunctions (com.biglybt.ui.UIFunctions)2 ActivitiesEntry (com.biglybt.activities.ActivitiesEntry)1 Core (com.biglybt.core.Core)1 ParameterListener (com.biglybt.core.config.ParameterListener)1 TranscodeFile (com.biglybt.core.devices.TranscodeFile)1 TranscodeJob (com.biglybt.core.devices.TranscodeJob)1 DownloadManagerState (com.biglybt.core.download.DownloadManagerState)1 DownloadHistory (com.biglybt.core.history.DownloadHistory)1 PEPeer (com.biglybt.core.peer.PEPeer)1 TagDownload (com.biglybt.core.tag.TagDownload)1 TOTorrent (com.biglybt.core.torrent.TOTorrent)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 TRTrackerScraperClientResolver (com.biglybt.core.tracker.client.TRTrackerScraperClientResolver)1 IdentityHashSet (com.biglybt.core.util.IdentityHashSet)1