Skip to content

Commit c41424e

Browse files
committed
fix(mdns): Cleanup mdns sender
1 parent 7330f78 commit c41424e

12 files changed

+527
-533
lines changed

components/mdns/mdns_browser.c

+22-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,28 @@ void mdns_priv_browse_result_add_srv(mdns_browse_t *browse, const char *hostname
585585
r->next = browse->result;
586586
browse->result = r;
587587
add_browse_result(out_sync_browse, r);
588-
return;
588+
}
589+
590+
/**4
591+
* @brief Browse sync result
592+
*/
593+
esp_err_t mdns_priv_browse_sync(mdns_browse_sync_t *browse_sync)
594+
{
595+
mdns_action_t *action = NULL;
596+
597+
action = (mdns_action_t *)mdns_mem_malloc(sizeof(mdns_action_t));
598+
if (!action) {
599+
HOOK_MALLOC_FAILED;
600+
return ESP_ERR_NO_MEM;
601+
}
602+
603+
action->type = ACTION_BROWSE_SYNC;
604+
action->data.browse_sync.browse_sync = browse_sync;
605+
if (!mdns_priv_queue_action(action)) {
606+
mdns_mem_free(action);
607+
return ESP_ERR_NO_MEM;
608+
}
609+
return ESP_OK;
589610
}
590611

591612
/**

components/mdns/mdns_pcb.c

+27-23
Original file line numberDiff line numberDiff line change
@@ -48,20 +48,23 @@ void mdns_priv_pcb_announce(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol,
4848
if (PCB_STATE_IS_PROBING(_pcb)) {
4949
mdns_priv_init_pcb_probe(tcpip_if, ip_protocol, services, len, include_ip);
5050
} else if (PCB_STATE_IS_ANNOUNCING(_pcb)) {
51-
mdns_tx_packet_t *p = _mdns_get_next_pcb_packet(tcpip_if, ip_protocol);
51+
mdns_tx_packet_t *p = mdns_priv_get_next_packet(tcpip_if, ip_protocol);
5252
if (p) {
5353
for (i = 0; i < len; i++) {
54-
if (!_mdns_alloc_answer(&p->answers, MDNS_TYPE_SDPTR, services[i]->service, NULL, false, false)
55-
|| !_mdns_alloc_answer(&p->answers, MDNS_TYPE_PTR, services[i]->service, NULL, false, false)
56-
|| !_mdns_alloc_answer(&p->answers, MDNS_TYPE_SRV, services[i]->service, NULL, true, false)
57-
|| !_mdns_alloc_answer(&p->answers, MDNS_TYPE_TXT, services[i]->service, NULL, true, false)) {
54+
if (!mdns_priv_create_answer(&p->answers, MDNS_TYPE_SDPTR, services[i]->service, NULL, false, false)
55+
|| !mdns_priv_create_answer(&p->answers, MDNS_TYPE_PTR, services[i]->service, NULL, false,
56+
false)
57+
|| !mdns_priv_create_answer(&p->answers, MDNS_TYPE_SRV, services[i]->service, NULL, true,
58+
false)
59+
|| !mdns_priv_create_answer(&p->answers, MDNS_TYPE_TXT, services[i]->service, NULL, true,
60+
false)) {
5861
break;
5962
}
6063
}
6164
if (include_ip) {
62-
_mdns_dealloc_answer(&p->additional, MDNS_TYPE_A, NULL);
63-
_mdns_dealloc_answer(&p->additional, MDNS_TYPE_AAAA, NULL);
64-
_mdns_append_host_list_in_services(&p->answers, services, len, true, false);
65+
mdns_priv_dealloc_answer(&p->additional, MDNS_TYPE_A, NULL);
66+
mdns_priv_dealloc_answer(&p->additional, MDNS_TYPE_AAAA, NULL);
67+
mdns_priv_append_host_list_in_services(&p->answers, services, len, true, false);
6568
}
6669
_pcb->state = PCB_ANNOUNCE_1;
6770
}
@@ -72,9 +75,9 @@ void mdns_priv_pcb_announce(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol,
7275
}
7376

7477
_pcb->state = PCB_ANNOUNCE_1;
75-
mdns_tx_packet_t *p = _mdns_create_announce_packet(tcpip_if, ip_protocol, services, len, include_ip);
78+
mdns_tx_packet_t *p = mdns_priv_create_announce_packet(tcpip_if, ip_protocol, services, len, include_ip);
7679
if (p) {
77-
mdns_send_schedule_tx_packet(p, 0);
80+
mdns_priv_send_after(p, 0);
7881
}
7982
}
8083
}
@@ -152,7 +155,7 @@ void mdns_priv_pcb_disable(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
152155
mdns_priv_netif_disable(tcpip_if);
153156

154157
if (mdns_priv_if_ready(tcpip_if, ip_protocol)) {
155-
_mdns_clear_pcb_tx_queue_head(tcpip_if, ip_protocol);
158+
mdns_priv_clear_tx_queue_if(tcpip_if, ip_protocol);
156159
deinit_pcb(tcpip_if, ip_protocol);
157160
mdns_if_t other_if = mdns_priv_netif_get_other_interface(tcpip_if);
158161
if (other_if != MDNS_MAX_INTERFACES && s_pcbs[other_if][ip_protocol].state == PCB_DUP) {
@@ -191,7 +194,7 @@ void mdns_priv_pcb_set_duplicate(mdns_if_t tcpip_if)
191194
if (mdns_priv_if_ready(other_if, i)) {
192195
//stop this interface and mark as dup
193196
if (mdns_priv_if_ready(tcpip_if, i)) {
194-
_mdns_clear_pcb_tx_queue_head(tcpip_if, i);
197+
mdns_priv_clear_tx_queue_if(tcpip_if, i);
195198
deinit_pcb(tcpip_if, i);
196199
}
197200
s_pcbs[tcpip_if][i].state = PCB_DUP;
@@ -220,13 +223,13 @@ void mdns_priv_pcb_schedule_tx_packet(mdns_tx_packet_t *p)
220223
}
221224
//fallthrough
222225
case PCB_PROBE_2:
223-
mdns_send_schedule_tx_packet(p, 250);
226+
mdns_priv_send_after(p, 250);
224227
pcb->state = (mdns_pcb_state_t)((uint8_t)(pcb->state) + 1);
225228
break;
226229
case PCB_PROBE_3:
227-
a = _mdns_create_announce_from_probe(p);
230+
a = mdns_priv_create_announce_from_probe(p);
228231
if (!a) {
229-
mdns_send_schedule_tx_packet(p, 250);
232+
mdns_priv_send_after(p, 250);
230233
break;
231234
}
232235
pcb->probe_running = false;
@@ -235,22 +238,22 @@ void mdns_priv_pcb_schedule_tx_packet(mdns_tx_packet_t *p)
235238
pcb->failed_probes = 0;
236239
mdns_mem_free(pcb->probe_services);
237240
pcb->probe_services = NULL;
238-
_mdns_free_tx_packet(p);
241+
mdns_priv_free_tx_packet(p);
239242
p = a;
240243
send_after = 250;
241244
//fallthrough
242245
case PCB_ANNOUNCE_1:
243246
//fallthrough
244247
case PCB_ANNOUNCE_2:
245-
mdns_send_schedule_tx_packet(p, send_after);
248+
mdns_priv_send_after(p, send_after);
246249
pcb->state = (mdns_pcb_state_t)((uint8_t)(pcb->state) + 1);
247250
break;
248251
case PCB_ANNOUNCE_3:
249252
pcb->state = PCB_RUNNING;
250-
_mdns_free_tx_packet(p);
253+
mdns_priv_free_tx_packet(p);
251254
break;
252255
default:
253-
_mdns_free_tx_packet(p);
256+
mdns_priv_free_tx_packet(p);
254257
break;
255258
}
256259
}
@@ -368,7 +371,8 @@ static void init_probe_new_service(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_pro
368371
pcb->probe_services_len = 0;
369372
pcb->probe_running = false;
370373

371-
mdns_tx_packet_t *packet = _mdns_create_probe_packet(tcpip_if, ip_protocol, s, services_final_len, true, probe_ip);
374+
mdns_tx_packet_t *packet = mdns_priv_create_probe_packet(tcpip_if, ip_protocol, s, services_final_len, true,
375+
probe_ip);
372376
if (!packet) {
373377
mdns_mem_free(s);
374378
return;
@@ -378,15 +382,15 @@ static void init_probe_new_service(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_pro
378382
pcb->probe_services = s;
379383
pcb->probe_services_len = services_final_len;
380384
pcb->probe_running = true;
381-
mdns_send_schedule_tx_packet(packet, ((pcb->failed_probes > 5) ? 1000 : 120) + (esp_random() & 0x7F));
385+
mdns_priv_send_after(packet, ((pcb->failed_probes > 5) ? 1000 : 120) + (esp_random() & 0x7F));
382386
pcb->state = PCB_PROBE_1;
383387
}
384388

385389
void mdns_priv_init_pcb_probe(mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol, mdns_srv_item_t **services, size_t len, bool probe_ip)
386390
{
387391
mdns_pcb_t *pcb = &s_pcbs[tcpip_if][ip_protocol];
388392

389-
_mdns_clear_pcb_tx_queue_head(tcpip_if, ip_protocol);
393+
mdns_priv_clear_tx_queue_if(tcpip_if, ip_protocol);
390394

391395
if (mdns_utils_str_null_or_empty(mdns_priv_get_global_hostname())) {
392396
pcb->state = PCB_RUNNING;
@@ -432,7 +436,7 @@ void mdns_priv_pcb_send_bye_service(mdns_srv_item_t **services, size_t len, bool
432436
for (i = 0; i < MDNS_MAX_INTERFACES; i++) {
433437
for (j = 0; j < MDNS_IP_PROTOCOL_MAX; j++) {
434438
if (mdns_priv_if_ready(i, j) && s_pcbs[i][j].state == PCB_RUNNING) {
435-
mdns_send_bye_pcb((mdns_if_t) i, (mdns_ip_protocol_t) j, services, len, include_ip);
439+
mdns_priv_send_bye((mdns_if_t) i, (mdns_ip_protocol_t) j, services, len, include_ip);
436440
}
437441
}
438442
}

components/mdns/mdns_querier.c

+5-5
Original file line numberDiff line numberDiff line change
@@ -267,15 +267,15 @@ mdns_search_once_t *mdns_priv_query_find(mdns_name_t *name, uint16_t type, mdns_
267267
static mdns_tx_packet_t *create_search_packet(mdns_search_once_t *search, mdns_if_t tcpip_if, mdns_ip_protocol_t ip_protocol)
268268
{
269269
mdns_result_t *r = NULL;
270-
mdns_tx_packet_t *packet = _mdns_alloc_packet_default(tcpip_if, ip_protocol);
270+
mdns_tx_packet_t *packet = mdns_priv_alloc_packet(tcpip_if, ip_protocol);
271271
if (!packet) {
272272
return NULL;
273273
}
274274

275275
mdns_out_question_t *q = (mdns_out_question_t *)mdns_mem_malloc(sizeof(mdns_out_question_t));
276276
if (!q) {
277277
HOOK_MALLOC_FAILED;
278-
_mdns_free_tx_packet(packet);
278+
mdns_priv_free_tx_packet(packet);
279279
return NULL;
280280
}
281281
q->next = NULL;
@@ -299,7 +299,7 @@ static mdns_tx_packet_t *create_search_packet(mdns_search_once_t *search, mdns_i
299299
mdns_out_answer_t *a = (mdns_out_answer_t *)mdns_mem_malloc(sizeof(mdns_out_answer_t));
300300
if (!a) {
301301
HOOK_MALLOC_FAILED;
302-
_mdns_free_tx_packet(packet);
302+
mdns_priv_free_tx_packet(packet);
303303
return NULL;
304304
}
305305
a->type = MDNS_TYPE_PTR;
@@ -330,8 +330,8 @@ void mdns_priv_query_send(mdns_search_once_t *search, mdns_if_t tcpip_if, mdns_i
330330
if (!packet) {
331331
return;
332332
}
333-
_mdns_dispatch_tx_packet(packet);
334-
_mdns_free_tx_packet(packet);
333+
mdns_priv_dispatch_tx_packet(packet);
334+
mdns_priv_free_tx_packet(packet);
335335
}
336336
}
337337

0 commit comments

Comments
 (0)