Refactor Overlay for Structured Network support:

* Move overlay up one directory
* Add abstract_protocol_handler, message_stream
* Add peer_protocol_detector
* Tidy up some declarations
* Use strand::running_in_this_thread instead of bool
* Update README.md
* Replace protocol message read loop:
  - Process data in arbitrary size chunks
  - message_stream extracts individual messages
  - peer_protocol_detector identifies the handshake
  - abstract_protocol_handler used for dispatching messages
* Remove unused protocol message types:
  - mtACCOUNT
  - mtCONTACT
  - mtERROR
  - mtGET_ACCOUNT
  - mtGET_CONTACTS
  - mtGET_VALIDATIONS
  - mtSEARCH_TRANSACTION
  - mtUNUSED_FIELD

Conflicts:
	src/ripple/module/app/main/Application.cpp
	src/ripple/module/app/misc/NetworkOPs.cpp
	src/ripple/module/app/peers/PeerSet.cpp
This commit is contained in:
Vinnie Falco
2014-06-10 14:56:45 -07:00
parent 3e2c3ba035
commit d6066183b9
39 changed files with 3307 additions and 3103 deletions

View File

@@ -2720,31 +2720,6 @@
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\net\rpc\RPCUtil.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\Message.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\Overlay.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\Peer.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\make_Overlay.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\predicates.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\overlay\impl\Message.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\module\overlay\impl\OverlayImpl.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\overlay\impl\OverlayImpl.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\overlay\impl\PeerDoor.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\overlay\impl\PeerDoor.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\impl\PeerImp.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\rpc\ErrorCodes.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\rpc\Manager.h">
@@ -3108,6 +3083,49 @@
<ClCompile Include="..\..\src\ripple\nodestore\tests\TimingTests.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\Message.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\Overlay.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\Peer.h">
</ClInclude>
<None Include="..\..\src\ripple\overlay\README.md">
</None>
<ClCompile Include="..\..\src\ripple\overlay\impl\Message.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClCompile Include="..\..\src\ripple\overlay\impl\OverlayImpl.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\impl\OverlayImpl.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\overlay\impl\PeerDoor.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerDoor.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\overlay\impl\PeerImp.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerImp.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\impl\Tuning.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\impl\abstract_protocol_handler.h">
</ClInclude>
<ClCompile Include="..\..\src\ripple\overlay\impl\message_name.cpp">
<ExcludedFromBuild>True</ExcludedFromBuild>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\impl\message_name.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\impl\message_stream.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\impl\peer_protocol_detector.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\make_Overlay.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\predicates.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\api\Callback.h">
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\api\Config.h">

View File

@@ -433,15 +433,6 @@
<Filter Include="ripple\module\net\rpc">
<UniqueIdentifier>{643F2F19-8319-49F7-7DF1-4BF4F52BF4BF}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\module\overlay">
<UniqueIdentifier>{AE687926-F53E-728F-2D48-A1DEC283E86E}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\module\overlay\api">
<UniqueIdentifier>{909364A1-443C-393A-3505-D36E048D7181}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\module\overlay\impl">
<UniqueIdentifier>{C04BC25B-9F43-7B79-91FE-6C62B0E206EE}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\module\rpc">
<UniqueIdentifier>{4DB18141-EDCD-D13F-A8D3-407F5EF72217}</UniqueIdentifier>
</Filter>
@@ -469,6 +460,12 @@
<Filter Include="ripple\nodestore\tests">
<UniqueIdentifier>{3FDC73B9-A9C7-3533-FD40-E4032B9FA9FB}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\overlay">
<UniqueIdentifier>{51E817F6-DC2E-045A-9009-37E3D16D0990}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\overlay\impl">
<UniqueIdentifier>{07E4BC73-2B68-D0D1-D922-FEBBB573F503}</UniqueIdentifier>
</Filter>
<Filter Include="ripple\peerfinder">
<UniqueIdentifier>{186385AD-A056-FA3A-7E0E-759EB55E9EAB}</UniqueIdentifier>
</Filter>
@@ -3858,39 +3855,6 @@
<ClInclude Include="..\..\src\ripple\module\net\rpc\RPCUtil.h">
<Filter>ripple\module\net\rpc</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\Message.h">
<Filter>ripple\module\overlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\Overlay.h">
<Filter>ripple\module\overlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\Peer.h">
<Filter>ripple\module\overlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\make_Overlay.h">
<Filter>ripple\module\overlay\api</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\api\predicates.h">
<Filter>ripple\module\overlay\api</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\overlay\impl\Message.cpp">
<Filter>ripple\module\overlay\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\module\overlay\impl\OverlayImpl.cpp">
<Filter>ripple\module\overlay\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\overlay\impl\OverlayImpl.h">
<Filter>ripple\module\overlay\impl</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\module\overlay\impl\PeerDoor.cpp">
<Filter>ripple\module\overlay\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\module\overlay\impl\PeerDoor.h">
<Filter>ripple\module\overlay\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\overlay\impl\PeerImp.h">
<Filter>ripple\module\overlay\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\module\rpc\ErrorCodes.h">
<Filter>ripple\module\rpc</Filter>
</ClInclude>
@@ -4293,6 +4257,63 @@
<ClCompile Include="..\..\src\ripple\nodestore\tests\TimingTests.cpp">
<Filter>ripple\nodestore\tests</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\Message.h">
<Filter>ripple\overlay</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\Overlay.h">
<Filter>ripple\overlay</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\Peer.h">
<Filter>ripple\overlay</Filter>
</ClInclude>
<None Include="..\..\src\ripple\overlay\README.md">
<Filter>ripple\overlay</Filter>
</None>
<ClCompile Include="..\..\src\ripple\overlay\impl\Message.cpp">
<Filter>ripple\overlay\impl</Filter>
</ClCompile>
<ClCompile Include="..\..\src\ripple\overlay\impl\OverlayImpl.cpp">
<Filter>ripple\overlay\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\impl\OverlayImpl.h">
<Filter>ripple\overlay\impl</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\overlay\impl\PeerDoor.cpp">
<Filter>ripple\overlay\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerDoor.h">
<Filter>ripple\overlay\impl</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\overlay\impl\PeerImp.cpp">
<Filter>ripple\overlay\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\impl\PeerImp.h">
<Filter>ripple\overlay\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\impl\Tuning.h">
<Filter>ripple\overlay\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\impl\abstract_protocol_handler.h">
<Filter>ripple\overlay\impl</Filter>
</ClInclude>
<ClCompile Include="..\..\src\ripple\overlay\impl\message_name.cpp">
<Filter>ripple\overlay\impl</Filter>
</ClCompile>
<ClInclude Include="..\..\src\ripple\overlay\impl\message_name.h">
<Filter>ripple\overlay\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\impl\message_stream.h">
<Filter>ripple\overlay\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\impl\peer_protocol_detector.h">
<Filter>ripple\overlay\impl</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\make_Overlay.h">
<Filter>ripple\overlay</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\overlay\predicates.h">
<Filter>ripple\overlay</Filter>
</ClInclude>
<ClInclude Include="..\..\src\ripple\peerfinder\api\Callback.h">
<Filter>ripple\peerfinder\api</Filter>
</ClInclude>

View File

@@ -23,8 +23,8 @@
#include <beast/asio/abstract_socket.h>
#include <beast/net/IPEndpoint.h>
#include <beast/module/asio/protocol/HandshakeDetectLogicPROXY.h>
#include <boost/asio/ip/tcp.hpp>
#include <boost/asio/ssl/context.hpp>
namespace ripple {

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/module/overlay/api/predicates.h>
#include <ripple/overlay/predicates.h>
namespace ripple {

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/module/overlay/api/Overlay.h>
#include <ripple/overlay/Overlay.h>
#include <ripple/nodestore/Database.h>
namespace ripple {
@@ -502,7 +502,7 @@ void InboundLedger::trigger (Peer::ptr const& peer)
if (iPeer)
{
mByHash = false;
iPeer->sendPacket (packet, false);
iPeer->send (packet);
}
}
}

View File

@@ -550,7 +550,7 @@ public:
tmBH.set_ledgerhash (nextLedger->getHash().begin (), 32);
Message::pointer packet = std::make_shared<Message> (tmBH, protocol::mtGET_OBJECTS);
target->sendPacket (packet, false);
target->send (packet);
WriteLog (lsTRACE, LedgerMaster) << "Requested fetch pack for " << nextLedger->getLedgerSeq() - 1;
}
else

View File

@@ -25,13 +25,15 @@
#include <ripple/common/seconds_clock.h>
#include <ripple/module/app/main/Tuning.h>
#include <ripple/module/app/misc/ProofOfWorkFactory.h>
#include <ripple/module/overlay/api/make_Overlay.h>
#include <ripple/module/rpc/Manager.h>
#include <ripple/module/rpc/Manager.h>
#include <ripple/nodestore/Database.h>
#include <ripple/nodestore/DummyScheduler.h>
#include <ripple/nodestore/Manager.h>
#include <ripple/overlay/make_Overlay.h>
#include <beast/asio/io_latency_probe.h>
#include <beast/module/core/thread/DeadlineTimer.h>
#include <fstream>
namespace ripple {
// VFALCO TODO Clean this global up

View File

@@ -18,8 +18,8 @@
//==============================================================================
#include <ripple/basics/utility/Time.h>
#include <ripple/overlay/predicates.h>
#include <ripple/common/jsonrpc_fields.h>
#include <ripple/module/overlay/api/predicates.h>
#include <beast/module/core/thread/DeadlineTimer.h>
#include <beast/module/core/system/SystemStats.h>
#include <tuple>
@@ -3288,7 +3288,7 @@ void NetworkOPsImp::makeFetchPack (Job&, std::weak_ptr<Peer> wPeer,
m_journal.info << "Built fetch pack with " << reply.objects ().size () << " nodes";
Message::pointer msg = std::make_shared<Message> (reply, protocol::mtGET_OBJECTS);
peer->sendPacket (msg, false);
peer->send (msg);
}
catch (...)
{

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/module/overlay/api/Overlay.h>
#include <ripple/overlay/Overlay.h>
#include <beast/asio/placeholders.h>
namespace ripple {
@@ -151,7 +151,7 @@ void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL, Peer::ptr const& p
if (!peer)
sendRequest (tmGL);
else
peer->sendPacket (std::make_shared<Message> (tmGL, protocol::mtGET_LEDGER), false);
peer->send (std::make_shared<Message> (tmGL, protocol::mtGET_LEDGER));
}
void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL)
@@ -169,7 +169,7 @@ void PeerSet::sendRequest (const protocol::TMGetLedger& tmGL)
Peer::ptr peer (getApp().overlay ().findPeerByShortID (p.first));
if (peer)
peer->sendPacket (packet, false);
peer->send (packet);
}
}

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_PEERSET_H
#define RIPPLE_PEERSET_H
#include <ripple/module/overlay/api/Peer.h>
#include <ripple/overlay/Peer.h>
namespace ripple {

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/module/overlay/api/Overlay.h>
#include <ripple/overlay/Overlay.h>
namespace ripple {

View File

@@ -1,16 +0,0 @@
# Overlay
## Introduction
The _Ripple payment network_ consists of a collection of _peers_ running the
**rippled software**. Each peer maintains multiple outgoing connections and
optional incoming connections to other peers. These connections are made over
both the public Internet and private local area networks. This network defines
a fully connected directed graph of nodes. Peers send and receive messages to
other connected peers. This peer to peer network, layered on top of the public
and private Internet, forms an [_overlay network_][overlay_network]. The
contents of the messages and the behavior of peers in response to the messages,
plus the information exchanged during the handshaking phase of connection
establishment, defines the _Peer Protocol_.
[overlay_network]: http://en.wikipedia.org/wiki/Overlay_network

File diff suppressed because it is too large Load Diff

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/module/overlay/api/Overlay.h>
#include <ripple/overlay/Overlay.h>
namespace ripple {

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/module/overlay/api/Overlay.h>
#include <ripple/overlay/Overlay.h>
namespace ripple {

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
#define RIPPLE_OVERLAY_OVERLAY_H_INCLUDED
#include <ripple/module/overlay/api/Peer.h>
#include <ripple/overlay/Peer.h>
// VFALCO TODO Remove this include dependency it shouldn't be needed
#include <ripple/peerfinder/api/Slot.h>
@@ -52,27 +52,43 @@ protected:
public:
typedef std::vector <Peer::ptr> PeerSequence;
virtual ~Overlay () = default;
virtual
~Overlay () = default;
// VFALCO NOTE These should be a private API
/** @{ */
virtual void remove (PeerFinder::Slot::ptr const& slot) = 0;
/** @} */
/** Establish a peer connection to the specified endpoint.
The call returns immediately, the connection attempt is
performed asynchronously.
*/
virtual
void
connect (beast::IP::Endpoint const& address) = 0;
virtual void connect (beast::IP::Endpoint const& address) = 0;
/** Returns the number of active peers.
Active peers are only those peers that have completed the
handshake and are using the peer protocol.
*/
virtual
std::size_t
size () = 0;
// Notification that a peer has connected.
virtual void onPeerActivated (Peer::ptr const& peer) = 0;
/** Return diagnostics on the status of all peers.
@deprecated This is superceded by PropertyStream
*/
virtual
Json::Value
json () = 0;
// Notification that a peer has disconnected.
virtual void onPeerDisconnect (Peer::ptr const& peer) = 0;
/** Returns a sequence representing the current list of peers.
The snapshot is made at the time of the call.
*/
virtual
PeerSequence
getActivePeers () = 0;
virtual std::size_t size () = 0;
virtual Json::Value json () = 0;
virtual PeerSequence getActivePeers () = 0;
// Peer 64-bit ID function
virtual Peer::ptr findPeerByShortID (Peer::ShortId const& id) = 0;
/** Returns the peer with the matching short id, or null. */
virtual
Peer::ptr
findPeerByShortID (Peer::ShortId const& id) = 0;
/** Visit every active peer and return a value
The functor must:
@@ -96,10 +112,8 @@ public:
foreach(Function f)
{
PeerSequence peers (getActivePeers());
for(PeerSequence::const_iterator i = peers.begin(); i != peers.end(); ++i)
f (*i);
return f();
}

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_OVERLAY_PEER_H_INCLUDED
#define RIPPLE_OVERLAY_PEER_H_INCLUDED
#include <ripple/module/overlay/api/Message.h>
#include <ripple/overlay/Message.h>
#include <ripple/unity/json.h>
#include <ripple/types/api/base_uint.h>
@@ -47,7 +47,7 @@ public:
// Network
//
virtual void sendPacket (const Message::pointer& packet, bool onStrand) = 0;
virtual void send (Message::pointer const& m) = 0;
virtual beast::IP::Endpoint getRemoteAddress() const = 0;
/** Adjust this peer's load balance based on the type of load imposed. */

View File

@@ -0,0 +1,25 @@
# Overlay
## Introduction
The _Ripple payment network_ consists of a collection of _peers_ running
**rippled**. Each peer maintains multiple outgoing connections and optional
incoming connections to other peers. These connections are made over both
the public Internet and private local area networks. This network defines a
fully connected directed graph of nodes where vertices are instances of rippled
and edges are persistent TCP/IP connections. Peers send and receive messages to
other connected peers. This peer to peer network, layered on top of the public
and private Internet, forms an [_overlay network_][overlay_network]. The
contents of the messages and the behavior of peers in response to the messages,
plus the information exchanged during the handshaking phase of connection
establishment, defines the _Ripple peer protocol_ (_protocol_ in this context).
## Overview
Each connection is represented by a _Peer_ object. The Overlay manager
establishes, receives, and maintains connections to peers. Protocol
messages are exchanged between peers and serialized using
[_Google Protocol Buffers_][protocol_buffers].
[overlay_network]: http://en.wikipedia.org/wiki/Overlay_network
[protocol_buffers]: https://developers.google.com/protocol-buffers/

View File

@@ -17,7 +17,7 @@
*/
//==============================================================================
#include <ripple/module/overlay/api/Message.h>
#include <ripple/overlay/Message.h>
#include <cstdint>

View File

@@ -17,12 +17,16 @@
*/
//==============================================================================
#include <ripple/module/overlay/impl/OverlayImpl.h>
#include <ripple/module/overlay/impl/PeerDoor.h>
#include <ripple/module/overlay/impl/PeerImp.h>
#include <ripple/overlay/impl/OverlayImpl.h>
#include <ripple/overlay/impl/PeerDoor.h>
#include <ripple/overlay/impl/PeerImp.h>
#include <beast/ByteOrder.h>
#if DOXYGEN
#include <ripple/overlay/README.md>
#endif
namespace ripple {
SETUP_LOG (Peer)
@@ -306,7 +310,7 @@ OverlayImpl::send (PeerFinder::Slot::ptr const& slot,
assert (iter != m_peers.end ());
PeerImp::ptr const peer (iter->second.lock());
assert (peer != nullptr);
peer->sendPacket (msg, false);
peer->send (msg);
}
}

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_OVERLAY_OVERLAYIMPL_H_INCLUDED
#define RIPPLE_OVERLAY_OVERLAYIMPL_H_INCLUDED
#include <ripple/module/overlay/api/Overlay.h>
#include <ripple/overlay/Overlay.h>
#include <ripple/common/Resolver.h>
#include <ripple/common/seconds_clock.h>
@@ -47,7 +47,7 @@ class OverlayImpl
: public Overlay
, public PeerFinder::Callback
{
public:
private:
typedef boost::asio::ip::tcp::socket socket_type;
typedef std::unordered_map <PeerFinder::Slot::ptr,
@@ -98,6 +98,7 @@ public:
//--------------------------------------------------------------------------
public:
OverlayImpl (Stoppable& parent,
Resource::Manager& resourceManager,
SiteFiles::Manager& siteFiles,
@@ -111,6 +112,22 @@ public:
OverlayImpl (OverlayImpl const&) = delete;
OverlayImpl& operator= (OverlayImpl const&) = delete;
void
connect (beast::IP::Endpoint const& remote_endpoint) override;
std::size_t
size() override;
Json::Value
json() override;
PeerSequence
getActivePeers () override;
Peer::ptr
findPeerByShortID (Peer::ShortId const& id) override;
public:
/** Process an incoming connection using the Peer protocol.
The caller transfers ownership of the socket via rvalue move.
@param proxyHandshake `true` If a PROXY handshake is required.
@@ -120,9 +137,6 @@ public:
accept (bool proxyHandshake,
socket_type&& socket);
void
connect (beast::IP::Endpoint const& remote_endpoint);
Peer::ShortId
next_id();
@@ -187,7 +201,7 @@ public:
//--------------------------------------------------------------------------
/** A peer has connected successfully
/** Called when a peer has connected successfully
This is called after the peer handshake has been completed and during
peer activation. At this point, the peer address and the public key
are known.
@@ -203,22 +217,7 @@ public:
void
onPeerDisconnect (Peer::ptr const& peer);
/** The number of active peers on the network
Active peers are only those peers that have completed the handshake
and are running the Ripple protocol.
*/
std::size_t
size ();
// Returns information on verified peers.
Json::Value
json ();
Overlay::PeerSequence
getActivePeers ();
Peer::ptr
findPeerByShortID (Peer::ShortId const& id);
private:
};
} // ripple

View File

@@ -17,8 +17,8 @@
*/
//==============================================================================
#include <ripple/module/overlay/impl/OverlayImpl.h>
#include <ripple/module/overlay/impl/PeerDoor.h>
#include <ripple/overlay/impl/OverlayImpl.h>
#include <ripple/overlay/impl/PeerDoor.h>
#include <beast/asio/placeholders.h>
namespace ripple {

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_PEERDOOR_H_INCLUDED
#define RIPPLE_PEERDOOR_H_INCLUDED
#include <ripple/module/overlay/impl/OverlayImpl.h>
#include <ripple/overlay/impl/OverlayImpl.h>
#include <beast/cxx14/memory.h> // <memory>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_OVERLAY_TUNING_H_INCLUDED
#define RIPPLE_OVERLAY_TUNING_H_INCLUDED
namespace ripple {
namespace Tuning
{
enum
{
/** Size of buffer used to read from the socket. */
readBufferBytes = 4096
};
} // Tuning
} // ripple
#endif

View File

@@ -0,0 +1,67 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_OVERLAY_ABSTRACT_PROTOCOL_HANDLER_H_INCLUDED
#define RIPPLE_OVERLAY_ABSTRACT_PROTOCOL_HANDLER_H_INCLUDED
#include "ripple.pb.h"
#include <boost/system/error_code.hpp>
#include <cstdint>
namespace ripple {
/** Handles protocol messages. */
class abstract_protocol_handler
{
protected:
typedef boost::system::error_code error_code;
public:
// Called for messages of unknown type
virtual error_code on_message_unknown (std::uint16_t type) = 0;
// Called before a specific message handler is invoked
virtual error_code on_message_begin (std::uint16_t type,
std::shared_ptr <::google::protobuf::Message> const& m) = 0;
// Called after a specific message handler is invoked,
// if on_message_begin did not return an error.
virtual void on_message_end (std::uint16_t type,
std::shared_ptr <::google::protobuf::Message> const& m) = 0;
virtual error_code on_message (std::shared_ptr <protocol::TMHello> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMPing> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMProofWork> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMCluster> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMGetPeers> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMPeers> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMEndpoints> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMTransaction> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMGetLedger> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMLedgerData> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMProposeSet> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMStatusChange> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMHaveTransactionSet> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMValidation> const& m) { return error_code(); }
virtual error_code on_message (std::shared_ptr <protocol::TMGetObjectByHash> const& m) { return error_code(); }
};
} // ripple
#endif

View File

@@ -0,0 +1,53 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_OVERLAY_MESSAGE_NAME_H_INCLUDED
#define RIPPLE_OVERLAY_MESSAGE_NAME_H_INCLUDED
namespace ripple {
char const*
protocol_message_name (int type)
{
switch (type)
{
case protocol::mtHELLO: return "hello";
case protocol::mtPING: return "ping";
case protocol::mtPROOFOFWORK: return "proof_of_work";
case protocol::mtCLUSTER: return "cluster";
case protocol::mtGET_PEERS: return "get_peers";
case protocol::mtPEERS: return "peers";
case protocol::mtENDPOINTS: return "endpoints";
case protocol::mtTRANSACTION: return "tx";
case protocol::mtGET_LEDGER: return "get_ledger";
case protocol::mtLEDGER_DATA: return "ledger_data";
case protocol::mtPROPOSE_LEDGER: return "propose";
case protocol::mtSTATUS_CHANGE: return "status";
case protocol::mtHAVE_SET: return "have_set";
case protocol::mtVALIDATION: return "validation";
case protocol::mtGET_OBJECTS: return "get_objects";
default:
break;
};
return "uknown";
}
}
#endif

View File

@@ -0,0 +1,30 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_OVERLAY_MESSAGE_NAME_H_INCLUDED
#define RIPPLE_OVERLAY_MESSAGE_NAME_H_INCLUDED
namespace ripple {
char const*
protocol_message_name (int type);
}
#endif

View File

@@ -0,0 +1,171 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_OVERLAY_MESSAGE_STREAM_H_INCLUDED
#define RIPPLE_OVERLAY_MESSAGE_STREAM_H_INCLUDED
#include <ripple/overlay/impl/abstract_protocol_handler.h>
#include <ripple/overlay/Message.h>
#include <boost/asio/buffer.hpp>
#include <boost/system/error_code.hpp>
#include <cassert>
#include <cstdint>
#include <memory>
#include <vector>
namespace ripple {
/** Turns a stream of bytes into protocol messages and invokes the handler. */
class message_stream
{
private:
abstract_protocol_handler& handler_;
std::size_t header_bytes_;
std::size_t body_bytes_;
std::uint32_t length_;
std::uint16_t type_;
std::vector <std::uint8_t> header_; // VFALCO TODO Use std::array
std::vector <std::uint8_t> body_;
static
boost::system::error_code
parse_error()
{
return boost::system::errc::make_error_code (
boost::system::errc::invalid_argument);
}
template <class Message>
boost::system::error_code
invoke()
{
boost::system::error_code ec;
std::shared_ptr <Message> m (std::make_shared <Message>());
bool const parsed (m->ParseFromArray (body_.data(), length_));
if (! parsed)
return parse_error();
ec = handler_.on_message_begin (type_, m);
if (! ec)
{
ec = handler_.on_message (m);
handler_.on_message_end (type_, m);
}
return ec;
}
public:
message_stream (abstract_protocol_handler& handler)
: handler_(handler)
, header_bytes_(0)
, body_bytes_(0)
{
header_.resize (Message::kHeaderBytes);
}
/** Push a single buffer through.
The handler is called for each complete protocol message contained
in the buffer.
*/
template <class ConstBuffer>
boost::system::error_code
write_one (ConstBuffer const& cb)
{
using namespace boost::asio;
boost::system::error_code ec;
const_buffer buffer (cb);
std::size_t remain (buffer_size(buffer));
while (remain)
{
if (header_bytes_ < header_.size())
{
std::size_t const n (buffer_copy (mutable_buffer (header_.data() +
header_bytes_, header_.size() - header_bytes_), buffer));
header_bytes_ += n;
buffer = buffer + n;
remain = remain - n;
if (header_bytes_ >= header_.size())
{
assert (header_bytes_ == header_.size());
length_ = Message::getLength (header_);
type_ = Message::getType (header_);
body_.resize (length_);
}
}
if (header_bytes_ >= header_.size())
{
std::size_t const n (buffer_copy (mutable_buffer (body_.data() +
body_bytes_, body_.size() - body_bytes_), buffer));
body_bytes_ += n;
buffer = buffer + n;
remain = remain - n;
if (body_bytes_ >= length_)
{
assert (body_bytes_ == length_);
switch (type_)
{
case protocol::mtHELLO: ec = invoke <protocol::TMHello> (); break;
case protocol::mtPING: ec = invoke <protocol::TMPing> (); break;
case protocol::mtPROOFOFWORK: ec = invoke <protocol::TMProofWork> (); break;
case protocol::mtCLUSTER: ec = invoke <protocol::TMCluster> (); break;
case protocol::mtGET_PEERS: ec = invoke <protocol::TMGetPeers> (); break;
case protocol::mtPEERS: ec = invoke <protocol::TMPeers> (); break;
case protocol::mtENDPOINTS: ec = invoke <protocol::TMEndpoints> (); break;
case protocol::mtTRANSACTION: ec = invoke <protocol::TMTransaction> (); break;
case protocol::mtGET_LEDGER: ec = invoke <protocol::TMGetLedger> (); break;
case protocol::mtLEDGER_DATA: ec = invoke <protocol::TMLedgerData> (); break;
case protocol::mtPROPOSE_LEDGER: ec = invoke <protocol::TMProposeSet> (); break;
case protocol::mtSTATUS_CHANGE: ec = invoke <protocol::TMStatusChange> (); break;
case protocol::mtHAVE_SET: ec = invoke <protocol::TMHaveTransactionSet> (); break;
case protocol::mtVALIDATION: ec = invoke <protocol::TMValidation> (); break;
case protocol::mtGET_OBJECTS: ec = invoke <protocol::TMGetObjectByHash> (); break;
default:
ec = handler_.on_message_unknown(type_);
break;
}
header_bytes_ = 0;
body_bytes_ = 0;
}
}
}
return ec;
}
/** Push a set of buffers through.
The handler is called for each complete protocol message contained
in the buffers.
*/
template <class ConstBufferSequence>
boost::system::error_code
write (ConstBufferSequence const& buffers)
{
boost::system::error_code ec;
for (auto const& buffer : buffers)
{
ec = write_one(buffer);
if (ec)
break;
}
return ec;
}
};
} // ripple
#endif

View File

@@ -0,0 +1,67 @@
//------------------------------------------------------------------------------
/*
This file is part of rippled: https://github.com/ripple/rippled
Copyright (c) 2012, 2013 Ripple Labs Inc.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
//==============================================================================
#ifndef RIPPLE_OVERLAY_PEER_PROTOCOL_DETECTOR_H_INCLUDED
#define RIPPLE_OVERLAY_PEER_PROTOCOL_DETECTOR_H_INCLUDED
#include <boost/asio/buffer.hpp>
#include <boost/logic/tribool.hpp>
#include <cstdint>
namespace ripple {
/** Detects the peer protocol handshake. */
class peer_protocol_detector
{
public:
/** Returns `true` if the buffers contain the required protocol messages.
The peer protcol requires the 'hello' message as the first item on
the stream. We check the 6-byte message header to determine if the
hello is present.
@return `false` if the buffers cannot possibly contain the message, or
`boost::indeterminate` if more data is needed.
*/
template <class ConstBufferSequence>
boost::tribool
operator() (ConstBufferSequence const& buffers)
{
std::array <std::uint8_t, 6> data;
std::size_t const n (boost::asio::buffer_copy (data, buffers));
/*
Protocol messages are framed by a 6 byte header which includes
a big-endian 4-byte length followed by a big-endian 2-byte type.
The type for 'hello' is 1.
*/
if (n>=1 && data[0] != 0)
return false;
if (n>=2 && data[1] != 0)
return false;
if (n>=5 && data[4] != 0)
return false;
if (n>=6 && data[5] != 1)
return false;
if (n>=6)
return true;
return boost::indeterminate;
}
};
} // ripple
#endif

View File

@@ -20,7 +20,7 @@
#ifndef RIPPLE_OVERLAY_MAKE_OVERLAY_H_INCLUDED
#define RIPPLE_OVERLAY_MAKE_OVERLAY_H_INCLUDED
#include <ripple/module/overlay/api/Overlay.h>
#include <ripple/overlay/Overlay.h>
#include <ripple/resource/api/Manager.h>
#include <ripple/sitefiles/api/Manager.h>

View File

@@ -20,8 +20,8 @@
#ifndef RIPPLE_OVERLAY_PREDICATES_H_INCLUDED
#define RIPPLE_OVERLAY_PREDICATES_H_INCLUDED
#include <ripple/module/overlay/api/Message.h>
#include <ripple/module/overlay/api/Peer.h>
#include <ripple/overlay/Message.h>
#include <ripple/overlay/Peer.h>
#include <set>
@@ -40,7 +40,7 @@ struct send_always
void operator()(Peer::ptr const& peer) const
{
peer->sendPacket (msg, false);
peer->send (msg);
}
};
@@ -62,7 +62,7 @@ struct send_if_pred
void operator()(Peer::ptr const& peer) const
{
if (predicate (peer))
peer->sendPacket (msg, false);
peer->send (msg);
}
};
@@ -93,7 +93,7 @@ struct send_if_not_pred
void operator()(Peer::ptr const& peer) const
{
if (!predicate (peer))
peer->sendPacket (msg, false);
peer->send (msg);
}
};

View File

@@ -2,40 +2,30 @@ package protocol;
enum MessageType
{
// core
mtHELLO = 1;
mtERROR_MSG = 2;
mtPING = 3;
mtPROOFOFWORK = 4;
mtCLUSTER = 5;
// network presence detection
mtGET_CONTACTS = 10;
mtCONTACT = 11;
mtGET_PEERS = 12;
mtPEERS = 13;
// This field was previous used for PeerFinder ENDPOINTS messages. Since the
// structure's required fields changed, the message number was changed.
mtUNUSED_FIELD = 14;
mtENDPOINTS = 15;
// operations for 'small' nodes
mtSEARCH_TRANSACTION = 20;
mtGET_ACCOUNT = 21;
mtACCOUNT = 22;
// transaction and ledger processing
mtTRANSACTION = 30;
mtGET_LEDGER = 31;
mtLEDGER_DATA = 32;
mtPROPOSE_LEDGER = 33;
mtSTATUS_CHANGE = 34;
mtHAVE_SET = 35;
// data replication and synchronization
mtGET_VALIDATIONS = 40;
mtVALIDATION = 41;
mtGET_OBJECTS = 42;
// <available> = 2;
// <available> = 10;
// <available> = 11;
// <available> = 14;
// <available> = 20;
// <available> = 21;
// <available> = 22;
// <available> = 40;
}
// token, iterations, target, challenge = issue demand for proof of work
@@ -199,31 +189,6 @@ message TMValidation
optional bool checkedSignature = 2; // node vouches signature is correct
}
message TMGetValidations
{
required uint32 ledgerIndex = 1;
repeated bytes hanko = 2;
optional uint32 count = 3; // get random validations
}
message TMContact
{
required bytes pubKey = 1;
required uint32 softwareVersion = 2;
required uint32 protoVersion = 3;
required uint64 nodeFlags = 4;
required uint64 timestamp = 5;
repeated bytes nodeInfo = 6;
required bytes signature = 7;
}
// request node information
message TMGetContacts
{
repeated bytes nodeIDs = 1; // specific nodes we want
optional uint32 nodeCount = 2; // get some random nodes
}
message TMGetPeers
{
required uint32 doWeNeedThis = 1; // yes since you are asserting that the packet size isn't 0 in Message
@@ -261,36 +226,6 @@ message TMEndpoints
repeated TMEndpoint endpoints = 2;
};
message TMSearchTransaction
{
required uint32 maxTrans = 1;
optional bytes toAccount = 2;
optional bytes fromAccount = 3;
optional uint32 minLedger = 4;
optional bytes fromAcctSeq = 5;
repeated bytes transID = 6;
}
message TMGetAccount
{
repeated bytes acctID = 1;
optional uint32 seq = 2;
}
message Account
{
required bytes accountID = 1;
required uint64 balance = 2;
required uint32 accountSeq = 3;
required uint32 ledgerSeq = 4;
}
message TMAccount
{
repeated Account accounts = 1;
optional uint32 seq = 2;
}
message TMIndexedObject
{
optional bytes hash = 1;
@@ -386,9 +321,3 @@ message TMPing
optional uint64 netTime = 4;
}
message TMErrorMsg
{
optional int32 errorCode = 1;
optional string message = 2;
}

View File

@@ -19,8 +19,9 @@
#include <BeastConfig.h>
#include <ripple/module/overlay/impl/Message.cpp>
#include <ripple/module/overlay/impl/OverlayImpl.cpp>
#include <ripple/module/overlay/impl/PeerImp.h>
#include <ripple/module/overlay/impl/PeerDoor.cpp>
#include <ripple/overlay/impl/Message.cpp>
#include <ripple/overlay/impl/message_name.cpp>
#include <ripple/overlay/impl/OverlayImpl.cpp>
#include <ripple/overlay/impl/PeerImp.cpp>
#include <ripple/overlay/impl/PeerDoor.cpp>

View File

@@ -28,7 +28,9 @@
#include <ripple/unity/rpcx.h>
#include <ripple/module/overlay/api/Overlay.h>
#include <ripple/module/rpc/RPCHandler.h>
#include <ripple/overlay/Overlay.h>
#include <tuple>
#include <ripple/module/rpc/RPCHandler.h>
#include <ripple/module/rpc/impl/ErrorCodes.cpp>