3#include <test/jtx/Env.h>
5#include <xrpld/app/main/Application.h>
6#include <xrpld/overlay/Message.h>
7#include <xrpld/overlay/Peer.h>
8#include <xrpld/overlay/detail/OverlayImpl.h>
9#include <xrpld/overlay/detail/PeerImp.h>
10#include <xrpld/overlay/detail/ProtocolVersion.h>
12#include <xrpl/basics/contract.h>
13#include <xrpl/basics/make_SSLContext.h>
14#include <xrpl/beast/net/IPEndpoint.h>
15#include <xrpl/peerfinder/Slot.h>
16#include <xrpl/protocol/KeyType.h>
17#include <xrpl/protocol/PublicKey.h>
18#include <xrpl/protocol/SecretKey.h>
19#include <xrpl/resource/Charge.h>
20#include <xrpl/resource/Consumer.h>
21#include <xrpl/server/Handoff.h>
23#include <boost/asio/ip/address.hpp>
24#include <boost/asio/ip/address_v4.hpp>
25#include <boost/asio/ip/tcp.hpp>
26#include <boost/asio/ssl/context.hpp>
27#include <boost/beast/core/tcp_stream.hpp>
28#include <boost/beast/ssl/ssl_stream.hpp>
126 return sent_.empty() ? nullptr :
sent_.back();
185inline boost::asio::ssl::context&
207template <
class PeerType = CapturePeer>
214 auto& overlay =
dynamic_cast<OverlayImpl&
>(env.
app().getOverlay());
222 auto consumer = overlay.resourceManager().newInboundEndpoint(remote);
223 auto [slot, _] = overlay.peerFinder().newInboundSlot(local, remote);
245 std::move(streamPtr),
248 overlay.addActive(peer);
A version-independent IP address and port combination.
PeerImp(PeerImp const &)=delete
resource::Charge currentFeeCharge() const
Read-only accessor for the accumulated peer-message charge.
Peer::ID id() const override
std::shared_ptr< peer_finder::Slot > const & slot()
std::uint32_t ID
Uniquely identifies a peer.
virtual boost::asio::io_context & getIOContext()=0
An endpoint that consumes resources.
std::vector< std::shared_ptr< Message > > sent_
void send(std::shared_ptr< Message > const &m) override
Captures the message instead of writing it, so replies are observable.
boost::asio::ip::tcp::socket SocketType
void run() override
Does nothing, so the peer stays registered.
boost::beast::tcp_stream MiddleType
resource::Charge feeCharge() const
Reads the accumulated charge without draining it through charge().
std::vector< std::shared_ptr< Message > > const & sent() const
std::shared_ptr< Message > lastSent() const
boost::beast::ssl_stream< MiddleType > StreamType
CapturePeer(Application &app, Peer::ID id, std::shared_ptr< peer_finder::Slot > const &slot, HttpRequestType request, PublicKey const &publicKey, ProtocolVersion protocol, resource::Consumer consumer, std::unique_ptr< StreamType > streamPtr, OverlayImpl &overlay)
Takes PeerImp's two rvalue-reference parameters by value instead, so a derived double can inherit thi...
~CapturePeer() override=default
A transaction testing environment.
constexpr std::uint16_t kCapturePeerPort
boost::asio::ssl::context & capturePeerSslContext()
Outlives every peer, whose stream keeps a reference to it.
beast::ip::Endpoint nextCapturePeerRemote()
Non-template for the same reason as nextCapturePeerId.
Peer::ID nextCapturePeerId()
Non-template, so all makeCapturePeer instantiations share one counter.
std::shared_ptr< PeerType > makeCapturePeer(jtx::Env &env, std::optional< PublicKey > key=std::nullopt, HttpRequestType request={})
Build an active CapturePeer and register it with the overlay.
ProtocolVersion newestSupportedProtocolVersion()
The version negotiated with a peer that speaks everything we speak, so also the one that enables ever...
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
std::string to_string(BaseUInt< Bits, Tag > const &a)
boost::beast::http::request< boost::beast::http::dynamic_body > HttpRequestType
std::shared_ptr< boost::asio::ssl::context > makeSslContext(std::string const &cipherList)
Create a self-signed SSL context that allows anonymous Diffie Hellman.
std::pair< std::uint16_t, std::uint16_t > ProtocolVersion
Represents a particular version of the peer-to-peer protocol.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)