Add private peers.

This commit is contained in:
Arthur Britto
2012-11-20 14:48:53 -08:00
parent ea00a2d0d0
commit ad4725ae74
4 changed files with 22 additions and 4 deletions

View File

@@ -300,6 +300,7 @@ void ConnectionPool::connectTo(const std::string& strIp, int iPort)
{
if (theConfig.RUN_STANDALONE)
return;
{
Database* db = theApp->getWalletDB()->getDB();
ScopedLock sl(theApp->getWalletDB()->getDBLock());

View File

@@ -430,24 +430,29 @@ void Peer::processReadBuffer()
case ripple::mtCONTACT:
{
ripple::TMContact msg;
if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
recvContact(msg);
else
cLog(lsWARNING) << "parse error: " << type;
}
break;
case ripple::mtGET_PEERS:
{
ripple::TMGetPeers msg;
if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
recvGetPeers(msg);
else
cLog(lsWARNING) << "parse error: " << type;
}
break;
case ripple::mtPEERS:
{
ripple::TMPeers msg;
if (msg.ParseFromArray(&mReadbuf[HEADER_SIZE], mReadbuf.size() - HEADER_SIZE))
recvPeers(msg);
else
@@ -666,7 +671,17 @@ void Peer::recvHello(ripple::TMHello& packet)
std::string strIP = getSocket().remote_endpoint().address().to_string();
int iPort = packet.ipv4port();
theApp->getConnectionPool().savePeer(strIP, iPort, UniqueNodeList::vsInbound);
if (mHello.nodeprivate())
{
cLog(lsINFO) << boost::str(boost::format("Recv(Hello): Private connection: %s %s") % strIP % iPort);
}
else
{
// Don't save IP address if the node wants privacy.
// Note: We don't go so far as to delete it. If a node which has previously announced itself now wants
// privacy, it should at least change its port.
theApp->getConnectionPool().savePeer(strIP, iPort, UniqueNodeList::vsInbound);
}
}
// Consider us connected. No longer accepting mtHELLO.
@@ -994,7 +1009,7 @@ void Peer::recvGetContacts(ripple::TMGetContacts& packet)
{
}
// return a list of your favorite people
// 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(ripple::TMGetPeers& packet)
@@ -1510,6 +1525,7 @@ void Peer::sendHello()
h.set_nodepublic(theApp->getWallet().getNodePublic().humanNodePublic());
h.set_nodeproof(&vchSig[0], vchSig.size());
h.set_ipv4port(theConfig.PEER_PORT);
h.set_nodeprivate(theConfig.PEER_PRIVATE);
Ledger::pointer closedLedger = theApp->getMasterLedger().getClosedLedger();
if (closedLedger && closedLedger->isClosed())
@@ -1526,7 +1542,7 @@ void Peer::sendHello()
void Peer::sendGetPeers()
{
// get other peers this guy knows about
// Ask peer for known other peers.
ripple::TMGetPeers getPeers;
getPeers.set_doweneedthis(1);

View File

@@ -49,6 +49,7 @@ private:
ipPort mIpPortConnect;
uint256 mCookieHash;
uint64 mPeerId;
bool mPrivate; // Keep peer IP private.
uint256 mClosedLedgerHash, mPreviousLedgerHash;
std::list<uint256> mRecentLedgers;

View File

@@ -34,7 +34,6 @@ enum MessageType {
// Sent on connect
message TMHello {
required uint32 protoVersion = 1;
required uint32 protoVersionMin = 2;
@@ -46,6 +45,7 @@ message TMHello {
optional uint32 ledgerIndex = 8;
optional bytes ledgerClosed = 9; // our last closed ledger
optional bytes ledgerPrevious = 10; // the ledger before the last closed ledger
optional bool nodePrivate = 11; // Request to not forward IP.
}