| 2333 | } |
| 2334 | |
| 2335 | bool CAddrDB::Read(CAddrMan& addr) |
| 2336 | { |
| 2337 | // open input file, and associate with CAutoFile |
| 2338 | FILE* file = fopen(pathAddr.string().c_str(), "rb"); |
| 2339 | CAutoFile filein(file, SER_DISK, CLIENT_VERSION); |
| 2340 | if (filein.IsNull()) |
| 2341 | return error("%s : Failed to open file %s", __func__, pathAddr.string()); |
| 2342 | |
| 2343 | // use file size to size memory buffer |
| 2344 | uint64_t fileSize = boost::filesystem::file_size(pathAddr); |
| 2345 | uint64_t dataSize = fileSize - sizeof(uint256); |
| 2346 | // Don't try to resize to a negative number if file is small |
| 2347 | if (fileSize >= sizeof(uint256)) |
| 2348 | dataSize = fileSize - sizeof(uint256); |
| 2349 | vector<unsigned char> vchData; |
| 2350 | vchData.resize(dataSize); |
| 2351 | uint256 hashIn; |
| 2352 | |
| 2353 | // read data and checksum from file |
| 2354 | try { |
| 2355 | filein.read((char*)&vchData[0], dataSize); |
| 2356 | filein >> hashIn; |
| 2357 | } catch (std::exception& e) { |
| 2358 | return error("%s : Deserialize or I/O error - %s", __func__, e.what()); |
| 2359 | } |
| 2360 | filein.fclose(); |
| 2361 | |
| 2362 | CDataStream ssPeers(vchData, SER_DISK, CLIENT_VERSION); |
| 2363 | |
| 2364 | // verify stored checksum matches input data |
| 2365 | uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end()); |
| 2366 | if (hashIn != hashTmp) |
| 2367 | return error("%s : Checksum mismatch, data corrupted", __func__); |
| 2368 | |
| 2369 | unsigned char pchMsgTmp[4]; |
| 2370 | try { |
| 2371 | // de-serialize file header (network specific magic number) and .. |
| 2372 | ssPeers >> FLATDATA(pchMsgTmp); |
| 2373 | |
| 2374 | // ... verify the network matches ours |
| 2375 | if (memcmp(pchMsgTmp, Params().MessageStart(), sizeof(pchMsgTmp))) |
| 2376 | return error("%s : Invalid network magic number", __func__); |
| 2377 | |
| 2378 | // de-serialize address data into one CAddrMan object |
| 2379 | ssPeers >> addr; |
| 2380 | } catch (std::exception& e) { |
| 2381 | return error("%s : Deserialize or I/O error - %s", __func__, e.what()); |
| 2382 | } |
| 2383 | |
| 2384 | return true; |
| 2385 | } |
| 2386 | |
| 2387 | unsigned int ReceiveFloodSize() { return 1000 * GetArg("-maxreceivebuffer", 5 * 1000); } |
| 2388 | unsigned int SendBufferSize() { return 1000 * GetArg("-maxsendbuffer", 1 * 1000); } |
no test coverage detected