mirror of
https://github.com/XRPLF/rippled.git
synced 2025-12-06 17:27:55 +00:00
Add PeerFinder peer discovery logic and unit test
This commit is contained in:
@@ -17,6 +17,7 @@ class ApplicationImp
|
||||
, public SharedSingleton <ApplicationImp>
|
||||
, public NodeStore::Scheduler
|
||||
, LeakChecked <ApplicationImp>
|
||||
, PeerFinder::Callback
|
||||
{
|
||||
public:
|
||||
// RAII container for a boost::asio::io_service run by beast threads
|
||||
@@ -175,6 +176,7 @@ public:
|
||||
, mUNL (UniqueNodeList::New ())
|
||||
, mProofOfWorkFactory (ProofOfWorkFactory::New ())
|
||||
, m_loadManager (LoadManager::New ())
|
||||
, mPeerFinder (PeerFinder::New (*this))
|
||||
// VFALCO End new stuff
|
||||
// VFALCO TODO replace all NULL with nullptr
|
||||
, mRpcDB (NULL)
|
||||
@@ -366,6 +368,11 @@ public:
|
||||
return *m_peers;
|
||||
}
|
||||
|
||||
PeerFinder& getPeerFinder ()
|
||||
{
|
||||
return *mPeerFinder;
|
||||
}
|
||||
|
||||
// VFALCO TODO Move these to the .cpp
|
||||
bool running ()
|
||||
{
|
||||
@@ -698,6 +705,8 @@ private:
|
||||
void startNewLedger ();
|
||||
bool loadOldLedger (const std::string&, bool);
|
||||
|
||||
void onAnnounceAddress ();
|
||||
|
||||
private:
|
||||
Application::LockType mMasterLock;
|
||||
|
||||
@@ -735,6 +744,7 @@ private:
|
||||
ScopedPointer <PeerDoor> m_peerProxyDoor;
|
||||
ScopedPointer <WSDoor> m_wsPublicDoor;
|
||||
ScopedPointer <WSDoor> m_wsPrivateDoor;
|
||||
ScopedPointer <PeerFinder> mPeerFinder;
|
||||
// VFALCO End Clean stuff
|
||||
|
||||
DatabaseCon* mRpcDB;
|
||||
@@ -1189,6 +1199,11 @@ void ApplicationImp::updateTables ()
|
||||
}
|
||||
}
|
||||
|
||||
void ApplicationImp::onAnnounceAddress ()
|
||||
{
|
||||
// NIKB CODEME
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
Application& getApp ()
|
||||
|
||||
@@ -28,6 +28,7 @@ class SerializedLedgerEntry;
|
||||
class TransactionMaster;
|
||||
class TxQueue;
|
||||
class LocalCredentials;
|
||||
class PeerFinder;
|
||||
|
||||
class DatabaseCon;
|
||||
|
||||
@@ -95,6 +96,7 @@ public:
|
||||
virtual TransactionMaster& getMasterTransaction () = 0;
|
||||
virtual TxQueue& getTxQueue () = 0;
|
||||
virtual LocalCredentials& getLocalCredentials () = 0;
|
||||
virtual PeerFinder& getPeerFinder () = 0;
|
||||
|
||||
virtual DatabaseCon* getRpcDB () = 0;
|
||||
virtual DatabaseCon* getTxnDB () = 0;
|
||||
|
||||
@@ -335,6 +335,7 @@ private:
|
||||
void sendPacketForce (const PackedMessage::pointer & packet);
|
||||
|
||||
void sendHello ();
|
||||
void SendAnnounce ();
|
||||
|
||||
void recvHello (protocol::TMHello & packet);
|
||||
void recvCluster (protocol::TMCluster & packet);
|
||||
@@ -345,6 +346,7 @@ private:
|
||||
void recvGetContacts (protocol::TMGetContacts & packet);
|
||||
void recvGetPeers (protocol::TMGetPeers & packet, Application::ScopedLockType& masterLockHolder);
|
||||
void recvPeers (protocol::TMPeers & packet);
|
||||
void recvAnnounce (protocol::TMAnnounce & packet);
|
||||
void recvGetObjectByHash (const boost::shared_ptr<protocol::TMGetObjectByHash>& packet);
|
||||
void recvPing (protocol::TMPing & packet);
|
||||
void recvErrorMessage (protocol::TMErrorMsg & packet);
|
||||
@@ -834,6 +836,17 @@ void PeerImp::processReadBuffer ()
|
||||
}
|
||||
break;
|
||||
|
||||
case protocol::mtANNOUNCE:
|
||||
{
|
||||
event->reName ("PeerImp::announce");
|
||||
protocol::TMAnnounce msg;
|
||||
|
||||
if(msg.ParseFromArray (&mReadbuf[PackedMessage::kHeaderBytes], mReadbuf.size() - PackedMessage::kHeaderBytes))
|
||||
recvAnnounce (msg);
|
||||
else
|
||||
WriteLog (lsWARNING, Peer) << "parse error: " << type;;
|
||||
}
|
||||
|
||||
case protocol::mtSEARCH_TRANSACTION:
|
||||
{
|
||||
event->reName ("PeerImp::searchtransaction");
|
||||
@@ -1606,6 +1619,15 @@ void PeerImp::recvPeers (protocol::TMPeers& packet)
|
||||
}
|
||||
}
|
||||
|
||||
void PeerImp::recvAnnounce (protocol::TMAnnounce& packet)
|
||||
{
|
||||
// NIKB TODO: First we need to push this announcement to peerfinder
|
||||
// and then this is not a private peer, we need to "adjust" this
|
||||
// announcement (i.e. the hop count) and push it out to all our
|
||||
// other peers. We must be careful to avoid cycles (that is to
|
||||
// never send an ANNOUNCE back to the peer we got it from).
|
||||
}
|
||||
|
||||
void PeerImp::recvGetObjectByHash (const boost::shared_ptr<protocol::TMGetObjectByHash>& ptr)
|
||||
{
|
||||
protocol::TMGetObjectByHash& packet = *ptr;
|
||||
@@ -2362,6 +2384,32 @@ void PeerImp::sendHello ()
|
||||
sendPacket (packet, true);
|
||||
}
|
||||
|
||||
void PeerImp::SendAnnounce ()
|
||||
{
|
||||
protocol::TMAnnounce a;
|
||||
|
||||
std::string selfID = getApp().getLocalCredentials ().getNodePublic ().humanNodePublic ();
|
||||
|
||||
a.set_serverid(selfID);
|
||||
|
||||
// Since we are announcing ourselves, the hopcount is one and the "via" peer is us.
|
||||
// If hopcount is anything else, the "via" peer must be different from the "serverid".
|
||||
a.set_viapeerid(selfID);
|
||||
a.set_hopcount(1); // A direct connection
|
||||
|
||||
// Announce whether we're a private peer or not. Should we even send an ANNOUNCE
|
||||
// for private peers?
|
||||
a.set_privatepeer(getConfig ().PEER_PRIVATE);
|
||||
|
||||
protocol::TMIPv4EndPoint *ep = a.add_connectpoints();
|
||||
|
||||
ep->set_ipv4(inet_addr (getNativeSocket ().local_endpoint ().address ().to_string ().c_str()));
|
||||
ep->set_ipv4port(getConfig ().peerListeningPort);
|
||||
|
||||
PackedMessage::pointer packet = boost::make_shared<PackedMessage> (a, protocol::mtANNOUNCE);
|
||||
sendPacket (packet, true);
|
||||
}
|
||||
|
||||
void PeerImp::sendGetPeers ()
|
||||
{
|
||||
// Ask peer for known other peers.
|
||||
|
||||
Reference in New Issue
Block a user