From e6464e28329f861983ae63bf09328cfda7a5e824 Mon Sep 17 00:00:00 2001 From: jed Date: Wed, 13 Jun 2012 09:57:08 -0700 Subject: [PATCH] more work on your peer list --- src/Application.cpp | 2 +- src/ConnectionPool.cpp | 6 ++---- src/ConnectionPool.h | 2 +- src/DBInit.cpp | 1 + src/Log.cpp | 2 +- src/Peer.cpp | 38 +++++++++++++++++++++++--------------- 6 files changed, 29 insertions(+), 22 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 241a4b878f..3218490bc4 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -21,7 +21,7 @@ DatabaseCon::DatabaseCon(const std::string& strName, const char *initStrings[], { boost::filesystem::path pPath = theConfig.DATA_DIR / strName; - mDatabase = new SqliteDatabase((const char*) pPath.c_str()); + mDatabase = new SqliteDatabase(pPath.string().c_str()); mDatabase->connect(); for(int i = 0; i < initCount; ++i) mDatabase->executeSQL(initStrings[i], true); diff --git a/src/ConnectionPool.cpp b/src/ConnectionPool.cpp index 398a9bcec1..11f32f587f 100644 --- a/src/ConnectionPool.cpp +++ b/src/ConnectionPool.cpp @@ -61,7 +61,7 @@ bool ConnectionPool::getTopNAddrs(int n,std::vector& addrs) return true; } -bool ConnectionPool::savePeer(const std::string& strIp, int iPort) +bool ConnectionPool::savePeer(const std::string& strIp, int iPort,char code) { Database* db = theApp->getWalletDB()->getDB(); @@ -73,7 +73,7 @@ bool ConnectionPool::savePeer(const std::string& strIp, int iPort) { if( db->getInt(0)==0) { - db->executeSQL(str(boost::format("INSERT INTO PeerIps (IpPort,Score,Source) values (%s,0,'a');") % ipPort)); + db->executeSQL(str(boost::format("INSERT INTO PeerIps (IpPort,Score,Source) values (%s,0,'%c');") % ipPort % code)); return true; }// else we already had this peer }else std::cout << "Error saving Peer" << std::endl; @@ -285,8 +285,6 @@ bool ConnectionPool::peerConnected(Peer::pointer peer, const NewcoinAddress& na) { mConnectedMap[na] = peer; bSuccess = true; - - savePeer(peer->getIP(),peer->getPort()); } diff --git a/src/ConnectionPool.h b/src/ConnectionPool.h index 7516e19576..0c84c20971 100644 --- a/src/ConnectionPool.h +++ b/src/ConnectionPool.h @@ -56,7 +56,7 @@ public: // Peer connectivity notification. // bool getTopNAddrs(int n,std::vector& addrs); - bool savePeer(const std::string& strIp, int iPort); + bool savePeer(const std::string& strIp, int iPort, char code); // Inbound connection, false=reject bool peerRegister(Peer::pointer peer, const std::string& strIp, int iPort); diff --git a/src/DBInit.cpp b/src/DBInit.cpp index 22d7b67d1a..a558a7642f 100644 --- a/src/DBInit.cpp +++ b/src/DBInit.cpp @@ -199,6 +199,7 @@ const char *WalletDBInit[] = { // 'V' = Validation file // 'M' = Manually added. // 'I' = Inbound connection. + // 'T' = Told by other peer // 'O' = Other. // ScanNext: // When to next scan. Null=not scanning. diff --git a/src/Log.cpp b/src/Log.cpp index ded888a6d6..243e9ee592 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -27,7 +27,7 @@ Log::~Log() boost::recursive_mutex::scoped_lock sl(sLock); if (mSeverity >= sMinSeverity) { - std::cerr << logMsg << std::endl; + // TEMP std::cerr << logMsg << std::endl; } } diff --git a/src/Peer.cpp b/src/Peer.cpp index 3a7507e49c..e0f4ce878f 100644 --- a/src/Peer.cpp +++ b/src/Peer.cpp @@ -572,6 +572,9 @@ void Peer::recvHello(newcoin::TMHello& packet) mClosedLedgerTime = boost::posix_time::second_clock::universal_time(); } + + theApp->getConnectionPool().savePeer(getIP(),packet.ipv4port(),'I'); + bDetach = false; } @@ -684,28 +687,33 @@ void Peer::recvGetContacts(newcoin::TMGetContacts& packet) } // return a list of your favorite people +// TODO: filter out all the LAN peers void Peer::recvGetPeers(newcoin::TMGetPeers& packet) { std::vector addrs; theApp->getConnectionPool().getTopNAddrs(30,addrs); - newcoin::TMPeers peers; - - for(int n=0; nset_ipv4(inet_addr(strIP.c_str())); - addr->set_ipv4port(port); + newcoin::TMPeers peers; - std::cout << "Teaching about: " << strIP << std::endl; + for(int n=0; nset_ipv4(inet_addr(strIP.c_str())); + addr->set_ipv4port(port); + + std::cout << "Teaching about: " << strIP << std::endl; + } + + + PackedMessage::pointer message = boost::make_shared(peers, newcoin::mtPEERS); + sendPacket(message); } - - - PackedMessage::pointer message = boost::make_shared(peers, newcoin::mtPEERS); - sendPacket(message); } +// TODO: filter out all the LAN peers void Peer::recvPeers(newcoin::TMPeers& packet) { for(int i = 0; i < packet.nodes().size(); ++i) @@ -717,7 +725,7 @@ void Peer::recvPeers(newcoin::TMPeers& packet) std::cout << "Learning about: " << strIP << std::endl; - theApp->getConnectionPool().savePeer(strIP,port); + theApp->getConnectionPool().savePeer(strIP,port,'T'); } }