resolver for writing a tool More...
#include "platform.h"#include "gnunet_util_lib.h"#include "gnunet_protocols.h"#include "gnunet_resolver_service.h"#include "resolver.h"Go to the source code of this file.
Data Structures | |
| struct | GNUNET_RESOLVER_RequestHandle |
| Handle to a request given to the resolver. More... | |
Macros | |
| #define | LOG(kind, ...) GNUNET_log_from (kind, "util-resolver-api", __VA_ARGS__) |
| #define | LOG_STRERROR(kind, syscall) |
| #define | MAX_HOSTNAME 1024 |
| Maximum supported length for a hostname. | |
Functions | |
| static int | check_config () |
| Check that the resolver service runs on localhost (or equivalent). | |
| void | GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
| Create the connection to the resolver service. | |
| void | GNUNET_RESOLVER_disconnect () |
| Destroy the connection to the resolver service. | |
| static void | shutdown_task (void *cls) |
| Task executed on system shutdown. | |
| static void | check_disconnect () |
| Consider disconnecting if we have no further requests pending. | |
| static char * | no_resolve (int af, const void *ip, socklen_t ip_len) |
| Convert IP address to string without DNS resolution. | |
| static void | reconnect (void) |
| Adjust exponential back-off and reconnect to the service. | |
| static void | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
| Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. | |
| static void | process_requests () |
| Process pending requests to the resolver. | |
| static int | check_response (void *cls, const struct GNUNET_RESOLVER_ResponseMessage *msg) |
| Check validity of response with a hostname for a DNS lookup. | |
| static void | handle_response (void *cls, const struct GNUNET_RESOLVER_ResponseMessage *msg) |
| Check validity of response with a hostname for a DNS lookup. | |
| static void | numeric_resolution (void *cls) |
| We've been asked to lookup the address for a hostname and were given a valid numeric string. | |
| static void | loopback_resolution (void *cls) |
| We've been asked to lookup the address for a hostname and were given a variant of "loopback". | |
| static void | reconnect_task (void *cls) |
| Now try to reconnect to the resolver service. | |
| static void | handle_lookup_timeout (void *cls) |
| A DNS resolution timed out. | |
| struct GNUNET_RESOLVER_RequestHandle * | GNUNET_RESOLVER_ip_get (const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls) |
| Convert a string to one or more IP addresses. | |
| static void | numeric_reverse (void *cls) |
| We've been asked to convert an address to a string without a reverse lookup, either because the client asked for it or because the DNS lookup hit a timeout. | |
| struct GNUNET_RESOLVER_RequestHandle * | GNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen, int do_resolve, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_HostnameCallback callback, void *cls) |
| Get an IP address as a string. | |
| char * | GNUNET_RESOLVER_local_fqdn_get () |
| Get local fully qualified af name. | |
| struct GNUNET_RESOLVER_RequestHandle * | GNUNET_RESOLVER_hostname_resolve (int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *cls) |
| Looking our own hostname. | |
| void | GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) |
| Cancel a request that is still pending with the resolver. | |
Variables | |
| static const char * | loopback [] |
| Possible hostnames for "loopback". | |
| static const struct GNUNET_CONFIGURATION_Handle * | resolver_cfg |
| Configuration. | |
| static struct GNUNET_MQ_Handle * | mq |
| Our connection to the resolver service, created on-demand, but then persists until error or shutdown. | |
| static struct GNUNET_RESOLVER_RequestHandle * | req_head |
| Head of DLL of requests. | |
| static struct GNUNET_RESOLVER_RequestHandle * | req_tail |
| Tail of DLL of requests. | |
| static uint32_t | last_request_id |
| ID of the last request we sent to the service. | |
| static struct GNUNET_TIME_Relative | backoff |
| How long should we wait to reconnect? | |
| static struct GNUNET_SCHEDULER_Task * | r_task |
| Task for reconnecting. | |
| static struct GNUNET_SCHEDULER_Task * | s_task |
| Task ID of shutdown task; only present while we have a connection to the resolver service. | |
resolver for writing a tool
Definition in file resolver_api.c.
| #define LOG | ( | kind, | |
| ... | |||
| ) | GNUNET_log_from (kind, "util-resolver-api", __VA_ARGS__) |
Definition at line 33 of file resolver_api.c.
| #define LOG_STRERROR | ( | kind, | |
| syscall | |||
| ) |
Definition at line 35 of file resolver_api.c.
| #define MAX_HOSTNAME 1024 |
Maximum supported length for a hostname.
Definition at line 42 of file resolver_api.c.
|
static |
Check that the resolver service runs on localhost (or equivalent).
Definition at line 191 of file resolver_api.c.
References _, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_have_value(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_OK, GNUNET_SYSERR, LOG, loopback, and resolver_cfg.
Referenced by GNUNET_RESOLVER_hostname_get(), and GNUNET_RESOLVER_ip_get().
|
static |
Task executed on system shutdown.
Definition at line 306 of file resolver_api.c.
References backoff, GNUNET_RESOLVER_RequestHandle::cls, GNUNET_RESOLVER_disconnect(), GNUNET_TIME_UNIT_MILLISECONDS, and s_task.
|
static |
Consider disconnecting if we have no further requests pending.
Definition at line 319 of file resolver_api.c.
References GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_RESOLVER_RequestHandle::next, r_task, req_head, s_task, and shutdown_task.
Referenced by GNUNET_RESOLVER_request_cancel(), and reconnect().
|
static |
Convert IP address to string without DNS resolution.
| af | address family |
| ip | the address |
| ip_len | number of bytes in ip |
Definition at line 348 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::af, GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_strdup, and LOG_STRERROR.
Referenced by handle_lookup_timeout(), handle_response(), and numeric_reverse().
|
static |
Adjust exponential back-off and reconnect to the service.
Definition at line 828 of file resolver_api.c.
References backoff, check_disconnect(), GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_STD_BACKOFF, GNUNET_YES, LOG, mq, r_task, reconnect_task(), req_head, req_tail, resolver_cfg, and GNUNET_RESOLVER_RequestHandle::was_transmitted.
Referenced by callback_reconnect(), disconnect_and_schedule_reconnect(), disconnect_and_schedule_reconnect(), do_connect(), error_handler(), error_handler(), error_handler(), error_handler(), error_handler(), error_handler(), force_reconnect(), GNUNET_ABD_connect(), GNUNET_CADET_connect(), GNUNET_CADET_get_channel(), GNUNET_CADET_get_path(), GNUNET_CADET_list_peers(), GNUNET_CADET_list_tunnels(), GNUNET_CORE_connect(), GNUNET_CORE_monitor_start(), GNUNET_DNS_connect(), GNUNET_GNS_connect(), GNUNET_IDENTITY_connect(), GNUNET_MESSENGER_connect(), GNUNET_NAMECACHE_connect(), GNUNET_NAMESTORE_connect(), GNUNET_NAMESTORE_zone_monitor_start(), GNUNET_NAMESTORE_zone_monitor_start2(), GNUNET_NSE_connect(), GNUNET_PEERSTORE_connect(), GNUNET_PEERSTORE_monitor_start(), GNUNET_PILS_connect(), GNUNET_RECLAIM_connect(), GNUNET_RECLAIM_ticket_consume(), GNUNET_RPS_connect(), GNUNET_TRANSPORT_application_init(), GNUNET_TRANSPORT_communicator_connect(), GNUNET_TRANSPORT_monitor(), handle_address_change_notification(), handle_incoming_ack(), handle_monitor_end(), handle_mq_error(), handle_response(), mq_error_handler(), mq_error_handler(), mq_error_handler(), mq_error_handler(), mq_error_handler(), mq_error_handler(), mq_error_handler(), mq_error_handler(), process_requests(), reconnect(), reconnect(), reconnect_cbk(), reconnect_task(), reconnect_task(), reconnect_task(), reconnect_task(), reconnect_task(), reconnect_task(), reconnect_task(), reconnect_task(), and reschedule_connect().
|
static |
Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.
Not every message queue implementation supports an error handler.
| cls | NULL |
| error | error code |
Definition at line 410 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_destroy(), LOG, mq, and reconnect().
Referenced by reconnect_task().
|
static |
Process pending requests to the resolver.
Definition at line 427 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::af, GNUNET_RESOLVER_RequestHandle::data_len, GNUNET_RESOLVER_RequestHandle::direction, env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_RESOLVER_REQUEST, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_YES, GNUNET_RESOLVER_RequestHandle::id, LOG, mq, msg, reconnect(), req_head, s_task, shutdown_task, and GNUNET_RESOLVER_RequestHandle::was_transmitted.
Referenced by GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), handle_lookup_timeout(), handle_response(), and reconnect_task().
|
static |
Check validity of response with a hostname for a DNS lookup.
| cls | NULL |
| msg | message with the hostname |
Definition at line 476 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::cls, GNUNET_OK, and msg.
|
static |
Check validity of response with a hostname for a DNS lookup.
NOTE: right now rather messy, might want to use different message types for different response formats in the future.
| cls | NULL |
| msg | message with the response |
Definition at line 496 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::addr_callback, GNUNET_RESOLVER_RequestHandle::af, GNUNET_RESOLVER_RequestHandle::cls, GNUNET_RESOLVER_RequestHandle::data_len, GNUNET_a2s(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_NO, GNUNET_RESOLVER_request_cancel(), GNUNET_SYSERR, GNUNET_YES, GNUNET_RESOLVER_RequestHandle::id, LOG, mq, msg, GNUNET_RESOLVER_RequestHandle::name_callback, GNUNET_RESOLVER_RequestHandle::next, no_resolve(), process_requests(), GNUNET_RESOLVER_RequestHandle::received_response, reconnect(), req_head, GNUNET_MessageHeader::size, size, and GNUNET_RESOLVER_RequestHandle::was_transmitted.
|
static |
We've been asked to lookup the address for a hostname and were given a valid numeric string.
Perform the callbacks for the numeric addresses.
| cls | struct GNUNET_RESOLVER_RequestHandle for the request |
Definition at line 652 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::addr_callback, GNUNET_RESOLVER_RequestHandle::af, GNUNET_RESOLVER_RequestHandle::cls, GNUNET_assert, GNUNET_free, GNUNET_SYSERR, GNUNET_RESOLVER_RequestHandle::task, and GNUNET_RESOLVER_RequestHandle::was_transmitted.
Referenced by GNUNET_RESOLVER_ip_get().
|
static |
We've been asked to lookup the address for a hostname and were given a variant of "loopback".
Perform the callbacks for the respective loopback numeric addresses.
| cls | struct GNUNET_RESOLVER_RequestHandle for the request |
Definition at line 728 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::addr_callback, GNUNET_RESOLVER_RequestHandle::af, GNUNET_RESOLVER_RequestHandle::cls, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_SYSERR, LOG, GNUNET_RESOLVER_RequestHandle::task, and GNUNET_RESOLVER_RequestHandle::was_transmitted.
Referenced by GNUNET_RESOLVER_ip_get().
|
static |
Now try to reconnect to the resolver service.
| cls | NULL |
Definition at line 792 of file resolver_api.c.
References GNUNET_MQ_MessageHandler::cls, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, handlers, LOG, mq, mq_error_handler(), process_requests(), r_task, reconnect(), req_head, resolver_cfg, and response.
Referenced by reconnect().
|
static |
A DNS resolution timed out.
Notify the application.
| cls | the struct GNUNET_RESOLVER_RequestHandle * |
Definition at line 880 of file resolver_api.c.
References _, GNUNET_RESOLVER_RequestHandle::af, GNUNET_RESOLVER_RequestHandle::cls, GNUNET_RESOLVER_RequestHandle::direction, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_NO, GNUNET_RESOLVER_request_cancel(), LOG, no_resolve(), process_requests(), GNUNET_RESOLVER_RequestHandle::task, and GNUNET_RESOLVER_RequestHandle::was_transmitted.
Referenced by GNUNET_RESOLVER_hostname_get(), and GNUNET_RESOLVER_ip_get().
|
static |
We've been asked to convert an address to a string without a reverse lookup, either because the client asked for it or because the DNS lookup hit a timeout.
Do the numeric conversion and invoke the callback.
| cls | struct GNUNET_RESOLVER_RequestHandle for the request |
Definition at line 1030 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::af, GNUNET_RESOLVER_RequestHandle::cls, GNUNET_RESOLVER_RequestHandle::data_len, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_SCHEDULER_cancel(), LOG, GNUNET_RESOLVER_RequestHandle::name_callback, no_resolve(), result, and GNUNET_RESOLVER_RequestHandle::task.
Referenced by GNUNET_RESOLVER_hostname_get().
|
static |
Possible hostnames for "loopback".
Definition at line 48 of file resolver_api.c.
Referenced by check_config(), and GNUNET_RESOLVER_ip_get().
|
static |
Configuration.
Definition at line 58 of file resolver_api.c.
Referenced by check_config(), GNUNET_RESOLVER_connect(), reconnect(), and reconnect_task().
|
static |
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Definition at line 64 of file resolver_api.c.
Referenced by add_service_handle(), adv_transmit(), cadet_mq_cancel_impl(), cadet_mq_destroy_impl(), cadet_mq_send_impl(), callback_client_connect(), check_peer_online(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), client_connect_cb(), connect_cb(), connect_cb(), connect_cb(), connect_handler(), connect_handler(), connect_notify(), connection_client_cancel_impl(), connection_client_destroy_impl(), connection_client_send_impl(), connects(), continue_writing(), core_connect_cb(), core_connect_cb(), core_connects(), core_mq_cancel_impl(), core_mq_destroy_impl(), core_mq_send_impl(), create_srv_handle(), do_send(), GCP_set_mq(), GNUNET_CADET_drop_message(), GNUNET_FS_indexing_send_list(), GNUNET_MQ_assoc_add(), GNUNET_MQ_assoc_get(), GNUNET_MQ_assoc_remove(), GNUNET_MQ_destroy(), GNUNET_MQ_destroy_notify(), GNUNET_MQ_destroy_notify_cancel(), GNUNET_MQ_env_get_options(), GNUNET_MQ_get_current_envelope(), GNUNET_MQ_get_last_envelope(), GNUNET_MQ_get_length(), GNUNET_MQ_impl_current(), GNUNET_MQ_impl_send_continue(), GNUNET_MQ_impl_send_in_flight(), GNUNET_MQ_impl_state(), GNUNET_MQ_inject_error(), GNUNET_MQ_inject_message(), GNUNET_MQ_queue_for_callbacks(), GNUNET_MQ_send(), GNUNET_MQ_send_cancel(), GNUNET_MQ_send_copy(), GNUNET_MQ_set_handlers_closure(), GNUNET_MQ_set_options(), GNUNET_MQ_unsent_head(), GNUNET_notification_context_add(), GNUNET_RESOLVER_disconnect(), GNUNET_TRANSPORT_communicator_mq_add(), GSC_KX_handle_client_monitor_peers(), GSF_peer_connect_handler(), handle_core_connect(), handle_core_connect(), handle_response(), handle_start(), handle_transport_notify_connect(), impl_send_continue(), mq_destroy(), mq_destroy(), mq_destroy(), mq_destroy_d(), mq_destroy_d(), mq_destroy_d(), mq_destroy_impl(), mq_destroy_kx(), mq_error_handler(), mq_send(), mq_send(), mq_send(), mq_send_d(), mq_send_d(), mq_send_d(), mq_send_impl(), mq_send_kx(), notify_connect(), notify_connect(), notify_connect(), path_info_iterator(), process_requests(), queue_destroy(), reconnect(), reconnect_task(), return_agpl(), return_agpl(), send_message(), send_msg_with_kx(), send_simple_cb(), send_simple_cb(), send_simple_cb(), send_to_channel(), send_tunnel_envelope(), service_mq_cancel(), service_mq_send(), set_mq(), and transmit_pending().
|
static |
Head of DLL of requests.
Definition at line 69 of file resolver_api.c.
Referenced by check_disconnect(), GNUNET_RESOLVER_disconnect(), GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), GNUNET_RESOLVER_request_cancel(), handle_response(), process_requests(), reconnect(), and reconnect_task().
|
static |
Tail of DLL of requests.
Definition at line 74 of file resolver_api.c.
Referenced by GNUNET_RESOLVER_disconnect(), GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), GNUNET_RESOLVER_request_cancel(), and reconnect().
|
static |
ID of the last request we sent to the service.
Definition at line 79 of file resolver_api.c.
Referenced by GNUNET_RESOLVER_hostname_get(), and GNUNET_RESOLVER_ip_get().
|
static |
How long should we wait to reconnect?
Definition at line 84 of file resolver_api.c.
Referenced by GNUNET_RESOLVER_connect(), reconnect(), and shutdown_task().
|
static |
Task for reconnecting.
Definition at line 89 of file resolver_api.c.
Referenced by check_disconnect(), GNUNET_RESOLVER_disconnect(), reconnect(), and reconnect_task().
|
static |
Task ID of shutdown task; only present while we have a connection to the resolver service.
Definition at line 95 of file resolver_api.c.
Referenced by check_disconnect(), GNUNET_RESOLVER_disconnect(), GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_ip_get(), process_requests(), and shutdown_task().