more work on your peer list

This commit is contained in:
jed
2012-06-13 09:57:08 -07:00
parent 089541d630
commit e6464e2832
6 changed files with 29 additions and 22 deletions

View File

@@ -21,7 +21,7 @@ DatabaseCon::DatabaseCon(const std::string& strName, const char *initStrings[],
{ {
boost::filesystem::path pPath = theConfig.DATA_DIR / strName; 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(); mDatabase->connect();
for(int i = 0; i < initCount; ++i) for(int i = 0; i < initCount; ++i)
mDatabase->executeSQL(initStrings[i], true); mDatabase->executeSQL(initStrings[i], true);

View File

@@ -61,7 +61,7 @@ bool ConnectionPool::getTopNAddrs(int n,std::vector<std::string>& addrs)
return true; 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(); Database* db = theApp->getWalletDB()->getDB();
@@ -73,7 +73,7 @@ bool ConnectionPool::savePeer(const std::string& strIp, int iPort)
{ {
if( db->getInt(0)==0) 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; return true;
}// else we already had this peer }// else we already had this peer
}else std::cout << "Error saving Peer" << std::endl; }else std::cout << "Error saving Peer" << std::endl;
@@ -285,8 +285,6 @@ bool ConnectionPool::peerConnected(Peer::pointer peer, const NewcoinAddress& na)
{ {
mConnectedMap[na] = peer; mConnectedMap[na] = peer;
bSuccess = true; bSuccess = true;
savePeer(peer->getIP(),peer->getPort());
} }

View File

@@ -56,7 +56,7 @@ public:
// Peer connectivity notification. // Peer connectivity notification.
// //
bool getTopNAddrs(int n,std::vector<std::string>& addrs); bool getTopNAddrs(int n,std::vector<std::string>& addrs);
bool savePeer(const std::string& strIp, int iPort); bool savePeer(const std::string& strIp, int iPort, char code);
// Inbound connection, false=reject // Inbound connection, false=reject
bool peerRegister(Peer::pointer peer, const std::string& strIp, int iPort); bool peerRegister(Peer::pointer peer, const std::string& strIp, int iPort);

View File

@@ -199,6 +199,7 @@ const char *WalletDBInit[] = {
// 'V' = Validation file // 'V' = Validation file
// 'M' = Manually added. // 'M' = Manually added.
// 'I' = Inbound connection. // 'I' = Inbound connection.
// 'T' = Told by other peer
// 'O' = Other. // 'O' = Other.
// ScanNext: // ScanNext:
// When to next scan. Null=not scanning. // When to next scan. Null=not scanning.

View File

@@ -27,7 +27,7 @@ Log::~Log()
boost::recursive_mutex::scoped_lock sl(sLock); boost::recursive_mutex::scoped_lock sl(sLock);
if (mSeverity >= sMinSeverity) if (mSeverity >= sMinSeverity)
{ {
std::cerr << logMsg << std::endl; // TEMP std::cerr << logMsg << std::endl;
} }
} }

View File

@@ -572,6 +572,9 @@ void Peer::recvHello(newcoin::TMHello& packet)
mClosedLedgerTime = boost::posix_time::second_clock::universal_time(); mClosedLedgerTime = boost::posix_time::second_clock::universal_time();
} }
theApp->getConnectionPool().savePeer(getIP(),packet.ipv4port(),'I');
bDetach = false; bDetach = false;
} }
@@ -684,10 +687,13 @@ void Peer::recvGetContacts(newcoin::TMGetContacts& packet)
} }
// return a list of your favorite people // return a list of your favorite people
// TODO: filter out all the LAN peers
void Peer::recvGetPeers(newcoin::TMGetPeers& packet) void Peer::recvGetPeers(newcoin::TMGetPeers& packet)
{ {
std::vector<std::string> addrs; std::vector<std::string> addrs;
theApp->getConnectionPool().getTopNAddrs(30,addrs); theApp->getConnectionPool().getTopNAddrs(30,addrs);
if(addrs.size())
{
newcoin::TMPeers peers; newcoin::TMPeers peers;
for(int n=0; n<addrs.size(); n++) for(int n=0; n<addrs.size(); n++)
@@ -706,6 +712,8 @@ void Peer::recvGetPeers(newcoin::TMGetPeers& packet)
PackedMessage::pointer message = boost::make_shared<PackedMessage>(peers, newcoin::mtPEERS); PackedMessage::pointer message = boost::make_shared<PackedMessage>(peers, newcoin::mtPEERS);
sendPacket(message); sendPacket(message);
} }
}
// TODO: filter out all the LAN peers
void Peer::recvPeers(newcoin::TMPeers& packet) void Peer::recvPeers(newcoin::TMPeers& packet)
{ {
for(int i = 0; i < packet.nodes().size(); ++i) 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; std::cout << "Learning about: " << strIP << std::endl;
theApp->getConnectionPool().savePeer(strIP,port); theApp->getConnectionPool().savePeer(strIP,port,'T');
} }
} }