53 : socket(io), wrap(cfg, stats)
55 socket.open(openvpn_io::ip::udp::v4());
56 socket.bind(openvpn_io::ip::udp::endpoint(openvpn_io::ip::make_address(
"127.0.0.1"), 0));
59 unsigned short port()
const
61 return socket.local_endpoint().port();
71 openvpn_io::error_code ec;
75 static constexpr std::uint16_t REPLY_PRIORITY = 5;
76 static constexpr std::uint16_t REPLY_WEIGHT = 9;
77 static constexpr std::uint16_t REPLY_CONNECT_LIFETIME = 42;
83 openvpn_io::ip::udp::endpoint sender;
88 auto rc = std::make_shared<RecvCtx>();
90 socket.async_receive_from(
rc->buf.mutable_buffer(),
rc->sender, [
this,
rc](
const openvpn_io::error_code &error,
const size_t n)
95 respond(rc->buf, rc->sender); });
98 void respond(
BufferAllocated &buf,
const openvpn_io::ip::udp::endpoint &sender)
103 if (wrap.unwrap(buf,
work, client_psid, pid) != ProtoContext::UnwrapStatus::OK)
110 .priority = REPLY_PRIORITY,
111 .weight = REPLY_WEIGHT,
112 .max_latency_diff = 0,
113 .connect_lifetime = REPLY_CONNECT_LIFETIME,
121 wrap.wrap(rbuf, rwork);
123 openvpn_io::error_code ec;
127 openvpn_io::ip::udp::socket socket;
133 std::vector<ServerProber::Result>
results;
138 results = std::move(r);
147 openvpn_io::io_context io(1);
154 FakeProbeServer server(io, make_plain_config(frame, rng, time), stats);
156 const unsigned short port = server.port();
162 auto prober = std::make_shared<ServerProber>(io,
164 make_plain_config(frame, rng, time),
167 Time::Duration::milliseconds(300));
173 ASSERT_TRUE(cb.done);
174 ASSERT_EQ(cb.results.size(), 1u);
178 EXPECT_EQ(r.
port, port);
179 EXPECT_EQ(r.
reply.
priority, FakeProbeServer::REPLY_PRIORITY);
180 EXPECT_EQ(r.
reply.
weight, FakeProbeServer::REPLY_WEIGHT);
182 EXPECT_LE(r.
rtt, Time::Duration::seconds(2));
190 openvpn_io::io_context io(1);
200 auto prober = std::make_shared<ServerProber>(io,
202 make_plain_config(frame, rng, time),
205 Time::Duration::milliseconds(200));
211 ASSERT_TRUE(cb.done);
212 EXPECT_EQ(cb.results.size(), 0u);
218 openvpn_io::io_context io(1);
227 auto prober = std::make_shared<ServerProber>(io,
229 make_plain_config(frame, rng, time),
232 Time::Duration::milliseconds(200));
238 ASSERT_TRUE(cb.done);
239 EXPECT_EQ(cb.results.size(), 0u);
249 explicit FakeRuntServer(openvpn_io::io_context &io)
252 socket.open(openvpn_io::ip::udp::v4());
253 socket.bind(openvpn_io::ip::udp::endpoint(openvpn_io::ip::make_address(
"127.0.0.1"), 0));
256 unsigned short port()
const
258 return socket.local_endpoint().port();
268 openvpn_io::error_code ec;
276 openvpn_io::ip::udp::endpoint sender;
281 auto rc = std::make_shared<RecvCtx>();
283 socket.async_receive_from(
rc->buf.mutable_buffer(),
rc->sender, [
this,
rc](
const openvpn_io::error_code &error,
const size_t n)
288 static const unsigned char runt[3] = {0x60, 0x01, 0x02};
289 openvpn_io::error_code ec;
290 socket.send_to(openvpn_io::buffer(runt,
sizeof(runt)),
rc->sender, 0, ec); });
293 openvpn_io::ip::udp::socket socket;
303 openvpn_io::io_context io(1);
309 FakeRuntServer server(io);
315 auto prober = std::make_shared<ServerProber>(io,
317 make_plain_config(frame, rng, time),
320 Time::Duration::milliseconds(300));
326 ASSERT_TRUE(cb.done);
327 EXPECT_EQ(cb.results.size(), 0u);
void reset(const size_t min_capacity, const BufferFlags flags=BufAllocFlags::NO_FLAGS)
Resets the buffer with the specified minimum capacity and flags.
openvpn_io::const_buffer const_buffer() const
Return an openvpn_io::const_buffer object used by asio write methods.
static Addr from_string(const std::string &ipstr, const TITLE &title, const Version required_version)
std::string to_string() const
Wrap an out-of-band SERVER_PROBE / unwrap the matching PROBE_REPLY.
Item::Ptr get_item(const size_t index) const
std::vector< Result > results
void work(openvpn_io::io_context &io_context, ThreadCommon &tc, MyRunContext &runctx, const unsigned int unit)
constexpr BufferFlags NO_FLAGS(0U)
no flags set
bool client_reply_write(Buffer &buf, const ProbeReply &reply)
Write a complete PROBE_REPLY (message header + probe_reply TLV). Server.
std::optional< ProbeParameter > server_probe_read(Buffer &buf)
auto port(const bool valid=true) -> Gen< int >
Generates a port number value.
virtual void server_probe_done(std::vector< Result > results)=0
called once when the probe window closes, with every reply collected
One responding server, with its measured latency and advertised parameters.
Time::Duration rtt
measured probe round-trip time
size_t remote_index
index of the remote in the RemoteList
unsigned short port
the port that answered
oob::ProbeReply reply
priority / weight / connect_lifetime / flags
IP::Addr addr
the address that answered
probe reply TLV (sent by the server in a PROBE_REPLY).
ProtoSessionID peer_session_id
echoes the session id of the request
std::uint16_t weight
DNS-SRV style weight.
std::uint16_t connect_lifetime
seconds the reply is valid as a handshake shortcut
std::uint16_t priority
DNS-SRV style priority (lower preferred)
TEST(ServerProber, plaintext_probe_roundtrip)