Info run(const string& path) { // adapted from dcpp::HashManager File f { path, File::READ, File::OPEN }; auto size = f.getSize(); f.close(); static const int64_t MIN_BLOCK_SIZE = 64 * 1024; auto bs = std::max(TigerTree::calcBlockSize(size, 10), MIN_BLOCK_SIZE); TigerTree tt { bs }; auto start = GET_TICK(); FileReader(true).read(path, [&](const void* buf, size_t n) -> bool { tt.update(buf, n); return true; }); tt.finalize(); auto end = GET_TICK(); double speed = 0.0; if(end > start) { speed = static_cast<double>(size) * 1000.0 / static_cast<double>(end - start); } Info ret { tt.getRoot().toBase32(), end - start, speed }; return ret; }
/* * Generates UDP key for specified IP address */ CID Utils::getUdpKey(const string& targetIp) { CID myUdpKey = CID(SETTING(DHT_KEY)); TigerTree th; th.update(myUdpKey.data(), sizeof(CID)); th.update(targetIp.c_str(), targetIp.size()); return CID(th.finalize()); }
void checkTrees() throw(FileException) { while(cur.getLeaves().size() > verified) { if(cur.getLeaves().size() > real.getLeaves().size() || !(cur.getLeaves()[verified] == real.getLeaves()[verified])) { throw FileException(STRING(TTH_INCONSISTENCY)); } verified++; } }
MemoryInputStream* ShareManager::getTree(const string& virtualFile) const { TigerTree tree; if(virtualFile.compare(0, 4, "TTH/") == 0) { if(!HashManager::getInstance()->getTree(TTHValue(virtualFile.substr(4)), tree)) return nullptr; } else { try { TTHValue tth = getTTH(virtualFile); //if(!tth) { return nullptr; } HashManager::getInstance()->getTree(tth, tree); } catch(const Exception&) { return nullptr; } } ByteVector buf = tree.getLeafData(); return new MemoryInputStream(&buf[0], buf.size()); }
TigerCheckOutputStream(const TigerTree& aTree, OutputStream* aStream) : s(aStream), real(aTree), cur(aTree.getBlockSize()), verified(0), bufPos(0) { }