Document media lookup lifetimes and remove obsolete shared state
This commit is contained in:
1 parent
093e537fed
commit
a3f3b2fff2
3 files changed
+48
-20
No files matched your search
@@ -118,10 +118,34 @@ static int msend(struct UTUN_INSTANCE* inst, uint64_t dst, const uint8_t* data,
|
||||
e->dgram[0] = ETCP_RT_ID_MEDIA_DELIVERY;
|
||||
memcpy(e->dgram + 1, data, len); e->len = (uint16_t)(len + 1);
|
||||
int rc = etcp_route_send(inst, TOPO_GROUP_UTUN, dst, e, 1, 0);
|
||||
if (rc != 0) { u_free(e->dgram); queue_entry_free(e); }
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int query_received, query_valid;
|
||||
static void (*saved_media_recv)(struct ETCP_CONN*, struct ll_entry*);
|
||||
|
||||
/* Перехватываем только ожидаемый ответ; прочие пакеты обрабатывает настоящий сервис. */
|
||||
static void query_recv(struct ETCP_CONN* conn, struct ll_entry* entry) {
|
||||
if (entry->len < ROUTER_SVC_PAYLOAD_OFF + 1 || entry->dgram[ROUTER_SVC_PAYLOAD_OFF] != MEDIA_SUBCMD_QUERY_RESP) {
|
||||
saved_media_recv(conn, entry); return;
|
||||
}
|
||||
query_received++;
|
||||
size_t len = entry->len - ROUTER_SVC_PAYLOAD_OFF;
|
||||
uint64_t source, group;
|
||||
memcpy(&source, entry->dgram + ROUTER_SVC_SRC_OFF, 8); memcpy(&group, entry->dgram + ROUTER_SVC_GROUP_OFF, 8);
|
||||
if (len == MEDIA_QUERY_RESP_HDR_SIZE + sizeof(struct media_pkt_query_resp_entry)) {
|
||||
const struct media_pkt_query_resp* r = (const struct media_pkt_query_resp*)(entry->dgram + ROUTER_SVC_PAYLOAD_OFF);
|
||||
const struct media_pkt_query_resp_entry* e = (const struct media_pkt_query_resp_entry*)((const uint8_t*)r + MEDIA_QUERY_RESP_HDR_SIZE);
|
||||
uint8_t block[16], request[16];
|
||||
for (int i = 0; i < 16; i++) block[i] = (uint8_t)(0x10 + i);
|
||||
memset(request, 0x91, 16);
|
||||
query_valid = source == g_nid_a && group == TOPO_GROUP_UTUN && r->status == MEDIA_QUERY_OK && r->num_blocks == 1
|
||||
&& !memcmp(r->request_id, request, 16) && !memcmp(r->media_id, block, 16) && !memcmp(e->block_id, block, 16)
|
||||
&& e->num_holders == 1 && e->holders[0] == g_nid_a;
|
||||
}
|
||||
queue_dgram_free(entry); queue_entry_free(entry);
|
||||
}
|
||||
|
||||
/* ── tests ── */
|
||||
|
||||
static void phase1_serve_reg(void) {
|
||||
@@ -181,12 +205,15 @@ static void phase3_query(void) {
|
||||
memcpy(q->media_id, block_uuid, 16);
|
||||
q->num_blocks = 1;
|
||||
memcpy(pkt + MEDIA_QUERY_HDR_SIZE, block_uuid, 16);
|
||||
|
||||
msend(g_b, g_nid_a, pkt, sizeof(pkt));
|
||||
/* QUERY_RESP arrives asynchronously — poll */
|
||||
int ok = 0, poll_count = 0;
|
||||
while (poll_count < 200) { uasync_poll(g_ua, POLL_MS); poll_count++; }
|
||||
(void)ok; OK(); /* smoke test: doesn't crash */
|
||||
media_delivery_send_have_block(g_a, TOPO_GROUP_UTUN, g_nid_a, block_uuid, block_uuid, 0);
|
||||
saved_media_recv = g_b->router_bindings.callbacks[ETCP_RT_ID_MEDIA_DELIVERY];
|
||||
g_b->router_bindings.callbacks[ETCP_RT_ID_MEDIA_DELIVERY] = query_recv;
|
||||
query_received = query_valid = 0;
|
||||
int rc = msend(g_b, g_nid_a, pkt, sizeof(pkt)), poll_count = 0;
|
||||
while (!query_received && poll_count++ < 2000) uasync_poll(g_ua, POLL_MS);
|
||||
g_b->router_bindings.callbacks[ETCP_RT_ID_MEDIA_DELIVERY] = saved_media_recv;
|
||||
if (!rc && query_received == 1 && query_valid) OK();
|
||||
else FAIL("send=%d received=%d valid=%d", rc, query_received, query_valid);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user