static int cert_updater_update(ProxyContext * const proxy_context) { CertUpdater *cert_updater = &proxy_context->cert_updater; DNSCRYPT_PROXY_CERTS_UPDATE_START(); if (cert_updater->evdns_base != NULL) { evdns_base_free(cert_updater->evdns_base, 0); } if ((cert_updater->evdns_base = evdns_base_new(proxy_context->event_loop, 0)) == NULL) { return -1; } if (evdns_base_nameserver_sockaddr_add(cert_updater->evdns_base, (struct sockaddr *) &proxy_context->resolver_sockaddr, proxy_context->resolver_sockaddr_len, DNS_QUERY_NO_SEARCH) != 0) { return -1; } if (proxy_context->tcp_only != 0) { (void) evdns_base_nameserver_ip_add(cert_updater->evdns_base, proxy_context->resolver_ip); } if (evdns_base_resolve_txt(cert_updater->evdns_base, proxy_context->provider_name, DNS_QUERY_NO_SEARCH, cert_query_cb, proxy_context) == NULL) { return -1; } return 0; }
static void dns_resolve_reverse(void *ptr) { struct in_addr in; struct event_base *base = event_base_new(); struct evdns_base *dns = evdns_base_new(base, 1/* init name servers */); struct evdns_request *req = NULL; tt_assert(base); tt_assert(dns); in.s_addr = htonl(0x7f000001ul); /* 127.0.0.1 */ dns_ok = 0; req = evdns_base_resolve_reverse( dns, &in, 0, dns_gethostbyname_cb, base); tt_assert(req); event_base_dispatch(base); tt_int_op(dns_ok, ==, DNS_PTR); end: if (dns) evdns_base_free(dns, 0); if (base) event_base_free(base); }
static int telex_client(int listen_port, int remote_port, int debug_level, const char *remote_host, const char *keyfile, const char *cafile) { if (debug_level >= 0) { LogOutputStream( stdout ); LogOutputStream( stdout ); LogOutputLevel( debug_level ); } struct telex_conf conf; memset(&conf, 0, sizeof(struct telex_conf)); conf.notblocked_port = remote_port; conf.notblocked_host = remote_host; conf.ca_list = (char *)cafile; conf.keyfile = (char *)keyfile; // counters conf.count_tunnels = 0; conf.count_open_tunnels = 0; if (ssl_init(&conf) < 0) { LogFatal("main", "Could not initialize OpenSSL"); return 1; } int ret = InitAndListenLoop(listen_port, (evconnlistener_cb)proxy_accept_cb, &conf); if (conf.ssl_ctx) { ssl_done(&conf); } if (conf.dns_base) { evdns_base_free(conf.dns_base, 1); } return ret; }
void server_term(void) { if (g_ctx.coap) { ec_term(g_ctx.coap); g_ctx.coap = NULL; } if (g_ctx.dns) { evdns_base_free(g_ctx.dns, 0); g_ctx.dns = NULL; } if (g_ctx.base) { event_base_free(g_ctx.base); g_ctx.base = NULL; } if (g_ctx.fs) { ec_filesys_destroy(g_ctx.fs); g_ctx.fs = NULL; } return; }
int main(int argc, char** argv) { LIST_INIT(&search_list); search_add(&search_list, "123", 3); base = event_base_new(); if (base) { dnsbase = evdns_base_new(base, 1); if (dnsbase) { create_request("http://yandex.ru/"); event_base_dispatch(base); evdns_base_free(dnsbase, 0); } else { fprintf(stderr, "evdns_base_new() failed\n"); } event_base_free(base); } else { perror("event_base_new()"); } search_clear(&search_list); return (EXIT_SUCCESS); }
int Spider_Url_Rinse::uninitialize() { write_history(); evdns_base_free(m_evdnsbase, 0); event_base_free(m_evbase); return 0; }
static void dns_search_test(void *arg) { struct basic_test_data *data = arg; struct event_base *base = data->base; struct evdns_base *dns = NULL; ev_uint16_t portnum = 0; char buf[64]; struct generic_dns_callback_result r[8]; tt_assert(regress_dnsserver(base, &portnum, search_table)); evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum); dns = evdns_base_new(base, 0); tt_assert(!evdns_base_nameserver_ip_add(dns, buf)); evdns_base_search_add(dns, "a.example.com"); evdns_base_search_add(dns, "b.example.com"); evdns_base_search_add(dns, "c.example.com"); n_replies_left = sizeof(r)/sizeof(r[0]); exit_base = base; evdns_base_resolve_ipv4(dns, "host", 0, generic_dns_callback, &r[0]); evdns_base_resolve_ipv4(dns, "host2", 0, generic_dns_callback, &r[1]); evdns_base_resolve_ipv4(dns, "host", DNS_NO_SEARCH, generic_dns_callback, &r[2]); evdns_base_resolve_ipv4(dns, "host2", DNS_NO_SEARCH, generic_dns_callback, &r[3]); evdns_base_resolve_ipv4(dns, "host3", 0, generic_dns_callback, &r[4]); evdns_base_resolve_ipv4(dns, "hostn.a.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[5]); evdns_base_resolve_ipv4(dns, "hostn.b.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[6]); evdns_base_resolve_ipv4(dns, "hostn.c.example.com", DNS_NO_SEARCH, generic_dns_callback, &r[7]); event_base_dispatch(base); tt_int_op(r[0].type, ==, DNS_IPv4_A); tt_int_op(r[0].count, ==, 1); tt_int_op(((ev_uint32_t*)r[0].addrs)[0], ==, htonl(0x0b16212c)); tt_int_op(r[1].type, ==, DNS_IPv4_A); tt_int_op(r[1].count, ==, 1); tt_int_op(((ev_uint32_t*)r[1].addrs)[0], ==, htonl(0xc8640064)); tt_int_op(r[2].result, ==, DNS_ERR_NOTEXIST); tt_int_op(r[3].result, ==, DNS_ERR_NOTEXIST); tt_int_op(r[4].result, ==, DNS_ERR_NOTEXIST); tt_int_op(r[5].result, ==, DNS_ERR_NODATA); tt_int_op(r[5].ttl, ==, 42); tt_int_op(r[6].result, ==, DNS_ERR_NOTEXIST); tt_int_op(r[6].ttl, ==, 42); tt_int_op(r[7].result, ==, DNS_ERR_NODATA); tt_int_op(r[7].ttl, ==, 0); end: if (dns) evdns_base_free(dns, 0); regress_clean_dnsserver(); }
void IoEvDNS_free(IoEvDNS *self) { if (DNS(self)) { int fail_requests = 0; evdns_base_free(DNS(self), fail_requests); IoObject_setDataPointer_(self, 0x0); } }
void cert_updater_free(ProxyContext * const proxy_context) { CertUpdater * const cert_updater = &proxy_context->cert_updater; event_free(cert_updater->cert_timer); cert_updater->cert_timer = NULL; if (cert_updater->evdns_base != NULL) { evdns_base_free(cert_updater->evdns_base, 0); cert_updater->evdns_base = NULL; } }
static void dns_reissue_test(void *arg) { struct basic_test_data *data = arg; struct event_base *base = data->base; struct evdns_server_port *port1 = NULL, *port2 = NULL; struct evdns_base *dns = NULL; struct generic_dns_callback_result r1; ev_uint16_t portnum1 = 0, portnum2=0; char buf1[64], buf2[64]; port1 = regress_get_dnsserver(base, &portnum1, NULL, regress_dns_server_cb, internal_error_table); tt_assert(port1); port2 = regress_get_dnsserver(base, &portnum2, NULL, regress_dns_server_cb, reissue_table); tt_assert(port2); evutil_snprintf(buf1, sizeof(buf1), "127.0.0.1:%d", (int)portnum1); evutil_snprintf(buf2, sizeof(buf2), "127.0.0.1:%d", (int)portnum2); dns = evdns_base_new(base, 0); tt_assert(!evdns_base_nameserver_ip_add(dns, buf1)); tt_assert(! evdns_base_set_option(dns, "timeout:", "0.3")); tt_assert(! evdns_base_set_option(dns, "max-timeouts:", "2")); tt_assert(! evdns_base_set_option(dns, "attempts:", "5")); memset(&r1, 0, sizeof(r1)); evdns_base_resolve_ipv4(dns, "foof.example.com", 0, generic_dns_callback, &r1); /* Add this after, so that we are sure to get a reissue. */ tt_assert(!evdns_base_nameserver_ip_add(dns, buf2)); n_replies_left = 1; exit_base = base; event_base_dispatch(base); tt_int_op(r1.result, ==, DNS_ERR_NONE); tt_int_op(r1.type, ==, DNS_IPv4_A); tt_int_op(r1.count, ==, 1); tt_int_op(((ev_uint32_t*)r1.addrs)[0], ==, htonl(0xf00ff00f)); /* Make sure we dropped at least once. */ tt_int_op(internal_error_table[0].seen, >, 0); end: if (dns) evdns_base_free(dns, 0); if (port1) evdns_close_server_port(port1); if (port2) evdns_close_server_port(port2); }
void closedown(struct running *rr) { log_debug(("closedown")); rotator_release(rr->rot); array_release(rr->src); array_release(rr->icc); assoc_release(rr->src_shop); assoc_release(rr->ic_shop); si_release(rr->si); event_del(rr->stat_timer); event_free(rr->stat_timer); event_del(rr->sigkill_timer); event_free(rr->sigkill_timer); evdns_base_free(rr->edb,1); event_base_free(rr->eb); }
void close_all(global_resources_struct *global_resources) { if (event_del(global_resources->int_signal_event)) everror("event_del"); event_free(global_resources->int_signal_event); if (event_del(global_resources->server_event)) everror("event_del"); event_free(global_resources->server_event); free_all_clients_events(global_resources->bases.base, client_handler_events_filter, client_handler_destruct); free_all_clients_events(global_resources->bases.base, transfer_events_filter, transfer_destruct); evdns_base_free(global_resources->bases.dns_base, 0); event_base_free(global_resources->bases.base); if (close(global_resources->server_sockfd)) perror("close"); }
void f4dns_free(f4dns_ctx_t *ctx) { assert( ctx != NULL ); if( ctx->server != NULL ) { evdns_close_server_port(ctx->server); } if( ctx->dns_base != NULL ) { evdns_base_free(ctx->dns_base, 1); } memset(ctx, 0, sizeof(f4dns_ctx_t)); free(ctx); }
static void dns_search_test(void *arg) { struct basic_test_data *data = arg; struct event_base *base = data->base; struct evdns_base *dns = NULL; ev_uint16_t portnum = 0; char buf[64]; struct generic_dns_callback_result r1, r2, r3, r4, r5; tt_assert(regress_dnsserver(base, &portnum, search_table)); evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum); dns = evdns_base_new(base, 0); tt_assert(!evdns_base_nameserver_ip_add(dns, buf)); evdns_base_search_add(dns, "a.example.com"); evdns_base_search_add(dns, "b.example.com"); evdns_base_search_add(dns, "c.example.com"); n_replies_left = 5; exit_base = base; evdns_base_resolve_ipv4(dns, "host", 0, generic_dns_callback, &r1); evdns_base_resolve_ipv4(dns, "host2", 0, generic_dns_callback, &r2); evdns_base_resolve_ipv4(dns, "host", DNS_NO_SEARCH, generic_dns_callback, &r3); evdns_base_resolve_ipv4(dns, "host2", DNS_NO_SEARCH, generic_dns_callback, &r4); evdns_base_resolve_ipv4(dns, "host3", 0, generic_dns_callback, &r5); event_base_dispatch(base); tt_int_op(r1.type, ==, DNS_IPv4_A); tt_int_op(r1.count, ==, 1); tt_int_op(((ev_uint32_t*)r1.addrs)[0], ==, htonl(0x0b16212c)); tt_int_op(r2.type, ==, DNS_IPv4_A); tt_int_op(r2.count, ==, 1); tt_int_op(((ev_uint32_t*)r2.addrs)[0], ==, htonl(0xc8640064)); tt_int_op(r3.result, ==, DNS_ERR_NOTEXIST); tt_int_op(r4.result, ==, DNS_ERR_NOTEXIST); tt_int_op(r5.result, ==, DNS_ERR_NOTEXIST); end: if (dns) evdns_base_free(dns, 0); regress_clean_dnsserver(); }
void io_shutdown(int sig) { INFO("Shutting down JSONRPC IO process...\n"); lock_get(jsonrpc_server_group_lock); /* blocking */ INIT_SERVER_LOOP FOREACH_SERVER_IN(global_server_group) close_server(server); ENDFOR evdns_base_free(global_evdns_base, 0); event_base_loopexit(global_ev_base, NULL); event_base_free(global_ev_base); lock_release(jsonrpc_server_group_lock); }
static void dns_cb(int errcode, struct evutil_addrinfo *addr, void *ptr) { struct tmate_ssh_client *client; struct evutil_addrinfo *ai; struct timeval tv; if (errcode) { tmate_status_message("%s lookup failure. Retrying in %d seconds (%s)", TMATE_HOST, TMATE_DNS_RETRY_TIMEOUT, evutil_gai_strerror(errcode)); tv.tv_sec = TMATE_DNS_RETRY_TIMEOUT; tv.tv_usec = 0; evtimer_assign(&ev_dns_retry, ev_base, on_dns_retry, NULL); evtimer_add(&ev_dns_retry, &tv); return; } tmate_status_message("Connecting to %s...", TMATE_HOST); for (ai = addr; ai; ai = ai->ai_next) { char buf[128]; const char *ip = NULL; if (ai->ai_family == AF_INET) { struct sockaddr_in *sin = (struct sockaddr_in *)ai->ai_addr; ip = evutil_inet_ntop(AF_INET, &sin->sin_addr, buf, 128); } else if (ai->ai_family == AF_INET6) { struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ai->ai_addr; ip = evutil_inet_ntop(AF_INET6, &sin6->sin6_addr, buf, 128); } tmate_debug("Trying server %s", ip); /* * Note: We don't deal with the client list. Clients manage it * and free client structs when necessary. */ (void)tmate_ssh_client_alloc(&tmate_session, ip); } evutil_freeaddrinfo(addr); evdns_base_free(ev_dnsbase, 0); ev_dnsbase = NULL; }
static void delete_http2_session_data(http2_session_data *session_data) { SSL *ssl = bufferevent_openssl_get_ssl(session_data->bev); if (ssl) { SSL_shutdown(ssl); } bufferevent_free(session_data->bev); session_data->bev = NULL; evdns_base_free(session_data->dnsbase, 1); session_data->dnsbase = NULL; nghttp2_session_del(session_data->session); session_data->session = NULL; if (session_data->stream_data) { delete_http2_stream_data(session_data->stream_data); session_data->stream_data = NULL; } free(session_data); }
static void dns_inflight_test(void *arg) { struct basic_test_data *data = arg; struct event_base *base = data->base; struct evdns_base *dns = NULL; ev_uint16_t portnum = 53900;/*XXXX let the code pick a port*/ struct generic_dns_callback_result r[20]; int i; tt_assert(regress_dnsserver(base, &portnum, reissue_table)); /* Make sure that having another (very bad!) RNG doesn't mess us * up. */ evdns_set_random_bytes_fn(dumb_bytes_fn); dns = evdns_base_new(base, 0); tt_assert(!evdns_base_nameserver_ip_add(dns, "127.0.0.1:53900")); tt_assert(! evdns_base_set_option(dns, "max-inflight:", "3", DNS_OPTIONS_ALL)); tt_assert(! evdns_base_set_option(dns, "randomize-case:", "0", DNS_OPTIONS_ALL)); for(i=0;i<20;++i) evdns_base_resolve_ipv4(dns, "foof.example.com", 0, generic_dns_callback, &r[i]); n_replies_left = 20; exit_base = base; event_base_dispatch(base); for (i=0;i<20;++i) { tt_int_op(r[i].type, ==, DNS_IPv4_A); tt_int_op(r[i].count, ==, 1); tt_int_op(((ev_uint32_t*)r[i].addrs)[0], ==, htonl(0xf00ff00f)); } end: if (dns) evdns_base_free(dns, 0); regress_clean_dnsserver(); }
static void dns_search_cancel_test(void *arg) { struct basic_test_data *data = arg; struct event_base *base = data->base; struct evdns_base *dns = NULL; struct evdns_server_port *port = NULL; ev_uint16_t portnum = 0; struct generic_dns_callback_result r1; char buf[64]; port = regress_get_dnsserver(base, &portnum, NULL, search_cancel_server_cb, NULL); tt_assert(port); evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum); dns = evdns_base_new(base, 0); tt_assert(!evdns_base_nameserver_ip_add(dns, buf)); evdns_base_search_add(dns, "a.example.com"); evdns_base_search_add(dns, "b.example.com"); evdns_base_search_add(dns, "c.example.com"); evdns_base_search_add(dns, "d.example.com"); exit_base = base; request_count = 3; n_replies_left = 1; current_req = evdns_base_resolve_ipv4(dns, "host", 0, generic_dns_callback, &r1); event_base_dispatch(base); tt_int_op(r1.result, ==, DNS_ERR_CANCEL); end: if (port) evdns_close_server_port(port); if (dns) evdns_base_free(dns, 0); }
static void dns_inflight_test(void *arg) { struct basic_test_data *data = arg; struct event_base *base = data->base; struct evdns_base *dns = NULL; ev_uint16_t portnum = 0; char buf[64]; struct generic_dns_callback_result r[20]; int i; tt_assert(regress_dnsserver(base, &portnum, reissue_table)); evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", (int)portnum); dns = evdns_base_new(base, 0); tt_assert(!evdns_base_nameserver_ip_add(dns, buf)); tt_assert(! evdns_base_set_option(dns, "max-inflight:", "3")); tt_assert(! evdns_base_set_option(dns, "randomize-case:", "0")); for (i=0;i<20;++i) evdns_base_resolve_ipv4(dns, "foof.example.com", 0, generic_dns_callback, &r[i]); n_replies_left = 20; exit_base = base; event_base_dispatch(base); for (i=0;i<20;++i) { tt_int_op(r[i].type, ==, DNS_IPv4_A); tt_int_op(r[i].count, ==, 1); tt_int_op(((ev_uint32_t*)r[i].addrs)[0], ==, htonl(0xf00ff00f)); } end: if (dns) evdns_base_free(dns, 0); regress_clean_dnsserver(); }
int main() { struct httpclient *cli; struct event_base *eb; struct evdns_base *edb; struct event *exit_ev,*ev,*ev2; struct timeval three_sec = {3,0}; struct timeval ten_sec = {10,0}; logging_fd(2); log_set_level("",LOG_DEBUG); eb = event_base_new(); edb = evdns_base_new(eb,1); cli = httpclient_create(eb,edb); exit_ev = evsignal_new(eb,SIGINT,do_exit,eb); event_add(exit_ev,0); http_request(cli,url,0,20,done,0); http_request(cli,url,0,20,done,0); http_request(cli,url,0,20,done,0); http_request(cli,url,0,20,done,0); http_request(cli,url,0,20,done,0); http_request(cli,url,0,20,done,0); ev = evtimer_new(eb,req,cli); evtimer_add(ev,&three_sec); ev2 = evtimer_new(eb,req,cli); evtimer_add(ev2,&ten_sec); event_base_loop(eb,0); httpclient_finish(cli); event_free(exit_ev); event_free(ev); event_free(ev2); evdns_base_free(edb,1); event_base_free(eb); fprintf(stderr,"exit\n"); logging_done(); return 0; }
static void cert_query_cb(int result, char type, int count, int ttl, void * const txt_records_, void * const arg) { Bincert *bincert = NULL; ProxyContext *proxy_context = arg; const struct txt_record *txt_records = txt_records_; int i = 0; (void) type; (void) ttl; DNSCRYPT_PROXY_CERTS_UPDATE_RECEIVED(); evdns_base_free(proxy_context->cert_updater.evdns_base, 0); proxy_context->cert_updater.evdns_base = NULL; if (result != DNS_ERR_NONE) { logger_noformat(proxy_context, LOG_ERR, "Unable to retrieve server certificates"); cert_reschedule_query_after_failure(proxy_context); DNSCRYPT_PROXY_CERTS_UPDATE_ERROR_COMMUNICATION(); return; } assert(count >= 0); while (i < count) { cert_open_bincert(proxy_context, (const SignedBincert *) txt_records[i].txt, txt_records[i].len, &bincert); i++; } if (bincert == NULL) { logger_noformat(proxy_context, LOG_ERR, "No useable certificates found"); cert_reschedule_query_after_failure(proxy_context); DNSCRYPT_PROXY_CERTS_UPDATE_ERROR_NOCERTS(); if (proxy_context->test_only) { exit(DNSCRYPT_EXIT_CERT_NOCERTS); } return; } if (proxy_context->test_only != 0) { const uint32_t now_u32 = (uint32_t) time(NULL); uint32_t ts_end; memcpy(&ts_end, bincert->ts_end, sizeof ts_end); ts_end = htonl(ts_end); if (ts_end < (uint32_t) proxy_context->test_cert_margin || now_u32 > ts_end - (uint32_t) proxy_context->test_cert_margin) { logger_noformat(proxy_context, LOG_WARNING, "The certificate is not valid for the given safety margin"); DNSCRYPT_PROXY_CERTS_UPDATE_ERROR_NOCERTS(); exit(DNSCRYPT_EXIT_CERT_MARGIN); } } COMPILER_ASSERT(sizeof proxy_context->resolver_publickey == sizeof bincert->server_publickey); memcpy(proxy_context->resolver_publickey, bincert->server_publickey, sizeof proxy_context->resolver_publickey); COMPILER_ASSERT(sizeof proxy_context->dnscrypt_magic_query == sizeof bincert->magic_query); memcpy(proxy_context->dnscrypt_magic_query, bincert->magic_query, sizeof proxy_context->dnscrypt_magic_query); cert_print_bincert_info(proxy_context, bincert); cert_print_server_key(proxy_context); dnscrypt_client_init_magic_query(&proxy_context->dnscrypt_client, bincert->magic_query); memset(bincert, 0, sizeof *bincert); free(bincert); if (proxy_context->test_only) { DNSCRYPT_PROXY_CERTS_UPDATE_DONE((unsigned char *) proxy_context->resolver_publickey); exit(0); } dnscrypt_client_init_nmkey(&proxy_context->dnscrypt_client, proxy_context->resolver_publickey); dnscrypt_proxy_start_listeners(proxy_context); proxy_context->cert_updater.query_retry_step = 0U; cert_reschedule_query_after_success(proxy_context); DNSCRYPT_PROXY_CERTS_UPDATE_DONE((unsigned char *) proxy_context->resolver_publickey); }
int main (int argc, char *argv[]) { struct event_base *evbase; struct evdns_base *dns_base; int i; int test_id = -1; struct evhttp_uri *uri; event_set_mem_functions (g_malloc, g_realloc, g_free); evbase = event_base_new (); dns_base = evdns_base_new (evbase, 1); app = g_new0 (Application, 1); app->evbase = evbase; app->dns_base = dns_base; app->stats = hfs_stats_srv_create (app); app->conf = conf_create (); conf_add_boolean (app->conf, "log.use_syslog", TRUE); conf_add_uint (app->conf, "auth.ttl", 85800); conf_add_int (app->conf, "pool.writers", 2); conf_add_int (app->conf, "pool.readers", 2); conf_add_int (app->conf, "pool.operations", 4); conf_add_uint (app->conf, "pool.max_requests_per_pool", 100); conf_add_int (app->conf, "connection.timeout", 20); conf_add_int (app->conf, "connection.retries", -1); conf_add_uint (app->conf, "filesystem.dir_cache_max_time", 5); conf_add_boolean (app->conf, "filesystem.cache_enabled", TRUE); conf_add_string (app->conf, "filesystem.cache_dir", "/tmp/hydrafs"); conf_add_string (app->conf, "filesystem.cache_dir_max_size", "1Gb"); conf_add_boolean (app->conf, "statistics.enabled", TRUE); conf_add_int (app->conf, "statistics.port", 8011); conf_add_string (app->conf, "auth.user", "test"); conf_add_string (app->conf, "auth.key", "test"); uri = evhttp_uri_parse ("http://127.0.0.1:8011/get_auth"); app->auth_client = auth_client_create (app, uri); if (argc > 1) test_id = atoi (argv[1]); if (test_id >= 0) // run_responce_test (evbase, dns_base, test_id); run_request_test (evbase, dns_base, test_id); else { for (i = 0; i < TID_last_test; i++) { run_responce_test (evbase, dns_base, i); } } evdns_base_free (dns_base, 0); event_base_free (evbase); return 0; }
/*{{{ application_destroy */ static void application_destroy (Application *app) { LOG_debug (APP_LOG, "Destroying application !"); g_free (app->conf_path); if (app->read_client_pool) client_pool_destroy (app->read_client_pool); if (app->write_client_pool) client_pool_destroy (app->write_client_pool); if (app->ops_client_pool) client_pool_destroy (app->ops_client_pool); if (app->dir_tree) dir_tree_destroy (app->dir_tree); if (app->cmng) cache_mng_destroy (app->cmng); if (app->sigint_ev) event_free (app->sigint_ev); if (app->sigterm_ev) event_free (app->sigterm_ev); if (app->sigpipe_ev) event_free (app->sigpipe_ev); if (app->sigusr1_ev) event_free (app->sigusr1_ev); if (app->sigusr2_ev) event_free (app->sigusr2_ev); if (app->service_con) http_connection_destroy (app->service_con); if (app->stat_srv) stat_srv_destroy (app->stat_srv); // destroy Fuse if (app->rfuse) rfuse_destroy (app->rfuse); if (app->dns_base) evdns_base_free (app->dns_base, 0); if (app->evbase) event_base_free (app->evbase); if (app->uri) evhttp_uri_free (app->uri); if (app->conf) conf_destroy (app->conf); if (app->fuse_opts) g_free (app->fuse_opts); #ifdef SSL_ENABLED SSL_CTX_free (app->ssl_ctx); #endif #ifdef MAGIC_ENABLED magic_close(app->magic_ctx); #endif logger_destroy (); if (app->f_log) fclose (app->f_log); if (app->log_file_name) g_free (app->log_file_name); g_free (app); ENGINE_cleanup (); CRYPTO_cleanup_all_ex_data (); ERR_free_strings (); ERR_remove_thread_state (NULL); EVP_cleanup (); }
static void test_bufferevent_connect_hostname(void *arg) { struct basic_test_data *data = arg; struct evconnlistener *listener = NULL; struct bufferevent *be1=NULL, *be2=NULL, *be3=NULL, *be4=NULL, *be5=NULL; int be1_outcome=0, be2_outcome=0, be3_outcome=0, be4_outcome=0, be5_outcome=0; struct evdns_base *dns=NULL; struct evdns_server_port *port=NULL; evutil_socket_t server_fd=-1; struct sockaddr_in sin; int listener_port=-1; ev_uint16_t dns_port=0; int n_accept=0, n_dns=0; char buf[128]; be_connect_hostname_base = data->base; /* Bind an address and figure out what port it's on. */ memset(&sin, 0, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(0x7f000001); /* 127.0.0.1 */ sin.sin_port = 0; listener = evconnlistener_new_bind(data->base, nil_accept_cb, &n_accept, LEV_OPT_REUSEABLE|LEV_OPT_CLOSE_ON_EXEC, -1, (struct sockaddr *)&sin, sizeof(sin)); listener_port = regress_get_socket_port( evconnlistener_get_fd(listener)); port = regress_get_dnsserver(data->base, &dns_port, NULL, be_getaddrinfo_server_cb, &n_dns); tt_assert(port); tt_int_op(dns_port, >=, 0); /* Start an evdns_base that uses the server as its resolver. */ dns = evdns_base_new(data->base, 0); evutil_snprintf(buf, sizeof(buf), "127.0.0.1:%d", dns_port); evdns_base_nameserver_ip_add(dns, buf); /* Now, finally, at long last, launch the bufferevents. One should do * a failing lookup IP, one should do a successful lookup by IP, * and one should do a successful lookup by hostname. */ be1 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE); be2 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE); be3 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE); be4 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE); be5 = bufferevent_socket_new(data->base, -1, BEV_OPT_CLOSE_ON_FREE); bufferevent_setcb(be1, NULL, NULL, be_connect_hostname_event_cb, &be1_outcome); bufferevent_setcb(be2, NULL, NULL, be_connect_hostname_event_cb, &be2_outcome); bufferevent_setcb(be3, NULL, NULL, be_connect_hostname_event_cb, &be3_outcome); bufferevent_setcb(be4, NULL, NULL, be_connect_hostname_event_cb, &be4_outcome); bufferevent_setcb(be5, NULL, NULL, be_connect_hostname_event_cb, &be5_outcome); /* Launch an async resolve that will fail. */ tt_assert(!bufferevent_socket_connect_hostname(be1, dns, AF_INET, "nosuchplace.example.com", listener_port)); /* Connect to the IP without resolving. */ tt_assert(!bufferevent_socket_connect_hostname(be2, dns, AF_INET, "127.0.0.1", listener_port)); /* Launch an async resolve that will succeed. */ tt_assert(!bufferevent_socket_connect_hostname(be3, dns, AF_INET, "nobodaddy.example.com", listener_port)); /* Use the blocking resolver. This one will fail if your resolver * can't resolve localhost to 127.0.0.1 */ tt_assert(!bufferevent_socket_connect_hostname(be4, NULL, AF_INET, "localhost", listener_port)); /* Use the blocking resolver with a nonexistent hostname. */ tt_assert(!bufferevent_socket_connect_hostname(be5, NULL, AF_INET, "nonesuch.nowhere.example.com", 80)); event_base_dispatch(data->base); tt_int_op(be1_outcome, ==, BEV_EVENT_ERROR); tt_int_op(be2_outcome, ==, BEV_EVENT_CONNECTED); tt_int_op(be3_outcome, ==, BEV_EVENT_CONNECTED); tt_int_op(be4_outcome, ==, BEV_EVENT_CONNECTED); tt_int_op(be5_outcome, ==, BEV_EVENT_ERROR); tt_int_op(n_accept, ==, 3); tt_int_op(n_dns, ==, 2); end: if (listener) evconnlistener_free(listener); if (server_fd>=0) EVUTIL_CLOSESOCKET(server_fd); if (port) evdns_close_server_port(port); if (dns) evdns_base_free(dns, 0); if (be1) bufferevent_free(be1); if (be2) bufferevent_free(be2); if (be3) bufferevent_free(be3); if (be4) bufferevent_free(be4); if (be5) bufferevent_free(be5); }
static void dns_retry_test(void *arg) { struct basic_test_data *data = arg; struct event_base *base = data->base; struct evdns_server_port *port = NULL; struct evdns_base *dns = NULL; int drop_count = 2; ev_uint16_t portnum = 53900;/*XXXX let the code pick a port*/ struct generic_dns_callback_result r1; port = regress_get_dnsserver(base, &portnum, NULL, fail_server_cb, &drop_count); tt_assert(port); dns = evdns_base_new(base, 0); tt_assert(!evdns_base_nameserver_ip_add(dns, "127.0.0.1:53900")); tt_assert(! evdns_base_set_option(dns, "timeout", "0.3", DNS_OPTIONS_ALL)); tt_assert(! evdns_base_set_option(dns, "max-timeouts:", "10", DNS_OPTIONS_ALL)); tt_assert(! evdns_base_set_option(dns, "initial-probe-timeout", "0.5", DNS_OPTIONS_ALL)); evdns_base_resolve_ipv4(dns, "host.example.com", 0, generic_dns_callback, &r1); n_replies_left = 1; exit_base = base; event_base_dispatch(base); tt_int_op(drop_count, ==, 0); tt_int_op(r1.type, ==, DNS_IPv4_A); tt_int_op(r1.count, ==, 1); tt_int_op(((ev_uint32_t*)r1.addrs)[0], ==, htonl(0x10204080)); /* Now try again, but this time have the server get treated as * failed, so we can send it a test probe. */ drop_count = 4; tt_assert(! evdns_base_set_option(dns, "max-timeouts:", "3", DNS_OPTIONS_ALL)); tt_assert(! evdns_base_set_option(dns, "attempts:", "4", DNS_OPTIONS_ALL)); memset(&r1, 0, sizeof(r1)); evdns_base_resolve_ipv4(dns, "host.example.com", 0, generic_dns_callback, &r1); n_replies_left = 2; /* This will run until it answers the "google.com" probe request. */ event_base_dispatch(base); /* We'll treat the server as failed here. */ tt_int_op(r1.result, ==, DNS_ERR_TIMEOUT); /* It should work this time. */ tt_int_op(drop_count, ==, 0); evdns_base_resolve_ipv4(dns, "host.example.com", 0, generic_dns_callback, &r1); event_base_dispatch(base); tt_int_op(r1.result, ==, DNS_ERR_NONE); tt_int_op(r1.type, ==, DNS_IPv4_A); tt_int_op(r1.count, ==, 1); tt_int_op(((ev_uint32_t*)r1.addrs)[0], ==, htonl(0x10204080)); end: if (dns) evdns_base_free(dns, 0); if (port) evdns_close_server_port(port); }
static void dns_server(void) { evutil_socket_t sock=-1; struct sockaddr_in my_addr; struct evdns_server_port *port=NULL; struct in_addr resolve_addr; struct in6_addr resolve_addr6; struct evdns_base *base=NULL; struct evdns_request *req=NULL; dns_ok = 1; base = evdns_base_new(NULL, 0); /* Add ourself as the only nameserver, and make sure we really are * the only nameserver. */ evdns_base_nameserver_ip_add(base, "127.0.0.1:35353"); tt_int_op(evdns_base_count_nameservers(base), ==, 1); /* Now configure a nameserver port. */ sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock<0) { tt_abort_perror("socket"); } evutil_make_socket_nonblocking(sock); memset(&my_addr, 0, sizeof(my_addr)); my_addr.sin_family = AF_INET; my_addr.sin_port = htons(35353); my_addr.sin_addr.s_addr = htonl(0x7f000001UL); if (bind(sock, (struct sockaddr*)&my_addr, sizeof(my_addr)) < 0) { tt_abort_perror("bind"); } port = evdns_add_server_port(sock, 0, dns_server_request_cb, NULL); /* Send some queries. */ evdns_base_resolve_ipv4(base, "zz.example.com", DNS_QUERY_NO_SEARCH, dns_server_gethostbyname_cb, NULL); evdns_base_resolve_ipv6(base, "zz.example.com", DNS_QUERY_NO_SEARCH, dns_server_gethostbyname_cb, NULL); resolve_addr.s_addr = htonl(0xc0a80b0bUL); /* 192.168.11.11 */ evdns_base_resolve_reverse(base, &resolve_addr, 0, dns_server_gethostbyname_cb, NULL); memcpy(resolve_addr6.s6_addr, "\xff\xf0\x00\x00\x00\x00\xaa\xaa" "\x11\x11\x00\x00\x00\x00\xef\xef", 16); evdns_base_resolve_reverse_ipv6(base, &resolve_addr6, 0, dns_server_gethostbyname_cb, (void*)6); req = evdns_base_resolve_ipv4(base, "drop.example.com", DNS_QUERY_NO_SEARCH, dns_server_gethostbyname_cb, (void*)(char*)90909); evdns_cancel_request(base, req); event_dispatch(); tt_assert(dns_got_cancel); test_ok = dns_ok; end: if (port) evdns_close_server_port(port); if (sock >= 0) EVUTIL_CLOSESOCKET(sock); if (base) evdns_base_free(base, 0); }
Global::~Global() { event_base_free(event_base); evdns_base_free(dns_base, 0); };
virtual void TearDown() { evhttp_connection_free(connection_); //evhttp_request_free(request_); evdns_base_free(dnsbase_, 0); event_base_free(base_); }
int main (int argc, char *argv[]) { gchar *in_dir; GList *tmp; struct evhttp_uri *uri; struct timeval tv; log_level = LOG_debug; event_set_mem_functions (g_malloc, g_realloc, g_free); // init SSL libraries CRYPTO_set_mem_functions (g_malloc0, g_realloc, g_free); ENGINE_load_builtin_engines (); ENGINE_register_all_complete (); ERR_load_crypto_strings (); OpenSSL_add_all_algorithms (); SSL_load_error_strings (); SSL_library_init (); if (!RAND_poll ()) { fprintf(stderr, "RAND_poll() failed.\n"); return 1; } g_random_set_seed (time (NULL)); in_dir = g_dir_make_tmp (NULL, NULL); g_assert (in_dir); app = g_new0 (Application, 1); app->files_count = 10; app->evbase = event_base_new (); app->dns_base = evdns_base_new (app->evbase, 1); app->conf = conf_create (); conf_add_boolean (app->conf, "log.use_syslog", TRUE); conf_add_uint (app->conf, "auth.ttl", 85800); conf_add_int (app->conf, "pool.writers", 2); conf_add_int (app->conf, "pool.readers", 2); conf_add_int (app->conf, "pool.operations", 4); conf_add_uint (app->conf, "pool.max_requests_per_pool", 100); conf_add_int (app->conf, "connection.timeout", 20); conf_add_int (app->conf, "connection.retries", -1); conf_add_uint (app->conf, "filesystem.dir_cache_max_time", 5); conf_add_boolean (app->conf, "filesystem.cache_enabled", TRUE); conf_add_string (app->conf, "filesystem.cache_dir", "/tmp/hydrafs"); conf_add_string (app->conf, "filesystem.cache_dir_max_size", "1Gb"); conf_add_boolean (app->conf, "statistics.enabled", TRUE); conf_add_int (app->conf, "statistics.port", 8011); conf_add_string (app->conf, "auth.user", "test:tester"); conf_add_string (app->conf, "auth.key", "testing"); uri = evhttp_uri_parse ("https://10.0.0.104:8080/auth/v1.0"); app->ssl_ctx = SSL_CTX_new (TLSv1_client_method ()); app->stats = hfs_stats_srv_create (app); app->auth_client = auth_client_create (app, uri); app->http = http_client_create (app); // start server start_srv (app->evbase, in_dir); app->timeout = evtimer_new (app->evbase, on_output_timer, NULL); evutil_timerclear(&tv); tv.tv_sec = 0; tv.tv_usec = 500; event_add (app->timeout, &tv); event_base_dispatch (app->evbase); evhttp_uri_free (uri); event_del (app->timeout); event_free (app->timeout); evhttp_free (app->http_srv); auth_client_destroy (app->auth_client); evdns_base_free (app->dns_base, 0); event_base_free (app->evbase); conf_destroy (app->conf); g_free (app); return 0; }