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);
}
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);
}
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);
}
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);
}
}
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);
}
}
}
}
Aggregations