Lines Matching defs:push_state
64 static void test_dns_push_send_push_subscribe(push_test_state_t *push_state, const char *name, int rrtype);
69 push_test_state_t *push_state = context;
74 TEST_PASSED(push_state->test_state);
81 test_dns_push_send_push_unsubscribe(push_test_state_t *push_state, int index)
83 if (push_state->subscribe_xids[index] != 0) {
90 INFO("unsubscribe %x %d", push_state->subscribe_xids[index], index);
91 dso_make_message(&message, buffer, sizeof(dns_message), push_state->dso_connection->dso, true, false, 0, 0, NULL);
98 dns_u16_to_wire(&towire, push_state->subscribe_xids[index]);
104 ioloop_send_message(push_state->dso_connection, NULL, &iov, 1);
105 push_state->subscribe_xids[index] = 0; // Don't unsubscribe again.
110 test_dns_push_unsubscribe_all(push_test_state_t *push_state)
118 if (!push_state->push_send_bogus_keepalive) {
119 for (int i = 0; i < push_state->num_subscribe_xids; i++) {
120 test_dns_push_send_push_unsubscribe(push_state, i);
125 dso_make_message(&message, buffer, sizeof(dns_message), push_state->dso_connection->dso, false, false, 0, 0, NULL);
135 if (push_state->push_send_bogus_keepalive) {
140 push_state->keepalive_xid = dns_message.id;
144 ioloop_send_message(push_state->dso_connection, NULL, &iov, 1);
150 push_test_state_t *push_state = context;
151 TEST_FAIL(push_state->test_state, "remote disconnect didn't happen");
155 test_dns_push_handle_retry_delay(push_test_state_t *push_state, dso_state_t *dso, uint32_t delay)
158 push_state->wait_for_remote_disconnect = ioloop_wakeup_create();
160 TEST_FAIL_CHECK(push_state->test_state, push_state->wait_for_remote_disconnect != NULL, "can't wait for remote disconnect.");
163 ioloop_add_wake_event(push_state->wait_for_remote_disconnect, push_state, test_dns_push_remote_disconnect_didnt_happen, NULL, 6 * 1000);
164 push_state->disconnect_expected = dso;
168 test_dns_push_address_update(push_test_state_t *push_state, dns_rr_t *rr, const char *name)
175 num = push_state->num_a_records;
177 ++push_state->num_a_records;
182 num = push_state->num_aaaa_records;
184 ++push_state->num_aaaa_records;
192 test_dns_push_update(push_test_state_t *push_state, dns_rr_t *rr)
198 TEST_FAIL_CHECK_STATUS(push_state->test_state, push_state->variant == PUSH_TEST_VARIANT_HARDWIRED,
201 TEST_FAIL_CHECK_STATUS(push_state->test_state, !strcmp(name, "default.service.arpa."), "bad name for SOA: %s", name);
206 push_state->srv_name = strdup("_dns-push-tls._tcp.default.service.arpa.");
207 test_dns_push_send_push_subscribe(push_state, push_state->srv_name, dns_rrtype_srv);
208 test_dns_push_send_push_unsubscribe(push_state, push_state->soa_index);
210 test_dns_push_address_update(push_state, rr, name);
211 if (push_state->server_was_crashed) {
213 push_state->num_address_removes++;
215 push_state->num_address_adds_post++;
218 push_state->num_address_adds_pre++;
221 TEST_FAIL_CHECK_STATUS(push_state->test_state, push_state->variant != PUSH_TEST_VARIANT_HARDWIRED,
223 TEST_FAIL_CHECK_STATUS(push_state->test_state, !strcmp(name, "_example._tcp.default.service.arpa."),
228 if (push_state->srv_name == NULL) {
229 push_state->srv_name = strdup(ptrname);
230 test_dns_push_send_push_subscribe(push_state, push_state->srv_name, dns_rrtype_srv);
232 if (push_state->server_was_crashed) {
234 push_state->num_service_removes++;
236 push_state->num_service_adds_post++;
239 push_state->num_service_adds_pre++;
245 TEST_FAIL_CHECK_STATUS(push_state->test_state, !strcmp(name, push_state->srv_name), "bad name for SRV: %s", name);
247 if (push_state->hostname == NULL) {
248 push_state->hostname = strdup(hnbuf);
249 TEST_FAIL_CHECK_STATUS(push_state->test_state, push_state->hostname != NULL, "no memory for %s", hnbuf);
251 test_dns_push_send_push_subscribe(push_state, push_state->hostname, dns_rrtype_a);
254 test_dns_push_send_push_subscribe(push_state, push_state->hostname, dns_rrtype_aaaa);
257 if (push_state->variant == PUSH_TEST_VARIANT_HARDWIRED) {
258 test_dns_push_send_push_unsubscribe(push_state, push_state->ds_index[0]);
259 test_dns_push_send_push_unsubscribe(push_state, push_state->ds_index[1]);
262 push_state->num_srv_records++;
267 push_state->num_txt_records++;
274 test_dns_push_send_appropriate_subscribe(push_test_state_t *push_state)
276 if (push_state->variant == PUSH_TEST_VARIANT_HARDWIRED) {
277 push_state->soa_index = push_state->num_subscribe_xids;
278 test_dns_push_send_push_subscribe(push_state, "default.service.arpa", dns_rrtype_soa);
279 push_state->ds_index[0] = push_state->num_subscribe_xids;
280 test_dns_push_send_push_subscribe(push_state, "default.service.arpa", dns_rrtype_ds);
281 push_state->ds_index[1] = push_state->num_subscribe_xids;
282 test_dns_push_send_push_subscribe(push_state, "default.service.arpa", dns_rrtype_ds);
284 test_dns_push_send_push_subscribe(push_state, "_example._tcp.default.service.arpa", dns_rrtype_ptr);
286 push_state->push_subscribe_sent = true;
290 test_dns_push_satisfied_check(push_test_state_t *push_state)
293 if (!push_state->have_address_records) {
295 switch(push_state->variant) {
297 satisfied = push_state->num_a_records != 0 && push_state->num_aaaa_records != 0;
301 satisfied = push_state->num_a_records != 0 || push_state->num_aaaa_records != 0;
304 satisfied = push_state->num_srv_records > 0 && push_state->num_txt_records > 0;
309 if (satisfied && push_state->variant == PUSH_TEST_VARIANT_DAEMON_CRASH) {
310 if (!push_state->server_was_crashed) {
313 if (!push_state->server_is_being_crashed) {
314 push_state->server_is_being_crashed = true;
318 push_state->server_was_crashed = true;
319 push_state->num_a_records = push_state->num_aaaa_records = 0;
320 dns_service_ref_t *ref = push_state->ptr_sdref;
321 TEST_FAIL_CHECK(push_state->test_state, ref != NULL, "ptr sdref is gone!");
322 for (int i = 0; i < push_state->num_txns; i++) {
323 DNSServiceRefDeallocate(push_state->txns[i]);
332 if (push_state->num_address_removes != push_state->num_address_adds_pre) {
335 if (push_state->num_address_adds_pre != push_state->num_address_adds_post) {
339 push_state->num_address_removes, push_state->num_address_adds_pre,
340 push_state->num_address_adds_post);
341 if (push_state->num_service_removes != push_state->num_service_adds_pre) {
345 push_state->num_service_removes, push_state->num_service_adds_pre,
346 push_state->num_service_adds_post);
350 push_state->have_address_records = true;
352 if (push_state->push_unsubscribe) {
353 test_dns_push_unsubscribe_all(push_state);
357 TEST_PASSED(push_state->test_state);
365 test_dns_push_dns_response(push_test_state_t *push_state, message_t *message)
385 TEST_FAIL_STATUS(push_state->test_state, "dns RR parse failed on rr %d", rr_index);
390 test_dns_push_update(push_state, &rr);
399 test_dns_push_satisfied_check(push_state);
403 test_dns_push_dso_message(push_test_state_t *push_state, message_t *message, dso_state_t *dso, bool response)
412 TEST_FAIL(push_state->test_state, "server sent a retry delay TLV as a response.");
419 TEST_FAIL_STATUS(push_state->test_state, "keepalive response from server, rcode = %d", dns_rcode_get(&message->wire));
427 if (!push_state->push_subscribe_sent) {
428 push_state->have_keepalive_response = true;
429 if (!push_state->need_service) {
430 test_dns_push_send_appropriate_subscribe(push_state);
438 TEST_FAIL_STATUS(push_state->test_state,
457 test_dns_push_update(push_state, &rr);
463 test_dns_push_satisfied_check(push_state);
469 for (int i = 0; i < push_state->num_subscribe_xids; i++) {
470 if (message->wire.id == htons(push_state->subscribe_xids[i])) {
474 TEST_FAIL_STATUS(push_state->test_state, "subscribe for %x failed",
475 push_state->subscribe_xids[i]);
481 } else if (message->wire.id == push_state->keepalive_xid) {
497 dso_simple_response(push_state->dso_connection, NULL, &message->wire, dns_rcode_dsotypeni);
505 push_test_state_t *push_state = context;
529 test_dns_push_dso_message(push_state, message, dso, false);
536 test_dns_push_dso_message(push_state, message, dso, true);
553 if (dso == push_state->disconnect_expected) {
568 if (!push_state->push_subscribe_sent && !push_state->need_service) {
569 test_dns_push_send_appropriate_subscribe(push_state);
571 push_state->have_keepalive_response = true;
578 test_dns_push_handle_retry_delay(push_state, dso, disconnect_context->reconnect_delay);
584 test_dns_push_send_push_subscribe(push_test_state_t *push_state, const char *name, int rrtype)
592 int i = push_state->num_subscribe_xids;
594 TEST_FAIL_STATUS(push_state->test_state, "subscribe xid limit reached: %d", i);
596 push_state->num_subscribe_xids++;
598 if (push_state->test_dns_push) {
600 dso_make_message(&message, buffer, sizeof(dns_message), push_state->dso_connection->dso, false, false, 0, 0, NULL);
602 push_state->subscribe_xids[i] = ntohs(dns_message.id);
603 INFO("push subscribe for %s, rrtype %d, xid %x, num %d", name, rrtype, push_state->subscribe_xids[i], i);
621 if (rrtype == dns_rrtype_srv && push_state->variant == PUSH_TEST_VARIANT_TWO_QUESTIONS) {
640 push_state->subscribe_xids[i] = ntohs(dns_message.id);
641 INFO("DNS query for %s, rrtype %d, xid %x, num %d", name, rrtype, push_state->subscribe_xids[i], i);
647 ioloop_send_message(push_state->dso_connection, NULL, &iov, 1);
653 push_test_state_t *push_state = context;
657 push_state, NULL, push_state->dso_connection);
680 ioloop_send_message(push_state->dso_connection, NULL, &iov, 1);
686 push_test_state_t *push_state = context;
687 TEST_FAIL(push_state->test_state, "push server disconnect.");
693 push_test_state_t *push_state = context;
698 test_dns_push_dns_response(push_state, message);
715 push_test_state_t *push_state = context;
716 test_state_t *state = push_state->test_state;
724 push_state->dso_connection = ioloop_connection_create(&address, true, true, true, true,
726 test_dns_push_disconnected, NULL, push_state);
727 TEST_FAIL_CHECK(state, push_state->dso_connection != NULL, "Unable to create dso connection.");
769 static void test_dns_push_register_example_service(push_test_state_t *push_state);
776 push_test_state_t *push_state = context;
777 test_state_t *state = push_state->test_state;
783 test_dns_push_register_example_service(push_state);
788 if (push_state->need_service) {
789 push_state->need_service = false;
790 if (push_state->have_keepalive_response) {
791 test_dns_push_send_appropriate_subscribe(push_state);
798 test_dns_push_register_example_service(push_test_state_t *push_state)
804 int ret = DNSServiceRegister(&push_state->register_ref, 0, kDNSServiceInterfaceIndexAny, NULL,
806 test_dns_push_register_callback, push_state);
807 TEST_FAIL_CHECK(push_state->test_state, ret == kDNSServiceErr_NoError, "failed to register example service.");
808 DNSServiceSetDispatchQueue(push_state->register_ref, dispatch_get_main_queue());
820 push_test_state_t *push_state = state->context;
822 push_state->ptr_sdref = ref;
824 if (push_state->num_txns < TXN_LIMIT) {
825 push_state->txns[push_state->num_txns++] = ref;
898 push_test_state_t *push_state = calloc(1, sizeof (*push_state));
899 TEST_FAIL_CHECK(state, push_state != NULL, "no memory for test-specific state.");
900 state->context = push_state;
901 push_state->test_state = state;
902 push_state->variant = variant;
903 push_state->test_dns_push = push;
906 push_state->push_unsubscribe = true;
909 srp_test_tls_listener_context = push_state;
919 push_state->need_service = true;
920 test_dns_push_register_example_service(push_state);