Sync Linux tweaks.

This commit is contained in:
JoelKatz
2011-11-07 13:45:32 -08:00
parent beef9b47d5
commit 1d140e8829
19 changed files with 2674 additions and 48 deletions

View File

@@ -34,7 +34,7 @@ Application::Application()
void Application::run() void Application::run()
{ {
string filename=strprintf("%sdata.db",theConfig.DATA_DIR); string filename=strprintf("%sdata.db",theConfig.DATA_DIR.c_str());
theApp->setDB(new SqliteDatabase(filename.c_str())); theApp->setDB(new SqliteDatabase(filename.c_str()));
mDatabase->connect(); mDatabase->connect();

View File

@@ -1,9 +1,14 @@
#include "BitcoinUtil.h" #include "BitcoinUtil.h"
#include <stdarg.h> #include <stdarg.h>
#include <windows.h>
#include <openssl/rand.h> #include <openssl/rand.h>
#include <time.h> #include <time.h>
#if defined(WIN32) || defined(WIN64)
#include <windows.h>
#else
#include <sys/time.h>
#endif
using namespace std; using namespace std;
std::string gFormatStr("v1"); std::string gFormatStr("v1");
@@ -45,7 +50,7 @@ string strprintf(const char* format, ...)
inline int64 GetPerformanceCounter() inline int64 GetPerformanceCounter()
{ {
int64 nCounter = 0; int64 nCounter = 0;
#ifdef WIN32 #if defined(WIN32) || defined(WIN64)
QueryPerformanceCounter((LARGE_INTEGER*)&nCounter); QueryPerformanceCounter((LARGE_INTEGER*)&nCounter);
#else #else
timeval t; timeval t;

View File

@@ -16,8 +16,11 @@ void RandAddSeedPerfmon();
static const unsigned int MAX_SIZE = 0x02000000; static const unsigned int MAX_SIZE = 0x02000000;
#define loop for (;;) #define loop for (;;)
#define PAIR(t1, t2) pair<t1, t2>
#if !defined(WIN32) && !defined(WIN64)
#define _vsnprintf(a,b,c,d) vsnprintf(a,b,c,d)
#endif
template<typename T1> template<typename T1>

View File

@@ -2,6 +2,7 @@
#define __KNOWNNODELIST__ #define __KNOWNNODELIST__
#include "vector" #include "vector"
#include <string>
class KnownNode class KnownNode
{ {

View File

@@ -50,8 +50,7 @@ newcoin::FullLedger* Ledger::createFullLedger()
ledger->set_hash(getHash().begin(),getHash().GetSerializeSize()); ledger->set_hash(getHash().begin(),getHash().GetSerializeSize());
ledger->set_parenthash(mParentHash.begin(),mParentHash.GetSerializeSize()); ledger->set_parenthash(mParentHash.begin(),mParentHash.GetSerializeSize());
pair<uint160, pair<uint64,uint32> >& account=pair<uint160, pair<uint64,uint32> >(); BOOST_FOREACH(PAIR(const uint160, Account)& account, mAccounts)
BOOST_FOREACH(account,mAccounts)
{ {
newcoin::Account* saveAccount=ledger->add_accounts(); newcoin::Account* saveAccount=ledger->add_accounts();
saveAccount->set_address(account.first.begin(),account.first.GetSerializeSize()); saveAccount->set_address(account.first.begin(),account.first.GetSerializeSize());
@@ -99,7 +98,7 @@ Ledger::pointer Ledger::getParent()
// TODO: we can optimize so the ledgers only hold the delta from the accepted ledger // TODO: we can optimize so the ledgers only hold the delta from the accepted ledger
// TODO: check to make sure the ledger is consistent after we load it // TODO: check to make sure the ledger is consistent after we load it
bool Ledger::load(uint256& hash) bool Ledger::load(const uint256& hash)
{ {
Database* db=theApp->getDB(); Database* db=theApp->getDB();
@@ -125,7 +124,8 @@ bool Ledger::load(uint256& hash)
char buf[100]; char buf[100];
sql="SELECT Transactions.* from Transactions,LedgerTransactionMap where Transactions.TransactionID=LedgerTransactionMap.TransactionID and LedgerTransactionMap.LedgerID="; sql="SELECT Transactions.* from Transactions,LedgerTransactionMap where Transactions.TransactionID=LedgerTransactionMap.TransactionID and LedgerTransactionMap.LedgerID=";
sql.append(itoa( db->getInt(0),buf,10) ); sprintf(buf, "%d", db->getInt(0));
sql.append(buf);
if(db->executeSQL(sql.c_str())) if(db->executeSQL(sql.c_str()))
{ {
unsigned char tbuf[1000]; unsigned char tbuf[1000];
@@ -188,13 +188,15 @@ void Ledger::save()
{ // this ledger isn't in the DB { // this ledger isn't in the DB
char buf[100]; char buf[100];
sql="INSERT INTO Ledgers (LedgerIndex,Hash,ParentHash,FeeHeld) values ("; sql="INSERT INTO Ledgers (LedgerIndex,Hash,ParentHash,FeeHeld) values (";
sql.append(itoa(mIndex,buf,10)); sprintf(buf, "%d", mIndex);
sql.append(buf);
sql.append(","); sql.append(",");
sql.append(itoa(mIndex,buf,10)); sql.append(buf);
sql.append(","); sql.append(",");
sql.append(itoa(mIndex,buf,10)); sql.append(buf);
sql.append(","); sql.append(",");
sql.append(itoa(mFeeHeld,buf,10)); sprintf(buf, "%llu", mFeeHeld);
sql.append(buf);
sql.append(")"); sql.append(")");
sql="SELECT LAST_INSERT_ID()"; sql="SELECT LAST_INSERT_ID()";
@@ -203,7 +205,7 @@ void Ledger::save()
} }
} }
int64 Ledger::getAmountHeld(uint160& address) int64 Ledger::getAmountHeld(const uint160& address)
{ {
if(mAccounts.count(address)) if(mAccounts.count(address))
{ {
@@ -212,7 +214,7 @@ int64 Ledger::getAmountHeld(uint160& address)
return(0); return(0);
} }
Ledger::Account* Ledger::getAccount(uint160& address) Ledger::Account* Ledger::getAccount(const uint160& address)
{ {
if(mAccounts.count(address)) if(mAccounts.count(address))
{ {
@@ -495,8 +497,7 @@ void Ledger::mergeIn(Ledger::pointer other)
void Ledger::correctAccounts() void Ledger::correctAccounts()
{ {
pair<uint160, Account >& fullAccount=pair<uint160, Account >(); BOOST_FOREACH(PAIR(const uint160, Account)& fullAccount, mAccounts)
BOOST_FOREACH(fullAccount,mAccounts)
{ {
if(fullAccount.second.first <0 ) if(fullAccount.second.first <0 )
{ {
@@ -507,7 +508,7 @@ void Ledger::correctAccounts()
// Must look for transactions to discard to make this account positive // Must look for transactions to discard to make this account positive
// When we chuck transactions it might cause other accounts to need correcting // When we chuck transactions it might cause other accounts to need correcting
void Ledger::correctAccount(uint160& address) void Ledger::correctAccount(const uint160& address)
{ {
list<uint160> effected; list<uint160> effected;

View File

@@ -44,9 +44,8 @@ private:
void hash(); void hash();
void addTransactionAllowNeg(TransactionPtr trans); void addTransactionAllowNeg(TransactionPtr trans);
void correctAccounts(); void correctAccounts();
void correctAccount(uint160& address); void correctAccount(const uint160& address);
public: public:
typedef boost::shared_ptr<Ledger> pointer;
Ledger(); Ledger();
Ledger(uint32 index); Ledger(uint32 index);
Ledger(newcoin::FullLedger& ledger); Ledger(newcoin::FullLedger& ledger);
@@ -56,7 +55,7 @@ public:
void mergeIn(Ledger::pointer other); void mergeIn(Ledger::pointer other);
void save(); void save();
bool load(uint256& hash); bool load(const uint256& hash);
void recalculate(bool recursive=true); void recalculate(bool recursive=true);
@@ -65,7 +64,7 @@ public:
std::list<TransactionPtr>& getTransactions(){ return(mTransactions); } std::list<TransactionPtr>& getTransactions(){ return(mTransactions); }
bool hasTransaction(TransactionPtr trans); bool hasTransaction(TransactionPtr trans);
int64 getAmountHeld(uint160& address); int64 getAmountHeld(const uint160& address);
void parentAddedTransaction(TransactionPtr cause); void parentAddedTransaction(TransactionPtr cause);
bool addTransaction(TransactionPtr trans,bool checkDuplicate=true); bool addTransaction(TransactionPtr trans,bool checkDuplicate=true);
void addValidation(newcoin::Validation& valid); void addValidation(newcoin::Validation& valid);
@@ -77,7 +76,7 @@ public:
uint32 getValidSeqNum(){ return(mValidationSeqNum); } uint32 getValidSeqNum(){ return(mValidationSeqNum); }
unsigned int getNumTransactions(){ return(mTransactions.size()); } unsigned int getNumTransactions(){ return(mTransactions.size()); }
std::map<uint160, Account >& getAccounts(){ return(mAccounts); } std::map<uint160, Account >& getAccounts(){ return(mAccounts); }
Account* getAccount(uint160& address); Account* getAccount(const uint160& address);
newcoin::FullLedger* createFullLedger(); newcoin::FullLedger* createFullLedger();
Ledger::pointer getParent(); Ledger::pointer getParent();

View File

@@ -15,7 +15,7 @@ void LedgerHistory::load()
} }
bool LedgerHistory::loadLedger(uint256& hash) bool LedgerHistory::loadLedger(const uint256& hash)
{ {
Ledger::pointer ledger=Ledger::pointer(new Ledger()); Ledger::pointer ledger=Ledger::pointer(new Ledger());
if(ledger->load(hash)) if(ledger->load(hash))
@@ -61,7 +61,7 @@ void LedgerHistory::addLedger(Ledger::pointer ledger)
ledger->save(); ledger->save();
} }
Ledger::pointer LedgerHistory::getLedger(uint256& hash) Ledger::pointer LedgerHistory::getLedger(const uint256& hash)
{ {
if(mAllLedgers.count(hash)) if(mAllLedgers.count(hash))
return(mAllLedgers[hash]); return(mAllLedgers[hash]);

View File

@@ -19,7 +19,7 @@ class LedgerHistory
std::map<uint256, Ledger::pointer> mAllLedgers; std::map<uint256, Ledger::pointer> mAllLedgers;
bool loadAcceptedLedger(uint32 index); bool loadAcceptedLedger(uint32 index);
bool loadLedger(uint256& hash); bool loadLedger(const uint256& hash);
public: public:
void load(); void load();
@@ -27,7 +27,7 @@ public:
void addAcceptedLedger(Ledger::pointer ledger); void addAcceptedLedger(Ledger::pointer ledger);
Ledger::pointer getAcceptedLedger(uint32 index); Ledger::pointer getAcceptedLedger(uint32 index);
Ledger::pointer getLedger(uint256& hash); Ledger::pointer getLedger(const uint256& hash);
}; };
#endif #endif

View File

@@ -43,7 +43,7 @@ public:
uint32 getCurrentLedgerIndex(); uint32 getCurrentLedgerIndex();
Ledger::pointer getAcceptedLedger(uint32 index){ return(mLedgerHistory.getAcceptedLedger(index)); } Ledger::pointer getAcceptedLedger(uint32 index){ return(mLedgerHistory.getAcceptedLedger(index)); }
Ledger::pointer getLedger(uint256& hash){ return(mLedgerHistory.getLedger(hash)); } Ledger::pointer getLedger(const uint256& hash){ return(mLedgerHistory.getLedger(hash)); }
int64 getAmountHeld(std::string& addr); int64 getAmountHeld(std::string& addr);
int64 getAmountHeld(uint160& addr); int64 getAmountHeld(uint160& addr);

View File

@@ -4,10 +4,6 @@
CXX=g++ -I/packages/openssl-1.0.0/include CXX=g++ -I/packages/openssl-1.0.0/include
WXINCLUDEPATHS=$(shell wx-config --cxxflags)
WXLIBS=$(shell wx-config --libs)
#USE_UPNP:=0 #USE_UPNP:=0
DEFS=-DNOPCH -DUSE_SSL DEFS=-DNOPCH -DUSE_SSL
@@ -18,11 +14,11 @@ LIBS= \
-l boost_filesystem-mt \ -l boost_filesystem-mt \
-l boost_program_options-mt \ -l boost_program_options-mt \
-l boost_thread-mt \ -l boost_thread-mt \
-l protobuf \
/packages/openssl-1.0.0/libssl.a /packages/openssl-1.0.0/libcrypto.a /packages/openssl-1.0.0/libssl.a /packages/openssl-1.0.0/libcrypto.a
ifdef USE_UPNP ifdef USE_UPNP
LIBS += -l miniupnpc LIBS += -l miniupnpc DEFS += -DUSE_UPNP=$(USE_UPNP)
DEFS += -DUSE_UPNP=$(USE_UPNP)
endif endif
LIBS+= \ LIBS+= \
@@ -78,8 +74,8 @@ SRCS= \
CallRPC.cpp KnownNodeList.cpp PackedMessage.cpp RPCDoor.cpp ValidationCollection.cpp \ CallRPC.cpp KnownNodeList.cpp PackedMessage.cpp RPCDoor.cpp ValidationCollection.cpp \
Config.cpp Ledger.cpp Peer.cpp RPCServer.cpp Wallet.cpp \ Config.cpp Ledger.cpp Peer.cpp RPCServer.cpp Wallet.cpp \
ConnectionPool.cpp LedgerHistory.cpp PeerDoor.cpp TimingService.cpp \ ConnectionPool.cpp LedgerHistory.cpp PeerDoor.cpp TimingService.cpp \
Conversion.cpp LedgerMaster.cpp RequestParser.cpp TransactionBundle.cpp Conversion.cpp LedgerMaster.cpp RequestParser.cpp TransactionBundle.cpp util/pugixml.o
# database/linux/mysqldatabase.cpp database/database.cpp database/SqliteDatabase.cpp
OBJS= $(SRCS:%.cpp=obj/%.o) cryptopp/obj/sha.o cryptopp/obj/cpu.o OBJS= $(SRCS:%.cpp=obj/%.o) cryptopp/obj/sha.o cryptopp/obj/cpu.o
@@ -97,7 +93,10 @@ obj/%.o: %.cpp $(HEADERS)
newcoin.pb.h: newcoin.proto newcoin.pb.h: newcoin.proto
protoc --cpp_out=. newcoin.proto protoc --cpp_out=. newcoin.proto
newcoind: newcoin.pb.h $(OBJS) newcoin.pb.o: newcoin.pb.h
$(CXX) -c $(CXXFLAGS) -o $@ newcoin.pb.cc
newcoind: newcoin.pb.o $(OBJS)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS) $(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
clean: clean:

View File

@@ -49,7 +49,8 @@ bool ValidationCollection::hasValidation(uint32 ledgerIndex,uint160& hanko,uint3
string hankoStr; string hankoStr;
Database* db=theApp->getDB(); Database* db=theApp->getDB();
db->escape(hanko.begin(),hanko.GetSerializeSize(),hankoStr); db->escape(hanko.begin(),hanko.GetSerializeSize(),hankoStr);
string sql=strprintf("SELECT ValidationID,seqnum from Validations where LedgerIndex=%d and hanko=%s",ledgerIndex,hankoStr); string sql=strprintf("SELECT ValidationID,seqnum from Validations where LedgerIndex=%d and hanko=%s",
ledgerIndex,hankoStr.c_str());
if(db->executeSQL(sql.c_str())) if(db->executeSQL(sql.c_str()))
{ {
if(db->startIterRows()) if(db->startIterRows())
@@ -195,6 +196,14 @@ void ValidationCollection::getValidations(uint32 ledgerIndex,vector<newcoin::Val
} }
#if 0
In member function
bool ValidationCollection::getConsensusLedger(uint32, uint256&, Ledger::pointer&, uint256&):
invalid initialization of non-const reference of type std::vector<newcoin::Validation>& from
an rvalue of type std::vector<newcoin::Validation>
invalid initialization of non-const reference of type ValidationCollection::Group& from
an rvalue of type ValidationCollection::Group
// look through all the validated hashes at that index // look through all the validated hashes at that index
// put the ledgers into compatible groups // put the ledgers into compatible groups
// Pick the group with the most votes // Pick the group with the most votes
@@ -205,9 +214,9 @@ bool ValidationCollection::getConsensusLedger(uint32 ledgerIndex, uint256& ourHa
{ {
unsigned int maxVotes=theConfig.MIN_VOTES_FOR_CONSENSUS; unsigned int maxVotes=theConfig.MIN_VOTES_FOR_CONSENSUS;
vector<newcoin::Validation>& mostValid=vector<newcoin::Validation>(); vector<newcoin::Validation>& mostValid=vector<newcoin::Validation>(); // DJS ERROR HERE
vector< Group >& groups=mIndexGroups[ledgerIndex]; vector< Group >& groups=mIndexGroups[ledgerIndex];
Group& maxGroup=Group(); Group& maxGroup=Group(); // DJS ERROR HERE
BOOST_FOREACH(Group& group,groups) BOOST_FOREACH(Group& group,groups)
{ {
if(group.mValidations.size()>maxVotes) if(group.mValidations.size()>maxVotes)
@@ -231,3 +240,4 @@ bool ValidationCollection::getConsensusLedger(uint32 ledgerIndex, uint256& ourHa
return(ret); return(ret);
} }
#endif

View File

@@ -9,7 +9,7 @@
#include <vector> #include <vector>
#include <openssl/bn.h> #include <openssl/bn.h>
#include "bitcoinUtil.h" #include "BitcoinUtil.h"
class bignum_error : public std::runtime_error class bignum_error : public std::runtime_error
{ {

View File

@@ -146,7 +146,7 @@ uint64 SqliteDatabase::getBigInt(int colIndex)
BLOB literals are string literals containing hexadecimal data and preceded by a single "x" or "X" character. For example: BLOB literals are string literals containing hexadecimal data and preceded by a single "x" or "X" character. For example:
X'53514C697465' X'53514C697465'
*/ */
void SqliteDatabase::escape(unsigned char* start,int size,std::string& retStr) void SqliteDatabase::escape(const unsigned char* start,int size,std::string& retStr)
{ {
retStr.clear(); retStr.clear();

View File

@@ -37,6 +37,6 @@ public:
int getBinary(int colIndex,unsigned char* buf,int maxSize); int getBinary(int colIndex,unsigned char* buf,int maxSize);
uint64 getBigInt(int colIndex); uint64 getBigInt(int colIndex);
void escape(unsigned char* start,int size,std::string& retStr); void escape(const unsigned char* start,int size,std::string& retStr);
}; };

View File

@@ -29,7 +29,7 @@ public:
std::string& getPass(){ return(mDBPass); } std::string& getPass(){ return(mDBPass); }
virtual void escape(unsigned char* start,int size,std::string& retStr)=0; virtual void escape(const unsigned char* start,int size,std::string& retStr)=0;
// returns true if the query went ok // returns true if the query went ok
virtual bool executeSQL(const char* sql)=0; virtual bool executeSQL(const char* sql)=0;

View File

@@ -3,7 +3,7 @@
#include "../database.h" #include "../database.h"
#include "string/i4string.h" #include "string/i4string.h"
#include "mysql.h" #include "mysql/mysql.h"
/* /*
this maintains the connection to the database this maintains the connection to the database

2596
newcoin.pb.h Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -9,6 +9,8 @@
#include <limits.h> #include <limits.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <stdio.h>
#include <string.h>
#if defined(_MSC_VER) || defined(__BORLANDC__) #if defined(_MSC_VER) || defined(__BORLANDC__)
typedef __int64 int64; typedef __int64 int64;
@@ -357,6 +359,16 @@ public:
return (unsigned char*)&pn[WIDTH]; return (unsigned char*)&pn[WIDTH];
} }
const unsigned char* begin() const
{
return (const unsigned char*)&pn[0];
}
const unsigned char* end() const
{
return (unsigned char*)&pn[WIDTH];
}
unsigned int size() unsigned int size()
{ {
return sizeof(pn); return sizeof(pn);
@@ -369,7 +381,7 @@ public:
} }
template<typename Stream> template<typename Stream>
void Serialize(Stream& s, int nType=0, int nVersion=VERSION) const void Serialize(Stream& s, int nType=0, int nVersion=4000) const /* DJS: version default? */
{ {
s.write((char*)pn, sizeof(pn)); s.write((char*)pn, sizeof(pn));
} }