![]() |
GNUnet
0.11.x
|
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 32 of file resolver_api.c.
Referenced by check_config(), GNUNET_RESOLVER_disconnect(), GNUNET_RESOLVER_hostname_get(), GNUNET_RESOLVER_hostname_resolve(), GNUNET_RESOLVER_ip_get(), GNUNET_RESOLVER_local_fqdn_get(), GNUNET_RESOLVER_request_cancel(), handle_lookup_timeout(), handle_response(), loopback_resolution(), mq_error_handler(), numeric_reverse(), process_requests(), reconnect(), and reconnect_task().
#define LOG_STRERROR | ( | kind, | |
syscall | |||
) |
Definition at line 34 of file resolver_api.c.
Referenced by GNUNET_RESOLVER_hostname_resolve(), GNUNET_RESOLVER_local_fqdn_get(), and no_resolve().
#define MAX_HOSTNAME 1024 |
Maximum supported length for a hostname.
Definition at line 41 of file resolver_api.c.
|
static |
Check that the resolver service runs on localhost (or equivalent).
Definition at line 190 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, hostname, LOG, and loopback.
Referenced by GNUNET_RESOLVER_hostname_get(), and GNUNET_RESOLVER_ip_get().
|
static |
Task executed on system shutdown.
Definition at line 305 of file resolver_api.c.
References backoff, GNUNET_RESOLVER_disconnect(), and GNUNET_TIME_UNIT_MILLISECONDS.
Referenced by check_disconnect(), and process_requests().
|
static |
Consider disconnecting if we have no further requests pending.
Definition at line 318 of file resolver_api.c.
References GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_RESOLVER_RequestHandle::next, 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 347 of file resolver_api.c.
References buf, GNUNET_break, GNUNET_ERROR_TYPE_WARNING, GNUNET_strdup, LOG_STRERROR, and reconnect().
Referenced by handle_lookup_timeout(), handle_response(), and numeric_reverse().
|
static |
Adjust exponential back-off and reconnect to the service.
Definition at line 827 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, reconnect_task(), and GNUNET_RESOLVER_RequestHandle::was_transmitted.
Referenced by handle_response(), mq_error_handler(), no_resolve(), 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 409 of file resolver_api.c.
References GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_destroy(), LOG, and reconnect().
Referenced by reconnect_task().
|
static |
Process pending requests to the resolver.
Definition at line 426 of file resolver_api.c.
References GNUNET_RESOLVER_GetMessage::af, GNUNET_RESOLVER_RequestHandle::af, GNUNET_RESOLVER_GetMessage::client_id, GNUNET_RESOLVER_RequestHandle::data_len, GNUNET_RESOLVER_GetMessage::direction, 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, msg, reconnect(), req_head, 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 475 of file resolver_api.c.
References GNUNET_OK.
|
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 495 of file resolver_api.c.
References GNUNET_RESOLVER_RequestHandle::addr_callback, GNUNET_RESOLVER_RequestHandle::af, GNUNET_RESOLVER_ResponseMessage::client_id, 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_ResponseMessage::header, hostname, GNUNET_RESOLVER_RequestHandle::id, LOG, GNUNET_RESOLVER_RequestHandle::name_callback, GNUNET_RESOLVER_RequestHandle::next, no_resolve(), process_requests(), GNUNET_RESOLVER_RequestHandle::received_response, reconnect(), req_head, size, GNUNET_MessageHeader::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 651 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, hostname, 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 727 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 791 of file resolver_api.c.
References GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_RESOLVER_RESPONSE, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, LOG, mq_error_handler(), process_requests(), reconnect(), and response.
Referenced by reconnect().
|
static |
A DNS resolution timed out.
Notify the application.
cls | the struct GNUNET_RESOLVER_RequestHandle * |
Definition at line 879 of file resolver_api.c.
References _, GNUNET_RESOLVER_RequestHandle::af, buf, 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 1029 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 47 of file resolver_api.c.
Referenced by check_config(), and GNUNET_RESOLVER_ip_get().
|
static |
Configuration.
Definition at line 57 of file resolver_api.c.
|
static |
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
Definition at line 63 of file resolver_api.c.
|
static |
Head of DLL of requests.
Definition at line 68 of file resolver_api.c.
Referenced by handle_response(), and process_requests().
|
static |
Tail of DLL of requests.
Definition at line 73 of file resolver_api.c.
|
static |
ID of the last request we sent to the service.
Definition at line 78 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 83 of file resolver_api.c.
Referenced by GNUNET_RESOLVER_connect(), reconnect(), and shutdown_task().
|
static |
Task for reconnecting.
Definition at line 88 of file resolver_api.c.
|
static |
Task ID of shutdown task; only present while we have a connection to the resolver service.
Definition at line 94 of file resolver_api.c.