Changeset 1426
- Timestamp:
- 07/07/05 12:02:02 (3 years ago)
- Files:
-
- hydranode/include/hn/endian.h (modified) (1 diff)
- hydranode/include/hn/hash.h (modified) (2 diffs)
- hydranode/include/hn/utils.h (modified) (3 diffs)
- hydranode/modules/ed2k/clients.cpp (modified) (5 diffs)
- hydranode/modules/ed2k/creditsdb.cpp (modified) (5 diffs)
- hydranode/modules/ed2k/ed2kfile.cpp (modified) (1 diff)
- hydranode/modules/ed2k/packets.cpp (modified) (42 diffs)
- hydranode/modules/ed2k/publickey.h (modified) (1 diff)
- hydranode/modules/ed2k/server.cpp (modified) (1 diff)
- hydranode/modules/ed2k/tag.cpp (modified) (4 diffs)
- hydranode/src/hash.cpp (modified) (4 diffs)
- hydranode/src/metadata.cpp (modified) (20 diffs)
- hydranode/src/metadb.cpp (modified) (1 diff)
- hydranode/src/partdata.cpp (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
hydranode/include/hn/endian.h
r1424 r1426 60 60 #endif 61 61 62 // We don't want these to be defined 63 #ifdef LITTLE_ENDIAN 64 #undef LITTLE_ENDIAN 65 #endif 66 #ifdef BIG_ENDIAN 67 #undef BIG_ENDIAN 68 #endif 69 62 70 #if defined (__sparc__) || defined (__alpha__) || defined (__PPC__) || defined (__mips__) || defined (__ppc__) 63 71 #define __BIG_ENDIAN__ 64 72 #endif 73 74 /** 75 * Endianess identifier 76 */ 77 enum { 78 LITTLE_ENDIAN = false, 79 BIG_ENDIAN = true, 80 #ifdef __BIG_ENDIAN__ 81 HOST_ENDIAN = BIG_ENDIAN //!< Host is big_endian system 82 #else 83 HOST_ENDIAN = LITTLE_ENDIAN //!< Host is little_endian system 84 #endif 85 }; 86 65 87 66 88 #if defined(__BIG_ENDIAN__) hydranode/include/hn/hash.h
r1151 r1426 378 378 break; 379 379 } 380 Utils::getVal<uint16_t>(i); // length380 (void)Utils::getVal<uint16_t>(i); // length 381 381 uint8_t id = Utils::getVal<uint8_t>(i); 382 382 if (id != FileHashType::getTypeId()) { … … 406 406 break; 407 407 } 408 Utils::getVal<uint16_t>(i); // length408 (void)Utils::getVal<uint16_t>(i); // length 409 409 uint8_t id = Utils::getVal<uint8_t>(i); 410 410 if (id != HashType::getTypeId()) { hydranode/include/hn/utils.h
r1394 r1426 33 33 #include <boost/shared_array.hpp> 34 34 #include <boost/filesystem/path.hpp> 35 #include <boost/type_traits.hpp> 35 36 36 37 /** … … 38 39 */ 39 40 namespace Utils { 41 42 /** 43 * A type to carry stream endianess 44 * 45 * @param Endianess Utils::LITTLE_ENDIAN or Utils::BIG_ENDIAN 46 */ 47 template<bool Endianess> class EndianType { }; 48 49 /** 50 * An object who's carrying endianess information. 51 * 52 * @param T Stream type 53 * @param Endianess Utils::LITTLE_ENDIAN or Utils::BIG_ENDIAN 54 */ 55 template<typename T, bool Endianess> class EndianStream 56 : public T, public EndianType<Endianess> { }; 57 58 /** 59 * Endianess test. GetEndianInfo<T>::value returns the endianess (if no 60 * endianess is available, Utils::LITTLE_ENDIAN is assumed) 61 */ 62 template<typename T> struct GetEndianInfo { 63 enum { value = 64 ::boost::is_base_and_derived< 65 EndianType<BIG_ENDIAN>, T 66 >::value 67 }; 68 }; 69 70 /** 71 * Swaps endianess if swap is true for various type of data T via the 72 * static function swap. 73 */ 74 template<typename T, bool Swap> struct SwapData; 75 76 //! @name Specializations for swapping various datas 77 //@{ 78 // If host endianess is equal to stream's one, then do not swap 79 template<typename T> struct SwapData<T, false> { 80 static T swap(T t) { return t; }; 81 }; 82 83 // uint8_t never get swapped 84 template<> struct SwapData<uint8_t, true> { 85 static uint8_t swap(uint8_t t) { return t; }; 86 }; 87 // uint16_t 88 template<> struct SwapData<uint16_t, true> { 89 static uint16_t swap(uint16_t t) { return SWAP16_ALWAYS(t); } 90 }; 91 // uint32_t 92 template<> struct SwapData<uint32_t, true> { 93 static uint32_t swap(uint32_t t) { return SWAP32_ALWAYS(t); } 94 }; 95 // uint64_t 96 template<> struct SwapData<uint64_t, true> { 97 static uint64_t swap(uint64_t t) { return SWAP64_ALWAYS(t); } 98 }; 99 // float 100 template<> struct SwapData<float, true> { 101 static float swap(float t) { 102 return (float)SWAP32_ALWAYS((uint32_t)t); 103 } 104 }; 105 // unimplemented 106 template<typename T> struct SwapData<T, true> { 107 static T swap(T t) { 108 BOOST_STATIC_ASSERT(sizeof(T::__type_not_supported__)); 109 } 110 }; 111 112 //@} 113 114 /** 115 * This function takes care of swapping data if streams need it. 116 */ 117 template<typename T, typename Stream> inline T swapHostToStream(T t) { 118 // since values are boolean, !! avoids this warning on gcc4.0.0: 119 // comparison between `enum Utils::GetEndianInfo<...> 120 // ::<anonymous>` and `enum Utils::<anonymous>` 121 122 return SwapData< 123 T, !!GetEndianInfo<Stream>::value != !!HOST_ENDIAN 124 >::swap(t); 125 } 126 40 127 /** 41 128 * Convert passed data into hexadecimal notation. … … 133 220 }; 134 221 135 //! Primary template is not implemented, and causes compile-time 136 //! error if instanciated. 137 template<class T> inline T getVal(std::istream &i) { 138 BOOST_STATIC_ASSERT(sizeof(T::__type_not_supported__)); 139 } 140 141 //! @name Specializations for reading various datas 142 //@{ 222 /** 223 * Generic getVal functor 224 */ 225 template<typename T = std::string> 226 struct getVal { 227 //! Conversion to T 228 operator T() const { return m_value; } 229 230 //! Explicit access to read value 231 T value() const { return m_value; } 232 233 //! Generic constructor 234 template<typename Stream> 235 getVal(Stream &s) { 236 s.read(reinterpret_cast<char *>(&m_value), sizeof(T)); 237 238 if(!s.good()) { 239 throw ReadError("reading from stream"); 240 } 241 m_value = swapHostToStream<T, Stream>(m_value); 242 } 243 private: 244 T m_value; 245 }; 246 247 /** 248 * std::string specialization of getVal 249 */ 143 250 template<> 144 inline uint8_t getVal(std::istream &i) { 145 uint8_t tmp; 146 i.read(reinterpret_cast<char*>(&tmp), 1); 147 if (!i.good()) { 148 throw ReadError("reading from stream"); 149 } 150 return tmp; 151 } 251 struct getVal<std::string> { 252 //! Conversion to T 253 operator std::string() const { return m_value; } 254 255 //! Explicit access to read value 256 std::string value() const { return m_value; } 257 258 //! @name std::string getVal constructors 259 //@{ 260 template<typename Stream> 261 getVal(Stream &i) { 262 uint16_t len = getVal<uint16_t>(i); 263 boost::scoped_array<char> buf(new char[len]); 264 i.read(buf.get(), len); 265 266 if (!i.good()) { 267 throw ReadError("reading from stream"); 268 } 269 270 m_value = std::string(buf.get(), len); 271 } 272 getVal(std::istream &i, uint32_t len) { 273 boost::scoped_array<char> tmp(new char[len]); 274 i.read(tmp.get(), len); 275 276 if (!i.good()) { 277 throw ReadError("reading from stream"); 278 } 279 280 m_value = std::string(tmp.get(), len); 281 } 282 //@} 283 private: 284 std::string m_value; 285 }; 286 287 /** 288 * Generic putVal functor 289 */ 290 template<typename T = std::string> 291 struct putVal { 292 //! Generic constructor 293 template<typename Stream> 294 putVal(Stream &s, T t) { 295 T tmp = swapHostToStream<T, Stream>(t); 296 297 s.write(reinterpret_cast<char *>(&tmp), sizeof(T)); 298 } 299 }; 300 301 /** 302 * std::string specialization of putVal 303 */ 152 304 template<> 153 inline uint16_t getVal(std::istream &i) { 154 uint16_t tmp; 155 i.read(reinterpret_cast<char*>(&tmp), 2); 156 tmp = SWAP16_ON_BE(tmp); 157 if (!i.good()) { 158 throw ReadError("reading from stream"); 159 } 160 return tmp; 161 } 162 template<> 163 inline uint32_t getVal(std::istream &i) { 164 uint32_t tmp; 165 i.read(reinterpret_cast<char*>(&tmp), 4); 166 tmp = SWAP32_ON_BE(tmp); 167 if (!i.good()) { 168 throw ReadError("reading from stream"); 169 } 170 return tmp; 171 } 172 template<> 173 inline uint64_t getVal(std::istream &i) { 174 uint64_t tmp; 175 i.read(reinterpret_cast<char*>(&tmp), 8); 176 tmp = SWAP64_ON_BE(tmp); 177 if (!i.good()) { 178 throw ReadError("reading from stream"); 179 } 180 return tmp; 181 } 182 template<> 183 inline float getVal(std::istream &i) { 184 float tmp; 185 i.read(reinterpret_cast<char*>(&tmp), 4); 186 tmp = (float)SWAP32_ON_BE(*(uint32_t*)(&tmp)); 187 if (!i.good()) { 188 throw ReadError("reading from stream"); 189 } 190 return tmp; 191 } 192 template<> 193 inline std::string getVal(std::istream &i) { 194 uint16_t len = getVal<uint16_t>(i); 195 boost::scoped_array<char> buf(new char[len]); 196 i.read(buf.get(), len); 197 if (!i.good()) { 198 throw ReadError("reading from stream"); 199 } 200 return std::string(buf.get(), len); 201 } 202 template<class T> 203 inline T getVal(std::istream &i, uint32_t len) { 204 T tmp; 205 i.read(&tmp, len); 206 if (!i.good()) { 207 throw ReadError("reading from stream"); 208 } 209 return tmp; 210 } 211 template<> 212 inline std::string getVal(std::istream &i, uint32_t len) { 213 boost::scoped_array<char> tmp(new char[len]); 214 i.read(tmp.get(), len); 215 if (!i.good()) { 216 throw ReadError("reading from stream"); 217 } 218 return std::string(tmp.get(), len); 219 } 220 //@} 221 222 //! Write. Primary template not implemented and causes compile-time 223 //! failure if instanciated. 224 template<class T> 225 inline void putVal(std::ostream &o, T val) { 226 BOOST_STATIC_ASSERT(sizeof(T::__undefined_type__)); 227 } 228 229 //! @name Writing function template specializations. 230 //@{ 231 template<> 232 inline void putVal(std::ostream &o, uint8_t val) { 233 o.put(val); 234 } 235 template<> 236 inline void putVal(std::ostream &o, uint16_t val) { 237 val = SWAP16_ON_BE(val); 238 o.write(reinterpret_cast<char*>(&val), 2); 239 } 240 template<> 241 inline void putVal(std::ostream &o, uint32_t val) { 242 val = SWAP32_ON_BE(val); 243 o.write(reinterpret_cast<char*>(&val), 4); 244 } 245 template<> 246 inline void putVal(std::ostream &o, uint64_t val) { 247 val = SWAP64_ON_BE(val); 248 o.write(reinterpret_cast<char*>(&val), 8); 249 } 250 template<> 251 inline void putVal(std::ostream &o, float val) { 252 val = (float)SWAP32_ON_BE(*(uint32_t*)&val); 253 o.write(reinterpret_cast<char*>(&val), 4); 254 } 255 template<> 256 inline void putVal(std::ostream &o, const std::string &str) { 257 putVal<uint16_t>(o, str.size()); 258 o.write(str.data(), str.size()); 259 } 260 template<> 261 inline void putVal(std::ostream &o, std::string str) { 262 putVal<uint16_t>(o, str.size()); 263 o.write(str.data(), str.size()); 264 } 265 inline void putVal( 266 std::ostream &o, const std::string &str, uint32_t len 267 ) { 268 o.write(str.data(), len); 269 } 270 inline void putVal( 271 std::ostream &o, const char *const str, uint32_t len 272 ) { 273 CHECK_THROW(str); 274 o.write(str, len); 275 } 276 inline void putVal( 277 std::ostream &o, const uint8_t *const str, uint32_t len 278 ) { 279 CHECK_THROW(str); 280 o.write(reinterpret_cast<const char*>(str), len); 281 } 282 inline void putVal( 283 std::ostream &o, const boost::shared_array<char> &str, 284 uint32_t len 285 ) { 286 CHECK_THROW(str); 287 o.write(str.get(), len); 288 } 289 //@} 305 struct putVal<std::string> { 306 //! @name std::string putVal constructors 307 //@{ 308 template<typename Stream> 309 putVal(Stream &o, const std::string &str) { 310 putVal<uint16_t>(o, str.size()); 311 o.write(str.data(), str.size()); 312 } 313 314 template<typename Stream> 315 putVal(Stream &o, const std::string &str, uint32_t len) { 316 o.write(str.data(), len); 317 } 318 319 template<typename Stream> 320 putVal(Stream &o, const char *const str, uint32_t len) { 321 CHECK_THROW(str); 322 o.write(str, len); 323 } 324 325 template<typename Stream> 326 putVal(Stream &o, const uint8_t *const str, uint32_t len) { 327 CHECK_THROW(str); 328 o.write(reinterpret_cast<const char*>(str), len); 329 } 330 331 template<typename Stream> 332 putVal( 333 Stream &o, 334 const boost::shared_array<char> &str, 335 uint32_t len 336 ) { 337 CHECK_THROW(str); 338 o.write(str.get(), len); 339 } 340 //@} 341 }; 290 342 291 343 /** hydranode/modules/ed2k/clients.cpp
r1382 r1426 243 243 m_callbackInProgress = true; 244 244 } catch (std::exception &e) { 245 (void)e; 245 246 logTrace( 246 247 TRACE_DEADSRC, boost::format( … … 867 868 establishConnection(); 868 869 } catch (std::exception &e) { 870 (void)e; 869 871 logTrace(TRACE_DEADSRC, 870 872 boost::format("[%s] Unable to connect to client: %s") … … 1417 1419 % getIpPort() % e.what() 1418 1420 ); 1421 (void)e; 1419 1422 } 1420 1423 … … 1533 1536 % getIpPort() % e.what() 1534 1537 ); 1538 (void)e; 1535 1539 } 1536 1540 … … 1645 1649 % getIpPort() % e.what() 1646 1650 ); 1651 (void)e; 1647 1652 } 1648 1653 hydranode/modules/ed2k/creditsdb.cpp
r1279 r1426 50 50 // Construct and load 51 51 Credits::Credits(std::istream &i, uint8_t ver) { 52 m_hash = Utils::getVal<std::string>(i, 16) ;52 m_hash = Utils::getVal<std::string>(i, 16).value(); 53 53 uint32_t uploadLow = Utils::getVal<uint32_t>(i); 54 54 uint32_t downloadLow = Utils::getVal<uint32_t>(i); … … 79 79 // Write to stream 80 80 std::ostream& operator<<(std::ostream &o, const Credits &c) { 81 Utils::putVal (o, c.m_hash.getData(), 16);81 Utils::putVal<std::string>(o, c.m_hash.getData(), 16); 82 82 Utils::putVal<uint32_t>(o, c.m_uploaded); 83 83 Utils::putVal<uint32_t>(o, c.m_downloaded); … … 88 88 89 89 Utils::putVal<uint8_t>(o, c.m_pubKey.size()); 90 Utils::putVal (o, c.m_pubKey.c_str(), c.m_pubKey.size());90 Utils::putVal<std::string>(o, c.m_pubKey.c_str(), c.m_pubKey.size()); 91 91 92 92 // add padding if keysize is < 80 (required for compatibility) 93 93 if ( c.m_pubKey.size() < ED2K_MaxKeySize ) { 94 94 std::string dummyStr(ED2K_MaxKeySize - c.m_pubKey.size(), '\0'); 95 Utils::putVal (o, dummyStr, dummyStr.size());95 Utils::putVal<std::string>(o, dummyStr, dummyStr.size()); 96 96 } 97 97 … … 268 268 // construct the message 269 269 std::ostringstream tmp; 270 Utils::putVal (tmp, key.c_str(), key.size());270 Utils::putVal<std::string>(tmp, key.c_str(), key.size()); 271 271 Utils::putVal<uint32_t>(tmp, challenge); 272 272 if (ipType) { … … 303 303 304 304 std::ostringstream tmp; 305 Utils::putVal (305 Utils::putVal<std::string>( 306 306 tmp, instance().m_pubKey.c_str(), instance().m_pubKey.size() 307 307 ); hydranode/modules/ed2k/ed2kfile.cpp
r818 r1426 54 54 55 55 std::ostream& operator<<(std::ostream &o, const ED2KFile &f) { 56 Utils::putVal (o, f.m_hash.getData(), 16);56 Utils::putVal<std::string>(o, f.m_hash.getData(), 16); 57 57 if (f.m_flags & ED2KFile::FL_USECOMPLETEINFO) { 58 58 if (f.m_flags & ED2KFile::FL_COMPLETE) { hydranode/modules/ed2k/packets.cpp
r1421 r1426 110 110 uint16_t cnt = Utils::getVal<uint16_t>(i); 111 111 while (cnt && i) { 112 std::bitset<8> tmp(Utils::getVal<uint8_t>(i) );112 std::bitset<8> tmp(Utils::getVal<uint8_t>(i).value()); 113 113 for (uint8_t i = 0; i < (cnt >= 8 ? 8 : cnt); ++i) { 114 114 partMap->push_back(tmp[i]); … … 161 161 Utils::putVal<uint8_t>(tmp, m_proto); 162 162 Utils::putVal<uint32_t>(tmp, packet.size()); 163 Utils::putVal (tmp, packet, packet.size());163 Utils::putVal<std::string>(tmp, packet, packet.size()); 164 164 #ifndef HEXDUMPS 165 165 if (hexDump) … … 201 201 std::ostringstream tmp; 202 202 Utils::putVal<uint8_t>(tmp, OP_LOGINREQUEST); 203 Utils::putVal (tmp, ED2K::instance().getHash().getData(), 16);203 Utils::putVal<std::string>(tmp, ED2K::instance().getHash().getData(), 16); 204 204 Utils::putVal<uint32_t>(tmp, 0); // clientid 205 205 Utils::putVal<uint16_t>(tmp, ED2K::instance().getTcpPort()); … … 251 251 // ----------------- 252 252 ServerIdent::ServerIdent(std::istream &i) { 253 m_hash = Utils::getVal<std::string>(i, 16) ;253 m_hash = Utils::getVal<std::string>(i, 16).value(); 254 254 m_addr.setAddr(Utils::getVal<uint32_t>(i)); 255 255 m_addr.setPort(Utils::getVal<uint16_t>(i)); … … 344 344 Utils::putVal<uint8_t>(tmp, stringParameter); 345 345 Utils::putVal<uint16_t>(tmp, terms.size()); 346 Utils::putVal (tmp, terms, terms.size());346 Utils::putVal<std::string>(tmp, terms, terms.size()); 347 347 ++paramCount; 348 348 … … 354 354 Utils::putVal<uint8_t>(tmp, typeParameter); 355 355 Utils::putVal<uint16_t>(tmp, type.size()); 356 Utils::putVal (tmp, type, type.size());356 Utils::putVal<std::string>(tmp, type, type.size()); 357 357 // Who on earth came up with the idea of a 3-byte field ? *DOH* 358 358 uint32_t _tmp(typeNemonic); … … 381 381 std::ostringstream packet; 382 382 Utils::putVal<uint8_t>(packet, OP_SEARCH); 383 Utils::putVal (packet, tmp.str(), tmp.str().size());383 Utils::putVal<std::string>(packet, tmp.str(), tmp.str().size()); 384 384 return makePacket(packet.str()); 385 385 } … … 395 395 while (count-- && i) { 396 396 Hash<ED2KHash> h(Utils::getVal<std::string>(i, 16)); 397 Utils::getVal<uint32_t>(i); // id - ignored398 Utils::getVal<uint16_t>(i); // port - ignored397 (void)Utils::getVal<uint32_t>(i); // id - ignored 398 (void)Utils::getVal<uint16_t>(i); // port - ignored 399 399 uint32_t tagCount = Utils::getVal<uint32_t>(i); 400 400 std::string name; … … 491 491 std::ostringstream tmp; 492 492 Utils::putVal<uint8_t>(tmp, OP_GETSOURCES); 493 Utils::putVal (tmp, m_hash.getData(), 16);493 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 494 494 return makePacket(tmp.str()); 495 495 } … … 498 498 // ------------------ 499 499 FoundSources::FoundSources(std::istream &i) : m_lowCount() { 500 m_hash = Utils::getVal<std::string>(i, 16) ;500 m_hash = Utils::getVal<std::string>(i, 16).value(); 501 501 uint8_t cnt = Utils::getVal<uint8_t>(i); 502 502 while (cnt--) { … … 518 518 Utils::putVal<uint8_t>(tmp, OP_GLOBGETSOURCES); 519 519 for (uint32_t i = 0; i < m_hashList.size(); ++i) { 520 Utils::putVal (tmp, m_hashList[i].first.getData(), 16);520 Utils::putVal<std::string>(tmp, m_hashList[i].first.getData(), 16); 521 521 if (m_sendSize) { 522 522 Utils::putVal<uint32_t>(tmp, m_hashList[i].second); … … 529 529 // ---------------------- 530 530 GlobFoundSources::GlobFoundSources(std::istream &i) { 531 m_hash = Utils::getVal<std::string>(i, 16) ;531 m_hash = Utils::getVal<std::string>(i, 16).value(); 532 532 uint8_t cnt = Utils::getVal<uint8_t>(i); 533 533 while (i && cnt--) { … … 612 612 } 613 613 } 614 m_hash = Utils::getVal<std::string>(i, 16) ;614 m_hash = Utils::getVal<std::string>(i, 16).value(); 615 615 m_clientAddr.setAddr(Utils::getVal<uint32_t>(i)); 616 616 m_clientAddr.setPort(Utils::getVal<uint16_t>(i)); … … 658 658 659 659 // Get our own userhash from ED2K class 660 Utils::putVal (tmp, ED2K::instance().getHash().getData(), 16);660 Utils::putVal<std::string>(tmp, ED2K::instance().getHash().getData(), 16); 661 661 // Get our own ip/port from ED2K class 662 662 Utils::putVal<uint32_t>(tmp, ED2K::instance().getId()); … … 787 787 ReqFile::ReqFile(std::istream &i) { 788 788 try { 789 m_hash = Utils::getVal<std::string>(i, 16) ;789 m_hash = Utils::getVal<std::string>(i, 16).value(); 790 790 readPartMap(i, &m_partMap); 791 791 m_srcCnt = Utils::getVal<uint16_t>(i); … … 796 796 std::ostringstream tmp; 797 797 Utils::putVal<uint8_t>(tmp, OP_REQFILE); 798 Utils::putVal (tmp, m_hash.getData(), 16);798 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 799 799 writePartMap(tmp, m_partMap); 800 800 Utils::putVal<uint16_t>(tmp, m_srcCnt); … … 807 807 : m_hash(h), m_name(filename) {} 808 808 FileName::FileName(std::istream &i) { 809 m_hash = Utils::getVal<std::string>(i, 16) ;809 m_hash = Utils::getVal<std::string>(i, 16).value(); 810 810 uint16_t len = Utils::getVal<uint16_t>(i); 811 811 m_name = Utils::getVal<std::string>(i, len); … … 814 814 std::ostringstream tmp; 815 815 Utils::putVal<uint8_t>(tmp, OP_FILENAME); 816 Utils::putVal (tmp, m_hash.getData(), 16);816 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 817 817 Utils::putVal<uint16_t>(tmp, m_name.size()); 818 Utils::putVal (tmp, m_name, m_name.size());818 Utils::putVal<std::string>(tmp, m_name, m_name.size()); 819 819 return makePacket(tmp.str()); 820 820 } … … 825 825 : m_rating(rating), m_comment(comment) {} 826 826 FileDesc::FileDesc(std::istream &i) { 827 m_rating = static_cast<ED2KFile::Rating>(Utils::getVal<uint8_t>(i) );827 m_rating = static_cast<ED2KFile::Rating>(Utils::getVal<uint8_t>(i).value()); 828 828 uint32_t len = Utils::getVal<uint32_t>(i); 829 829 m_comment = Utils::getVal<std::string>(i, len); … … 834 834 Utils::putVal<uint8_t>(tmp, m_rating); 835 835 Utils::putVal<uint32_t>(tmp, m_comment.size()); 836 Utils::putVal (tmp, m_comment, m_comment.size());836 Utils::putVal<std::string>(tmp, m_comment, m_comment.size()); 837 837 return makePacket(tmp.str()); 838 838 } … … 842 842 SetReqFileId::SetReqFileId(const Hash<ED2KHash> &hash) : m_hash(hash) {} 843 843 SetReqFileId::SetReqFileId(std::istream &i) { 844 m_hash = Utils::getVal<std::string>(i, 16) ;844 m_hash = Utils::getVal<std::string>(i, 16).value(); 845 845 } 846 846 SetReqFileId::operator std::string() { 847 847 std::ostringstream tmp; 848 848 Utils::putVal<uint8_t>(tmp, OP_SETREQFILEID); 849 Utils::putVal (tmp, m_hash.getData(), 16);849 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 850 850 return makePacket(tmp.str()); 851 851 } … … 855 855 NoFile::NoFile(const Hash<ED2KHash> &hash) : m_hash(hash) {} 856 856 NoFile::NoFile(std::istream &i) { 857 m_hash = Utils::getVal<std::string>(i, 16) ;857 m_hash = Utils::getVal<std::string>(i, 16).value(); 858 858 } 859 859 NoFile::operator std::string() { 860 860 std::ostringstream tmp; 861 861 Utils::putVal<uint8_t>(tmp, OP_REQFILE_NOFILE); 862 Utils::putVal (tmp, m_hash.getData(), 16);862 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 863 863 return makePacket(tmp.str()); 864 864 } … … 875 875 std::ostringstream tmp; 876 876 Utils::putVal<uint8_t>(tmp, OP_REQFILE_STATUS); 877 Utils::putVal (tmp, m_hash.getData(), 16);877 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 878 878 writePartMap(tmp, m_partMap); 879 879 return makePacket(tmp.str()); … … 881 881 882 882 FileStatus::FileStatus(std::istream &i) { 883 m_hash = Utils::getVal<std::string>(i, 16) ;883 m_hash = Utils::getVal<std::string>(i, 16).value(); 884 884 readPartMap(i, &m_partMap); 885 885 } … … 893 893 std::ostringstream tmp; 894 894 Utils::putVal<uint8_t>(tmp, OP_REQHASHSET); 895 Utils::putVal (tmp, m_hash.getData(), 16);895 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 896 896 return makePacket(tmp.str()); 897 897 } … … 902 902 HashSet::HashSet(std::istream &i) { 903 903 m_hashSet.reset(new ED2KHashSet()); 904 m_hashSet->setFileHash(Utils::getVal<std::string>(i, 16) );904 m_hashSet->setFileHash(Utils::getVal<std::string>(i, 16).value()); 905 905 uint16_t count = Utils::getVal<uint16_t>(i); 906 906 while (count--) { 907 m_hashSet->addChunkHash(Utils::getVal<std::string>(i, 16) );907 m_hashSet->addChunkHash(Utils::getVal<std::string>(i, 16).value()); 908 908 } 909 909 } … … 912 912 std::ostringstream tmp; 913 913 Utils::putVal<uint8_t>(tmp, OP_HASHSET); 914 Utils::putVal (tmp, m_tmpSet->getFileHash().getData(), 16);914 Utils::putVal<std::string>(tmp, m_tmpSet->getFileHash().getData(), 16); 915 915 Utils::putVal<uint16_t>(tmp, m_tmpSet->getChunkCnt()); 916 916 for (uint32_t i = 0; i < m_tmpSet->getChunkCnt(); ++i) { 917 Utils::putVal (tmp, (*m_tmpSet)[i].getData(), 16);917 Utils::putVal<std::string>(tmp, (*m_tmpSet)[i].getData(), 16); 918 918 } 919 919 return makePacket(tmp.str()); … … 927 927 // Optional 928 928 try { 929 m_hash = Utils::getVal<std::string>(i, 16) ;929 m_hash = Utils::getVal<std::string>(i, 16).value(); 930 930 } catch (Utils::ReadError&) {} 931 931 } … … 934 934 Utils::putVal<uint8_t>(tmp, OP_STARTUPLOADREQ); 935 935 if (!m_hash.isEmpty()) { 936 Utils::putVal (tmp, m_hash.getData(), 16);936 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 937 937 } 938 938 return makePacket(tmp.str()); … … 989 989 } 990 990 ReqChunks::ReqChunks(std::istream &i) { 991 m_hash = Utils::getVal<std::string>(i, 16) ;991 m_hash = Utils::getVal<std::string>(i, 16).value(); 992 992 boost::tuple<uint32_t, uint32_t, uint32_t> begins; 993 993 boost::tuple<uint32_t, uint32_t, uint32_t> ends; … … 1014 1014 std::ostringstream tmp; 1015 1015 Utils::putVal<uint8_t>(tmp, OP_REQCHUNKS); 1016 Utils::putVal (tmp, m_hash.getData(), 16);1016 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 1017 1017 CHECK_THROW(m_reqChunks.size()); 1018 1018 Utils::putVal<uint32_t>(tmp, m_reqChunks.at(0).begin()); … … 1052 1052 } 1053 1053 DataChunk::DataChunk(std::istream &i) { 1054 m_hash = Utils::getVal<std::string>(i, 16) ;1054 m_hash = Utils::getVal<std::string>(i, 16).value(); 1055 1055 m_begin = Utils::getVal<uint32_t>(i); 1056 1056 m_end = Utils::getVal<uint32_t>(i); … … 1060 1060 std::ostringstream tmp; 1061 1061 Utils::putVal<uint8_t>(tmp, OP_SENDINGCHUNK); 1062 Utils::putVal (tmp, m_hash.getData(), 16);1062 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 1063 1063 Utils::putVal<uint32_t>(tmp, m_begin); 1064 1064 Utils::putVal<uint32_t>(tmp, m_end); 1065 Utils::putVal (tmp, m_data, m_data.size());1065 Utils::putVal<std::string>(tmp, m_data, m_data.size()); 1066 1066 return makePacket(tmp.str()); 1067 1067 } … … 1082 1082 // in, but I see no other way - blame the protocol :( 1083 1083 PackedChunk::PackedChunk(std::istream &i) : Packet(PR_EMULE) { 1084 m_hash = Utils::getVal<std::string>(i, 16) ;1084 m_hash = Utils::getVal<std::string>(i, 16).value(); 1085 1085 m_begin = Utils::getVal<uint32_t>(i); 1086 1086 m_size = Utils::getVal<uint32_t>(i); … … 1091 1091 std::ostringstream tmp; 1092 1092 Utils::putVal<uint8_t>(tmp, OP_PACKEDCHUNK); 1093 Utils::putVal (tmp, m_hash.getData(), 16);1093 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 1094 1094 Utils::putVal<uint32_t>(tmp, m_begin); 1095 1095 Utils::putVal<uint32_t>(tmp, m_size); 1096 Utils::putVal (tmp, m_data, m_data.size());1096 Utils::putVal<std::string>(tmp, m_data, m_data.size()); 1097 1097 return makePacket(tmp.str()); 1098 1098 } … … 1115 1115 } 1116 1116 SourceExchReq::SourceExchReq(std::istream &i) { 1117 m_hash = Utils::getVal<std::string>(i, 16) ;1117 m_hash = Utils::getVal<std::string>(i, 16).value(); 1118 1118 } 1119 1119 SourceExchReq::operator std::string() { 1120 1120 std::ostringstream tmp; 1121 1121 Utils::putVal<uint8_t>(tmp, OP_REQSOURCES); 1122 Utils::putVal (tmp, m_hash.getData(), 16);1122 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 1123 1123 return makePacket(tmp.str()); 1124 1124 } … … 1131 1131 } 1132 1132 AnswerSources::AnswerSources(std::istringstream &i) { 1133 m_hash = Utils::getVal<std::string>(i, 16) ;1133 m_hash = Utils::getVal<std::string>(i, 16).value(); 1134 1134 uint16_t cnt = Utils::getVal<uint16_t>(i); 1135 1135 bool hashes = true; … … 1188 1188 std::ostringstream tmp; 1189 1189 Utils::putVal<uint16_t>(tmp, m_message.size()); 1190 Utils::putVal (tmp, m_message, m_message.size());1190 Utils::putVal<std::string>(tmp, m_message, m_message.size()); 1191 1191 return makePacket(tmp.str()); 1192 1192 } … … 1244 1244 Utils::putVal<uint8_t>(tmp, OP_PUBLICKEY); 1245 1245 Utils::putVal<uint8_t>(tmp, m_pubKey.size()); 1246 Utils::putVal (tmp, m_pubKey.c_str(), m_pubKey.size());1246 Utils::putVal<std::string>(tmp, m_pubKey.c_str(), m_pubKey.size()); 1247 1247 return makePacket(tmp.str()); 1248 1248 } … … 1268 1268 Utils::putVal<uint8_t>(tmp, OP_SIGNATURE); 1269 1269 Utils::putVal<uint8_t>(tmp, m_signature.size()); 1270 Utils::putVal (tmp, m_signature, m_signature.size());1270 Utils::putVal<std::string>(tmp, m_signature, m_signature.size()); 1271 1271 if (m_ipType) { 1272 1272 Utils::putVal<uint8_t>(tmp, m_ipType); … … 1287 1287 m_udpVersion(udpVersion) {} 1288 1288 ReaskFilePing::ReaskFilePing(std::istream &i) { 1289 m_hash = Utils::getVal<std::string>(i, 16) ;1289 m_hash = Utils::getVal<std::string>(i, 16).value(); 1290 1290 std::istringstream &tmp = dynamic_cast<std::istringstream&>(i); 1291 1291 if (tmp.str().size() >= 20) { // UDPv4 … … 1300 1300 Utils::putVal<uint8_t>(tmp, PR_EMULE); 1301 1301 Utils::putVal<uint8_t>(tmp, OP_REASKFILEPING); 1302 Utils::putVal (tmp, m_hash.getData(), 16);1302 Utils::putVal<std::string>(tmp, m_hash.getData(), 16); 1303 1303 if (m_udpVersion >= 4) { 1304 1304 writePartMap(tmp, m_partMap); hydranode/modules/ed2k/publickey.h
r1001 r1426 44 44 operator bool() const { return m_key; } 45 45 46 //! Assignment operator 47 PublicKey& operator=(const std::string &key) { 48
