From: <arn...@us...> - 2007-12-17 23:14:50
|
Revision: 946 http://dcplusplus.svn.sourceforge.net/dcplusplus/?rev=946&view=rev Author: arnetheduck Date: 2007-12-17 15:14:47 -0800 (Mon, 17 Dec 2007) Log Message: ----------- Patches, initial hub-side bloom filter support Modified Paths: -------------- dcplusplus/trunk/changelog.txt dcplusplus/trunk/dcpp/AdcHub.cpp dcplusplus/trunk/dcpp/AdcHub.h dcplusplus/trunk/dcpp/BitOutputStream.h dcplusplus/trunk/dcpp/BloomFilter.h dcplusplus/trunk/dcpp/BufferedSocket.cpp dcplusplus/trunk/dcpp/BufferedSocket.h dcplusplus/trunk/dcpp/CID.h dcplusplus/trunk/dcpp/ClientManager.cpp dcplusplus/trunk/dcpp/ClientManager.h dcplusplus/trunk/dcpp/DCPlusPlus.h dcplusplus/trunk/dcpp/DirectoryListing.h dcplusplus/trunk/dcpp/FavoriteManager.h dcplusplus/trunk/dcpp/File.h dcplusplus/trunk/dcpp/HashManager.h dcplusplus/trunk/dcpp/HashValue.h dcplusplus/trunk/dcpp/MerkleTree.h dcplusplus/trunk/dcpp/NmdcHub.cpp dcplusplus/trunk/dcpp/QueueManager.cpp dcplusplus/trunk/dcpp/QueueManager.h dcplusplus/trunk/dcpp/SettingsManager.cpp dcplusplus/trunk/dcpp/SettingsManager.h dcplusplus/trunk/dcpp/ShareManager.cpp dcplusplus/trunk/dcpp/ShareManager.h dcplusplus/trunk/dcpp/Socket.cpp dcplusplus/trunk/win32/AboutDlg.cpp Added Paths: ----------- dcplusplus/trunk/dcpp/HashBloom.cpp dcplusplus/trunk/dcpp/HashBloom.h Modified: dcplusplus/trunk/changelog.txt =================================================================== --- dcplusplus/trunk/changelog.txt 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/changelog.txt 2007-12-17 23:14:47 UTC (rev 946) @@ -1,5 +1,7 @@ -- 0.705 -- * Several patches for better *nix compatibility of the core (thanks steven sheehy et al) +* Improve segmented download file sharing +* Fix search request ip when using multiple ip's (thanks stanislav maslovski) -- 0.704 2007-12-14 -- * Hub lists added to utilize Coral's distributed network (ullner) Modified: dcplusplus/trunk/dcpp/AdcHub.cpp =================================================================== --- dcplusplus/trunk/dcpp/AdcHub.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/AdcHub.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -44,6 +44,7 @@ const string AdcHub::BAS0_SUPPORT("ADBAS0"); const string AdcHub::TIGR_SUPPORT("ADTIGR"); const string AdcHub::UCM0_SUPPORT("ADUCM0"); +const string AdcHub::BLO0_SUPPORT("ADBLO0"); AdcHub::AdcHub(const string& aHubURL, bool secure) : Client(aHubURL, '\n', secure), oldPassword(false), sid(0) { TimerManager::getInstance()->addListener(this); @@ -476,6 +477,31 @@ SearchManager::getInstance()->onRES(c, ou->getUser()); } +void AdcHub::handle(AdcCommand::GET, AdcCommand& c) throw() { + if(c.getParameters().size() < 5) { + dcdebug("Get with few parameters"); + // TODO return STA? + return; + } + const string& type = c.getParam(0); + string tmp; + if(type == "blom" && c.getParam("BK", 4, tmp)) { + ByteVector v; + size_t m = Util::toUInt32(c.getParam(3)) * 8; + size_t k = Util::toUInt32(tmp); + + ShareManager::getInstance()->getBloom(v, k, m); + AdcCommand cmd(AdcCommand::CMD_SND, AdcCommand::TYPE_HUB); + cmd.addParam(c.getParam(0)); + cmd.addParam(c.getParam(1)); + cmd.addParam(c.getParam(2)); + cmd.addParam(c.getParam(3)); + cmd.addParam(c.getParam(4)); + send(cmd); + send((char*)&v[0], v.size()); + } +} + void AdcHub::connect(const OnlineUser& user, const string& token) { connect(user, token, CryptoManager::getInstance()->TLSOk() && user.getUser()->isSet(User::TLS)); } @@ -699,6 +725,9 @@ if(BOOLSETTING(HUB_USER_COMMANDS)) { cmd.addParam(UCM0_SUPPORT); } + if(BOOLSETTING(SEND_BLOOM)) { + cmd.addParam(BLO0_SUPPORT); + } send(cmd); } Modified: dcplusplus/trunk/dcpp/AdcHub.h =================================================================== --- dcplusplus/trunk/dcpp/AdcHub.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/AdcHub.h 2007-12-17 23:14:47 UTC (rev 946) @@ -83,7 +83,8 @@ static const string BAS0_SUPPORT; static const string TIGR_SUPPORT; static const string UCM0_SUPPORT; - + static const string BLO0_SUPPORT; + virtual string checkNick(const string& nick); OnlineUser& getUser(const uint32_t aSID, const CID& aCID); @@ -105,6 +106,7 @@ void handle(AdcCommand::SCH, AdcCommand& c) throw(); void handle(AdcCommand::CMD, AdcCommand& c) throw(); void handle(AdcCommand::RES, AdcCommand& c) throw(); + void handle(AdcCommand::GET, AdcCommand& c) throw(); template<typename T> void handle(T, AdcCommand&) { } Modified: dcplusplus/trunk/dcpp/BitOutputStream.h =================================================================== --- dcplusplus/trunk/dcpp/BitOutputStream.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/BitOutputStream.h 2007-12-17 23:14:47 UTC (rev 946) @@ -27,8 +27,8 @@ BitOutputStream(string& aStream) : is(aStream), bitPos(0), next(0) { } ~BitOutputStream() { } - void put(vector<uint8_t>& b) { - for(vector<uint8_t>::iterator i = b.begin(); i != b.end(); ++i) { + void put(const ByteVector& b) { + for(ByteVector::const_iterator i = b.begin(); i != b.end(); ++i) { next |= (*i) << bitPos++; if(bitPos > 7) { Modified: dcplusplus/trunk/dcpp/BloomFilter.h =================================================================== --- dcplusplus/trunk/dcpp/BloomFilter.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/BloomFilter.h 2007-12-17 23:14:47 UTC (rev 946) @@ -23,13 +23,7 @@ namespace dcpp { -struct CRC32Hash { - size_t operator()(const void* buf, size_t len) { f(buf, len); return f.getValue(); } -private: - CRC32Filter f; -}; - -template<size_t N, class HashFunc = CRC32Hash> +template<size_t N> class BloomFilter { public: BloomFilter(size_t tableSize) { table.resize(tableSize); } @@ -79,10 +73,15 @@ } } - /* Same functionality, but the old one did not want to compile for some reason. */ + /* This is roughly how boost::hash does it */ size_t getPos(const string& s, size_t i, size_t l) const { - HashFunc hf; - return (hf(&s[i], l) % table.size()); + size_t h = 0; + const char* c = s.data() + i; + const char* end = s.data() + l; + for(; c < end; ++c) { + h ^= *c + 0x9e3779b9 + (h<<6) + (h>>2); + } + return (h % table.size()); } vector<bool> table; Modified: dcplusplus/trunk/dcpp/BufferedSocket.cpp =================================================================== --- dcplusplus/trunk/dcpp/BufferedSocket.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/BufferedSocket.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -273,8 +273,8 @@ size_t sockSize = (size_t)sock->getSocketOptInt(SO_SNDBUF); size_t bufSize = max(sockSize, (size_t)64*1024); - vector<uint8_t> readBuf(bufSize); - vector<uint8_t> writeBuf(bufSize); + ByteVector readBuf(bufSize); + ByteVector writeBuf(bufSize); size_t readPos = 0; Modified: dcplusplus/trunk/dcpp/BufferedSocket.h =================================================================== --- dcplusplus/trunk/dcpp/BufferedSocket.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/BufferedSocket.h 2007-12-17 23:14:47 UTC (rev 946) @@ -130,9 +130,9 @@ size_t rollback; bool failed; string line; - vector<uint8_t> inbuf; - vector<uint8_t> writeBuf; - vector<uint8_t> sendBuf; + ByteVector inbuf; + ByteVector writeBuf; + ByteVector sendBuf; Socket* sock; bool disconnecting; Modified: dcplusplus/trunk/dcpp/CID.h =================================================================== --- dcplusplus/trunk/dcpp/CID.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/CID.h 2007-12-17 23:14:47 UTC (rev 946) @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if !defined(CID_H) -#define CID_H +#ifndef DCPLUSPLUS_DCPP_CID_H +#define DCPLUSPLUS_DCPP_CID_H #include "Encoder.h" #include "Util.h" @@ -28,9 +28,6 @@ public: enum { SIZE = 192 / 8 }; - struct Hash { - size_t operator()(const CID& c) const { return c.toHash(); } - }; CID() { memset(cid, 0, sizeof(cid)); } explicit CID(const uint8_t* data) { memcpy(cid, data, sizeof(cid)); } explicit CID(const string& base32) { Encoder::fromBase32(base32.c_str(), cid, sizeof(cid)); } @@ -60,4 +57,14 @@ } // namespace dcpp +namespace std { namespace tr1 { +template<> +struct hash<dcpp::CID> { + size_t operator()(const dcpp::CID& rhs) const { + return *reinterpret_cast<const size_t*>(rhs.data()); + } +}; +} +} + #endif // !defined(CID_H) Modified: dcplusplus/trunk/dcpp/ClientManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/ClientManager.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/ClientManager.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -409,8 +409,6 @@ void ClientManager::search(int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken) { Lock l(cs); - updateCachedIp(); // no point in doing a resolve for every single hub we're searching on - for(Client::Iter i = clients.begin(); i != clients.end(); ++i) { if((*i)->isConnected()) { (*i)->search(aSizeMode, aSize, aFileType, aString, aToken); @@ -421,8 +419,6 @@ void ClientManager::search(StringList& who, int aSizeMode, int64_t aSize, int aFileType, const string& aString, const string& aToken) { Lock l(cs); - updateCachedIp(); // no point in doing a resolve for every single hub we're searching on - for(StringIter it = who.begin(); it != who.end(); ++it) { string& client = *it; for(Client::Iter j = clients.begin(); j != clients.end(); ++j) { @@ -493,25 +489,4 @@ } } -void ClientManager::updateCachedIp() { - // Best case - the server detected it - if((!BOOLSETTING(NO_IP_OVERRIDE) || SETTING(EXTERNAL_IP).empty())) { - for(Client::Iter i = clients.begin(); i != clients.end(); ++i) { - if(!(*i)->getMyIdentity().getIp().empty()) { - cachedIp = (*i)->getMyIdentity().getIp(); - return; - } - } - } - - if(!SETTING(EXTERNAL_IP).empty()) { - cachedIp = Socket::resolve(SETTING(EXTERNAL_IP)); - return; - } - - //if we've come this far just use the first client to get the ip. - if(clients.size() > 0) - cachedIp = (*clients.begin())->getLocalIp(); -} - } // namespace dcpp Modified: dcplusplus/trunk/dcpp/ClientManager.h =================================================================== --- dcplusplus/trunk/dcpp/ClientManager.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/ClientManager.h 2007-12-17 23:14:47 UTC (rev 946) @@ -91,8 +91,6 @@ Client::List& getClients() { return clients; } - string getCachedIp() const { Lock l(cs); return cachedIp; } - CID getMyCID(); const CID& getMyPID(); @@ -100,10 +98,10 @@ typedef unordered_map<string, UserPtr> LegacyMap; typedef LegacyMap::iterator LegacyIter; - typedef unordered_map<CID, UserPtr, CID::Hash> UserMap; + typedef unordered_map<CID, UserPtr> UserMap; typedef UserMap::iterator UserIter; - typedef unordered_multimap<CID, OnlineUser*, CID::Hash> OnlineMap; + typedef unordered_multimap<CID, OnlineUser*> OnlineMap; typedef OnlineMap::iterator OnlineIter; typedef OnlineMap::const_iterator OnlineIterC; typedef pair<OnlineIter, OnlineIter> OnlinePair; @@ -119,7 +117,6 @@ Socket udp; - string cachedIp; CID pid; friend class Singleton<ClientManager>; @@ -132,8 +129,6 @@ TimerManager::getInstance()->removeListener(this); } - void updateCachedIp(); - // ClientListener virtual void on(Connected, Client* c) throw() { fire(ClientManagerListener::ClientConnected(), c); } virtual void on(UserUpdated, Client*, const OnlineUser& user) throw() { fire(ClientManagerListener::UserUpdated(), user); } Modified: dcplusplus/trunk/dcpp/DCPlusPlus.h =================================================================== --- dcplusplus/trunk/dcpp/DCPlusPlus.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/DCPlusPlus.h 2007-12-17 23:14:47 UTC (rev 946) @@ -97,6 +97,8 @@ typedef vector<WStringPair> WStringPairList; typedef WStringPairList::iterator WStringPairIter; +typedef vector<uint8_t> ByteVector; + #if defined(_MSC_VER) || defined(__MINGW32__) #define _LL(x) x##ll #define _ULL(x) x##ull Modified: dcplusplus/trunk/dcpp/DirectoryListing.h =================================================================== --- dcplusplus/trunk/dcpp/DirectoryListing.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/DirectoryListing.h 2007-12-17 23:14:47 UTC (rev 946) @@ -80,7 +80,7 @@ typedef vector<Ptr> List; typedef List::iterator Iter; - typedef unordered_set<TTHValue, TTHValue::Hash> TTHSet; + typedef unordered_set<TTHValue> TTHSet; List directories; File::List files; Modified: dcplusplus/trunk/dcpp/FavoriteManager.h =================================================================== --- dcplusplus/trunk/dcpp/FavoriteManager.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/FavoriteManager.h 2007-12-17 23:14:47 UTC (rev 946) @@ -59,7 +59,7 @@ bool isDownloading() { return (useHttp && running); } // Favorite Users - typedef unordered_map<CID, FavoriteUser, CID::Hash> FavoriteMap; + typedef unordered_map<CID, FavoriteUser> FavoriteMap; FavoriteMap getFavoriteUsers() { Lock l(cs); return users; } void addFavoriteUser(UserPtr& aUser); Modified: dcplusplus/trunk/dcpp/File.h =================================================================== --- dcplusplus/trunk/dcpp/File.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/File.h 2007-12-17 23:14:47 UTC (rev 946) @@ -16,8 +16,8 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if !defined(FILE_H) -#define FILE_H +#ifndef DCPLUSPLUS_DCPP_FILE_H +#define DCPLUSPLUS_DCPP_FILE_H #include "SettingsManager.h" Added: dcplusplus/trunk/dcpp/HashBloom.cpp =================================================================== --- dcplusplus/trunk/dcpp/HashBloom.cpp (rev 0) +++ dcplusplus/trunk/dcpp/HashBloom.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -0,0 +1,68 @@ +#include "stdinc.h" +#include "DCPlusPlus.h" + +#include "HashBloom.h" + +namespace dcpp { + +size_t HashBloom::get_k(size_t n) { + const size_t bits = TTHValue::SIZE * 8; + for(size_t k = static_cast<size_t>(sqrt(bits)); k > 1; --k) { + // We only want the k's where the bits will end up on a byte boundary to ease hash implementation + if((bits % k) == 0 && (bits / k) % 8 == 0) { + uint64_t m = get_m(n, k); + if(m >> (TTHValue::SIZE * 8 / k) == 0) { + return k; + } + } + } + return 1; +} + +uint64_t HashBloom::get_m(size_t n, size_t k) { + uint64_t m = (static_cast<uint64_t>(ceil(static_cast<double>(n) * k / log(2.)))); + return ((m / 8) + 1) * 8; +} + +void HashBloom::add(const TTHValue& tth) { + for(size_t i = 0; i < k; ++i) { + bloom[pos(tth, i)] = true; + } +} + +bool HashBloom::match(const TTHValue& tth) const { + if(bloom.empty()) { + return true; + } + for(size_t i = 0; i < k; ++i) { + if(!bloom[pos(tth, i)]) { + return false; + } + } + return true; +} + +void HashBloom::push_back(bool v) { + bloom.push_back(v); +} + +void HashBloom::reset(size_t k_, size_t m) { + bloom.resize(m); + k = k_; +} + +size_t HashBloom::pos(const TTHValue& tth, size_t n) const { + return (*(size_t*)(tth.data + (TTHValue::SIZE / k) * n )) % bloom.size(); +} + +void HashBloom::copy_to(ByteVector& v) const { + size_t ones = 0; + v.resize(bloom.size() / 8); + for(size_t i = 0; i < bloom.size(); ++i) { + ones += bloom[i]; + v[i/8] |= bloom[i] << i % 8; + } + dcdebug("Bloom fill: %u/%u = %lf\n", ones, bloom.size(), static_cast<double>(ones)/bloom.size()); +} + +} Added: dcplusplus/trunk/dcpp/HashBloom.h =================================================================== --- dcplusplus/trunk/dcpp/HashBloom.h (rev 0) +++ dcplusplus/trunk/dcpp/HashBloom.h 2007-12-17 23:14:47 UTC (rev 946) @@ -0,0 +1,40 @@ +#ifndef HASHBLOOM_H_ +#define HASHBLOOM_H_ + +#include "MerkleTree.h" + +namespace dcpp { +/** + * According to http://www.eecs.harvard.edu/~michaelm/NEWWORK/postscripts/BloomFilterSurvey.pdf + * the optimal number of hashes k is (m/n)*ln(2), m = number of bits in the filter and n = number + * of items added. The largest k that we can get from a single TTH value depends on the number of + * bits we need to address the bloom structure, which in turn depends on m, so the optimal size + * for our filter is m = n * k / ln(2) where n is the number of TTH values, or in our case, number of + * files in share since each file is identified by one TTH value. We try that for each even dividend + * of the key size (2, 3, 4, 6, 8, 12) and if m fits within the bits we're able to address (2^(keysize/k)), + * we can use that value when requesting the bloom filter. + */ +class HashBloom { +public: + /** Return the largest k such that get_m returns a value smaller than 2^(TTHValue::SIZE/k) */ + static size_t get_k(size_t n); + /** Optimal number of bits to allocate for n elements when using k hashes */ + static uint64_t get_m(size_t n, size_t k); + + void add(const TTHValue& tth); + bool match(const TTHValue& tth) const; + void reset(size_t k, size_t m); + void push_back(bool v); + + void copy_to(ByteVector& v) const; +private: + + size_t pos(const TTHValue& tth, size_t n) const; + + std::vector<bool> bloom; + size_t k; +}; + +} + +#endif /*HASHBLOOM_H_*/ Modified: dcplusplus/trunk/dcpp/HashManager.h =================================================================== --- dcplusplus/trunk/dcpp/HashManager.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/HashManager.h 2007-12-17 23:14:47 UTC (rev 946) @@ -178,7 +178,7 @@ typedef unordered_map<string, FileInfoList> DirMap; typedef DirMap::iterator DirIter; - typedef unordered_map<TTHValue, TreeInfo, TTHValue::Hash> TreeMap; + typedef unordered_map<TTHValue, TreeInfo> TreeMap; typedef TreeMap::iterator TreeIter; friend class HashLoader; Modified: dcplusplus/trunk/dcpp/HashValue.h =================================================================== --- dcplusplus/trunk/dcpp/HashValue.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/HashValue.h 2007-12-17 23:14:47 UTC (rev 946) @@ -16,10 +16,11 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#if !defined(HASH_VALUE_H) -#define HASH_VALUE_H +#ifndef DCPLUSPLUS_DCPP_HASH_VALUE_H +#define DCPLUSPLUS_DCPP_HASH_VALUE_H #include "FastAlloc.h" +#include "Encoder.h" namespace dcpp { @@ -27,25 +28,30 @@ struct HashValue : FastAlloc<HashValue<Hasher> >{ static const size_t SIZE = Hasher::HASH_SIZE; - struct Hash { - size_t operator()(const HashValue& rhs) const { return *(size_t*)&rhs; } - }; - HashValue() { } explicit HashValue(uint8_t* aData) { memcpy(data, aData, SIZE); } - explicit HashValue(const string& base32) { Encoder::fromBase32(base32.c_str(), data, SIZE); } + explicit HashValue(const std::string& base32) { Encoder::fromBase32(base32.c_str(), data, SIZE); } HashValue(const HashValue& rhs) { memcpy(data, rhs.data, SIZE); } HashValue& operator=(const HashValue& rhs) { memcpy(data, rhs.data, SIZE); return *this; } bool operator!=(const HashValue& rhs) const { return !(*this == rhs); } bool operator==(const HashValue& rhs) const { return memcmp(data, rhs.data, SIZE) == 0; } bool operator<(const HashValue& rhs) const { return memcmp(data, rhs.data, SIZE) < 0; } - string toBase32() const { return Encoder::toBase32(data, SIZE); } - string& toBase32(string& tmp) const { return Encoder::toBase32(data, SIZE, tmp); } + std::string toBase32() const { return Encoder::toBase32(data, SIZE); } + std::string& toBase32(std::string& tmp) const { return Encoder::toBase32(data, SIZE, tmp); } uint8_t data[SIZE]; }; } // namespace dcpp +namespace std { namespace tr1 { +template<> +template<typename T> +struct hash<dcpp::HashValue<T> > { + size_t operator()(const dcpp::HashValue<T>& rhs) const { return *(size_t*)rhs.data; } +}; +} +} + #endif // !defined(HASH_VALUE_H) Modified: dcplusplus/trunk/dcpp/MerkleTree.h =================================================================== --- dcplusplus/trunk/dcpp/MerkleTree.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/MerkleTree.h 2007-12-17 23:14:47 UTC (rev 946) @@ -146,8 +146,8 @@ root = getHash(0, fileSize); } - vector<uint8_t> getLeafData() { - vector<uint8_t> buf(getLeaves().size() * HASH_SIZE); + ByteVector getLeafData() { + ByteVector buf(getLeaves().size() * HASH_SIZE); uint8_t* p = &buf[0]; for(size_t i = 0; i < getLeaves().size(); ++i) { memcpy(p + i * HASH_SIZE, &getLeaves()[i], HASH_SIZE); Modified: dcplusplus/trunk/dcpp/NmdcHub.cpp =================================================================== --- dcplusplus/trunk/dcpp/NmdcHub.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/NmdcHub.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -238,7 +238,7 @@ // Filter own searches if(ClientManager::getInstance()->isActive()) { - if(seeker == (ClientManager::getInstance()->getCachedIp() + ":" + Util::toString(SearchManager::getInstance()->getPort()))) { + if(seeker == (getLocalIp() + ":" + Util::toString(SearchManager::getInstance()->getPort()))) { return; } } else { @@ -810,7 +810,7 @@ int chars = 0; size_t BUF_SIZE; if(ClientManager::getInstance()->isActive()) { - string x = ClientManager::getInstance()->getCachedIp(); + string x = getLocalIp(); BUF_SIZE = x.length() + aString.length() + 64; buf = new char[BUF_SIZE]; chars = snprintf(buf, BUF_SIZE, "$Search %s:%d %c?%c?%s?%d?%s|", x.c_str(), (int)SearchManager::getInstance()->getPort(), c1, c2, Util::toString(aSize).c_str(), aFileType+1, tmp.c_str()); Modified: dcplusplus/trunk/dcpp/QueueManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/QueueManager.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/QueueManager.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -556,7 +556,7 @@ return qi->getPriority(); } namespace { -typedef unordered_map<TTHValue, const DirectoryListing::File*, TTHValue::Hash> TTHMap; +typedef unordered_map<TTHValue, const DirectoryListing::File*> TTHMap; // *** WARNING *** // Lock(cs) makes sure that there's only one thread accessing this Modified: dcplusplus/trunk/dcpp/QueueManager.h =================================================================== --- dcplusplus/trunk/dcpp/QueueManager.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/QueueManager.h 2007-12-17 23:14:47 UTC (rev 946) @@ -135,7 +135,7 @@ CriticalSection cs; } mover; - typedef unordered_map<CID, string, CID::Hash> PfsQueue; + typedef unordered_map<CID, string> PfsQueue; typedef PfsQueue::iterator PfsIter; /** All queue items by target */ Modified: dcplusplus/trunk/dcpp/SettingsManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/SettingsManager.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/SettingsManager.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -77,6 +77,7 @@ "UseTLS", "AutoSearchLimit", "AltSortOrder", "AutoKickNoFavs", "PromptPassword", "SpyFrameIgnoreTthSearches", "DontDlAlreadyQueued", "MaxCommandLength", "AllowUntrustedHubs", "AllowUntrustedClients", "TLSPort", "FastHash", "SortFavUsersFirst", "ShowShellMenu", "MinSegmentSize", "FollowLinks", + "SendBloom", "SENTRY", // Int64 "TotalUpload", "TotalDownload", @@ -271,6 +272,7 @@ setDefault(SHOW_SHELL_MENU, false); setDefault(MIN_SEGMENT_SIZE, 1024); setDefault(FOLLOW_LINKS, false); + setDefault(SEND_BLOOM, true); #ifdef _WIN32 setDefault(MAIN_WINDOW_STATE, SW_SHOWNORMAL); Modified: dcplusplus/trunk/dcpp/SettingsManager.h =================================================================== --- dcplusplus/trunk/dcpp/SettingsManager.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/SettingsManager.h 2007-12-17 23:14:47 UTC (rev 946) @@ -89,6 +89,7 @@ USE_TLS, AUTO_SEARCH_LIMIT, ALT_SORT_ORDER, AUTO_KICK_NO_FAVS, PROMPT_PASSWORD, SPY_FRAME_IGNORE_TTH_SEARCHES, DONT_DL_ALREADY_QUEUED, MAX_COMMAND_LENGTH, ALLOW_UNTRUSTED_HUBS, ALLOW_UNTRUSTED_CLIENTS, TLS_PORT, FAST_HASH, SORT_FAVUSERS_FIRST, SHOW_SHELL_MENU, MIN_SEGMENT_SIZE, FOLLOW_LINKS, + SEND_BLOOM, INT_LAST }; enum Int64Setting { INT64_FIRST = INT_LAST + 1, Modified: dcplusplus/trunk/dcpp/ShareManager.cpp =================================================================== --- dcplusplus/trunk/dcpp/ShareManager.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/ShareManager.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -36,6 +36,7 @@ #include "Transfer.h" #include "UserConnection.h" #include "Download.h" +#include "HashBloom.h" #ifndef _WIN32 #include <sys/types.h> @@ -178,7 +179,7 @@ } } - vector<uint8_t> buf = tree.getLeafData(); + ByteVector buf = tree.getLeafData(); return new MemoryInputStream(&buf[0], buf.size()); } @@ -831,6 +832,19 @@ return 0; } +void ShareManager::getBloom(ByteVector& v, size_t k, size_t m) const { + dcdebug("Creating bloom filter, k=%u, m=%u\n", k, m); + Lock l(cs); + + HashBloom bloom; + bloom.reset(k, m); + for(HashFileMap::const_iterator i = tthIndex.begin(); i != tthIndex.end(); ++i) { + bloom.add(i->first); + } + bloom.copy_to(v); +} + + void ShareManager::generateXmlList() { Lock l(cs); if(xmlDirty && (lastXmlUpdate + 15 * 60 * 1000 < GET_TICK() || lastXmlUpdate < lastFullUpdate)) { Modified: dcplusplus/trunk/dcpp/ShareManager.h =================================================================== --- dcplusplus/trunk/dcpp/ShareManager.h 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/ShareManager.h 2007-12-17 23:14:47 UTC (rev 946) @@ -80,6 +80,8 @@ string getShareSizeString() const { return Util::toString(getShareSize()); } string getShareSizeString(const string& aDir) const { return Util::toString(getShareSize(aDir)); } + + void getBloom(ByteVector& v, size_t k, size_t m) const; SearchManager::TypeModes getType(const string& fileName) const throw(); @@ -256,7 +258,7 @@ // Map real name to directory structure Directory::Map directories; - typedef unordered_map<TTHValue, Directory::File::Set::const_iterator, TTHValue::Hash> HashFileMap; + typedef unordered_map<TTHValue, Directory::File::Set::const_iterator> HashFileMap; typedef HashFileMap::iterator HashFileIter; HashFileMap tthIndex; Modified: dcplusplus/trunk/dcpp/Socket.cpp =================================================================== --- dcplusplus/trunk/dcpp/Socket.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/dcpp/Socket.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -179,7 +179,7 @@ socksAuth(timeLeft(start, timeout)); - vector<uint8_t> connStr; + ByteVector connStr; // Authenticated, let's get on with it... connStr.push_back(5); // SOCKSv5 Modified: dcplusplus/trunk/win32/AboutDlg.cpp =================================================================== --- dcplusplus/trunk/win32/AboutDlg.cpp 2007-12-15 22:26:23 UTC (rev 945) +++ dcplusplus/trunk/win32/AboutDlg.cpp 2007-12-17 23:14:47 UTC (rev 946) @@ -41,7 +41,8 @@ "defr, ullner, fleetcommand, liny, xan, olle svensson, mark gillespie, jeremy huddleston, " "bsod, sulan, jonathan stone, tim burton, izzzo, guitarm, paka, nils maier, jens oknelid, yoji, " "krzysztof tyszecki, poison, pothead, pur, bigmuscle, martin, jove, bart vullings, " -"steven sheehy, tobias nygren, poy, dorian, stephan hohe, mafa_45, mikael eman, james ross. " +"steven sheehy, tobias nygren, poy, dorian, stephan hohe, mafa_45, mikael eman, james ross," +"stanislav maslovski. " "Keep it coming!"; AboutDlg::AboutDlg(SmartWin::Widget* parent) : SmartWin::WidgetFactory<SmartWin::WidgetModalDialog>(parent) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |