From 51c5de61d93022d964b3ff9b9ebd88ee5143cee8 Mon Sep 17 00:00:00 2001 From: JoelKatz Date: Fri, 12 Oct 2012 03:59:25 -0700 Subject: [PATCH] TMGetObjectByHash design changes. --- src/Peer.cpp | 38 +++++++++++++++++++++----------------- src/Peer.h | 2 -- src/newcoin.proto | 44 ++++++++++++++++++++------------------------ 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/Peer.cpp b/src/Peer.cpp index 585b720d7f..45ffc4b375 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -540,7 +540,7 @@ void Peer::processReadBuffer() break; #endif - case newcoin::mtGET_OBJECT: + case newcoin::mtGET_OBJECTS: { newcoin::TMGetObjectByHash msg; if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) @@ -549,15 +549,6 @@ void Peer::processReadBuffer() } break; - case newcoin::mtOBJECT: - { - newcoin::TMObjectByHash msg; - if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE)) - recvObjectByHash(msg); - else std::cerr << "parse error: " << type << std::endl; - } - break; - default: std::cerr << "Unknown Msg: " << type << std::endl; std::cerr << strHex(&mReadbuf[0], mReadbuf.size()); @@ -872,16 +863,29 @@ void Peer::recvPeers(newcoin::TMPeers& packet) } } -void Peer::recvIndexedObject(newcoin::TMIndexedObject& packet) -{ -} - void Peer::recvGetObjectByHash(newcoin::TMGetObjectByHash& packet) { -} + if (packet.query()) + { // this is a query + newcoin::TMGetObjectByHash reply; -void Peer::recvObjectByHash(newcoin::TMObjectByHash& packet) -{ + reply.clear_query(); + if (packet.has_seq()) + reply.set_seq(packet.seq()); + reply.set_type(packet.type()); + if (packet.has_ledgerhash()) + reply.set_ledgerhash(packet.ledgerhash()); + + for (unsigned i = 0; i < packet.objects_size(); ++i) + { + const newcoin::TMIndexedObject& obj = packet.objects(i); + // WRITEME + } + } + else + { // this is a reply + // WRITEME + } } void Peer::recvPing(newcoin::TMPing& packet) diff --git a/src/Peer.h b/src/Peer.h index 0b28a1dc9b..301089caec 100644 --- a/src/Peer.h +++ b/src/Peer.h @@ -102,9 +102,7 @@ protected: void recvGetContacts(newcoin::TMGetContacts& packet); void recvGetPeers(newcoin::TMGetPeers& packet); void recvPeers(newcoin::TMPeers& packet); - void recvIndexedObject(newcoin::TMIndexedObject& packet); void recvGetObjectByHash(newcoin::TMGetObjectByHash& packet); - void recvObjectByHash(newcoin::TMObjectByHash& packet); void recvPing(newcoin::TMPing& packet); void recvErrorMessage(newcoin::TMErrorMsg& packet); void recvSearchTransaction(newcoin::TMSearchTransaction& packet); diff --git a/src/newcoin.proto b/src/newcoin.proto index cd33de9f0f..743ab55eaa 100644 --- a/src/newcoin.proto +++ b/src/newcoin.proto @@ -28,8 +28,7 @@ enum MessageType { // data replication and synchronization mtGET_VALIDATIONS = 40; mtVALIDATION = 41; - mtGET_OBJECT = 42; - mtOBJECT = 43; + mtGET_OBJECTS = 42; } @@ -193,34 +192,31 @@ message TMAccount{ message TMIndexedObject { - enum ObjectType { - 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; - required ObjectType type = 2; + optional bytes hash = 1; + optional bytes nodeID = 2; + optional bytes index = 3; + optional bytes data = 4; } - - message TMGetObjectByHash { - required TMIndexedObject object = 1; - optional uint32 seq = 2; // used to match replies to queries + enum ObjectType { + otUNKNOWN = 0; + otLEDGER = 1; + otTRANSACTION = 2; + otTRANSACTION_NODE = 3; + otSTATE_NODE = 4; + otCAS_OBJECT = 5; + } + + required ObjectType type = 1; + required bool query = 2; // is this a query or a reply? + optional uint32 seq = 3; // used to match replies to queries + optional bytes ledgerHash = 4; // the hash of the ledger these queries are for + optional bool fat = 5; // return related nodes + repeated TMIndexedObject objects = 6; // the specific objects requested } -message TMObjectByHash -{ - optional TMIndexedObject object = 1; // present unless no object found - optional bytes data = 2; // present unless no object found - optional uint32 seq = 3; // matches seq from query -} message TMLedgerNode { required bytes nodedata = 1;