diff --git a/Application.cpp b/Application.cpp index 80f46a7f68..cd062455f1 100644 --- a/Application.cpp +++ b/Application.cpp @@ -30,6 +30,7 @@ Application::Application() mWallet.load(); mPeerDoor=NULL; mRPCDoor=NULL; + mDatabase=NULL; CKey::pointer account_key(new CKey(CKey::GetBaseFromString("This is my payphrase."), 0, false)); diff --git a/Peer.cpp b/Peer.cpp index 2e58022d49..49475dbc38 100644 --- a/Peer.cpp +++ b/Peer.cpp @@ -28,7 +28,7 @@ void Peer::handle_write(const boost::system::error_code& error , size_t bytes_tr cout << "Peer::handle_write Error: " << error << " bytes: "<< bytes_transferred << endl; mSendingPacket=PackedMessage::pointer(); - if(mSendQ.size()) + if(!mSendQ.empty()) { PackedMessage::pointer packet=mSendQ.front(); @@ -126,7 +126,7 @@ void Peer::processReadBuffer() int type=PackedMessage::getType(mReadbuf); switch(type) { - case newcoin::HELLO: + case newcoin::mtHELLO: { newcoin::TMHello msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -135,7 +135,7 @@ void Peer::processReadBuffer() } break; - case newcoin::ERROR_MSG: + case newcoin::mtERROR_MSG: { newcoin::TMErrorMsg msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -143,7 +143,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::PING: + case newcoin::mtPING: { newcoin::TMPing msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -151,7 +151,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::GET_CONTACTS: + case newcoin::mtGET_CONTACTS: { newcoin::TMGetContacts msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -159,7 +159,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::CONTACT: + case newcoin::mtCONTACT: { newcoin::TMContact msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -167,7 +167,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::SEARCH_TRANSACTION: + case newcoin::mtSEARCH_TRANSACTION: { newcoin::TMSearchTransaction msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -175,7 +175,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::GET_ACCOUNT: + case newcoin::mtGET_ACCOUNT: { newcoin::TMGetAccount msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -183,7 +183,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::ACCOUNT: + case newcoin::mtACCOUNT: { newcoin::TMAccount msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -191,7 +191,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::TRANSACTION: + case newcoin::mtTRANSACTION: { newcoin::TMTransaction msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -199,7 +199,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::GET_LEDGER: + case newcoin::mtGET_LEDGER: { newcoin::TMGetLedger msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -207,7 +207,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::LEDGER: + case newcoin::mtLEDGER: { newcoin::TMLedger msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -216,7 +216,7 @@ void Peer::processReadBuffer() } #if 0 - case newcoin::PROPOSE_LEDGER: + case newcoin::mtPROPOSE_LEDGER: { newcoin::TM msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -224,7 +224,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::CLOSE_LEDGER: + case newcoin::mtCLOSE_LEDGER: { newcoin::TM msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -232,7 +232,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::GET_VALIDATION: + case newcoin::mtGET_VALIDATION: { newcoin::TM msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -240,7 +240,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::VALIDATION: + case newcoin::mtVALIDATION: { newcoin::TM msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -250,7 +250,7 @@ void Peer::processReadBuffer() #endif - case newcoin::GET_OBJECT: + case newcoin::mtGET_OBJECT: { newcoin::TMGetObjectByHash msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -258,7 +258,7 @@ void Peer::processReadBuffer() else cout << "pars error: " << type << endl; } - case newcoin::OBJECT: + case newcoin::mtOBJECT: { newcoin::TMObjectByHash msg; if(msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -272,6 +272,78 @@ void Peer::processReadBuffer() } +void Peer::recvHello(newcoin::TMHello& packet) +{ +} + +void Peer::recvTransaction(newcoin::TMTransaction& packet) +{ +} + +void Peer::recvValidation(newcoin::TMValidation& packet) +{ +} + +void Peer::recvGetValidation(newcoin::TMGetValidations& packet) +{ +} + +void Peer::recvContact(newcoin::TMContact& packet) +{ +} + +void Peer::recvGetContacts(newcoin::TMGetContacts& packet) +{ +} + +void Peer::recvIndexedObject(newcoin::TMIndexedObject& packet) +{ +} + +void Peer::recvGetObjectByHash(newcoin::TMGetObjectByHash& packet) +{ +} + +void Peer::recvObjectByHash(newcoin::TMObjectByHash& packet) +{ +} + +void Peer::recvPing(newcoin::TMPing& packet) +{ +} + +void Peer::recvErrorMessage(newcoin::TMErrorMsg& packet) +{ +} + +void Peer::recvSearchTransaction(newcoin::TMSearchTransaction& packet) +{ +} + +void Peer::recvGetAccount(newcoin::TMGetAccount& packet) +{ +} + +void Peer::recvAccount(newcoin::TMAccount& packet) +{ +} + +void Peer::recvGetLedger(newcoin::TMGetLedger& packet) +{ +} + +void Peer::recvLedger(newcoin::TMLedger& packet) +{ +} + +void Peer::sendHello() +{ + newcoin::TMHello* h=new newcoin::TMHello(); + // set up parameters + PackedMessage::pointer packet(new PackedMessage(PackedMessage::MessagePointer(h), newcoin::mtHELLO)); + sendPacket(packet); +} + #if 0 @@ -282,7 +354,7 @@ void Peer::sendHello() hello->set_port(theConfig.PEER_PORT); hello->set_version(theConfig.VERSION); - PackedMessage::pointer packet(new PackedMessage(PackedMessage::MessagePointer(hello),newcoin::HELLO)); + PackedMessage::pointer packet(new PackedMessage(PackedMessage::MessagePointer(hello),newcoin::mtHELLO)); sendPacket(packet); } /* @@ -413,8 +485,6 @@ void Peer::receiveFullLedger(newcoin::FullLedger& packet) theApp->getLedgerMaster().addFullLedger(packet); } -#endif - void Peer::connectTo(KnownNode& node) { tcp::endpoint endpoint( address::from_string(node.mIP), node.mPort); @@ -423,3 +493,4 @@ void Peer::connectTo(KnownNode& node) } +#endif diff --git a/Peer.h b/Peer.h index 2979dc1f93..1bc6fdd2cf 100644 --- a/Peer.h +++ b/Peer.h @@ -1,6 +1,7 @@ #ifndef __PEER__ #define __PEER__ +#include #include #include #include @@ -10,28 +11,22 @@ #include "Transaction.h" #include "list" -class KnownNode; - -/* -This is one other node you are connected to. -When you connect you: - Send Hello - Send Your latest ledger - -*/ - class Peer : public boost::enable_shared_from_this { - // Must keep track of the messages you have already sent to or received from this peer - // Well actually we can just keep track of if we have broadcast each message +public: + static const int psbGotHello=0, psbSentHello=1, psbInMap=2, psbTrusted=3; + static const int psbNoLedgers=4, psbNoTransactions=5, psbDownLevel=6; +protected: boost::asio::ip::tcp::socket mSocket; std::vector mReadbuf; std::list mSendQ; PackedMessage::pointer mSendingPacket; + std::bitset<32> mPeerBits; Peer(boost::asio::io_service& io_service); + void handle_write(const boost::system::error_code& error, size_t bytes_transferred); //void handle_read(const boost::system::error_code& error, size_t bytes_transferred); void handle_read_header(const boost::system::error_code& error); @@ -81,9 +76,6 @@ public: void connected(const boost::system::error_code& error); - // try to connect to this Peer - void connectTo(KnownNode& node); - void sendPacket(PackedMessage::pointer packet); void sendLedgerProposal(Ledger::pointer ledger); void sendFullLedger(Ledger::pointer ledger); @@ -93,8 +85,6 @@ public: static PackedMessage::pointer createLedgerProposal(Ledger::pointer ledger); static PackedMessage::pointer createValidation(Ledger::pointer ledger); static PackedMessage::pointer createGetFullLedger(uint256& hash); - - }; #endif diff --git a/SHAMapDiff.cpp b/SHAMapDiff.cpp index 00a29a8fe4..ccc9f0fc50 100644 --- a/SHAMapDiff.cpp +++ b/SHAMapDiff.cpp @@ -29,7 +29,7 @@ bool SHAMap::compare(SHAMap::pointer otherMap, SHAMapDiff& differences, int maxC nodeStack.push(SHAMapDiffNode(SHAMapNode(), getHash(), otherMap->getHash())); ScopedLock sl(Lock()); - while(nodeStack.size()) + while(!nodeStack.empty()) { SHAMapDiffNode node(nodeStack.top()); nodeStack.pop(); diff --git a/SHAMapNodes.cpp b/SHAMapNodes.cpp index 9554cc2a91..cf6b2b02dd 100644 --- a/SHAMapNodes.cpp +++ b/SHAMapNodes.cpp @@ -168,7 +168,7 @@ bool SHAMapLeafNode::addUpdateItem(SHAMapItem::pointer item) std::cerr << " addi(" << item->getTag().GetHex() << std::endl; #endif std::list::iterator it; - for(it=mItems.begin(); it!=mItems.end(); it++) + for(it=mItems.begin(); it!=mItems.end(); ++it) { SHAMapItem &nodeItem=**it; if(nodeItem.getTag()==item->getTag()) @@ -191,7 +191,7 @@ bool SHAMapLeafNode::addUpdateItem(SHAMapItem::pointer item) bool SHAMapLeafNode::delItem(const uint256& tag) { std::list::iterator it; - for(it=mItems.begin(); it!=mItems.end(); it++) + for(it=mItems.begin(); it!=mItems.end(); ++it) { if((*it)->getTag()==tag) { @@ -211,7 +211,7 @@ SHAMapItem::pointer SHAMapLeafNode::findItem(const uint256& tag) SHAMapItem::pointer SHAMapLeafNode::firstItem() { - if(mItems.size()==0) return SHAMapItem::pointer(); + if(mItems.empty()) return SHAMapItem::pointer(); return *(mItems.begin()); } @@ -254,7 +254,7 @@ SHAMapItem::pointer SHAMapLeafNode::prevItem(const uint256& tag) SHAMapItem::pointer SHAMapLeafNode::lastItem() { - if(mItems.size()==0) return SHAMapItem::pointer(); + if(mItems.empty()) return SHAMapItem::pointer(); return *(mItems.rbegin()); } @@ -262,7 +262,7 @@ SHAMapItem::pointer SHAMapLeafNode::lastItem() bool SHAMapLeafNode::updateHash() { uint256 nh; - if(mItems.size()!=0) + if(!mItems.empty()) { Serializer s; BOOST_FOREACH(const SHAMapItem::pointer &mi, mItems) diff --git a/Transaction.cpp b/Transaction.cpp index 01cefc7312..2c58cec1a4 100644 --- a/Transaction.cpp +++ b/Transaction.cpp @@ -9,7 +9,7 @@ using namespace std; Transaction::Transaction() : mTransactionID(0), mAccountFrom(0), mAccountTo(0), - mAmount(0), mFromAccountSeq(0), mSourceLedger(0), mIdent(0), + mAmount(0), mFee(0), mFromAccountSeq(0), mSourceLedger(0), mIdent(0), mInLedger(0), mStatus(INVALID) { } diff --git a/newcoin.proto b/newcoin.proto index 9106c3b2c9..0974f6ea6a 100644 --- a/newcoin.proto +++ b/newcoin.proto @@ -2,32 +2,32 @@ package newcoin; enum MessageType { // core - HELLO= 0; - ERROR_MSG= 1; - PING= 2; + mtHELLO= 0; + mtERROR_MSG= 1; + mtPING= 2; // network presence detection - GET_CONTACTS= 10; - CONTACT= 11; + mtGET_CONTACTS= 10; + mtCONTACT= 11; // operations for 'small' nodes - SEARCH_TRANSACTION= 20; - GET_ACCOUNT= 21; - ACCOUNT= 22; + mtSEARCH_TRANSACTION= 20; + mtGET_ACCOUNT= 21; + mtACCOUNT= 22; // transaction and ledger processing - TRANSACTION= 30; - GET_LEDGER= 31; - LEDGER= 32; - PROPOSE_LEDGER= 33; - CLOSE_LEDGER= 35; + mtTRANSACTION= 30; + mtGET_LEDGER= 31; + mtLEDGER= 32; + mtPROPOSE_LEDGER= 33; + mtCLOSE_LEDGER= 35; // data replication and synchronization - GET_VALIDATIONS= 40; - VALIDATION= 41; - GET_OBJECT= 42; - OBJECT= 43; + mtGET_VALIDATIONS= 40; + mtVALIDATION= 41; + mtGET_OBJECT= 42; + mtOBJECT= 43; } @@ -47,14 +47,14 @@ you must first combine coins from one address to another. */ enum TransactionStatus { - NEW = 1; // origin node did/could not validate - CURRENT = 2; // scheduled to go in this ledger - COMMITED = 3; // in a closed ledger - REJECT_CONFLICT = 4; - REJECT_INVALID = 5; - REJECT_FUNDS = 6; - HELD_SEQ = 7; - HELD_LEDGER = 8; // held for future ledger + tsNEW = 1; // origin node did/could not validate + tsCURRENT = 2; // scheduled to go in this ledger + tsCOMMITED = 3; // in a closed ledger + tsREJECT_CONFLICT = 4; + tsREJECT_INVALID = 5; + tsREJECT_FUNDS = 6; + tsHELD_SEQ = 7; + tsHELD_LEDGER = 8; // held for future ledger } message TMTransaction { @@ -143,13 +143,13 @@ message TMAccount{ message TMIndexedObject { enum ObjectType { - TRANSACTION = 1; - TRANSACTION_NODE = 2; // a node in a transaction tree - TRANSACTION_LEAF = 3; // a leaf in a transaction tree - ACCOUNT = 4; // a single account state (with balance/sequence) - ACCOUNT_NODE = 5; // a node in an account state tree - ACCOUNT_LEAF = 6; // a leaf in an account state tree - LEDGER = 7; + otTRANSACTION = 1; + otTRANSACTION_NODE = 2; // a node in a transaction tree + otTRANSACTION_LEAF = 3; // a leaf in a transaction tree + otACCOUNT = 4; // a single account state (with balance/sequence) + otACCOUNT_NODE = 5; // a node in an account state tree + otACCOUNT_LEAF = 6; // a leaf in an account state tree + otLEDGER = 7; } required bytes hash = 1; diff --git a/rpc.cpp b/rpc.cpp index e5c185423d..7a1cefd503 100644 --- a/rpc.cpp +++ b/rpc.cpp @@ -215,7 +215,6 @@ bool HTTPAuthorized(map& mapHeaders) // // 1.0 spec: http://json-rpc.org/wiki/specification // 1.2 spec: http://groups.google.com/group/json-rpc/web/json-rpc-over-http -// http://www.codeproject.com/KB/recipes/JSON_Spirit.aspx // std::string JSONRPCRequest(const std::string& strMethod, const Json::Value& params, const Json::Value& id) diff --git a/uint256.h b/uint256.h index aff3487965..4ee67d2638 100644 --- a/uint256.h +++ b/uint256.h @@ -12,13 +12,8 @@ #include #include -#if defined(_MSC_VER) || defined(__BORLANDC__) -typedef __int64 int64; -typedef unsigned __int64 uint64; -#else -typedef long long int64; -typedef unsigned long long uint64; -#endif +#include "types.h" + #if defined(_MSC_VER) && _MSC_VER < 1300 #define for if (false) ; else for #endif @@ -59,7 +54,7 @@ public: base_uint ret; for (int i = 0; i < WIDTH; i++) ret.pn[i] = ~pn[i]; - ret++; + ++ret; return ret; } @@ -649,17 +644,17 @@ inline int Testuint256AdHoc(std::vector vArg) printf("%s\n", g.ToString().c_str()); - g--; printf("g--\n"); + --g; printf("--g\n"); printf("%s\n", g.ToString().c_str()); g--; printf("g--\n"); printf("%s\n", g.ToString().c_str()); g++; printf("g++\n"); printf("%s\n", g.ToString().c_str()); - g++; printf("g++\n"); + ++g; printf("++g\n"); printf("%s\n", g.ToString().c_str()); g++; printf("g++\n"); printf("%s\n", g.ToString().c_str()); - g++; printf("g++\n"); + ++g; printf("++g\n"); printf("%s\n", g.ToString().c_str());