From 465bbbf406bcc03cf798196914fcc95439689d63 Mon Sep 17 00:00:00 2001 From: Arvid Norberg Date: Sun, 23 Jun 2013 08:07:39 +0000 Subject: [PATCH] fix dht issue for platforms where char is unsigned. introduce assert --- src/kademlia/node.cpp | 7 ++++--- test/test_dht.cpp | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/kademlia/node.cpp b/src/kademlia/node.cpp index aae75de1e..27d361d55 100644 --- a/src/kademlia/node.cpp +++ b/src/kademlia/node.cpp @@ -128,7 +128,7 @@ bool node_impl::verify_token(std::string const& token, char const* info_hash h1.update((char*)info_hash, sha1_hash::size); sha1_hash h = h1.final(); - if (std::equal(token.begin(), token.end(), (signed char*)&h[0])) + if (std::equal(token.begin(), token.end(), (char*)&h[0])) return true; hasher h2; @@ -136,7 +136,7 @@ bool node_impl::verify_token(std::string const& token, char const* info_hash h2.update((char*)&m_secret[1], sizeof(m_secret[1])); h2.update((char*)info_hash, sha1_hash::size); h = h2.final(); - if (std::equal(token.begin(), token.end(), (signed char*)&h[0])) + if (std::equal(token.begin(), token.end(), (char*)&h[0])) return true; return false; } @@ -154,7 +154,8 @@ std::string node_impl::generate_token(udp::endpoint const& addr, char const* inf h.update(info_hash, sha1_hash::size); sha1_hash hash = h.final(); - std::copy(hash.begin(), hash.begin() + 4, (signed char*)&token[0]); + std::copy(hash.begin(), hash.begin() + 4, (char*)&token[0]); + TORRENT_ASSERT(std::equal(token.begin(), token.end(), (char*)&hash[0])); return token; } diff --git a/test/test_dht.cpp b/test/test_dht.cpp index 711e37014..5e600e1fa 100644 --- a/test/test_dht.cpp +++ b/test/test_dht.cpp @@ -122,7 +122,8 @@ void send_dht_msg(node_impl& node, char const* msg, udp::endpoint const& ep char msg_buf[1500]; int size = bencode(msg_buf, e); #if defined TORRENT_DEBUG && TORRENT_USE_IOSTREAM - std::cerr << "sending: " << e << "\n"; +// this yields a lot of output. too much +// std::cerr << "sending: " << e << "\n"; #endif lazy_entry decoded;