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. More... | |
Functions | |
static int | check_config () |
Check that the resolver service runs on localhost (or equivalent). More... | |
void | GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg) |
Create the connection to the resolver service. More... | |
void | GNUNET_RESOLVER_disconnect () |
Destroy the connection to the resolver service. More... | |
static void | shutdown_task (void *cls) |
Task executed on system shutdown. More... | |
static void | check_disconnect () |
Consider disconnecting if we have no further requests pending. More... | |
static char * | no_resolve (int af, const void *ip, socklen_t ip_len) |
Convert IP address to string without DNS resolution. More... | |
static void | reconnect (void) |
Adjust exponential back-off and reconnect to the service. More... | |
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. More... | |
static void | process_requests () |
Process pending requests to the resolver. More... | |
static int | check_response (void *cls, const struct GNUNET_RESOLVER_ResponseMessage *msg) |
Check validity of response with a hostname for a DNS lookup. More... | |
static void | handle_response (void *cls, const struct GNUNET_RESOLVER_ResponseMessage *msg) |
Check validity of response with a hostname for a DNS lookup. More... | |
static void | numeric_resolution (void *cls) |
We've been asked to lookup the address for a hostname and were given a valid numeric string. More... | |
static void | loopback_resolution (void *cls) |
We've been asked to lookup the address for a hostname and were given a variant of "loopback". More... | |
static void | reconnect_task (void *cls) |
Now try to reconnect to the resolver service. More... | |
static void | handle_lookup_timeout (void *cls) |
A DNS resolution timed out. More... | |
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. More... | |
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. More... | |
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. More... | |
char * | GNUNET_RESOLVER_local_fqdn_get () |
Get local fully qualified af name. More... | |
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. More... | |
void | GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh) |
Cancel a request that is still pending with the resolver. More... | |
Variables | |
static const char * | loopback [] |
Possible hostnames for "loopback". More... | |
static const struct GNUNET_CONFIGURATION_Handle * | resolver_cfg |
Configuration. More... | |
static struct GNUNET_MQ_Handle * | mq |
Our connection to the resolver service, created on-demand, but then persists until error or shutdown. More... | |
static struct GNUNET_RESOLVER_RequestHandle * | req_head |
Head of DLL of requests. More... | |
static struct GNUNET_RESOLVER_RequestHandle * | req_tail |
Tail of DLL of requests. More... | |
static uint32_t | last_request_id |
ID of the last request we sent to the service. More... | |
static struct GNUNET_TIME_Relative | backoff |
How long should we wait to reconnect? More... | |
static struct GNUNET_SCHEDULER_Task * | r_task |
Task for reconnecting. More... | |
static struct GNUNET_SCHEDULER_Task * | s_task |
Task ID of shutdown task; only present while we have a connection to the resolver service. More... | |
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.
Referenced by check_disconnect(), and process_requests().
|
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 handle_response(), mq_error_handler(), process_requests(), and reconnect_task().
|
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 GNUNET_RESOLVER_disconnect(), handle_response(), mq_error_handler(), process_requests(), reconnect(), and reconnect_task().
|
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().