mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
more work on your peer list
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -61,7 +61,7 @@ bool ConnectionPool::getTopNAddrs(int n,std::vector<std::string>& 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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
// Peer connectivity notification.
|
||||
//
|
||||
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
|
||||
bool peerRegister(Peer::pointer peer, const std::string& strIp, int iPort);
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
src/Peer.cpp
10
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,10 +687,13 @@ 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<std::string> addrs;
|
||||
theApp->getConnectionPool().getTopNAddrs(30,addrs);
|
||||
if(addrs.size())
|
||||
{
|
||||
newcoin::TMPeers peers;
|
||||
|
||||
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);
|
||||
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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user