48 .request_id = 0xdeadbeefcafef00dULL,
49 .timestamp = 0x0123456789abcdefULL,
71 assert_int_equal(
BLEN(&buf), 0);
85 .request_id = 0x1122334455667788ULL,
86 .timestamp = 0x0102030405060708ULL,
92 const uint8_t expected[] = {
95 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
96 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
97 0x00, 0x00, 0x00, 0x00,
100 assert_int_equal(
BLEN(&buf),
sizeof(expected));
101 assert_memory_equal(
BPTR(&buf), expected,
sizeof(expected));
114 .request_id = 0x1122334455667788ULL,
117 .max_latency_diff = 25,
118 .connect_lifetime = 30,
142 assert_int_equal(
BLEN(&buf), 0);
157 .request_id = 0x1122334455667788ULL,
160 .max_latency_diff = 25,
161 .connect_lifetime = 30,
168 const uint8_t expected[] = {
171 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
179 assert_int_equal(
BLEN(&buf),
sizeof(expected));
180 assert_memory_equal(
BPTR(&buf), expected,
sizeof(expected));
203 assert_int_equal(
BLEN(&value), extended_len);
208 assert_true(out.
timestamp == 0xdeadbeefULL);
209 assert_true(out.
flags == 0x80000000);
211 assert_int_equal(
BLEN(&buf), 0);
241 for (
int i = 0; i < 4; i++)
259 const uint16_t bad[] = {
264 const uint16_t good[] = {
271 for (
size_t i = 0; i <
SIZE(bad) +
SIZE(good); i++)
273 const bool expect_ok = i >=
SIZE(bad);
274 const uint16_t flags = expect_ok ? good[i -
SIZE(bad)] : bad[i];
327 const struct probe_request in = { .request_id = 1, .timestamp = 1 };
329 for (
int i = 0; i < trailing; i++)
348 const struct probe_request in = { .request_id = 1, .timestamp = 7 };
370 const struct probe_request in = { .request_id = 1, .timestamp = 7 };
403 for (
int i = 0; i < 2; i++)
struct buffer alloc_buf_gc(size_t size, struct gc_arena *gc)
Allocate a buffer of the given size under garbage collection.
static bool buf_write_u16(struct buffer *dest, uint16_t data)
Append a uint16_t to a buffer in network byte order.
#define BPTR(buf)
Return a pointer to the start of the buffer content.
static bool buf_write_u32(struct buffer *dest, uint32_t data)
Append a uint32_t to a buffer in network byte order.
static bool buf_write_u8(struct buffer *dest, uint8_t data)
Append a uint8_t to a buffer.
#define BLEN(buf)
Return the length of the buffer content in bytes.
static void gc_free(struct gc_arena *a)
Free all allocations in a garbage collection arena.
static struct gc_arena gc_new(void)
Allocate and return a new, empty garbage collection arena.
static bool buf_write_u64(struct buffer *dest, uint64_t data)
Append a uint64_t to a buffer in network byte order.
bool ctrl_msg_tlv_peek_header(const struct buffer *buf, struct ctrl_msg_tlv_header *hdr)
Read a TLV header from buf without consuming it.
bool ctrl_msg_tlv_write_header(struct buffer *buf, uint16_t type, bool optional, uint16_t value_len)
Write a TLV header (type + optional flag + value length) to buf.
bool ctrl_msg_find_tlv(struct buffer *payload, uint16_t wanted_type, struct buffer *value)
Scan payload for the TLV of type wanted_type, skipping any other TLV type that is marked optional.
TLV framing shared by the TLV-based control messages of the wire protocol.
#define CTRL_MSG_TLV_HEADER_LEN
#define TLV_TYPE_PROBE_REQUEST
#define TLV_TYPE_PROBE_REPLY
bool probe_reply_write(struct buffer *buf, const struct probe_reply *r)
Write a complete probe reply TLV, header and value, to buf.
bool probe_request_read(struct buffer *buf, struct probe_request *r)
Read a probe request TLV value from buf.
bool probe_request_write(struct buffer *buf, const struct probe_request *r)
Write a complete probe request TLV, header and value, to buf.
bool probe_reply_read(struct buffer *buf, struct probe_reply *r)
Read a probe reply TLV value from buf.
Encoding and decoding of the server probe TLVs.
#define PROBE_REPLY_FLAG_LIFETIME_SHARED
the connect_lifetime holds against those other addresses too, so a reply from one of them can skip th...
#define PROBE_REPLY_FLAG_ADDRS_EQUAL
the other addresses of this remote are the same server, no need to probe them
#define PROBE_REQUEST_FLAG_PROBE_ONLY
probe request flags.
#define PROBE_REPLY_LEN
request_id (u64), then priority, weight, max_latency_diff, connect_lifetime and flags (u16 each)
#define PROBE_REQUEST_LEN
request_id (u64), timestamp (u64), flags (u32)
#define PROBE_REPLY_FLAG_PROBE_MORE
the other addresses of this remote are distinct servers, so probe them too
#define PROBE_REPLY_FLAG_RESEND_WKC
complete the handshake with P_CONTROL_WKC_V1 rather than P_CONTROL_V1
Wrapper structure for dynamically allocated memory.
Garbage collection arena used to keep track of dynamically allocated memory.
probe reply TLV, a server's answer to a probe request
uint16_t priority
DNS SRV style priority, lower is preferred.
uint16_t connect_lifetime
For how many seconds, counted from the moment the client sent its own probe request,...
uint16_t weight
DNS SRV style weight.
uint64_t request_id
echoes the request_id of the request
uint16_t max_latency_diff
candidate band in ms around the fastest server
uint16_t flags
PROBE_REPLY_FLAG_*.
probe request TLV, sent by a client to probe a server
uint32_t flags
PROBE_REQUEST_FLAG_*.
uint64_t timestamp
The client clock as a UNIX timestamp in seconds.
uint64_t request_id
identifies this probe, echoed in the reply
void test_find_tlv_rejects_unknown_mandatory(void **state)
void test_probe_request_wire_format(void **state)
void test_probe_reply_roundtrip(void **state)
void test_find_tlv_empty_payload(void **state)
void test_probe_reply_wire_format(void **state)
void test_find_tlv_rejects_duplicate(void **state)
void test_find_tlv_value_truncated(void **state)
void test_find_tlv_trailing_bytes(void **state)
void test_find_tlv_skips_optional_after_wanted(void **state)
void test_probe_reply_flags_contradict(void **state)
void test_probe_request_too_short(void **state)
void test_probe_request_forward_compat(void **state)
void test_probe_request_roundtrip(void **state)
void test_probe_reply_too_short(void **state)