From f1277325ff9d2cd0fe4f1cd5be49c5bc74842751 Mon Sep 17 00:00:00 2001 From: jed Date: Wed, 13 Jun 2012 10:50:02 -0700 Subject: [PATCH] fix for unl_add --- src/DBInit.cpp | 5 +++-- src/Peer.cpp | 1 + src/RPCServer.cpp | 12 ++++++++---- src/UniqueNodeList.cpp | 14 +++++++++++--- 4 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/DBInit.cpp b/src/DBInit.cpp index a558a7642f..fc4a1d6d4a 100644 --- a/src/DBInit.cpp +++ b/src/DBInit.cpp @@ -54,7 +54,7 @@ int LedgerDBCount = sizeof(LedgerDBInit) / sizeof(const char *); // Wallet database holds local accounts and trusted nodes const char *WalletDBInit[] = { - // Node identity must be persisted for CAS routing and responsibilites. + // Node identity must be persisted for CAS routing and responsibilities. "CREATE TABLE NodeIdentity ( \ PublicKey CHARACTER(53), \ PrivateKey CHARACTER(52), \ @@ -148,7 +148,8 @@ const char *WalletDBInit[] = { "CREATE TABLE TrustedNodes ( \ PublicKey CHARACTER(53) PRIMARY KEY NOT NULL, \ Score INTEGER DEFAULT 0 NOT NULL, \ - Seen DATETIME \ + Seen DATETIME, \ + Comment TEXT \ );", // List of referrals. diff --git a/src/Peer.cpp b/src/Peer.cpp index e0f4ce878f..f540186fee 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -688,6 +688,7 @@ void Peer::recvGetContacts(newcoin::TMGetContacts& packet) // return a list of your favorite people // TODO: filter out all the LAN peers +// TODO: filter out the peer you are talking to void Peer::recvGetPeers(newcoin::TMGetPeers& packet) { std::vector addrs; diff --git a/src/RPCServer.cpp b/src/RPCServer.cpp index 55c72fd07f..6f56fe499e 100644 --- a/src/RPCServer.cpp +++ b/src/RPCServer.cpp @@ -1466,7 +1466,7 @@ Json::Value RPCServer::doAccountTransactions(Json::Value& params) Json::Value RPCServer::doUnlAdd(Json::Value& params) { std::string strNode = params[0u].asString(); - std::string strComment = (params.size() == 2) ? "" : params[1u].asString(); + std::string strComment = (params.size() == 2) ? params[1u].asString() : ""; NewcoinAddress nodePublic; @@ -1988,7 +1988,8 @@ Json::Value RPCServer::doUnlDefault(Json::Value& params) { } // unl_delete -Json::Value RPCServer::doUnlDelete(Json::Value& params) { +Json::Value RPCServer::doUnlDelete(Json::Value& params) +{ std::string strNodePublic = params[0u].asString(); NewcoinAddress naNodePublic; @@ -2005,8 +2006,11 @@ Json::Value RPCServer::doUnlDelete(Json::Value& params) { } } -Json::Value RPCServer::doUnlList(Json::Value& params) { - return theApp->getUNL().getUnlJson(); +Json::Value RPCServer::doUnlList(Json::Value& params) +{ + Json::Value obj(Json::objectValue); + obj["unl"]=theApp->getUNL().getUnlJson(); + return obj; } // unl_reset diff --git a/src/UniqueNodeList.cpp b/src/UniqueNodeList.cpp index 72730a17d0..be3d39dff0 100644 --- a/src/UniqueNodeList.cpp +++ b/src/UniqueNodeList.cpp @@ -1195,7 +1195,6 @@ void UniqueNodeList::setSeedDomains(const seedDomain& sdSource, bool bNext) } // Add a trusted node. Called by RPC or other source. -// XXX allow update of comment. // XXX Broken should operate on seeds. void UniqueNodeList::nodeAddPublic(const NewcoinAddress& naNodePublic, const std::string& strComment) { @@ -1205,8 +1204,17 @@ void UniqueNodeList::nodeAddPublic(const NewcoinAddress& naNodePublic, const std Database* db=theApp->getWalletDB()->getDB(); ScopedLock sl(theApp->getWalletDB()->getDBLock()); - db->executeSQL(str(boost::format("INSERT INTO TrustedNodes (PublicKey,Comment) values (%s,%s);") - % db->escape(strPublicKey) % db->escape(strComment))); + if( db->executeSQL(str(boost::format("SELECT count(*) from TrustedNodes where PublicKey=%s;") % db->escape(strPublicKey))) && + db->startIterRows() && db->getInt(0)==1 ) + { // exists. update the comment + db->executeSQL(str(boost::format("UPDATE TrustedNodes set Comment=%s where PublicKey=%s;") % db->escape(strComment) % db->escape(strPublicKey) )); + }else + { // new node + db->executeSQL(str(boost::format("INSERT INTO TrustedNodes (PublicKey,Comment) values (%s,%s);") + % db->escape(strPublicKey) % db->escape(strComment))); + } + + } {