MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / Read

Method Read

src/net.cpp:2034–2070  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2032}
2033
2034bool CAddrDB::Read(CAddrMan& addr)
2035{
2036 // open input file, and associate with CAutoFile
2037 FILE *file = fopen(pathAddr.string().c_str(), "rb");
2038 CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
2039 if (filein.IsNull())
2040 return error("%s: Failed to open file %s", __func__, pathAddr.string());
2041
2042 // use file size to size memory buffer
2043 int fileSize = boost::filesystem::file_size(pathAddr);
2044 int dataSize = fileSize - sizeof(uint256);
2045 // Don't try to resize to a negative number if file is small
2046 if (dataSize < 0)
2047 dataSize = 0;
2048 vector<unsigned char> vchData;
2049 vchData.resize(dataSize);
2050 uint256 hashIn;
2051
2052 // read data and checksum from file
2053 try {
2054 filein.read((char *)&vchData[0], dataSize);
2055 filein >> hashIn;
2056 }
2057 catch (const std::exception& e) {
2058 return error("%s: Deserialize or I/O error - %s", __func__, e.what());
2059 }
2060 filein.fclose();
2061
2062 CDataStream ssPeers(vchData, SER_DISK, CLIENT_VERSION);
2063
2064 // verify stored checksum matches input data
2065 uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end());
2066 if (hashIn != hashTmp)
2067 return error("%s: Checksum mismatch, data corrupted", __func__);
2068
2069 return Read(addr, ssPeers);
2070}
2071
2072bool CAddrDB::Read(CAddrMan& addr, CDataStream& ssPeers)
2073{

Callers 4

ReadFeeEstimatesMethod · 0.45
GetCoinsMethod · 0.45
GetBestBlockMethod · 0.45
StartNodeFunction · 0.45

Calls 10

errorFunction · 0.85
resizeMethod · 0.80
HashFunction · 0.70
ParamsClass · 0.70
IsNullMethod · 0.45
readMethod · 0.45
fcloseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
ClearMethod · 0.45

Tested by

no test coverage detected