use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.
the class SearchSubsUtils method getHashStatus.
public static int getHashStatus(SearchSubsResultBase result) {
if (result == null) {
return (HS_NONE);
}
byte[] hash = result.getHash();
if (hash == null || hash.length != 20) {
return (HS_UNKNOWN);
}
long now = SystemTime.getMonotonousTime();
Object[] entry = (Object[]) result.getUserData(HS_KEY);
if (entry != null) {
long time = (Long) entry[0];
if (now - time < 10 * 1000) {
return ((Integer) entry[1]);
}
}
synchronized (HS_KEY) {
if (gm == null) {
Core core = CoreFactory.getSingleton();
gm = core.getGlobalManager();
dm = core.getPluginManager().getDefaultPluginInterface().getDownloadManager();
hm = (DownloadHistoryManager) gm.getDownloadHistoryManager();
}
}
int hs_result;
com.biglybt.core.download.DownloadManager dl = gm.getDownloadManager(new HashWrapper(hash));
if (dl != null) {
DownloadManagerState downloadState = dl.getDownloadState();
hs_result = downloadState != null && downloadState.getFlag(DownloadManagerState.FLAG_METADATA_DOWNLOAD) ? HS_FETCHING : HS_LIBRARY;
} else if (dm.lookupDownloadStub(hash) != null) {
hs_result = HS_ARCHIVE;
} else if (hm.getDates(hash) != null) {
hs_result = HS_HISTORY;
} else {
hs_result = HS_NONE;
}
result.setUserData(HS_KEY, new Object[] { now + RandomUtils.nextInt(2500), hs_result });
return (hs_result);
}
use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.
the class SBC_DownloadHistoryView method defaultSelected.
@Override
public void defaultSelected(TableRowCore[] rows, int stateMask) {
if (rows.length == 1) {
DownloadHistory dh = (DownloadHistory) rows[0].getDataSource();
byte[] hash = dh.getTorrentHash();
DownloadManager dm = CoreFactory.getSingleton().getGlobalManager().getDownloadManager(new HashWrapper(hash));
if (dm != null) {
UIFunctionsManagerSWT.getUIFunctionsSWT().getMDISWT().showEntryByID(MultipleDocumentInterface.SIDEBAR_SECTION_LIBRARY);
dm.fireGlobalManagerEvent(GlobalManagerEvent.ET_REQUEST_ATTENTION);
}
}
}
use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.
the class DHTLog method getString.
public static String getString(Map s) {
if (logging_on) {
StringBuilder sb = new StringBuilder(128);
sb.append("{");
Iterator it = s.keySet().iterator();
while (it.hasNext()) {
if (sb.length() > 1) {
sb.append(",");
}
sb.append(getString((HashWrapper) it.next()));
}
sb.append("}");
return (sb.toString());
} else {
return ("");
}
}
use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.
the class DHTDBMapping method getOriginatorValueID.
private HashWrapper getOriginatorValueID(DHTDBValueImpl value) {
DHTTransportContact originator = value.getOriginator();
byte[] originator_id = originator.getID();
return (new HashWrapper(originator_id));
/*
byte[] value_bytes = value.getValue();
byte[] x = new byte[originator_id.length + value_bytes.length];
System.arraycopy( originator_id, 0, x, 0, originator_id.length );
System.arraycopy( value_bytes, 0, x, originator_id.length, value_bytes.length );
HashWrapper originator_value_id = new HashWrapper( new SHA1Hasher().calculateHash( x ));
return( originator_value_id );
*/
}
use of com.biglybt.core.util.HashWrapper in project BiglyBT by BiglySoftware.
the class DHTDBMapping method getAnyValue.
protected DHTDBValueImpl getAnyValue(DHTTransportContact originator) {
DHTDBValueImpl res = null;
try {
Map<HashWrapper, DHTDBValueImpl> map = direct_originator_map_may_be_null;
if (map != null) {
HashWrapper originator_id = new HashWrapper(originator.getID());
res = (DHTDBValueImpl) map.get(originator_id);
}
if (res == null) {
Iterator<DHTDBValueImpl> it = indirect_originator_value_map.values().iterator();
if (it.hasNext()) {
res = it.next();
}
}
} catch (Throwable e) {
// slight chance of conc exception here, don't care
}
return (res);
}
Aggregations