20 #include <ripple/app/ledger/Ledger.h>
21 #include <ripple/app/ledger/LedgerMaster.h>
22 #include <ripple/app/misc/Manifest.h>
23 #include <ripple/beast/unit_test.h>
24 #include <ripple/beast/utility/Journal.h>
25 #include <ripple/core/TimeKeeper.h>
26 #include <ripple/overlay/Compression.h>
27 #include <ripple/overlay/Message.h>
28 #include <ripple/overlay/impl/ProtocolMessage.h>
29 #include <ripple/overlay/impl/ZeroCopyStream.h>
30 #include <ripple/protocol/HashPrefix.h>
31 #include <ripple/protocol/PublicKey.h>
32 #include <ripple/protocol/SecretKey.h>
33 #include <ripple/protocol/Sign.h>
34 #include <ripple/protocol/digest.h>
35 #include <ripple/protocol/jss.h>
36 #include <ripple/shamap/SHAMapNodeID.h>
37 #include <boost/asio/ip/address_v4.hpp>
38 #include <boost/beast/core/multi_buffer.hpp>
39 #include <boost/endian/conversion.hpp>
41 #include <ripple.pb.h>
42 #include <test/jtx/Account.h>
43 #include <test/jtx/Env.h>
44 #include <test/jtx/WSClient.h>
45 #include <test/jtx/amount.h>
46 #include <test/jtx/pay.h>
85 protocol::MessageType mt,
89 testcase(
"Compress/Decompress: " + msg);
93 auto& buffer = m.
getBuffer(Compressed::On);
95 boost::beast::multi_buffer buffers;
98 auto sz = buffer.
size() / nbuffers;
99 for (
int i = 0; i < nbuffers; i++)
101 auto start = buffer.begin() + sz * i;
102 auto end = i < nbuffers - 1 ? (buffer.begin() + sz * (i + 1))
105 buffers.commit(boost::asio::buffer_copy(
106 buffers.prepare(slice.
size()), boost::asio::buffer(slice)));
109 boost::system::error_code ec;
111 ec, buffers.data(), buffer.size());
113 BEAST_EXPECT(header);
115 if (header->algorithm == Algorithm::None)
119 decompressed.
resize(header->uncompressed_size);
122 header->payload_wire_size == buffer.size() - header->header_size);
125 stream.Skip(header->header_size);
129 header->payload_wire_size,
131 header->uncompressed_size);
132 BEAST_EXPECT(decompressedSize == header->uncompressed_size);
133 auto const proto1 = std::make_shared<T>();
136 proto1->ParseFromArray(decompressed.
data(), decompressedSize));
137 auto uncompressed = m.
getBuffer(Compressed::Off);
141 decompressed.
begin()));
147 auto manifests = std::make_shared<protocol::TMManifests>();
148 manifests->mutable_list()->Reserve(n);
149 for (
int i = 0; i < n; i++)
170 std::get<1>(signing));
173 auto*
manifest = manifests->add_list();
182 auto endpoints = std::make_shared<protocol::TMEndpoints>();
183 endpoints->mutable_endpoints_v2()->Reserve(n);
184 for (
int i = 0; i < n; i++)
186 auto ep = endpoints->add_endpoints_v2();
190 endpoints->set_version(2);
200 auto const alice =
Account(
"alice");
201 auto const bob =
Account(
"bob");
202 env.
fund(
XRP(fund),
"alice",
"bob");
203 env.
trust(bob[
"USD"](fund), alice);
210 reinterpret_cast<char const*
>(blob->data()), blob->
size()};
218 jrequestUsd[jss::tx_json] =
219 pay(
"bob",
"alice", bob[
"USD"](fund / 2));
220 Json::Value jreply_usd = wsc->invoke(
"sign", jrequestUsd);
223 toBinary(jreply_usd[jss::result][jss::tx_blob].asString());
226 auto transaction = std::make_shared<protocol::TMTransaction>();
227 transaction->set_rawtransaction(usdTxBlob);
228 transaction->set_status(protocol::tsNEW);
230 transaction->set_receivetimestamp(tk->now().time_since_epoch().count());
231 transaction->set_deferred(
true);
239 auto getLedger = std::make_shared<protocol::TMGetLedger>();
240 getLedger->set_itype(protocol::liTS_CANDIDATE);
241 getLedger->set_ltype(protocol::TMLedgerType::ltACCEPTED);
243 getLedger->set_ledgerhash(hash.
begin(), hash.
size());
244 getLedger->set_ledgerseq(123456789);
247 getLedger->set_requestcookie(123456789);
248 getLedger->set_querytype(protocol::qtINDIRECT);
249 getLedger->set_querydepth(3);
256 auto ledgerData = std::make_shared<protocol::TMLedgerData>();
258 ledgerData->set_ledgerhash(hash.
data(), hash.
size());
259 ledgerData->set_ledgerseq(123456789);
260 ledgerData->set_type(protocol::TMLedgerInfoType::liAS_NODE);
261 ledgerData->set_requestcookie(123456789);
262 ledgerData->set_error(protocol::TMReplyError::reNO_LEDGER);
263 ledgerData->mutable_nodes()->Reserve(n);
265 for (
int i = 0; i < n; i++)
281 ledgerData->add_nodes()->set_nodedata(
291 auto getObject = std::make_shared<protocol::TMGetObjectByHash>();
293 getObject->set_type(protocol::TMGetObjectByHash_ObjectType::
294 TMGetObjectByHash_ObjectType_otTRANSACTION);
295 getObject->set_query(
true);
296 getObject->set_seq(123456789);
298 getObject->set_ledgerhash(hash.
data(), hash.
size());
299 getObject->set_fat(
true);
300 for (
int i = 0; i < 100; i++)
303 auto object = getObject->add_objects();
304 object->set_hash(hash.
data(), hash.
size());
307 object->set_index(
"");
308 object->set_data(
"");
309 object->set_ledgerseq(i);
317 auto list = std::make_shared<protocol::TMValidatorList>();
335 list->set_manifest(s.
data(), s.
size());
336 list->set_version(3);
342 list->set_signature(s1.
data(), s1.
size());
350 testcase(
"Message Compression");
352 auto thresh = beast::severities::Severity::kInfo;
353 auto logs = std::make_unique<Logs>(thresh);
355 protocol::TMManifests manifests;
356 protocol::TMEndpoints endpoints;
357 protocol::TMTransaction transaction;
358 protocol::TMGetLedger get_ledger;
359 protocol::TMLedgerData ledger_data;
360 protocol::TMGetObjectByHash get_object;
361 protocol::TMValidatorList validator_list;
364 doTest(buildManifests(20), protocol::mtMANIFESTS, 4,
"TMManifests20");
366 doTest(buildManifests(100), protocol::mtMANIFESTS, 4,
"TMManifests100");
368 doTest(buildEndpoints(10), protocol::mtENDPOINTS, 4,
"TMEndpoints10");
370 doTest(buildEndpoints(100), protocol::mtENDPOINTS, 4,
"TMEndpoints100");
373 buildTransaction(*logs),
374 protocol::mtTRANSACTION,
378 doTest(buildGetLedger(), protocol::mtGET_LEDGER, 1,
"TMGetLedger");
381 buildLedgerData(500, *logs),
382 protocol::mtLEDGER_DATA,
387 buildLedgerData(1000, *logs),
388 protocol::mtLEDGER_DATA,
393 buildLedgerData(10000, *logs),
394 protocol::mtLEDGER_DATA,
396 "TMLedgerData10000");
399 buildLedgerData(100000, *logs),
400 protocol::mtLEDGER_DATA,
402 "TMLedgerData100000");
405 buildLedgerData(500000, *logs),
406 protocol::mtLEDGER_DATA,
408 "TMLedgerData500000");
411 buildGetObjectByHash(),
412 protocol::mtGET_OBJECTS,
414 "TMGetObjectByHash");
417 buildValidatorList(),
418 protocol::mtVALIDATORLIST,