Debian Codegraph @

tests/unit_tests/levin.cpp

raw symbols SCIP
1 // Copyright (c) 2019-2022, The Monero Project
2 //
3 // All rights reserved.
4 //
5 // Redistribution and use in source and binary forms, with or without modification, are
6 // permitted provided that the following conditions are met:
7 //
8 // 1. Redistributions of source code must retain the above copyright notice, this list of
9 // conditions and the following disclaimer.
10 //
11 // 2. Redistributions in binary form must reproduce the above copyright notice, this list
12 // of conditions and the following disclaimer in the documentation and/or other
13 // materials provided with the distribution.
14 //
15 // 3. Neither the name of the copyright holder nor the names of its contributors may be
16 // used to endorse or promote products derived from this software without specific
17 // prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
20 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22 // THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
27 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 #include <algorithm>
30 #include <boost/uuid/nil_generator.hpp>
31 #include <boost/uuid/random_generator.hpp>
32 #include <boost/uuid/uuid.hpp>
33 #include <cstring>
34 #include <gtest/gtest.h>
35 #include <limits>
36 #include <set>
37 #include <map>
38
39 #include "byte_slice.h"
40 #include "crypto/crypto.h"
41 #include "cryptonote_basic/connection_context.h"
42 #include "cryptonote_config.h"
43 #include "cryptonote_core/cryptonote_core.h"
44 #include "cryptonote_core/i_core_events.h"
45 #include "cryptonote_protocol/cryptonote_protocol_defs.h"
46 #include "cryptonote_protocol/levin_notify.h"
47 #include "int-util.h"
48 #include "p2p/net_node.h"
49 #include "net/dandelionpp.h"
50 #include "net/levin_base.h"
51 #include "span.h"
52
53 namespace
54 {
55 class test_endpoint final : public epee::net_utils::i_service_endpoint
56 {
57 boost::asio::io_context& io_service_;
58 std::size_t ref_count_;
59
60 virtual bool do_send(epee::byte_slice message) override final
61 {
62 send_queue_.push_back(std::move(message));
63 return true;
64 }
65
66 virtual bool close(const bool wait_for_shutdown) override final
67 {
68 return true;
69 }
70
71 virtual bool send_done() override final
72 {
73 throw std::logic_error{"send_done not implemented"};
74 }
75
76 virtual bool call_run_once_service_io() override final
77 {
78 return io_service_.run_one();
79 }
80
81 virtual bool request_callback() override final
82 {
83 throw std::logic_error{"request_callback not implemented"};
84 }
85
86 virtual boost::asio::io_context& get_io_context() override final
87 {
88 return io_service_;
89 }
90
91 virtual bool add_ref() override final
92 {
93 ++ref_count_;
94 return true;
95 }
96
97 virtual bool release() override final
98 {
99 --ref_count_;
100 return true;
101 }
102
103 public:
104 test_endpoint(boost::asio::io_context& io_service)
105 : epee::net_utils::i_service_endpoint(),
106 io_service_(io_service),
107 ref_count_(0),
108 send_queue_()
109 {}
110
111 virtual ~test_endpoint() noexcept(false) override final
112 {
113 EXPECT_EQ(0u, ref_count_);
114 }
115
116 std::deque<epee::byte_slice> send_queue_;
117 };
118
119 class test_core_events final : public cryptonote::i_core_events
120 {
121 std::map<cryptonote::relay_method, std::vector<cryptonote::blobdata>> relayed_;
122
123 virtual bool is_synchronized() const final
124 {
125 return false;
126 }
127
128 virtual uint64_t get_current_blockchain_height() const final
129 {
130 return 0;
131 }
132
133 virtual void on_transactions_relayed(epee::span<const cryptonote::blobdata> txes, cryptonote::relay_method relay) override final
134 {
135 std::vector<cryptonote::blobdata>& cached = relayed_[relay];
136 for (const auto& tx : txes)
137 cached.push_back(tx);
138 }
139
140 public:
141 test_core_events()
142 : relayed_()
143 {}
144
145 std::size_t relayed_method_size() const noexcept
146 {
147 return relayed_.size();
148 }
149
150 bool has_stem_txes() const noexcept
151 {
152 return relayed_.count(cryptonote::relay_method::stem);
153 }
154
155 std::vector<cryptonote::blobdata> take_relayed(cryptonote::relay_method relay)
156 {
157 auto elems = relayed_.find(relay);
158 if (elems == relayed_.end())
159 throw std::logic_error{"on_transactions_relayed empty"};
160
161 std::vector<cryptonote::blobdata> out{std::move(elems->second)};
162 relayed_.erase(elems);
163 return out;
164 }
165 };
166
167 class test_connection
168 {
169 test_endpoint endpoint_;
170 cryptonote::levin::detail::p2p_context context_;
171 epee::levin::async_protocol_handler<cryptonote::levin::detail::p2p_context> handler_;
172
173 public:
174 test_connection(boost::asio::io_context& io_service, cryptonote::levin::connections& connections, boost::uuids::random_generator& random_generator, const bool is_incoming)
175 : endpoint_(io_service),
176 context_(),
177 handler_(std::addressof(endpoint_), connections, context_)
178 {
179 using base_type = epee::net_utils::connection_context_base;
180 static_cast<base_type&>(context_) = base_type{random_generator(), {}, is_incoming, false};
181 context_.m_state = cryptonote::cryptonote_connection_context::state_normal;
182 handler_.after_init_connection();
183 }
184
185 //\return Number of messages processed
186 std::size_t process_send_queue(const bool valid = true)
187 {
188 std::size_t count = 0;
189 for ( ; !endpoint_.send_queue_.empty(); ++count, endpoint_.send_queue_.pop_front())
190 {
191 EXPECT_EQ(valid, handler_.handle_recv(endpoint_.send_queue_.front().data(), endpoint_.send_queue_.front().size()));
192 }
193 return count;
194 }
195
196 const boost::uuids::uuid& get_id() const noexcept
197 {
198 return context_.m_connection_id;
199 }
200
201 bool is_incoming() const noexcept
202 {
203 return context_.m_is_income;
204 }
205 };
206
207 struct received_message
208 {
209 boost::uuids::uuid connection;
210 int command;
211 std::string payload;
212 };
213
214 class test_receiver final : public epee::levin::levin_commands_handler<cryptonote::levin::detail::p2p_context>
215 {
216 std::deque<received_message> invoked_;
217 std::deque<received_message> notified_;
218
219 template<typename T>
220 static std::pair<boost::uuids::uuid, typename T::request> get_message(std::deque<received_message>& queue)
221 {
222 if (queue.empty())
223 throw std::logic_error{"Queue has no received messges"};
224
225 if (queue.front().command != T::ID)
226 throw std::logic_error{"Unexpected ID at front of message queue"};
227
228 epee::serialization::portable_storage storage{};
229 if(!storage.load_from_binary(epee::strspan<std::uint8_t>(queue.front().payload)))
230 throw std::logic_error{"Unable to parse epee binary format"};
231
232 typename T::request request{};
233 if (!request.load(storage))
234 throw std::logic_error{"Unable to load into expected request"};
235
236 boost::uuids::uuid connection = queue.front().connection;
237 queue.pop_front();
238 return {connection, std::move(request)};
239 }
240
241 static received_message get_raw_message(std::deque<received_message>& queue)
242 {
243 received_message out{std::move(queue.front())};
244 queue.pop_front();
245 return out;
246 }
247
248 virtual int invoke(int command, const epee::span<const uint8_t> in_buff, epee::byte_stream& buff_out, cryptonote::levin::detail::p2p_context& context) override final
249 {
250 buff_out.clear();
251 invoked_.push_back(
252 {context.m_connection_id, command, std::string{reinterpret_cast<const char*>(in_buff.data()), in_buff.size()}}
253 );
254 return 1;
255 }
256
257 virtual int notify(int command, const epee::span<const uint8_t> in_buff, cryptonote::levin::detail::p2p_context& context) override final
258 {
259 notified_.push_back(
260 {context.m_connection_id, command, std::string{reinterpret_cast<const char*>(in_buff.data()), in_buff.size()}}
261 );
262 return 1;
263 }
264
265 virtual void callback(cryptonote::levin::detail::p2p_context& context) override final
266 {}
267
268 virtual void on_connection_new(cryptonote::levin::detail::p2p_context& context) override final
269 {
270 if (notifier)
271 notifier->on_handshake_complete(context.m_connection_id, context.m_is_income);
272 }
273
274 virtual void on_connection_close(cryptonote::levin::detail::p2p_context& context) override final
275 {
276 if (notifier)
277 notifier->on_connection_close(context.m_connection_id);
278 }
279
280 public:
281 test_receiver()
282 : epee::levin::levin_commands_handler<cryptonote::levin::detail::p2p_context>(),
283 invoked_(),
284 notified_()
285 {}
286
287 virtual ~test_receiver() noexcept override final{}
288
289 std::size_t invoked_size() const noexcept
290 {
291 return invoked_.size();
292 }
293
294 std::size_t notified_size() const noexcept
295 {
296 return notified_.size();
297 }
298
299 template<typename T>
300 std::pair<boost::uuids::uuid, typename T::request> get_invoked()
301 {
302 return get_message<T>(invoked_);
303 }
304
305 template<typename T>
306 std::pair<boost::uuids::uuid, typename T::request> get_notification()
307 {
308 return get_message<T>(notified_);
309 }
310
311 received_message get_raw_notification()
312 {
313 return get_raw_message(notified_);
314 }
315
316 std::shared_ptr<cryptonote::levin::notify> notifier{};
317 };
318
319 class levin_notify : public ::testing::Test
320 {
321 const std::shared_ptr<cryptonote::levin::connections> connections_;
322 std::set<boost::uuids::uuid> connection_ids_;
323
324 public:
325 levin_notify()
326 : ::testing::Test(),
327 connections_(std::make_shared<cryptonote::levin::connections>()),
328 connection_ids_(),
329 random_generator_(),
330 io_service_(),
331 receiver_(),
332 contexts_(),
333 events_()
334 {
335 connections_->set_handler(std::addressof(receiver_), nullptr);
336 }
337
338 virtual void TearDown() override final
339 {
340 EXPECT_EQ(0u, receiver_.invoked_size());
341 EXPECT_EQ(0u, receiver_.notified_size());
342 EXPECT_EQ(0u, events_.relayed_method_size());
343 }
344
345 cryptonote::levin::connections& get_connections() noexcept { return *connections_; }
346
347 void add_connection(const bool is_incoming)
348 {
349 contexts_.emplace_back(io_service_, *connections_, random_generator_, is_incoming);
350 EXPECT_TRUE(connection_ids_.emplace(contexts_.back().get_id()).second);
351 EXPECT_EQ(connection_ids_.size(), connections_->get_connections_count());
352 }
353
354 std::shared_ptr<cryptonote::levin::notify> make_notifier(const std::size_t noise_size, bool is_public, bool pad_txs)
355 {
356 epee::byte_slice noise = nullptr;
357 if (noise_size)
358 noise = epee::levin::make_noise_notify(noise_size);
359 epee::net_utils::zone zone = is_public ? epee::net_utils::zone::public_ : epee::net_utils::zone::i2p;
360 receiver_.notifier.reset(
361 new cryptonote::levin::notify{io_service_, connections_, std::move(noise), zone, pad_txs, events_}
362 );
363 return receiver_.notifier;
364 }
365
366 boost::uuids::random_generator random_generator_;
367 boost::asio::io_context io_service_;
368 test_receiver receiver_;
369 std::deque<test_connection> contexts_;
370 test_core_events events_;
371 };
372 }
373
374 TEST(make_header, no_expect_return)
375 {
376 static constexpr const std::size_t max_length = std::numeric_limits<std::size_t>::max();
377
378 const epee::levin::bucket_head2 header1 = epee::levin::make_header(1024, max_length, 5601, false);
379 EXPECT_EQ(SWAP64LE(LEVIN_SIGNATURE), header1.m_signature);
380 EXPECT_FALSE(header1.m_have_to_return_data);
381 EXPECT_EQ(SWAP64LE(max_length), header1.m_cb);
382 EXPECT_EQ(SWAP32LE(1024), header1.m_command);
383 EXPECT_EQ(SWAP32LE(LEVIN_PROTOCOL_VER_1), header1.m_protocol_version);
384 EXPECT_EQ(SWAP32LE(5601), header1.m_flags);
385 }
386
387 TEST(make_header, expect_return)
388 {
389 const epee::levin::bucket_head2 header1 = epee::levin::make_header(65535, 0, 0, true);
390 EXPECT_EQ(SWAP64LE(LEVIN_SIGNATURE), header1.m_signature);
391 EXPECT_TRUE(header1.m_have_to_return_data);
392 EXPECT_EQ(0u, header1.m_cb);
393 EXPECT_EQ(SWAP32LE(65535), header1.m_command);
394 EXPECT_EQ(SWAP32LE(LEVIN_PROTOCOL_VER_1), header1.m_protocol_version);
395 EXPECT_EQ(0u, header1.m_flags);
396 }
397
398 TEST(message_writer, invoke_with_empty_payload)
399 {
400 const epee::byte_slice message = epee::levin::message_writer{}.finalize_invoke(443);
401 const epee::levin::bucket_head2 header =
402 epee::levin::make_header(443, 0, LEVIN_PACKET_REQUEST, true);
403 ASSERT_EQ(sizeof(header), message.size());
404 EXPECT_TRUE(std::memcmp(std::addressof(header), message.data(), sizeof(header)) == 0);
405 }
406
407 TEST(message_writer, invoke_with_payload)
408 {
409 std::string bytes(100, 'a');
410 std::generate(bytes.begin(), bytes.end(), crypto::random_device{});
411
412 epee::levin::message_writer writer{};
413 writer.buffer.write(epee::to_span(bytes));
414
415 const epee::byte_slice message = writer.finalize_invoke(443);
416 const epee::levin::bucket_head2 header =
417 epee::levin::make_header(443, bytes.size(), LEVIN_PACKET_REQUEST, true);
418
419 ASSERT_EQ(sizeof(header) + bytes.size(), message.size());
420 EXPECT_TRUE(std::memcmp(std::addressof(header), message.data(), sizeof(header)) == 0);
421 EXPECT_TRUE(std::memcmp(bytes.data(), message.data() + sizeof(header), bytes.size()) == 0);
422 }
423
424 TEST(message_writer, notify_with_empty_payload)
425 {
426 const epee::byte_slice message = epee::levin::message_writer{}.finalize_notify(443);
427 const epee::levin::bucket_head2 header =
428 epee::levin::make_header(443, 0, LEVIN_PACKET_REQUEST, false);
429 ASSERT_EQ(sizeof(header), message.size());
430 EXPECT_TRUE(std::memcmp(std::addressof(header), message.data(), sizeof(header)) == 0);
431 }
432
433 TEST(message_writer, notify_with_payload)
434 {
435 std::string bytes(100, 'a');
436 std::generate(bytes.begin(), bytes.end(), crypto::random_device{});
437
438 epee::levin::message_writer writer{};
439 writer.buffer.write(epee::to_span(bytes));
440
441 const epee::byte_slice message = writer.finalize_notify(443);
442 const epee::levin::bucket_head2 header =
443 epee::levin::make_header(443, bytes.size(), LEVIN_PACKET_REQUEST, false);
444
445 ASSERT_EQ(sizeof(header) + bytes.size(), message.size());
446 EXPECT_TRUE(std::memcmp(std::addressof(header), message.data(), sizeof(header)) == 0);
447 EXPECT_TRUE(std::memcmp(bytes.data(), message.data() + sizeof(header), bytes.size()) == 0);
448 }
449
450 TEST(message_writer, response_with_empty_payload)
451 {
452 const epee::byte_slice message = epee::levin::message_writer{}.finalize_response(443, 1);
453 epee::levin::bucket_head2 header =
454 epee::levin::make_header(443, 0, LEVIN_PACKET_RESPONSE, false);
455 header.m_return_code = SWAP32LE(1);
456 ASSERT_EQ(sizeof(header), message.size());
457 EXPECT_TRUE(std::memcmp(std::addressof(header), message.data(), sizeof(header)) == 0);
458 }
459
460 TEST(message_writer, response_with_payload)
461 {
462 std::string bytes(100, 'a');
463 std::generate(bytes.begin(), bytes.end(), crypto::random_device{});
464
465 epee::levin::message_writer writer{};
466 writer.buffer.write(epee::to_span(bytes));
467
468 const epee::byte_slice message = writer.finalize_response(443, 6450);
469 epee::levin::bucket_head2 header =
470 epee::levin::make_header(443, bytes.size(), LEVIN_PACKET_RESPONSE, false);
471 header.m_return_code = SWAP32LE(6450);
472
473 ASSERT_EQ(sizeof(header) + bytes.size(), message.size());
474 EXPECT_TRUE(std::memcmp(std::addressof(header), message.data(), sizeof(header)) == 0);
475 EXPECT_TRUE(std::memcmp(bytes.data(), message.data() + sizeof(header), bytes.size()) == 0);
476 }
477
478 TEST(message_writer, error)
479 {
480 epee::levin::message_writer writer{};
481 writer.buffer.clear();
482
483 EXPECT_THROW(writer.finalize_invoke(0), std::runtime_error);
484 EXPECT_THROW(writer.finalize_notify(0), std::runtime_error);
485 EXPECT_THROW(writer.finalize_response(0, 0), std::runtime_error);
486 }
487
488 TEST(make_noise, invalid)
489 {
490 EXPECT_TRUE(epee::levin::make_noise_notify(sizeof(epee::levin::bucket_head2) - 1).empty());
491 }
492
493 TEST(make_noise, valid)
494 {
495 static constexpr const std::uint32_t flags =
496 LEVIN_PACKET_BEGIN | LEVIN_PACKET_END;
497
498 const epee::byte_slice noise = epee::levin::make_noise_notify(1024);
499 const epee::levin::bucket_head2 header =
500 epee::levin::make_header(0, 1024 - sizeof(epee::levin::bucket_head2), flags, false);
501
502 ASSERT_EQ(1024, noise.size());
503 EXPECT_TRUE(std::memcmp(std::addressof(header), noise.data(), sizeof(header)) == 0);
504 EXPECT_EQ(1024 - sizeof(header), std::count(noise.cbegin() + sizeof(header), noise.cend(), 0));
505 }
506
507 TEST(make_fragment, invalid)
508 {
509 EXPECT_TRUE(epee::levin::make_fragmented_notify(0, 0, epee::levin::message_writer{}).empty());
510 }
511
512 TEST(make_fragment, single)
513 {
514 const epee::byte_slice noise = epee::levin::make_noise_notify(1024);
515 const epee::byte_slice fragment = epee::levin::make_fragmented_notify(noise.size(), 11, epee::levin::message_writer{});
516 const epee::levin::bucket_head2 header =
517 epee::levin::make_header(11, 1024 - sizeof(epee::levin::bucket_head2), LEVIN_PACKET_REQUEST, false);
518
519 EXPECT_EQ(1024, noise.size());
520 ASSERT_EQ(1024, fragment.size());
521 EXPECT_TRUE(std::memcmp(std::addressof(header), fragment.data(), sizeof(header)) == 0);
522 EXPECT_EQ(1024 - sizeof(header), std::count(noise.cbegin() + sizeof(header), noise.cend(), 0));
523 }
524
525 TEST(make_fragment, multiple)
526 {
527 std::string bytes(1024 * 3 - 150, 'a');
528 std::generate(bytes.begin(), bytes.end(), crypto::random_device{});
529
530 epee::levin::message_writer message;
531 message.buffer.write(epee::to_span(bytes));
532
533 const epee::byte_slice noise = epee::levin::make_noise_notify(1024);
534 epee::byte_slice fragment = epee::levin::make_fragmented_notify(noise.size(), 114, std::move(message));
535
536 EXPECT_EQ(1024 * 3, fragment.size());
537
538 epee::levin::bucket_head2 header =
539 epee::levin::make_header(0, 1024 - sizeof(epee::levin::bucket_head2), LEVIN_PACKET_BEGIN, false);
540
541 ASSERT_LE(sizeof(header), fragment.size());
542 EXPECT_TRUE(std::memcmp(std::addressof(header), fragment.data(), sizeof(header)) == 0);
543
544 fragment.take_slice(sizeof(header));
545 header.m_flags = LEVIN_PACKET_REQUEST;
546 header.m_cb = bytes.size();
547 header.m_command = 114;
548
549 ASSERT_LE(sizeof(header), fragment.size());
550 EXPECT_TRUE(std::memcmp(std::addressof(header), fragment.data(), sizeof(header)) == 0);
551
552 fragment.take_slice(sizeof(header));
553
554 ASSERT_LE(bytes.size(), fragment.size());
555 EXPECT_TRUE(std::memcmp(bytes.data(), fragment.data(), 1024 - sizeof(header) * 2) == 0);
556
557 bytes.erase(0, 1024 - sizeof(header) * 2);
558 fragment.take_slice(1024 - sizeof(header) * 2);
559 header.m_flags = 0;
560 header.m_cb = 1024 - sizeof(header);
561 header.m_command = 0;
562
563 ASSERT_LE(sizeof(header), fragment.size());
564 EXPECT_TRUE(std::memcmp(std::addressof(header), fragment.data(), sizeof(header)) == 0);
565
566 fragment.take_slice(sizeof(header));
567
568 ASSERT_LE(bytes.size(), fragment.size());
569 EXPECT_TRUE(std::memcmp(bytes.data(), fragment.data(), 1024 - sizeof(header)) == 0);
570
571 bytes.erase(0, 1024 - sizeof(header));
572 fragment.take_slice(1024 - sizeof(header));
573 header.m_flags = LEVIN_PACKET_END;
574
575 ASSERT_LE(sizeof(header), fragment.size());
576 EXPECT_TRUE(std::memcmp(std::addressof(header), fragment.data(), sizeof(header)) == 0);
577
578 fragment.take_slice(sizeof(header));
579 EXPECT_TRUE(std::memcmp(bytes.data(), fragment.data(), bytes.size()) == 0);
580
581 fragment.take_slice(bytes.size());
582
583 EXPECT_EQ(18, fragment.size());
584 EXPECT_EQ(18, std::count(fragment.cbegin(), fragment.cend(), 0));
585 }
586
587 TEST_F(levin_notify, defaulted)
588 {
589 cryptonote::levin::notify notifier{};
590 {
591 const auto status = notifier.get_status();
592 EXPECT_FALSE(status.has_noise);
593 EXPECT_FALSE(status.connections_filled);
594 EXPECT_FALSE(status.has_outgoing);
595 }
596 EXPECT_TRUE(notifier.send_txs({}, random_generator_(), cryptonote::relay_method::local));
597
598 std::vector<cryptonote::blobdata> txs(2);
599 txs[0].resize(100, 'e');
600 EXPECT_FALSE(notifier.send_txs(std::move(txs), random_generator_(), cryptonote::relay_method::local));
601 }
602
603 TEST_F(levin_notify, fluff_without_padding)
604 {
605 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
606 auto &notifier = *notifier_ptr;
607
608 for (unsigned count = 0; count < 10; ++count)
609 add_connection(count % 2 == 0);
610
611 {
612 const auto status = notifier.get_status();
613 EXPECT_FALSE(status.has_noise);
614 EXPECT_FALSE(status.connections_filled);
615 EXPECT_TRUE(status.has_outgoing);
616 }
617 notifier.new_out_connection();
618 io_service_.poll();
619
620 std::vector<cryptonote::blobdata> txs(2);
621 txs[0].resize(100, 'f');
622 txs[1].resize(200, 'e');
623
624 ASSERT_EQ(10u, contexts_.size());
625 {
626 auto context = contexts_.begin();
627 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff));
628
629 io_service_.restart();
630 ASSERT_LT(0u, io_service_.poll());
631 notifier.run_fluff();
632 ASSERT_LT(0u, io_service_.poll());
633
634 EXPECT_EQ(0u, context->process_send_queue());
635 for (++context; context != contexts_.end(); ++context)
636 EXPECT_EQ(1u, context->process_send_queue());
637
638 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
639 std::sort(txs.begin(), txs.end());
640 ASSERT_EQ(9u, receiver_.notified_size());
641 for (unsigned count = 0; count < 9; ++count)
642 {
643 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
644 EXPECT_EQ(txs, notification.txs);
645 EXPECT_TRUE(notification._.empty());
646 EXPECT_TRUE(notification.dandelionpp_fluff);
647 }
648 }
649 }
650
651 TEST_F(levin_notify, stem_without_padding)
652 {
653 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
654 auto &notifier = *notifier_ptr;
655
656 for (unsigned count = 0; count < 10; ++count)
657 add_connection(count % 2 == 0);
658
659 {
660 const auto status = notifier.get_status();
661 EXPECT_FALSE(status.has_noise);
662 EXPECT_FALSE(status.connections_filled);
663 EXPECT_TRUE(status.has_outgoing);
664 }
665 notifier.new_out_connection();
666 io_service_.poll();
667
668 std::vector<cryptonote::blobdata> txs(2);
669 txs[0].resize(100, 'f');
670 txs[1].resize(200, 'e');
671
672 std::vector<cryptonote::blobdata> sorted_txs = txs;
673 std::sort(sorted_txs.begin(), sorted_txs.end());
674
675 ASSERT_EQ(10u, contexts_.size());
676 bool has_stemmed = false;
677 bool has_fluffed = false;
678 while (!has_stemmed || !has_fluffed)
679 {
680 auto context = contexts_.begin();
681 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem));
682
683 io_service_.restart();
684 ASSERT_LT(0u, io_service_.poll());
685 const bool is_stem = events_.has_stem_txes();
686 EXPECT_EQ(txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff));
687
688 if (!is_stem)
689 {
690 notifier.run_fluff();
691 ASSERT_LT(0u, io_service_.poll());
692 }
693
694 std::size_t send_count = 0;
695 EXPECT_EQ(0u, context->process_send_queue());
696 for (++context; context != contexts_.end(); ++context)
697 {
698 const std::size_t sent = context->process_send_queue();
699 if (sent && is_stem)
700 {
701 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
702 }
703 send_count += sent;
704 }
705
706 EXPECT_EQ(is_stem ? 1u : 9u, send_count);
707 ASSERT_EQ(is_stem ? 1u : 9u, receiver_.notified_size());
708 for (unsigned count = 0; count < (is_stem ? 1u : 9u); ++count)
709 {
710 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
711 if (is_stem)
712 EXPECT_EQ(txs, notification.txs);
713 else
714 EXPECT_EQ(sorted_txs, notification.txs);
715 EXPECT_TRUE(notification._.empty());
716 EXPECT_EQ(!is_stem, notification.dandelionpp_fluff);
717 }
718
719 has_stemmed |= is_stem;
720 has_fluffed |= !is_stem;
721 notifier.run_epoch();
722 }
723 }
724
725 TEST_F(levin_notify, stem_no_outs_without_padding)
726 {
727 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
728 auto &notifier = *notifier_ptr;
729
730 for (unsigned count = 0; count < 10; ++count)
731 add_connection(true);
732
733 {
734 const auto status = notifier.get_status();
735 EXPECT_FALSE(status.has_noise);
736 EXPECT_FALSE(status.connections_filled);
737 EXPECT_FALSE(status.has_outgoing);
738 }
739 notifier.new_out_connection();
740 io_service_.poll();
741
742 std::vector<cryptonote::blobdata> txs(2);
743 txs[0].resize(100, 'f');
744 txs[1].resize(200, 'e');
745
746 std::vector<cryptonote::blobdata> sorted_txs = txs;
747 std::sort(sorted_txs.begin(), sorted_txs.end());
748
749 ASSERT_EQ(10u, contexts_.size());
750
751 auto context = contexts_.begin();
752 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem));
753
754 io_service_.restart();
755 ASSERT_LT(0u, io_service_.poll());
756 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
757 if (events_.has_stem_txes())
758 {
759 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem));
760 }
761
762 notifier.run_fluff();
763 ASSERT_LT(0u, io_service_.poll());
764
765 std::size_t send_count = 0;
766 EXPECT_EQ(0u, context->process_send_queue());
767 for (++context; context != contexts_.end(); ++context)
768 {
769 send_count += context->process_send_queue();
770 }
771
772 EXPECT_EQ(9u, send_count);
773 ASSERT_EQ(9u, receiver_.notified_size());
774 for (unsigned count = 0; count < 9u; ++count)
775 {
776 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
777 EXPECT_EQ(sorted_txs, notification.txs);
778 EXPECT_TRUE(notification._.empty());
779 EXPECT_TRUE(notification.dandelionpp_fluff);
780 }
781 }
782
783 TEST_F(levin_notify, local_without_padding)
784 {
785 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
786 auto &notifier = *notifier_ptr;
787
788 for (unsigned count = 0; count < 10; ++count)
789 add_connection(count % 2 == 0);
790
791 {
792 const auto status = notifier.get_status();
793 EXPECT_FALSE(status.has_noise);
794 EXPECT_FALSE(status.connections_filled);
795 EXPECT_TRUE(status.has_outgoing);
796 }
797 notifier.new_out_connection();
798 io_service_.poll();
799
800 std::vector<cryptonote::blobdata> my_txs(2);
801 my_txs[0].resize(100, 'f');
802 my_txs[1].resize(200, 'e');
803
804 std::vector<cryptonote::blobdata> their_txs{2};
805 their_txs[0].resize(300, 'g');
806 their_txs[1].resize(250, 'h');
807
808 std::vector<cryptonote::blobdata> my_sorted_txs = my_txs;
809 std::sort(my_sorted_txs.begin(), my_sorted_txs.end());
810
811 std::vector<cryptonote::blobdata> their_sorted_txs = their_txs;
812 std::sort(their_sorted_txs.begin(), their_sorted_txs.end());
813
814 ASSERT_EQ(10u, contexts_.size());
815 bool has_stemmed = false;
816 bool has_fluffed = false;
817 while (!has_stemmed || !has_fluffed)
818 {
819 // run their "their" txes first
820 auto context = contexts_.begin();
821 EXPECT_TRUE(notifier.send_txs(their_txs, context->get_id(), cryptonote::relay_method::stem));
822
823 io_service_.restart();
824 ASSERT_LT(0u, io_service_.poll());
825 const bool is_stem = events_.has_stem_txes();
826 EXPECT_EQ(their_txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff));
827
828 if (!is_stem)
829 {
830 notifier.run_fluff();
831 ASSERT_LT(0u, io_service_.poll());
832 }
833
834 std::size_t send_count = 0;
835 EXPECT_EQ(0u, context->process_send_queue());
836 for (++context; context != contexts_.end(); ++context)
837 {
838 const std::size_t sent = context->process_send_queue();
839 if (sent && is_stem)
840 {
841 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
842 }
843 send_count += sent;
844 }
845
846 EXPECT_EQ(is_stem ? 1u : 9u, send_count);
847 ASSERT_EQ(is_stem ? 1u : 9u, receiver_.notified_size());
848 for (unsigned count = 0; count < (is_stem ? 1u : 9u); ++count)
849 {
850 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
851 if (is_stem)
852 EXPECT_EQ(their_txs, notification.txs);
853 else
854 EXPECT_EQ(their_sorted_txs, notification.txs);
855 EXPECT_TRUE(notification._.empty());
856 EXPECT_EQ(!is_stem, notification.dandelionpp_fluff);
857 }
858
859 // run "my" txes which must always be stem
860 context = contexts_.begin();
861 EXPECT_TRUE(notifier.send_txs(my_txs, context->get_id(), cryptonote::relay_method::local));
862
863 io_service_.restart();
864 ASSERT_LT(0u, io_service_.poll());
865 EXPECT_TRUE(events_.has_stem_txes());
866 EXPECT_EQ(my_txs, events_.take_relayed(cryptonote::relay_method::stem));
867
868 send_count = 0;
869 EXPECT_EQ(0u, context->process_send_queue());
870 for (++context; context != contexts_.end(); ++context)
871 {
872 const std::size_t sent = context->process_send_queue();
873 if (sent)
874 {
875 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
876 }
877 send_count += sent;
878 }
879
880 EXPECT_EQ(1u, send_count);
881 EXPECT_EQ(1u, receiver_.notified_size());
882 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
883 EXPECT_EQ(my_txs, notification.txs);
884 EXPECT_TRUE(notification._.empty());
885 EXPECT_TRUE(!notification.dandelionpp_fluff);
886
887 has_stemmed |= is_stem;
888 has_fluffed |= !is_stem;
889 notifier.run_epoch();
890 }
891 }
892
893 TEST_F(levin_notify, forward_without_padding)
894 {
895 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
896 auto &notifier = *notifier_ptr;
897
898 for (unsigned count = 0; count < 10; ++count)
899 add_connection(count % 2 == 0);
900
901 {
902 const auto status = notifier.get_status();
903 EXPECT_FALSE(status.has_noise);
904 EXPECT_FALSE(status.connections_filled);
905 EXPECT_TRUE(status.has_outgoing);
906 }
907 notifier.new_out_connection();
908 io_service_.poll();
909
910 std::vector<cryptonote::blobdata> txs(2);
911 txs[0].resize(100, 'f');
912 txs[1].resize(200, 'e');
913
914 std::vector<cryptonote::blobdata> sorted_txs = txs;
915 std::sort(sorted_txs.begin(), sorted_txs.end());
916
917 ASSERT_EQ(10u, contexts_.size());
918 bool has_stemmed = false;
919 bool has_fluffed = false;
920 while (!has_stemmed || !has_fluffed)
921 {
922 auto context = contexts_.begin();
923 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::forward));
924
925 io_service_.restart();
926 ASSERT_LT(0u, io_service_.poll());
927 const bool is_stem = events_.has_stem_txes();
928 EXPECT_EQ(txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff));
929
930 if (!is_stem)
931 {
932 notifier.run_fluff();
933 ASSERT_LT(0u, io_service_.poll());
934 }
935
936 std::size_t send_count = 0;
937 EXPECT_EQ(0u, context->process_send_queue());
938 for (++context; context != contexts_.end(); ++context)
939 {
940 const std::size_t sent = context->process_send_queue();
941 if (sent && is_stem)
942 {
943 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
944 }
945 send_count += sent;
946 }
947
948 EXPECT_EQ(is_stem ? 1u : 9u, send_count);
949 ASSERT_EQ(is_stem ? 1u : 9u, receiver_.notified_size());
950 for (unsigned count = 0; count < (is_stem ? 1u : 9u); ++count)
951 {
952 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
953 if (is_stem)
954 EXPECT_EQ(txs, notification.txs);
955 else
956 EXPECT_EQ(sorted_txs, notification.txs);
957 EXPECT_TRUE(notification._.empty());
958 EXPECT_EQ(!is_stem, notification.dandelionpp_fluff);
959 }
960
961 has_stemmed |= is_stem;
962 has_fluffed |= !is_stem;
963 notifier.run_epoch();
964 }
965 }
966
967 TEST_F(levin_notify, block_without_padding)
968 {
969 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
970 auto &notifier = *notifier_ptr;
971
972 for (unsigned count = 0; count < 10; ++count)
973 add_connection(count % 2 == 0);
974
975 {
976 const auto status = notifier.get_status();
977 EXPECT_FALSE(status.has_noise);
978 EXPECT_FALSE(status.connections_filled);
979 EXPECT_TRUE(status.has_outgoing);
980 }
981 notifier.new_out_connection();
982 io_service_.poll();
983
984 std::vector<cryptonote::blobdata> txs(2);
985 txs[0].resize(100, 'e');
986 txs[1].resize(200, 'f');
987
988 ASSERT_EQ(10u, contexts_.size());
989 {
990 auto context = contexts_.begin();
991 EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::block));
992
993 io_service_.restart();
994 ASSERT_EQ(0u, io_service_.poll());
995 }
996 }
997
998 TEST_F(levin_notify, none_without_padding)
999 {
1000 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
1001 auto &notifier = *notifier_ptr;
1002
1003 for (unsigned count = 0; count < 10; ++count)
1004 add_connection(count % 2 == 0);
1005
1006 {
1007 const auto status = notifier.get_status();
1008 EXPECT_FALSE(status.has_noise);
1009 EXPECT_FALSE(status.connections_filled);
1010 EXPECT_TRUE(status.has_outgoing);
1011 }
1012 notifier.new_out_connection();
1013 io_service_.poll();
1014
1015 std::vector<cryptonote::blobdata> txs(2);
1016 txs[0].resize(100, 'e');
1017 txs[1].resize(200, 'f');
1018
1019 ASSERT_EQ(10u, contexts_.size());
1020 {
1021 auto context = contexts_.begin();
1022 EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::none));
1023
1024 io_service_.restart();
1025 ASSERT_EQ(0u, io_service_.poll());
1026 }
1027 }
1028
1029 TEST_F(levin_notify, fluff_with_padding)
1030 {
1031 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, true);
1032 auto &notifier = *notifier_ptr;
1033
1034 for (unsigned count = 0; count < 10; ++count)
1035 add_connection(count % 2 == 0);
1036
1037 {
1038 const auto status = notifier.get_status();
1039 EXPECT_FALSE(status.has_noise);
1040 EXPECT_FALSE(status.connections_filled);
1041 EXPECT_TRUE(status.has_outgoing);
1042 }
1043 notifier.new_out_connection();
1044 io_service_.poll();
1045
1046 std::vector<cryptonote::blobdata> txs(2);
1047 txs[0].resize(100, 'f');
1048 txs[1].resize(200, 'e');
1049
1050 ASSERT_EQ(10u, contexts_.size());
1051 {
1052 auto context = contexts_.begin();
1053 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff));
1054
1055 io_service_.restart();
1056 ASSERT_LT(0u, io_service_.poll());
1057 notifier.run_fluff();
1058 ASSERT_LT(0u, io_service_.poll());
1059
1060 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
1061 std::sort(txs.begin(), txs.end());
1062 EXPECT_EQ(0u, context->process_send_queue());
1063 for (++context; context != contexts_.end(); ++context)
1064 EXPECT_EQ(1u, context->process_send_queue());
1065
1066 ASSERT_EQ(9u, receiver_.notified_size());
1067 for (unsigned count = 0; count < 9; ++count)
1068 {
1069 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1070 EXPECT_EQ(txs, notification.txs);
1071 EXPECT_FALSE(notification._.empty());
1072 EXPECT_TRUE(notification.dandelionpp_fluff);
1073 }
1074 }
1075 }
1076
1077 TEST_F(levin_notify, stem_with_padding)
1078 {
1079 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, true);
1080 auto &notifier = *notifier_ptr;
1081
1082 for (unsigned count = 0; count < 10; ++count)
1083 add_connection(count % 2 == 0);
1084
1085 {
1086 const auto status = notifier.get_status();
1087 EXPECT_FALSE(status.has_noise);
1088 EXPECT_FALSE(status.connections_filled);
1089 EXPECT_TRUE(status.has_outgoing);
1090 }
1091 notifier.new_out_connection();
1092 io_service_.poll();
1093
1094 std::vector<cryptonote::blobdata> txs(2);
1095 txs[0].resize(100, 'e');
1096 txs[1].resize(200, 'f');
1097
1098 ASSERT_EQ(10u, contexts_.size());
1099 bool has_stemmed = false;
1100 bool has_fluffed = false;
1101 while (!has_stemmed || !has_fluffed)
1102 {
1103 auto context = contexts_.begin();
1104 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem));
1105
1106 io_service_.restart();
1107 ASSERT_LT(0u, io_service_.poll());
1108 const bool is_stem = events_.has_stem_txes();
1109 EXPECT_EQ(txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff));
1110
1111 if (!is_stem)
1112 {
1113 notifier.run_fluff();
1114 ASSERT_LT(0u, io_service_.poll());
1115 }
1116
1117 std::size_t send_count = 0;
1118 EXPECT_EQ(0u, context->process_send_queue());
1119 for (++context; context != contexts_.end(); ++context)
1120 {
1121 const std::size_t sent = context->process_send_queue();
1122 if (sent && is_stem)
1123 {
1124 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
1125 EXPECT_FALSE(context->is_incoming());
1126 }
1127 send_count += sent;
1128 }
1129
1130 EXPECT_EQ(is_stem ? 1u : 9u, send_count);
1131 ASSERT_EQ(is_stem ? 1u : 9u, receiver_.notified_size());
1132 for (unsigned count = 0; count < (is_stem ? 1u : 9u); ++count)
1133 {
1134 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1135 EXPECT_EQ(txs, notification.txs);
1136 EXPECT_FALSE(notification._.empty());
1137 EXPECT_EQ(!is_stem, notification.dandelionpp_fluff);
1138 }
1139
1140 has_stemmed |= is_stem;
1141 has_fluffed |= !is_stem;
1142 notifier.run_epoch();
1143 }
1144 }
1145
1146 TEST_F(levin_notify, stem_no_outs_with_padding)
1147 {
1148 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, true);
1149 auto &notifier = *notifier_ptr;
1150
1151 for (unsigned count = 0; count < 10; ++count)
1152 add_connection(true);
1153
1154 {
1155 const auto status = notifier.get_status();
1156 EXPECT_FALSE(status.has_noise);
1157 EXPECT_FALSE(status.connections_filled);
1158 EXPECT_FALSE(status.has_outgoing);
1159 }
1160 notifier.new_out_connection();
1161 io_service_.poll();
1162
1163 std::vector<cryptonote::blobdata> txs(2);
1164 txs[0].resize(100, 'f');
1165 txs[1].resize(200, 'e');
1166
1167 std::vector<cryptonote::blobdata> sorted_txs = txs;
1168 std::sort(sorted_txs.begin(), sorted_txs.end());
1169
1170 ASSERT_EQ(10u, contexts_.size());
1171
1172 auto context = contexts_.begin();
1173 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem));
1174
1175 io_service_.restart();
1176 ASSERT_LT(0u, io_service_.poll());
1177 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
1178 if (events_.has_stem_txes())
1179 {
1180 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem));
1181 }
1182
1183 notifier.run_fluff();
1184 ASSERT_LT(0u, io_service_.poll());
1185
1186 std::size_t send_count = 0;
1187 EXPECT_EQ(0u, context->process_send_queue());
1188 for (++context; context != contexts_.end(); ++context)
1189 {
1190 send_count += context->process_send_queue();
1191 }
1192
1193 EXPECT_EQ(9u, send_count);
1194 ASSERT_EQ(9u, receiver_.notified_size());
1195 for (unsigned count = 0; count < 9u; ++count)
1196 {
1197 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1198 EXPECT_EQ(sorted_txs, notification.txs);
1199 EXPECT_FALSE(notification._.empty());
1200 EXPECT_TRUE(notification.dandelionpp_fluff);
1201 }
1202 }
1203
1204 TEST_F(levin_notify, local_with_padding)
1205 {
1206 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, true);
1207 auto &notifier = *notifier_ptr;
1208
1209 for (unsigned count = 0; count < 10; ++count)
1210 add_connection(count % 2 == 0);
1211
1212 {
1213 const auto status = notifier.get_status();
1214 EXPECT_FALSE(status.has_noise);
1215 EXPECT_FALSE(status.connections_filled);
1216 EXPECT_TRUE(status.has_outgoing);
1217 }
1218 notifier.new_out_connection();
1219 io_service_.poll();
1220
1221 std::vector<cryptonote::blobdata> my_txs(2);
1222 my_txs[0].resize(100, 'e');
1223 my_txs[1].resize(200, 'f');
1224
1225 std::vector<cryptonote::blobdata> their_txs{2};
1226 their_txs[0].resize(300, 'g');
1227 their_txs[1].resize(250, 'h');
1228
1229 ASSERT_EQ(10u, contexts_.size());
1230 bool has_stemmed = false;
1231 bool has_fluffed = false;
1232 while (!has_stemmed || !has_fluffed)
1233 {
1234 // run their "their" txes first
1235 auto context = contexts_.begin();
1236 EXPECT_TRUE(notifier.send_txs(their_txs, context->get_id(), cryptonote::relay_method::stem));
1237
1238 io_service_.restart();
1239 ASSERT_LT(0u, io_service_.poll());
1240 const bool is_stem = events_.has_stem_txes();
1241 EXPECT_EQ(their_txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff));
1242
1243 if (!is_stem)
1244 {
1245 notifier.run_fluff();
1246 ASSERT_LT(0u, io_service_.poll());
1247 }
1248
1249 std::size_t send_count = 0;
1250 EXPECT_EQ(0u, context->process_send_queue());
1251 for (++context; context != contexts_.end(); ++context)
1252 {
1253 const std::size_t sent = context->process_send_queue();
1254 if (sent && is_stem)
1255 {
1256 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
1257 EXPECT_FALSE(context->is_incoming());
1258 }
1259 send_count += sent;
1260 }
1261
1262 EXPECT_EQ(is_stem ? 1u : 9u, send_count);
1263 ASSERT_EQ(is_stem ? 1u : 9u, receiver_.notified_size());
1264 for (unsigned count = 0; count < (is_stem ? 1u : 9u); ++count)
1265 {
1266 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1267 EXPECT_EQ(their_txs, notification.txs);
1268 EXPECT_FALSE(notification._.empty());
1269 EXPECT_EQ(!is_stem, notification.dandelionpp_fluff);
1270 }
1271
1272 // run "my" txes which must always be stem
1273 context = contexts_.begin();
1274 EXPECT_TRUE(notifier.send_txs(my_txs, context->get_id(), cryptonote::relay_method::local));
1275
1276 io_service_.restart();
1277 ASSERT_LT(0u, io_service_.poll());
1278 EXPECT_TRUE(events_.has_stem_txes());
1279 EXPECT_EQ(my_txs, events_.take_relayed(cryptonote::relay_method::stem));
1280
1281 send_count = 0;
1282 EXPECT_EQ(0u, context->process_send_queue());
1283 for (++context; context != contexts_.end(); ++context)
1284 {
1285 const std::size_t sent = context->process_send_queue();
1286 if (sent)
1287 {
1288 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
1289 }
1290 send_count += sent;
1291 }
1292
1293 EXPECT_EQ(1u, send_count);
1294 EXPECT_EQ(1u, receiver_.notified_size());
1295 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1296 EXPECT_EQ(my_txs, notification.txs);
1297 EXPECT_FALSE(notification._.empty());
1298 EXPECT_TRUE(!notification.dandelionpp_fluff);
1299
1300 has_stemmed |= is_stem;
1301 has_fluffed |= !is_stem;
1302 notifier.run_epoch();
1303 }
1304 }
1305
1306 TEST_F(levin_notify, forward_with_padding)
1307 {
1308 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, true);
1309 auto &notifier = *notifier_ptr;
1310
1311 for (unsigned count = 0; count < 10; ++count)
1312 add_connection(count % 2 == 0);
1313
1314 {
1315 const auto status = notifier.get_status();
1316 EXPECT_FALSE(status.has_noise);
1317 EXPECT_FALSE(status.connections_filled);
1318 EXPECT_TRUE(status.has_outgoing);
1319 }
1320 notifier.new_out_connection();
1321 io_service_.poll();
1322
1323 std::vector<cryptonote::blobdata> txs(2);
1324 txs[0].resize(100, 'e');
1325 txs[1].resize(200, 'f');
1326
1327 ASSERT_EQ(10u, contexts_.size());
1328 bool has_stemmed = false;
1329 bool has_fluffed = false;
1330 while (!has_stemmed || !has_fluffed)
1331 {
1332 auto context = contexts_.begin();
1333 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::forward));
1334
1335 io_service_.restart();
1336 ASSERT_LT(0u, io_service_.poll());
1337 const bool is_stem = events_.has_stem_txes();
1338 EXPECT_EQ(txs, events_.take_relayed(is_stem ? cryptonote::relay_method::stem : cryptonote::relay_method::fluff));
1339
1340 if (!is_stem)
1341 {
1342 notifier.run_fluff();
1343 ASSERT_LT(0u, io_service_.poll());
1344 }
1345
1346 std::size_t send_count = 0;
1347 EXPECT_EQ(0u, context->process_send_queue());
1348 for (++context; context != contexts_.end(); ++context)
1349 {
1350 const std::size_t sent = context->process_send_queue();
1351 if (sent && is_stem)
1352 {
1353 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
1354 EXPECT_FALSE(context->is_incoming());
1355 }
1356 send_count += sent;
1357 }
1358
1359 EXPECT_EQ(is_stem ? 1u : 9u, send_count);
1360 ASSERT_EQ(is_stem ? 1u : 9u, receiver_.notified_size());
1361 for (unsigned count = 0; count < (is_stem ? 1u : 9u); ++count)
1362 {
1363 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1364 EXPECT_EQ(txs, notification.txs);
1365 EXPECT_FALSE(notification._.empty());
1366 EXPECT_EQ(!is_stem, notification.dandelionpp_fluff);
1367 }
1368
1369 has_stemmed |= is_stem;
1370 has_fluffed |= !is_stem;
1371 notifier.run_epoch();
1372 }
1373 }
1374
1375 TEST_F(levin_notify, block_with_padding)
1376 {
1377 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, true);
1378 auto &notifier = *notifier_ptr;
1379
1380 for (unsigned count = 0; count < 10; ++count)
1381 add_connection(count % 2 == 0);
1382
1383 {
1384 const auto status = notifier.get_status();
1385 EXPECT_FALSE(status.has_noise);
1386 EXPECT_FALSE(status.connections_filled);
1387 EXPECT_TRUE(status.has_outgoing);
1388 }
1389 notifier.new_out_connection();
1390 io_service_.poll();
1391
1392 std::vector<cryptonote::blobdata> txs(2);
1393 txs[0].resize(100, 'e');
1394 txs[1].resize(200, 'f');
1395
1396 ASSERT_EQ(10u, contexts_.size());
1397 {
1398 auto context = contexts_.begin();
1399 EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::block));
1400
1401 io_service_.restart();
1402 ASSERT_EQ(0u, io_service_.poll());
1403 }
1404 }
1405
1406 TEST_F(levin_notify, none_with_padding)
1407 {
1408 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, true);
1409 auto &notifier = *notifier_ptr;
1410
1411 for (unsigned count = 0; count < 10; ++count)
1412 add_connection(count % 2 == 0);
1413
1414 {
1415 const auto status = notifier.get_status();
1416 EXPECT_FALSE(status.has_noise);
1417 EXPECT_FALSE(status.connections_filled);
1418 EXPECT_TRUE(status.has_outgoing);
1419 }
1420 notifier.new_out_connection();
1421 io_service_.poll();
1422
1423 std::vector<cryptonote::blobdata> txs(2);
1424 txs[0].resize(100, 'e');
1425 txs[1].resize(200, 'f');
1426
1427 ASSERT_EQ(10u, contexts_.size());
1428 {
1429 auto context = contexts_.begin();
1430 EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::none));
1431
1432 io_service_.restart();
1433 ASSERT_EQ(0u, io_service_.poll());
1434 }
1435 }
1436
1437 TEST_F(levin_notify, private_fluff_without_padding)
1438 {
1439 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, false);
1440 auto &notifier = *notifier_ptr;
1441
1442 for (unsigned count = 0; count < 10; ++count)
1443 add_connection(count % 2 == 0);
1444
1445 {
1446 const auto status = notifier.get_status();
1447 EXPECT_FALSE(status.has_noise);
1448 EXPECT_FALSE(status.connections_filled);
1449 EXPECT_TRUE(status.has_outgoing);
1450 }
1451 notifier.new_out_connection();
1452 io_service_.poll();
1453
1454 std::vector<cryptonote::blobdata> txs(2);
1455 txs[0].resize(100, 'e');
1456 txs[1].resize(200, 'f');
1457
1458 ASSERT_EQ(10u, contexts_.size());
1459 {
1460 auto context = contexts_.begin();
1461 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff));
1462
1463 io_service_.restart();
1464 ASSERT_LT(0u, io_service_.poll());
1465 notifier.run_fluff();
1466 io_service_.restart();
1467 ASSERT_LT(0u, io_service_.poll());
1468
1469 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
1470
1471 EXPECT_EQ(0u, context->process_send_queue());
1472 for (++context; context != contexts_.end(); ++context)
1473 {
1474 const bool is_incoming = ((context - contexts_.begin()) % 2 == 0);
1475 EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue());
1476 }
1477
1478 ASSERT_EQ(5u, receiver_.notified_size());
1479 for (unsigned count = 0; count < 5; ++count)
1480 {
1481 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1482 EXPECT_EQ(txs, notification.txs);
1483 EXPECT_TRUE(notification._.empty());
1484 EXPECT_TRUE(notification.dandelionpp_fluff);
1485 }
1486 }
1487 }
1488
1489 TEST_F(levin_notify, private_stem_without_padding)
1490 {
1491 // private mode always uses fluff but marked as stem
1492 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, false);
1493 auto &notifier = *notifier_ptr;
1494
1495 for (unsigned count = 0; count < 10; ++count)
1496 add_connection(count % 2 == 0);
1497
1498 {
1499 const auto status = notifier.get_status();
1500 EXPECT_FALSE(status.has_noise);
1501 EXPECT_FALSE(status.connections_filled);
1502 EXPECT_TRUE(status.has_outgoing);
1503 }
1504 notifier.new_out_connection();
1505 io_service_.poll();
1506
1507 std::vector<cryptonote::blobdata> txs(2);
1508 txs[0].resize(100, 'e');
1509 txs[1].resize(200, 'f');
1510
1511 ASSERT_EQ(10u, contexts_.size());
1512 {
1513 auto context = contexts_.begin();
1514 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem));
1515
1516 io_service_.restart();
1517 ASSERT_LT(0u, io_service_.poll());
1518 notifier.run_fluff();
1519 io_service_.restart();
1520 ASSERT_LT(0u, io_service_.poll());
1521
1522 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem));
1523
1524 EXPECT_EQ(0u, context->process_send_queue());
1525 for (++context; context != contexts_.end(); ++context)
1526 {
1527 const bool is_incoming = ((context - contexts_.begin()) % 2 == 0);
1528 EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue());
1529 }
1530
1531 ASSERT_EQ(5u, receiver_.notified_size());
1532 for (unsigned count = 0; count < 5; ++count)
1533 {
1534 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1535 EXPECT_EQ(txs, notification.txs);
1536 EXPECT_TRUE(notification._.empty());
1537 EXPECT_TRUE(notification.dandelionpp_fluff);
1538 }
1539 }
1540 }
1541
1542 TEST_F(levin_notify, private_local_without_padding)
1543 {
1544 // private mode always uses fluff but marked as stem
1545 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, false);
1546 auto &notifier = *notifier_ptr;
1547
1548 for (unsigned count = 0; count < 10; ++count)
1549 add_connection(count % 2 == 0);
1550
1551 {
1552 const auto status = notifier.get_status();
1553 EXPECT_FALSE(status.has_noise);
1554 EXPECT_FALSE(status.connections_filled);
1555 EXPECT_TRUE(status.has_outgoing);
1556 }
1557 notifier.new_out_connection();
1558 io_service_.poll();
1559
1560 std::vector<cryptonote::blobdata> txs(2);
1561 txs[0].resize(100, 'e');
1562 txs[1].resize(200, 'f');
1563
1564 ASSERT_EQ(10u, contexts_.size());
1565 {
1566 auto context = contexts_.begin();
1567 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::local));
1568
1569 io_service_.restart();
1570 ASSERT_LT(0u, io_service_.poll());
1571 notifier.run_fluff();
1572 io_service_.restart();
1573 ASSERT_LT(0u, io_service_.poll());
1574
1575 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::local));
1576
1577 EXPECT_EQ(0u, context->process_send_queue());
1578 for (++context; context != contexts_.end(); ++context)
1579 {
1580 const bool is_incoming = ((context - contexts_.begin()) % 2 == 0);
1581 EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue());
1582 }
1583
1584 ASSERT_EQ(5u, receiver_.notified_size());
1585 for (unsigned count = 0; count < 5; ++count)
1586 {
1587 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1588 EXPECT_EQ(txs, notification.txs);
1589 EXPECT_TRUE(notification._.empty());
1590 EXPECT_TRUE(notification.dandelionpp_fluff);
1591 }
1592 }
1593 }
1594
1595 TEST_F(levin_notify, private_forward_without_padding)
1596 {
1597 // private mode always uses fluff but marked as stem
1598 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, false);
1599 auto &notifier = *notifier_ptr;
1600
1601 for (unsigned count = 0; count < 10; ++count)
1602 add_connection(count % 2 == 0);
1603
1604 {
1605 const auto status = notifier.get_status();
1606 EXPECT_FALSE(status.has_noise);
1607 EXPECT_FALSE(status.connections_filled);
1608 EXPECT_TRUE(status.has_outgoing);
1609 }
1610 notifier.new_out_connection();
1611 io_service_.poll();
1612
1613 std::vector<cryptonote::blobdata> txs(2);
1614 txs[0].resize(100, 'e');
1615 txs[1].resize(200, 'f');
1616
1617 ASSERT_EQ(10u, contexts_.size());
1618 {
1619 auto context = contexts_.begin();
1620 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::forward));
1621
1622 io_service_.restart();
1623 ASSERT_LT(0u, io_service_.poll());
1624 notifier.run_fluff();
1625 io_service_.restart();
1626 ASSERT_LT(0u, io_service_.poll());
1627
1628 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::forward));
1629
1630 EXPECT_EQ(0u, context->process_send_queue());
1631 for (++context; context != contexts_.end(); ++context)
1632 {
1633 const bool is_incoming = ((context - contexts_.begin()) % 2 == 0);
1634 EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue());
1635 }
1636
1637 ASSERT_EQ(5u, receiver_.notified_size());
1638 for (unsigned count = 0; count < 5; ++count)
1639 {
1640 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1641 EXPECT_EQ(txs, notification.txs);
1642 EXPECT_TRUE(notification._.empty());
1643 EXPECT_TRUE(notification.dandelionpp_fluff);
1644 }
1645 }
1646 }
1647
1648 TEST_F(levin_notify, private_block_without_padding)
1649 {
1650 // private mode always uses fluff but marked as stem
1651 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, false);
1652 auto &notifier = *notifier_ptr;
1653
1654 for (unsigned count = 0; count < 10; ++count)
1655 add_connection(count % 2 == 0);
1656
1657 {
1658 const auto status = notifier.get_status();
1659 EXPECT_FALSE(status.has_noise);
1660 EXPECT_FALSE(status.connections_filled);
1661 EXPECT_TRUE(status.has_outgoing);
1662 }
1663 notifier.new_out_connection();
1664 io_service_.poll();
1665
1666 std::vector<cryptonote::blobdata> txs(2);
1667 txs[0].resize(100, 'e');
1668 txs[1].resize(200, 'f');
1669
1670 ASSERT_EQ(10u, contexts_.size());
1671 {
1672 auto context = contexts_.begin();
1673 EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::block));
1674
1675 io_service_.restart();
1676 ASSERT_EQ(0u, io_service_.poll());
1677 }
1678 }
1679
1680 TEST_F(levin_notify, private_none_without_padding)
1681 {
1682 // private mode always uses fluff but marked as stem
1683 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, false);
1684 auto &notifier = *notifier_ptr;
1685
1686 for (unsigned count = 0; count < 10; ++count)
1687 add_connection(count % 2 == 0);
1688
1689 {
1690 const auto status = notifier.get_status();
1691 EXPECT_FALSE(status.has_noise);
1692 EXPECT_FALSE(status.connections_filled);
1693 EXPECT_TRUE(status.has_outgoing);
1694 }
1695 notifier.new_out_connection();
1696 io_service_.poll();
1697
1698 std::vector<cryptonote::blobdata> txs(2);
1699 txs[0].resize(100, 'e');
1700 txs[1].resize(200, 'f');
1701
1702 ASSERT_EQ(10u, contexts_.size());
1703 {
1704 auto context = contexts_.begin();
1705 EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::none));
1706
1707 io_service_.restart();
1708 ASSERT_EQ(0u, io_service_.poll());
1709 }
1710 }
1711
1712 TEST_F(levin_notify, private_fluff_with_padding)
1713 {
1714 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, true);
1715 auto &notifier = *notifier_ptr;
1716
1717 for (unsigned count = 0; count < 10; ++count)
1718 add_connection(count % 2 == 0);
1719
1720 {
1721 const auto status = notifier.get_status();
1722 EXPECT_FALSE(status.has_noise);
1723 EXPECT_FALSE(status.connections_filled);
1724 EXPECT_TRUE(status.has_outgoing);
1725 }
1726 notifier.new_out_connection();
1727 io_service_.poll();
1728
1729 std::vector<cryptonote::blobdata> txs(2);
1730 txs[0].resize(100, 'e');
1731 txs[1].resize(200, 'f');
1732
1733 ASSERT_EQ(10u, contexts_.size());
1734 {
1735 auto context = contexts_.begin();
1736 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff));
1737
1738 io_service_.restart();
1739 ASSERT_LT(0u, io_service_.poll());
1740 notifier.run_fluff();
1741 io_service_.restart();
1742 ASSERT_LT(0u, io_service_.poll());
1743
1744 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
1745
1746 EXPECT_EQ(0u, context->process_send_queue());
1747 for (++context; context != contexts_.end(); ++context)
1748 {
1749 const bool is_incoming = ((context - contexts_.begin()) % 2 == 0);
1750 EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue());
1751 }
1752
1753 ASSERT_EQ(5u, receiver_.notified_size());
1754 for (unsigned count = 0; count < 5; ++count)
1755 {
1756 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1757 EXPECT_EQ(txs, notification.txs);
1758 EXPECT_FALSE(notification._.empty());
1759 EXPECT_TRUE(notification.dandelionpp_fluff);
1760 }
1761 }
1762 }
1763
1764 TEST_F(levin_notify, private_stem_with_padding)
1765 {
1766 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, true);
1767 auto &notifier = *notifier_ptr;
1768
1769 for (unsigned count = 0; count < 10; ++count)
1770 add_connection(count % 2 == 0);
1771
1772 {
1773 const auto status = notifier.get_status();
1774 EXPECT_FALSE(status.has_noise);
1775 EXPECT_FALSE(status.connections_filled);
1776 EXPECT_TRUE(status.has_outgoing);
1777 }
1778 notifier.new_out_connection();
1779 io_service_.poll();
1780
1781 std::vector<cryptonote::blobdata> txs(2);
1782 txs[0].resize(100, 'e');
1783 txs[1].resize(200, 'f');
1784
1785 ASSERT_EQ(10u, contexts_.size());
1786 {
1787 auto context = contexts_.begin();
1788 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem));
1789
1790 io_service_.restart();
1791 ASSERT_LT(0u, io_service_.poll());
1792 notifier.run_fluff();
1793 io_service_.restart();
1794 ASSERT_LT(0u, io_service_.poll());
1795
1796 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem));
1797
1798 EXPECT_EQ(0u, context->process_send_queue());
1799 for (++context; context != contexts_.end(); ++context)
1800 {
1801 const bool is_incoming = ((context - contexts_.begin()) % 2 == 0);
1802 EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue());
1803 }
1804
1805 ASSERT_EQ(5u, receiver_.notified_size());
1806 for (unsigned count = 0; count < 5; ++count)
1807 {
1808 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1809 EXPECT_EQ(txs, notification.txs);
1810 EXPECT_FALSE(notification._.empty());
1811 EXPECT_TRUE(notification.dandelionpp_fluff);
1812 }
1813 }
1814 }
1815
1816 TEST_F(levin_notify, private_local_with_padding)
1817 {
1818 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, true);
1819 auto &notifier = *notifier_ptr;
1820
1821 for (unsigned count = 0; count < 10; ++count)
1822 add_connection(count % 2 == 0);
1823
1824 {
1825 const auto status = notifier.get_status();
1826 EXPECT_FALSE(status.has_noise);
1827 EXPECT_FALSE(status.connections_filled);
1828 EXPECT_TRUE(status.has_outgoing);
1829 }
1830 notifier.new_out_connection();
1831 io_service_.poll();
1832
1833 std::vector<cryptonote::blobdata> txs(2);
1834 txs[0].resize(100, 'e');
1835 txs[1].resize(200, 'f');
1836
1837 ASSERT_EQ(10u, contexts_.size());
1838 {
1839 auto context = contexts_.begin();
1840 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::local));
1841
1842 io_service_.restart();
1843 ASSERT_LT(0u, io_service_.poll());
1844 notifier.run_fluff();
1845 io_service_.restart();
1846 ASSERT_LT(0u, io_service_.poll());
1847
1848 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::local));
1849
1850 EXPECT_EQ(0u, context->process_send_queue());
1851 for (++context; context != contexts_.end(); ++context)
1852 {
1853 const bool is_incoming = ((context - contexts_.begin()) % 2 == 0);
1854 EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue());
1855 }
1856
1857 ASSERT_EQ(5u, receiver_.notified_size());
1858 for (unsigned count = 0; count < 5; ++count)
1859 {
1860 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1861 EXPECT_EQ(txs, notification.txs);
1862 EXPECT_FALSE(notification._.empty());
1863 EXPECT_TRUE(notification.dandelionpp_fluff);
1864 }
1865 }
1866 }
1867
1868 TEST_F(levin_notify, private_forward_with_padding)
1869 {
1870 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, true);
1871 auto &notifier = *notifier_ptr;
1872
1873 for (unsigned count = 0; count < 10; ++count)
1874 add_connection(count % 2 == 0);
1875
1876 {
1877 const auto status = notifier.get_status();
1878 EXPECT_FALSE(status.has_noise);
1879 EXPECT_FALSE(status.connections_filled);
1880 EXPECT_TRUE(status.has_outgoing);
1881 }
1882 notifier.new_out_connection();
1883 io_service_.poll();
1884
1885 std::vector<cryptonote::blobdata> txs(2);
1886 txs[0].resize(100, 'e');
1887 txs[1].resize(200, 'f');
1888
1889 ASSERT_EQ(10u, contexts_.size());
1890 {
1891 auto context = contexts_.begin();
1892 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::forward));
1893
1894 io_service_.restart();
1895 ASSERT_LT(0u, io_service_.poll());
1896 notifier.run_fluff();
1897 io_service_.restart();
1898 ASSERT_LT(0u, io_service_.poll());
1899
1900 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::forward));
1901
1902 EXPECT_EQ(0u, context->process_send_queue());
1903 for (++context; context != contexts_.end(); ++context)
1904 {
1905 const bool is_incoming = ((context - contexts_.begin()) % 2 == 0);
1906 EXPECT_EQ(is_incoming ? 0u : 1u, context->process_send_queue());
1907 }
1908
1909 ASSERT_EQ(5u, receiver_.notified_size());
1910 for (unsigned count = 0; count < 5; ++count)
1911 {
1912 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
1913 EXPECT_EQ(txs, notification.txs);
1914 EXPECT_FALSE(notification._.empty());
1915 EXPECT_TRUE(notification.dandelionpp_fluff);
1916 }
1917 }
1918 }
1919
1920 TEST_F(levin_notify, private_block_with_padding)
1921 {
1922 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, true);
1923 auto &notifier = *notifier_ptr;
1924
1925 for (unsigned count = 0; count < 10; ++count)
1926 add_connection(count % 2 == 0);
1927
1928 {
1929 const auto status = notifier.get_status();
1930 EXPECT_FALSE(status.has_noise);
1931 EXPECT_FALSE(status.connections_filled);
1932 EXPECT_TRUE(status.has_outgoing);
1933 }
1934 notifier.new_out_connection();
1935 io_service_.poll();
1936
1937 std::vector<cryptonote::blobdata> txs(2);
1938 txs[0].resize(100, 'e');
1939 txs[1].resize(200, 'f');
1940
1941 ASSERT_EQ(10u, contexts_.size());
1942 {
1943 auto context = contexts_.begin();
1944 EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::block));
1945
1946 io_service_.restart();
1947 ASSERT_EQ(0u, io_service_.poll());
1948 }
1949 }
1950
1951 TEST_F(levin_notify, private_none_with_padding)
1952 {
1953 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, false, true);
1954 auto &notifier = *notifier_ptr;
1955
1956 for (unsigned count = 0; count < 10; ++count)
1957 add_connection(count % 2 == 0);
1958
1959 {
1960 const auto status = notifier.get_status();
1961 EXPECT_FALSE(status.has_noise);
1962 EXPECT_FALSE(status.connections_filled);
1963 EXPECT_TRUE(status.has_outgoing);
1964 }
1965 notifier.new_out_connection();
1966 io_service_.poll();
1967
1968 std::vector<cryptonote::blobdata> txs(2);
1969 txs[0].resize(100, 'e');
1970 txs[1].resize(200, 'f');
1971
1972 ASSERT_EQ(10u, contexts_.size());
1973 {
1974 auto context = contexts_.begin();
1975 EXPECT_FALSE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::none));
1976
1977 io_service_.restart();
1978 ASSERT_EQ(0u, io_service_.poll());
1979 }
1980 }
1981
1982 TEST_F(levin_notify, stem_mappings)
1983 {
1984 static constexpr const unsigned test_connections_count = (CRYPTONOTE_DANDELIONPP_STEMS + 1) * 2;
1985
1986 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
1987 auto &notifier = *notifier_ptr;
1988
1989 for (unsigned count = 0; count < test_connections_count; ++count)
1990 add_connection(count % 2 == 0);
1991
1992 {
1993 const auto status = notifier.get_status();
1994 EXPECT_FALSE(status.has_noise);
1995 EXPECT_FALSE(status.connections_filled);
1996 EXPECT_TRUE(status.has_outgoing);
1997 }
1998 notifier.new_out_connection();
1999 io_service_.poll();
2000
2001 std::vector<cryptonote::blobdata> txs(2);
2002 txs[0].resize(100, 'e');
2003 txs[1].resize(200, 'f');
2004
2005 ASSERT_EQ(test_connections_count, contexts_.size());
2006 for (;;)
2007 {
2008 auto context = contexts_.begin();
2009 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem));
2010
2011 io_service_.restart();
2012 ASSERT_LT(0u, io_service_.poll());
2013 if (events_.has_stem_txes())
2014 break;
2015
2016 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
2017 notifier.run_fluff();
2018 io_service_.restart();
2019 ASSERT_LT(0u, io_service_.poll());
2020
2021 EXPECT_EQ(0u, context->process_send_queue());
2022 for (++context; context != contexts_.end(); ++context)
2023 EXPECT_EQ(1u, context->process_send_queue());
2024
2025 ASSERT_EQ(test_connections_count - 1, receiver_.notified_size());
2026 for (unsigned count = 0; count < test_connections_count - 1; ++count)
2027 {
2028 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2029 EXPECT_EQ(txs, notification.txs);
2030 EXPECT_TRUE(notification._.empty());
2031 EXPECT_TRUE(notification.dandelionpp_fluff);
2032 }
2033
2034 notifier.run_epoch();
2035 io_service_.restart();
2036 ASSERT_LT(0u, io_service_.poll());
2037 }
2038 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem));
2039
2040 std::set<boost::uuids::uuid> used;
2041 std::map<boost::uuids::uuid, boost::uuids::uuid> mappings;
2042 {
2043 std::size_t send_count = 0;
2044 for (auto context = contexts_.begin(); context != contexts_.end(); ++context)
2045 {
2046 const std::size_t sent = context->process_send_queue();
2047 if (sent)
2048 {
2049 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
2050 EXPECT_FALSE(context->is_incoming());
2051 used.insert(context->get_id());
2052 mappings[contexts_.front().get_id()] = context->get_id();
2053 }
2054 send_count += sent;
2055 }
2056
2057 EXPECT_EQ(1u, send_count);
2058 ASSERT_EQ(1u, receiver_.notified_size());
2059 for (unsigned count = 0; count < 1u; ++count)
2060 {
2061 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2062 EXPECT_EQ(txs, notification.txs);
2063 EXPECT_TRUE(notification._.empty());
2064 EXPECT_FALSE(notification.dandelionpp_fluff);
2065 }
2066 }
2067
2068 for (unsigned i = 0; i < contexts_.size() * 2; i += 2)
2069 {
2070 auto& incoming = contexts_[i % contexts_.size()];
2071 EXPECT_TRUE(notifier.send_txs(txs, incoming.get_id(), cryptonote::relay_method::stem));
2072
2073 io_service_.restart();
2074 ASSERT_LT(0u, io_service_.poll());
2075 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem));
2076
2077 std::size_t send_count = 0;
2078 for (auto context = contexts_.begin(); context != contexts_.end(); ++context)
2079 {
2080 const std::size_t sent = context->process_send_queue();
2081 if (sent)
2082 {
2083 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
2084 EXPECT_FALSE(context->is_incoming());
2085 used.insert(context->get_id());
2086
2087 auto inserted = mappings.emplace(incoming.get_id(), context->get_id()).first;
2088 EXPECT_EQ(inserted->second, context->get_id()) << "incoming index " << i;
2089 }
2090 send_count += sent;
2091 }
2092
2093 EXPECT_EQ(1u, send_count);
2094 ASSERT_EQ(1u, receiver_.notified_size());
2095 for (unsigned count = 0; count < 1u; ++count)
2096 {
2097 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2098 EXPECT_EQ(txs, notification.txs);
2099 EXPECT_TRUE(notification._.empty());
2100 EXPECT_FALSE(notification.dandelionpp_fluff);
2101 }
2102 }
2103
2104 EXPECT_EQ(CRYPTONOTE_DANDELIONPP_STEMS, used.size());
2105 }
2106
2107 TEST_F(levin_notify, fluff_multiple)
2108 {
2109 static constexpr const unsigned test_connections_count = (CRYPTONOTE_DANDELIONPP_STEMS + 1) * 2;
2110
2111 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
2112 auto &notifier = *notifier_ptr;
2113
2114 for (unsigned count = 0; count < test_connections_count; ++count)
2115 add_connection(count % 2 == 0);
2116
2117 {
2118 const auto status = notifier.get_status();
2119 EXPECT_FALSE(status.has_noise);
2120 EXPECT_FALSE(status.connections_filled);
2121 EXPECT_TRUE(status.has_outgoing);
2122 }
2123 notifier.new_out_connection();
2124 io_service_.poll();
2125
2126 std::vector<cryptonote::blobdata> txs(2);
2127 txs[0].resize(100, 'e');
2128 txs[1].resize(200, 'f');
2129
2130 ASSERT_EQ(test_connections_count, contexts_.size());
2131 for (;;)
2132 {
2133 auto context = contexts_.begin();
2134 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::stem));
2135
2136 io_service_.restart();
2137 ASSERT_LT(0u, io_service_.poll());
2138 if (!events_.has_stem_txes())
2139 break;
2140
2141 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::stem));
2142
2143 std::size_t send_count = 0;
2144 EXPECT_EQ(0u, context->process_send_queue());
2145 for (++context; context != contexts_.end(); ++context)
2146 {
2147 const std::size_t sent = context->process_send_queue();
2148 if (sent)
2149 {
2150 EXPECT_EQ(1u, (context - contexts_.begin()) % 2);
2151 EXPECT_FALSE(context->is_incoming());
2152 }
2153 send_count += sent;
2154 }
2155
2156 EXPECT_EQ(1u, send_count);
2157 ASSERT_EQ(1u, receiver_.notified_size());
2158 for (unsigned count = 0; count < 1; ++count)
2159 {
2160 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2161 EXPECT_EQ(txs, notification.txs);
2162 EXPECT_TRUE(notification._.empty());
2163 EXPECT_FALSE(notification.dandelionpp_fluff);
2164 }
2165
2166 notifier.run_epoch();
2167 io_service_.restart();
2168 ASSERT_LT(0u, io_service_.poll());
2169 }
2170 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
2171 notifier.run_fluff();
2172 io_service_.restart();
2173 ASSERT_LT(0u, io_service_.poll());
2174 {
2175 auto context = contexts_.begin();
2176 EXPECT_EQ(0u, context->process_send_queue());
2177 for (++context; context != contexts_.end(); ++context)
2178 EXPECT_EQ(1u, context->process_send_queue());
2179
2180 ASSERT_EQ(contexts_.size() - 1, receiver_.notified_size());
2181 for (unsigned count = 0; count < contexts_.size() - 1; ++count)
2182 {
2183 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2184 EXPECT_EQ(txs, notification.txs);
2185 EXPECT_TRUE(notification._.empty());
2186 EXPECT_TRUE(notification.dandelionpp_fluff);
2187 }
2188 }
2189
2190 for (unsigned i = 0; i < contexts_.size() * 2; i += 2)
2191 {
2192 auto& incoming = contexts_[i % contexts_.size()];
2193 EXPECT_TRUE(notifier.send_txs(txs, incoming.get_id(), cryptonote::relay_method::stem));
2194
2195 io_service_.restart();
2196 ASSERT_LT(0u, io_service_.poll());
2197 notifier.run_fluff();
2198 io_service_.restart();
2199 ASSERT_LT(0u, io_service_.poll());
2200
2201 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
2202
2203 for (auto& context : contexts_)
2204 {
2205 if (std::addressof(incoming) == std::addressof(context))
2206 EXPECT_EQ(0u, context.process_send_queue());
2207 else
2208 EXPECT_EQ(1u, context.process_send_queue());
2209 }
2210
2211 ASSERT_EQ(contexts_.size() - 1, receiver_.notified_size());
2212 for (unsigned count = 0; count < contexts_.size() - 1; ++count)
2213 {
2214 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2215 EXPECT_EQ(txs, notification.txs);
2216 EXPECT_TRUE(notification._.empty());
2217 EXPECT_TRUE(notification.dandelionpp_fluff);
2218 }
2219 }
2220 }
2221
2222 TEST_F(levin_notify, fluff_with_duplicate)
2223 {
2224 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(0, true, false);
2225 auto &notifier = *notifier_ptr;
2226
2227 for (unsigned count = 0; count < 10; ++count)
2228 add_connection(count % 2 == 0);
2229
2230 {
2231 const auto status = notifier.get_status();
2232 EXPECT_FALSE(status.has_noise);
2233 EXPECT_FALSE(status.connections_filled);
2234 EXPECT_TRUE(status.has_outgoing);
2235 }
2236 notifier.new_out_connection();
2237 io_service_.poll();
2238
2239 std::vector<cryptonote::blobdata> txs(9);
2240 txs[0].resize(100, 'e');
2241 txs[1].resize(100, 'e');
2242 txs[2].resize(100, 'e');
2243 txs[3].resize(100, 'e');
2244 txs[4].resize(200, 'f');
2245 txs[5].resize(200, 'f');
2246 txs[6].resize(200, 'f');
2247 txs[7].resize(200, 'f');
2248 txs[8].resize(200, 'f');
2249
2250 ASSERT_EQ(10u, contexts_.size());
2251 {
2252 auto context = contexts_.begin();
2253 EXPECT_TRUE(notifier.send_txs(txs, context->get_id(), cryptonote::relay_method::fluff));
2254
2255 io_service_.restart();
2256 ASSERT_LT(0u, io_service_.poll());
2257 notifier.run_fluff();
2258 ASSERT_LT(0u, io_service_.poll());
2259
2260 EXPECT_EQ(0u, context->process_send_queue());
2261 for (++context; context != contexts_.end(); ++context)
2262 EXPECT_EQ(1u, context->process_send_queue());
2263
2264 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
2265 std::sort(txs.begin(), txs.end());
2266 ASSERT_EQ(9u, receiver_.notified_size());
2267 for (unsigned count = 0; count < 9; ++count)
2268 {
2269 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2270 EXPECT_NE(txs, notification.txs);
2271 EXPECT_EQ(notification.txs.size(), 2);
2272 EXPECT_TRUE(notification._.empty());
2273 EXPECT_TRUE(notification.dandelionpp_fluff);
2274 }
2275 }
2276
2277 }
2278
2279 TEST_F(levin_notify, noise)
2280 {
2281 for (unsigned count = 0; count < 10; ++count)
2282 add_connection(count % 2 == 0);
2283
2284 std::vector<cryptonote::blobdata> txs(1);
2285 txs[0].resize(1900, 'h');
2286
2287 const boost::uuids::uuid incoming_id = random_generator_();
2288 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(2048, false, true);
2289 auto &notifier = *notifier_ptr;
2290
2291 {
2292 const auto status = notifier.get_status();
2293 EXPECT_TRUE(status.has_noise);
2294 EXPECT_FALSE(status.connections_filled);
2295 EXPECT_FALSE(status.has_outgoing);
2296 }
2297 ASSERT_LT(0u, io_service_.poll());
2298 {
2299 const auto status = notifier.get_status();
2300 EXPECT_TRUE(status.has_noise);
2301 EXPECT_TRUE(status.connections_filled);
2302 EXPECT_TRUE(status.has_outgoing);
2303 }
2304
2305 notifier.run_stems();
2306 io_service_.restart();
2307 ASSERT_LT(0u, io_service_.poll());
2308 {
2309 std::size_t sent = 0;
2310 for (auto& context : contexts_)
2311 sent += context.process_send_queue();
2312
2313 EXPECT_EQ(2u, sent);
2314 EXPECT_EQ(0u, receiver_.notified_size());
2315 }
2316
2317 EXPECT_TRUE(notifier.send_txs(txs, incoming_id, cryptonote::relay_method::local));
2318 notifier.run_stems();
2319 io_service_.restart();
2320 ASSERT_LT(0u, io_service_.poll());
2321
2322 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::local));
2323 {
2324 std::size_t sent = 0;
2325 for (auto& context : contexts_)
2326 sent += context.process_send_queue();
2327
2328 ASSERT_EQ(2u, sent);
2329 while (sent--)
2330 {
2331 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2332 EXPECT_EQ(txs, notification.txs);
2333 EXPECT_TRUE(notification._.empty());
2334 EXPECT_FALSE(notification.dandelionpp_fluff);
2335 }
2336 }
2337
2338 txs[0].resize(3000, 'r');
2339 EXPECT_TRUE(notifier.send_txs(txs, incoming_id, cryptonote::relay_method::fluff));
2340 notifier.run_stems();
2341 io_service_.restart();
2342 ASSERT_LT(0u, io_service_.poll());
2343
2344 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::fluff));
2345 {
2346 std::size_t sent = 0;
2347 for (auto& context : contexts_)
2348 sent += context.process_send_queue();
2349
2350 EXPECT_EQ(2u, sent);
2351 EXPECT_EQ(0u, receiver_.notified_size());
2352 }
2353
2354 notifier.run_stems();
2355 io_service_.restart();
2356 ASSERT_LT(0u, io_service_.poll());
2357 {
2358 std::size_t sent = 0;
2359 for (auto& context : contexts_)
2360 sent += context.process_send_queue();
2361
2362 ASSERT_EQ(2u, sent);
2363 while (sent--)
2364 {
2365 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2366 EXPECT_EQ(txs, notification.txs);
2367 EXPECT_TRUE(notification._.empty());
2368 EXPECT_FALSE(notification.dandelionpp_fluff);
2369 }
2370 }
2371 }
2372
2373 TEST_F(levin_notify, noise_stem)
2374 {
2375 for (unsigned count = 0; count < 10; ++count)
2376 add_connection(count % 2 == 0);
2377
2378 std::vector<cryptonote::blobdata> txs(1);
2379 txs[0].resize(1900, 'h');
2380
2381 const boost::uuids::uuid incoming_id = random_generator_();
2382 std::shared_ptr<cryptonote::levin::notify> notifier_ptr = make_notifier(2048, false, true);
2383 auto &notifier = *notifier_ptr;
2384
2385 {
2386 const auto status = notifier.get_status();
2387 EXPECT_TRUE(status.has_noise);
2388 EXPECT_FALSE(status.connections_filled);
2389 EXPECT_FALSE(status.has_outgoing);
2390 }
2391 ASSERT_LT(0u, io_service_.poll());
2392 {
2393 const auto status = notifier.get_status();
2394 EXPECT_TRUE(status.has_noise);
2395 EXPECT_TRUE(status.connections_filled);
2396 EXPECT_TRUE(status.has_outgoing);
2397 }
2398
2399 notifier.run_stems();
2400 io_service_.restart();
2401 ASSERT_LT(0u, io_service_.poll());
2402 {
2403 std::size_t sent = 0;
2404 for (auto& context : contexts_)
2405 sent += context.process_send_queue();
2406
2407 EXPECT_EQ(2u, sent);
2408 EXPECT_EQ(0u, receiver_.notified_size());
2409 }
2410
2411 EXPECT_TRUE(notifier.send_txs(txs, incoming_id, cryptonote::relay_method::stem));
2412 notifier.run_stems();
2413 io_service_.restart();
2414 ASSERT_LT(0u, io_service_.poll());
2415
2416 // downgraded to local when being notified
2417 EXPECT_EQ(txs, events_.take_relayed(cryptonote::relay_method::local));
2418 {
2419 std::size_t sent = 0;
2420 for (auto& context : contexts_)
2421 sent += context.process_send_queue();
2422
2423 ASSERT_EQ(2u, sent);
2424 while (sent--)
2425 {
2426 auto notification = receiver_.get_notification<cryptonote::NOTIFY_NEW_TRANSACTIONS>().second;
2427 EXPECT_EQ(txs, notification.txs);
2428 EXPECT_TRUE(notification._.empty());
2429 EXPECT_FALSE(notification.dandelionpp_fluff);
2430 }
2431 }
2432 }
2433
2434 TEST_F(levin_notify, command_max_bytes)
2435 {
2436 static constexpr int ping_command = nodetool::COMMAND_PING::ID;
2437
2438 add_connection(true);
2439
2440 std::string payload(4096, 'h');
2441 epee::byte_slice bytes;
2442 {
2443 epee::levin::message_writer dest{};
2444 dest.buffer.write(epee::to_span(payload));
2445 bytes = dest.finalize_notify(ping_command);
2446 }
2447
2448 EXPECT_EQ(1, get_connections().send(bytes.clone(), contexts_.front().get_id()));
2449 EXPECT_EQ(1u, contexts_.front().process_send_queue(true));
2450 EXPECT_EQ(1u, receiver_.notified_size());
2451
2452 const received_message msg = receiver_.get_raw_notification();
2453 EXPECT_EQ(ping_command, msg.command);
2454 EXPECT_EQ(contexts_.front().get_id(), msg.connection);
2455 EXPECT_EQ(payload, msg.payload);
2456
2457 {
2458 payload.push_back('h');
2459 epee::levin::message_writer dest{};
2460 dest.buffer.write(epee::to_span(payload));
2461 bytes = dest.finalize_notify(ping_command);
2462 }
2463
2464 EXPECT_EQ(1, get_connections().send(std::move(bytes), contexts_.front().get_id()));
2465 EXPECT_EQ(1u, contexts_.front().process_send_queue(false));
2466 EXPECT_EQ(0u, receiver_.notified_size());
2467 }