1#include <test/jtx/Account.h> 
    2#include <test/jtx/Env.h> 
    3#include <test/jtx/WSClient.h> 
    4#include <test/jtx/amount.h> 
    5#include <test/jtx/pay.h> 
    7#include <xrpld/app/ledger/Ledger.h> 
    8#include <xrpld/app/ledger/LedgerMaster.h> 
    9#include <xrpld/overlay/Compression.h> 
   10#include <xrpld/overlay/Message.h> 
   11#include <xrpld/overlay/detail/Handshake.h> 
   12#include <xrpld/overlay/detail/ProtocolMessage.h> 
   13#include <xrpld/overlay/detail/ZeroCopyStream.h> 
   15#include <xrpl/basics/random.h> 
   16#include <xrpl/beast/unit_test.h> 
   17#include <xrpl/beast/utility/Journal.h> 
   18#include <xrpl/protocol/HashPrefix.h> 
   19#include <xrpl/protocol/PublicKey.h> 
   20#include <xrpl/protocol/SecretKey.h> 
   21#include <xrpl/protocol/Sign.h> 
   22#include <xrpl/protocol/digest.h> 
   23#include <xrpl/protocol/jss.h> 
   24#include <xrpl/protocol/messages.h> 
   25#include <xrpl/shamap/SHAMapNodeID.h> 
   27#include <boost/asio/ip/address_v4.hpp> 
   28#include <boost/beast/core/multi_buffer.hpp> 
   29#include <boost/endian/conversion.hpp> 
   70        protocol::MessageType mt,
 
   74        testcase(
"Compress/Decompress: " + msg);
 
   78        auto& buffer = m.
getBuffer(Compressed::On);
 
   80        boost::beast::multi_buffer buffers;
 
   83        auto sz = buffer.
size() / nbuffers;
 
   84        for (
int i = 0; i < nbuffers; i++)
 
   86            auto start = buffer.begin() + sz * i;
 
   87            auto end = i < nbuffers - 1 ? (buffer.begin() + sz * (i + 1))
 
   90            buffers.commit(boost::asio::buffer_copy(
 
   91                buffers.prepare(slice.
size()), boost::asio::buffer(slice)));
 
   94        boost::system::error_code ec;
 
   96            ec, buffers.data(), buffer.size());
 
  100        if (!header || header->algorithm == Algorithm::None)
 
  104        decompressed.
resize(header->uncompressed_size);
 
  107            header->payload_wire_size == buffer.size() - header->header_size);
 
  110        stream.Skip(header->header_size);
 
  114            header->payload_wire_size,
 
  116            header->uncompressed_size);
 
  117        BEAST_EXPECT(decompressedSize == header->uncompressed_size);
 
  121            proto1->ParseFromArray(decompressed.
data(), decompressedSize));
 
  122        auto uncompressed = m.
getBuffer(Compressed::Off);
 
  126            decompressed.
begin()));
 
 
  133        manifests->mutable_list()->Reserve(n);
 
  134        for (
int i = 0; i < n; i++)
 
  158            auto* 
manifest = manifests->add_list();
 
 
  168        endpoints->mutable_endpoints_v2()->Reserve(n);
 
  169        for (
int i = 0; i < n; i++)
 
  171            auto ep = endpoints->add_endpoints_v2();
 
  175        endpoints->set_version(2);
 
 
  185        auto const alice = 
Account(
"alice");
 
  186        auto const bob = 
Account(
"bob");
 
  195                reinterpret_cast<char const*
>(blob->data()), blob->
size()};
 
  203            jrequestUsd[jss::tx_json] =
 
  204                pay(
"bob", 
"alice", bob[
"USD"](
fund / 2));
 
  205            Json::Value jreply_usd = wsc->invoke(
"sign", jrequestUsd);
 
  208                toBinary(jreply_usd[jss::result][jss::tx_blob].asString());
 
  212        transaction->set_rawtransaction(usdTxBlob);
 
  213        transaction->set_status(protocol::tsNEW);
 
  214        transaction->set_receivetimestamp(rand_int<std::uint64_t>());
 
  215        transaction->set_deferred(
true);
 
 
  224        getLedger->set_itype(protocol::liTS_CANDIDATE);
 
  225        getLedger->set_ltype(protocol::TMLedgerType::ltACCEPTED);
 
  227        getLedger->set_ledgerhash(hash.
begin(), hash.
size());
 
  228        getLedger->set_ledgerseq(123456789);
 
  231        getLedger->set_requestcookie(123456789);
 
  232        getLedger->set_querytype(protocol::qtINDIRECT);
 
  233        getLedger->set_querydepth(3);
 
 
  242        ledgerData->set_ledgerhash(hash.
data(), hash.
size());
 
  243        ledgerData->set_ledgerseq(123456789);
 
  244        ledgerData->set_type(protocol::TMLedgerInfoType::liAS_NODE);
 
  245        ledgerData->set_requestcookie(123456789);
 
  246        ledgerData->set_error(protocol::TMReplyError::reNO_LEDGER);
 
  247        ledgerData->mutable_nodes()->Reserve(n);
 
  253        for (
int i = 0; i < n; i++)
 
  269            ledgerData->add_nodes()->set_nodedata(
 
 
  281        getObject->set_type(protocol::TMGetObjectByHash_ObjectType::
 
  282                                TMGetObjectByHash_ObjectType_otTRANSACTION);
 
  283        getObject->set_query(
true);
 
  284        getObject->set_seq(123456789);
 
  286        getObject->set_ledgerhash(hash.
data(), hash.
size());
 
  287        getObject->set_fat(
true);
 
  288        for (
int i = 0; i < 100; i++)
 
  291            auto object = getObject->add_objects();
 
  292            object->set_hash(hash.
data(), hash.
size());
 
  295            object->set_index(
"");
 
  296            object->set_data(
"");
 
  297            object->set_ledgerseq(i);
 
 
  323        list->set_manifest(s.
data(), s.
size());
 
  324        list->set_version(3);
 
  330        list->set_signature(s1.
data(), s1.
size());
 
 
  356        list->set_manifest(s.
data(), s.
size());
 
  357        list->set_version(4);
 
  363        auto& blob = *list->add_blobs();
 
  364        blob.set_signature(s1.
data(), s1.
size());
 
 
  375        protocol::TMManifests manifests;
 
  376        protocol::TMEndpoints endpoints;
 
  377        protocol::TMTransaction transaction;
 
  378        protocol::TMGetLedger get_ledger;
 
  379        protocol::TMLedgerData ledger_data;
 
  380        protocol::TMGetObjectByHash get_object;
 
  381        protocol::TMValidatorList validator_list;
 
  382        protocol::TMValidatorListCollection validator_list_collection;
 
  395            protocol::mtTRANSACTION,
 
  403            protocol::mtLEDGER_DATA,
 
  409            protocol::mtLEDGER_DATA,
 
  415            protocol::mtLEDGER_DATA,
 
  417            "TMLedgerData10000");
 
  421            protocol::mtLEDGER_DATA,
 
  423            "TMLedgerData100000");
 
  427            protocol::mtLEDGER_DATA,
 
  429            "TMLedgerData500000");
 
  433            protocol::mtGET_OBJECTS,
 
  435            "TMGetObjectByHash");
 
  439            protocol::mtVALIDATORLIST,
 
  444            protocol::mtVALIDATORLISTCOLLECTION,
 
  446            "TMValidatorListCollection");
 
 
  453        auto getEnv = [&](
bool enable) {
 
  456            str << 
"[reduce_relay]\n" 
  457                << 
"vp_base_squelch_enable=1\n" 
  463            env->app().config().VP_REDUCE_RELAY_BASE_SQUELCH_ENABLE =
 
  467        auto handshake = [&](
int outboundEnable, 
int inboundEnable) {
 
  469                boost::asio::ip::make_address(
"172.1.1.100");
 
  471            auto env = getEnv(outboundEnable);
 
  474                env->app().config().COMPRESSION,
 
  476                env->app().config().TX_REDUCE_RELAY_ENABLE,
 
  477                env->app().config().VP_REDUCE_RELAY_BASE_SQUELCH_ENABLE);
 
  479            http_request.version(request.version());
 
  480            http_request.base() = request.base();
 
  483            auto const peerEnabled = inboundEnable && outboundEnable;
 
  488            BEAST_EXPECT(!(peerEnabled ^ inboundEnabled));
 
  491            env = getEnv(inboundEnable);
 
  505            BEAST_EXPECT(!(peerEnabled ^ outboundEnabled));
 
 
 
  521BEAST_DEFINE_TESTSUITE_MANUAL(compression, overlay, 
ripple);
 
testcase_t testcase
Memberspace for declaring test cases.
 
virtual Config & config()=0
 
bool VP_REDUCE_RELAY_BASE_SQUELCH_ENABLE
 
void loadFromString(std::string const &fileContents)
Load the config from the contents of the string.
 
Manages partitions for logging.
 
std::vector< uint8_t > const & getBuffer(Compressed tryCompressed)
Retrieve the packed message data.
 
Identifies a node inside a SHAMap.
 
std::string getRawString() const
 
void add(Serializer &s) const override
 
std::size_t size() const noexcept
 
void const * data() const noexcept
 
Slice slice() const noexcept
 
void const * getDataPtr() const
 
constexpr value_type drops() const
Returns the number of drops.
 
static constexpr std::size_t size()
 
std::shared_ptr< protocol::TMGetObjectByHash > buildGetObjectByHash()
 
void run() override
Runs the suite.
 
std::shared_ptr< protocol::TMManifests > buildManifests(int n)
 
std::shared_ptr< protocol::TMLedgerData > buildLedgerData(uint32_t n, Logs &logs)
 
std::shared_ptr< protocol::TMValidatorListCollection > buildValidatorListCollection()
 
void doTest(std::shared_ptr< T > proto, protocol::MessageType mt, uint16_t nbuffers, std::string msg)
 
std::shared_ptr< protocol::TMValidatorList > buildValidatorList()
 
std::shared_ptr< protocol::TMGetLedger > buildGetLedger()
 
std::shared_ptr< protocol::TMTransaction > buildTransaction(Logs &logs)
 
std::shared_ptr< protocol::TMEndpoints > buildEndpoints(int n)
 
Immutable cryptographic account descriptor.
 
A transaction testing environment.
 
bool close(NetClock::time_point closeTime, std::optional< std::chrono::milliseconds > consensusDelay=std::nullopt)
Close and advance the ledger.
 
void trust(STAmount const &amount, Account const &account)
Establish trust lines.
 
void fund(bool setDefaultRipple, STAmount const &amount, Account const &account)
 
boost::asio::ip::address Address
 
std::size_t constexpr headerBytes
 
std::size_t decompress(InputStream &in, std::size_t inSize, std::uint8_t *decompressed, std::size_t decompressedSize, Algorithm algorithm=Algorithm::LZ4)
Decompress input stream.
 
std::optional< MessageHeader > parseMessageHeader(boost::system::error_code &ec, BufferSequence const &bufs, std::size_t size)
Parse a message header.
 
Json::Value pay(AccountID const &account, AccountID const &to, AnyAmount amount)
Create a payment.
 
void fund(jtx::Env &env, jtx::Account const &gw, std::vector< jtx::Account > const &accounts, std::vector< STAmount > const &amts, Fund how)
 
std::unique_ptr< Config > envconfig()
creates and initializes a default configuration for jtx::Env
 
void sign(Json::Value &jv, Account const &account, Json::Value &sigObject)
Sign automatically into a specific Json field of the jv object.
 
XRP_t const XRP
Converts to XRP Issue or STAmount.
 
static uint256 ledgerHash(LedgerInfo const &info)
 
std::unique_ptr< WSClient > makeWSClient(Config const &cfg, bool v2, unsigned rpc_version, std::unordered_map< std::string, std::string > const &headers)
Returns a client operating through WebSockets/S.
 
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
 
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
 
std::optional< Blob > strUnHex(std::size_t strSize, Iterator begin, Iterator end)
 
static constexpr char FEATURE_COMPR[]
 
http_response_type makeResponse(bool crawlPublic, http_request_type const &req, beast::IP::Address public_ip, beast::IP::Address remote_ip, uint256 const &sharedValue, std::optional< std::uint32_t > networkID, ProtocolVersion protocol, Application &app)
Make http response.
 
Buffer sign(PublicKey const &pk, SecretKey const &sk, Slice const &message)
Generate a signature for a message.
 
std::string strHex(FwdIt begin, FwdIt end)
 
std::enable_if_t< std::is_same< T, char >::value||std::is_same< T, unsigned char >::value, Slice > makeSlice(std::array< T, N > const &a)
 
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
 
bool peerFeatureEnabled(headers const &request, std::string const &feature, std::string value, bool config)
Check if a feature should be enabled for a peer.
 
auto makeRequest(bool crawlPublic, bool comprEnabled, bool ledgerReplayEnabled, bool txReduceRelayEnabled, bool vpReduceRelayEnabled) -> request_type
Make outbound http request.
 
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
 
@ ledgerMaster
ledger master data for signing
 
void addRaw(LedgerHeader const &, Serializer &, bool includeHash=false)
 
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
 
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
 
T time_since_epoch(T... args)