Skip to content
This repository has been archived by the owner on Feb 1, 2021. It is now read-only.

Commit

Permalink
Merge pull request #63 from project-ecc/dev
Browse files Browse the repository at this point in the history
Version 0.2.5.7
Contains sync fixes, startup time fixes, ANS service, and performance updates
  • Loading branch information
Greg-Griffith authored Apr 20, 2018
2 parents 7bfb7dd + 537ebcb commit 9114a76
Show file tree
Hide file tree
Showing 167 changed files with 11,131 additions and 6,090 deletions.
Empty file modified contrib/cmake/CMakeLists.txt
100644 → 100755
Empty file.
318 changes: 175 additions & 143 deletions contrib/cmake/src/CMakeLists.txt

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions eccoin-qt.pro
Original file line number Diff line number Diff line change
Expand Up @@ -291,15 +291,20 @@ HEADERS += \
src/crypto/hash.h \
src/chain/checkpoints.h \
src/chain/chainman.h \
src/signals.h \
src/networks/networktemplate.h \
src/tx/servicetx.h \
src/crypto/chacha20.h \
src/processtx.h \
src/verifydb.h \
src/rpc/events.h \
src/ans/ans.h \
src/ans/ansrecord.h
src/ans/ansrecord.h \
src/addrdb.h \
src/threadinterrupt.h \
src/netaddress.h \
src/netmessagemaker.h \
src/service_leveldb.h \
src/stxmempool.h


# organize compiles of cpp files by section, this seems to be a logical order where the files lower down generally depend
Expand Down Expand Up @@ -404,14 +409,19 @@ SOURCES += \
src/crypto/hash.cpp \
src/chain/checkpoints.cpp \
src/chain/chainman.cpp \
src/signals.cpp \
src/eccoind.cpp \
src/tx/servicetx.cpp \
src/crypto/chacha20.cpp \
src/processtx.cpp \
src/verifydb.cpp \
src/ans/ans.cpp \
src/ans/ansrecord.cpp
src/ans/ansrecord.cpp \
src/addrdb.cpp \
src/threadinterrupt.cpp \
src/netaddress.cpp \
src/rpc/rpcans.cpp \
src/service_leveldb.cpp \
src/stxmempool.cpp



Expand Down
1 change: 1 addition & 0 deletions generatebuild.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
./share/genbuild.sh build ./src/build/
11 changes: 9 additions & 2 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ endif
.PHONY: FORCE check-symbols check-security
# bitcoin core #
BITCOIN_CORE_H = \
addrdb.h \
addrman.h \
amount.h \
ans/ansrecord.h \
args.h \
arith_uint256.h \
base58.h \
Expand Down Expand Up @@ -83,7 +85,9 @@ BITCOIN_CORE_H = \
merkleblock.h \
miner.h \
net.h \
netaddress.h \
netbase.h \
netmessagemaker.h \
networks/netman.h \
networks/network.h \
networks/networktemplate.h \
Expand Down Expand Up @@ -116,13 +120,13 @@ BITCOIN_CORE_H = \
script/standard.h \
crypto/scrypt.h \
serialize.h \
signals.h \
streams.h \
support/allocators/secure.h \
support/allocators/zeroafterfree.h \
support/cleanse.h \
support/pagelocker.h \
sync.h \
threadinterrupt.h \
threadsafety.h \
timedata.h \
tinyformat.h \
Expand Down Expand Up @@ -158,7 +162,9 @@ libbitcoin_util_a-clientversion.$(OBJEXT): build/build.h
libbitcoin_server_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS)
libbitcoin_server_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIC_FLAGS) $(PIE_FLAGS)
libbitcoin_server_a_SOURCES = \
addrdb.cpp \
addrman.cpp \
ans/ansrecord.cpp \
bloom.cpp \
chain/chain.cpp \
chain/checkpoints.cpp \
Expand All @@ -171,6 +177,7 @@ libbitcoin_server_a_SOURCES = \
merkleblock.cpp \
miner.cpp \
net.cpp \
netaddress.cpp \
noui.cpp \
policy/fees.cpp \
policy/policy.cpp \
Expand Down Expand Up @@ -240,7 +247,6 @@ libbitcoin_server_a_SOURCES = \
util/utilstrencodings.cpp \
util/utiltime.cpp \
verifydb.cpp \
signals.cpp \
crypto/chacha20.cpp \
crypto/chacha20.h \
crypto/common.h \
Expand All @@ -266,6 +272,7 @@ libbitcoin_server_a_SOURCES = \
wallet/walletdb.cpp \
policy/rbf.cpp \
rpc/rpcclient.cpp \
threadinterrupt.cpp \
$(BITCOIN_CORE_H)

if GLIBC_BACK_COMPAT
Expand Down
208 changes: 208 additions & 0 deletions src/addrdb.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
// Copyright (c) 2009-2010 Satoshi Nakamoto
// Copyright (c) 2009-2016 The Bitcoin Core developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include "addrdb.h"

#include "addrman.h"
#include "clientversion.h"
#include "crypto/hash.h"
#include "init.h"
#include "random.h"
#include "streams.h"
#include "tinyformat.h"
#include "util/util.h"

#include <boost/filesystem.hpp>

CBanDB::CBanDB() {
pathBanlist = GetDataDir() / "banlist.dat";
}

bool CBanDB::Write(const banmap_t &banSet) {
// Generate random temporary filename
unsigned short randv = 0;
GetRandBytes((uint8_t *)&randv, sizeof(randv));
std::string tmpfn = strprintf("banlist.dat.%04x", randv);

// serialize banlist, checksum data up to that point, then append csum
CDataStream ssBanlist(SER_DISK, CLIENT_VERSION);
ssBanlist << FLATDATA(pnetMan->getActivePaymentNetwork()->MessageStart());
ssBanlist << banSet;
uint256 hash = Hash(ssBanlist.begin(), ssBanlist.end());
ssBanlist << hash;

// open temp output file, and associate with CAutoFile
fs::path pathTmp = GetDataDir() / tmpfn;
FILE *file = fopen(pathTmp.string().c_str(), "wb");
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
if (fileout.IsNull())
return error("%s: Failed to open file %s", __func__, pathTmp.string());

// Write and commit header, data
try {
fileout << ssBanlist;
} catch (const std::exception &e) {
return error("%s: Serialize or I/O error - %s", __func__, e.what());
}
FileCommit(fileout.Get());
fileout.fclose();

// replace existing banlist.dat, if any, with new banlist.dat.XXXX
if (!RenameOver(pathTmp, pathBanlist))
return error("%s: Rename-into-place failed", __func__);

return true;
}

bool CBanDB::Read(banmap_t &banSet) {
// open input file, and associate with CAutoFile
FILE *file = fopen(pathBanlist.string().c_str(), "rb");
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
if (filein.IsNull())
return error("%s: Failed to open file %s", __func__,
pathBanlist.string());

// use file size to size memory buffer
uint64_t fileSize = fs::file_size(pathBanlist);
uint64_t dataSize = 0;
// Don't try to resize to a negative number if file is small
if (fileSize >= sizeof(uint256)) dataSize = fileSize - sizeof(uint256);
std::vector<uint8_t> vchData;
vchData.resize(dataSize);
uint256 hashIn;

// read data and checksum from file
try {
filein.read((char *)&vchData[0], dataSize);
filein >> hashIn;
} catch (const std::exception &e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}
filein.fclose();

CDataStream ssBanlist(vchData, SER_DISK, CLIENT_VERSION);

// verify stored checksum matches input data
uint256 hashTmp = Hash(ssBanlist.begin(), ssBanlist.end());
if (hashIn != hashTmp)
return error("%s: Checksum mismatch, data corrupted", __func__);

uint8_t pchMsgTmp[4];
try {
// de-serialize file header (network specific magic number) and ..
ssBanlist >> FLATDATA(pchMsgTmp);

// ... verify the network matches ours
if (memcmp(pchMsgTmp, std::begin(pnetMan->getActivePaymentNetwork()->MessageStart()),
sizeof(pchMsgTmp))) {
return error("%s: Invalid network magic number", __func__);
}

// de-serialize ban data
ssBanlist >> banSet;
} catch (const std::exception &e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}

return true;
}

CAddrDB::CAddrDB() {
pathAddr = GetDataDir() / "peers.dat";
}

bool CAddrDB::Write(const CAddrMan &addr) {
// Generate random temporary filename
unsigned short randv = 0;
GetRandBytes((uint8_t *)&randv, sizeof(randv));
std::string tmpfn = strprintf("peers.dat.%04x", randv);

// serialize addresses, checksum data up to that point, then append csum
CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
ssPeers << FLATDATA(pnetMan->getActivePaymentNetwork()->MessageStart());
ssPeers << addr;
uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
ssPeers << hash;

// open temp output file, and associate with CAutoFile
fs::path pathTmp = GetDataDir() / tmpfn;
FILE *file = fopen(pathTmp.string().c_str(), "wb");
CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
if (fileout.IsNull())
return error("%s: Failed to open file %s", __func__, pathTmp.string());

// Write and commit header, data
try {
fileout << ssPeers;
} catch (const std::exception &e) {
return error("%s: Serialize or I/O error - %s", __func__, e.what());
}
FileCommit(fileout.Get());
fileout.fclose();

// replace existing peers.dat, if any, with new peers.dat.XXXX
if (!RenameOver(pathTmp, pathAddr))
return error("%s: Rename-into-place failed", __func__);

return true;
}

bool CAddrDB::Read(CAddrMan &addr) {
// open input file, and associate with CAutoFile
FILE *file = fopen(pathAddr.string().c_str(), "rb");
CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
if (filein.IsNull())
return error("%s: Failed to open file %s", __func__, pathAddr.string());

// use file size to size memory buffer
uint64_t fileSize = fs::file_size(pathAddr);
uint64_t dataSize = 0;
// Don't try to resize to a negative number if file is small
if (fileSize >= sizeof(uint256)) dataSize = fileSize - sizeof(uint256);
std::vector<uint8_t> vchData;
vchData.resize(dataSize);
uint256 hashIn;

// read data and checksum from file
try {
filein.read((char *)&vchData[0], dataSize);
filein >> hashIn;
} catch (const std::exception &e) {
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}
filein.fclose();

CDataStream ssPeers(vchData, SER_DISK, CLIENT_VERSION);

// verify stored checksum matches input data
uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end());
if (hashIn != hashTmp)
return error("%s: Checksum mismatch, data corrupted", __func__);

return Read(addr, ssPeers);
}

bool CAddrDB::Read(CAddrMan &addr, CDataStream &ssPeers) {
uint8_t pchMsgTmp[4];
try {
// de-serialize file header (network specific magic number) and ..
ssPeers >> FLATDATA(pchMsgTmp);

// ... verify the network matches ours
if (memcmp(pchMsgTmp, std::begin(pnetMan->getActivePaymentNetwork()->MessageStart()),
sizeof(pchMsgTmp))) {
return error("%s: Invalid network magic number", __func__);
}

// de-serialize address data into one CAddrMan object
ssPeers >> addr;
} catch (const std::exception &e) {
// de-serialization has failed, ensure addrman is left in a clean state
addr.Clear();
return error("%s: Deserialize or I/O error - %s", __func__, e.what());
}

return true;
}
Loading

0 comments on commit 9114a76

Please sign in to comment.