682{
683 static std::uint8_t reply_bytes[] = {0, 90, 0, 0, 0xff, 0, 0xad, 0};
684
686 {
687 std::atomic<unsigned> called_;
688 bool expected_;
689
690 resolve_client(stream_type::socket&& proxy)
692 , called_(0)
694 {};
695
696 virtual void done(boost::system::error_code error, std::shared_ptr<client> self) override
697 {
699 EXPECT_EQ(expected_,
bool(error)) <<
"Resolve failure: " <<
error.message();
700
701 if (!error)
702 {
704 EXPECT_EQ(0u, std::memcmp(
buffer().data(), reply_bytes,
sizeof(reply_bytes)));
705 }
706
707 ++called_;
708 }
709 };
710
711 io_thread io{};
712 stream_type::socket client{io.io_service};
713
714 auto test_client = std::make_shared<resolve_client>(std::move(client));
716
717 ASSERT_TRUE(test_client->set_resolve_command(
"example.com"));
720 while (!io.connected)
722
723 const std::uint8_t expected_bytes[] = {
724 4, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00,
725 'e', 'x', 'a', 'm', 'p', 'l', 'e', '.', 'c', 'o', 'm', 0x00
726 };
727
728 std::uint8_t actual_bytes[sizeof(expected_bytes)];
729 boost::asio::read(io.server, boost::asio::buffer(actual_bytes));
730 EXPECT_TRUE(std::memcmp(expected_bytes, actual_bytes,
sizeof(actual_bytes)) == 0);
731
732 boost::asio::write(io.server, boost::asio::buffer(reply_bytes));
733
734
735 while (test_client->called_ == 0);
736
737 test_client->expected_ = true;
738 ASSERT_TRUE(test_client->set_resolve_command(
"example.com"));
741
742 boost::asio::read(io.server, boost::asio::buffer(actual_bytes));
743 EXPECT_TRUE(std::memcmp(expected_bytes, actual_bytes,
sizeof(actual_bytes)) == 0);
744
745 reply_bytes[1] = 91;
746 boost::asio::write(io.server, boost::asio::buffer(reply_bytes));
747
748
749 while (test_client->called_ == 1);
750}
Client support for socks connect and resolve commands.
epee::span< const std::uint8_t > buffer() const noexcept
#define ASSERT_EQ(val1, val2)
error
Tracks LMDB error codes.
@ v4a_tor
Extensions defined in Tor codebase.
const T & move(const T &t)