GNUnet  0.10.x
Typedefs | Functions
Resolver service

Asynchronous standard DNS lookups. More...

Typedefs

typedef void(* GNUNET_RESOLVER_AddressCallback) (void *cls, const struct sockaddr *addr, socklen_t addrlen)
 Function called by the resolver for each address obtained from DNS. More...
 
typedef void(* GNUNET_RESOLVER_HostnameCallback) (void *cls, const char *hostname)
 Function called by the resolver for each hostname obtained from DNS. More...
 

Functions

void GNUNET_RESOLVER_connect (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Create the connection to the resolver service. More...
 
void GNUNET_RESOLVER_disconnect (void)
 Destroy the connection to the resolver service. More...
 
struct GNUNET_RESOLVER_RequestHandleGNUNET_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...
 
struct GNUNET_RESOLVER_RequestHandleGNUNET_RESOLVER_hostname_resolve (int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *cls)
 Resolve our hostname to an IP address. More...
 
char * GNUNET_RESOLVER_local_fqdn_get (void)
 Get local fully qualified domain name. More...
 
struct GNUNET_RESOLVER_RequestHandleGNUNET_RESOLVER_hostname_get (const struct sockaddr *sa, socklen_t salen, int do_resolve, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_HostnameCallback callback, void *cls)
 Perform a reverse DNS lookup. More...
 
void GNUNET_RESOLVER_request_cancel (struct GNUNET_RESOLVER_RequestHandle *rh)
 Cancel a request that is still pending with the resolver. More...
 

Detailed Description

Asynchronous standard DNS lookups.

Typedef Documentation

◆ GNUNET_RESOLVER_AddressCallback

typedef void(* GNUNET_RESOLVER_AddressCallback) (void *cls, const struct sockaddr *addr, socklen_t addrlen)

Function called by the resolver for each address obtained from DNS.

Parameters
clsclosure
addrone of the addresses of the host, NULL for the last address
addrlenlength of addr

Definition at line 56 of file gnunet_resolver_service.h.

◆ GNUNET_RESOLVER_HostnameCallback

typedef void(* GNUNET_RESOLVER_HostnameCallback) (void *cls, const char *hostname)

Function called by the resolver for each hostname obtained from DNS.

Parameters
clsclosure
hostnameone of the names for the host, NULL on the last call to the callback

Definition at line 125 of file gnunet_resolver_service.h.

Function Documentation

◆ GNUNET_RESOLVER_connect()

void GNUNET_RESOLVER_connect ( const struct GNUNET_CONFIGURATION_Handle cfg)

Create the connection to the resolver service.

Parameters
cfgconfiguration to use

Definition at line 254 of file resolver_api.c.

References backoff, cfg, GNUNET_assert, and GNUNET_TIME_UNIT_MILLISECONDS.

Referenced by GNUNET_PROGRAM_run2(), GNUNET_SERVICE_run_(), program_main(), reversal_test(), and service_task().

255 {
256  GNUNET_assert (NULL != cfg);
258  resolver_cfg = cfg;
259 }
static struct GNUNET_TIME_Relative backoff
How long should we wait to reconnect?
Definition: resolver_api.c:81
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static const struct GNUNET_CONFIGURATION_Handle * resolver_cfg
Configuration.
Definition: resolver_api.c:55
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
Here is the caller graph for this function:

◆ GNUNET_RESOLVER_disconnect()

void GNUNET_RESOLVER_disconnect ( void  )

Destroy the connection to the resolver service.

Definition at line 266 of file resolver_api.c.

References GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, LOG, and GNUNET_RESOLVER_RequestHandle::was_transmitted.

Referenced by shutdown_task().

267 {
269 
270  while (NULL != (rh = req_head))
271  {
274  req_tail,
275  rh);
276  GNUNET_free (rh);
277  }
278  if (NULL != mq)
279  {
281  "Disconnecting from DNS service\n");
283  mq = NULL;
284  }
285  if (NULL != r_task)
286  {
288  r_task = NULL;
289  }
290  if (NULL != s_task)
291  {
293  s_task = NULL;
294  }
295 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_SCHEDULER_Task * r_task
Task for reconnecting.
Definition: resolver_api.c:86
static struct GNUNET_RESOLVER_RequestHandle * req_tail
Tail of DLL of requests.
Definition: resolver_api.c:71
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define LOG(kind,...)
Definition: resolver_api.c:32
int was_transmitted
Has this request been transmitted to the service? GNUNET_YES if transmitted GNUNET_YES if not transmi...
Definition: resolver_api.c:157
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Handle to a request given to the resolver.
Definition: resolver_api.c:100
static struct GNUNET_SCHEDULER_Task * s_task
Task ID of shutdown task; only present while we have a connection to the resolver service...
Definition: resolver_api.c:92
static struct GNUNET_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown...
Definition: resolver_api.c:61
static struct GNUNET_RESOLVER_RequestHandle * req_head
Head of DLL of requests.
Definition: resolver_api.c:66
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_RESOLVER_ip_get()

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.

Parameters
hostnamethe hostname to resolve
afAF_INET or AF_INET6; use AF_UNSPEC for "any"
callbackfunction to call with addresses
callback_clsclosure for callback
timeouthow long to try resolving
Returns
handle that can be used to cancel the request, NULL on error

Definition at line 927 of file resolver_api.c.

References GNUNET_RESOLVER_RequestHandle::addr_callback, GNUNET_RESOLVER_RequestHandle::af, check_config(), GNUNET_RESOLVER_RequestHandle::cls, GNUNET_RESOLVER_RequestHandle::data_len, GNUNET_RESOLVER_RequestHandle::direction, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_malloc, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, handle_lookup_timeout(), GNUNET_RESOLVER_RequestHandle::id, inet_pton(), last_request_id, LOG, loopback, loopback_resolution(), numeric_resolution(), process_requests(), GNUNET_RESOLVER_RequestHandle::task, GNUNET_RESOLVER_RequestHandle::timeout, and GNUNET_RESOLVER_RequestHandle::was_queued.

Referenced by dns_result_parser(), dyndns_lookup(), GNUNET_CONNECTION_create_from_connect(), GNUNET_NAT_stun_make_request(), GNUNET_RESOLVER_hostname_resolve(), handle_gns_cname_result(), http_common_dns_ip_lookup(), recursive_gns2dns_resolution(), run(), and start_connect().

932 {
934  size_t slen;
935  struct in_addr v4;
936  struct in6_addr v6;
937 
938  slen = strlen (hostname) + 1;
939  if (slen + sizeof (struct GNUNET_RESOLVER_GetMessage) >=
941  {
942  GNUNET_break (0);
943  return NULL;
944  }
946  "Trying to resolve hostname `%s'.\n",
947  hostname);
948  rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + slen);
949  rh->af = af;
950  rh->id = ++last_request_id;
951  rh->addr_callback = callback;
952  rh->cls = callback_cls;
953  GNUNET_memcpy (&rh[1],
954  hostname,
955  slen);
956  rh->data_len = slen;
958  rh->direction = GNUNET_NO;
959  /* first, check if this is a numeric address */
960  if ( ( (1 == inet_pton (AF_INET,
961  hostname,
962  &v4)) &&
963  ( (af == AF_INET) ||
964  (af == AF_UNSPEC) ) ) ||
965  ( (1 == inet_pton (AF_INET6,
966  hostname,
967  &v6)) &&
968  ( (af == AF_INET6) ||
969  (af == AF_UNSPEC)) ) )
970  {
972  rh);
973  return rh;
974  }
975  /* then, check if this is a loopback address */
976  for (unsigned int i = 0;
977  NULL != loopback[i];
978  i++)
979  if (0 == strcasecmp (loopback[i],
980  hostname))
981  {
983  rh);
984  return rh;
985  }
986  if (GNUNET_OK != check_config ())
987  {
988  GNUNET_free (rh);
989  return NULL;
990  }
991  rh->task = GNUNET_SCHEDULER_add_delayed (timeout,
993  rh);
995  req_tail,
996  rh);
997  rh->was_queued = GNUNET_YES;
998  if (NULL != s_task)
999  {
1001  s_task = NULL;
1002  }
1003  process_requests ();
1004  return rh;
1005 }
static struct GNUNET_RESOLVER_RequestHandle * req_tail
Tail of DLL of requests.
Definition: resolver_api.c:71
GNUNET_RESOLVER_AddressCallback addr_callback
Callback if this is an name resolution request, otherwise NULL.
Definition: resolver_api.c:117
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
static void numeric_resolution(void *cls)
We've been asked to lookup the address for a hostname and were given a valid numeric string...
Definition: resolver_api.c:645
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void process_requests()
Process pending requests to the resolver.
Definition: resolver_api.c:421
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define LOG(kind,...)
Definition: resolver_api.c:32
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
#define GNUNET_memcpy(dst, src, n)
static const char * loopback[]
Possible hostnames for "loopback".
Definition: resolver_api.c:45
static uint32_t last_request_id
ID of the last request we sent to the service.
Definition: resolver_api.c:76
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
int af
Desired address family.
Definition: resolver_api.c:144
struct GNUNET_TIME_Absolute timeout
When should this request time out?
Definition: resolver_api.c:133
struct GNUNET_SCHEDULER_Task * task
Task handle for making reply callbacks in numeric lookups asynchronous, and for timeout handling...
Definition: resolver_api.c:139
Handle to a request given to the resolver.
Definition: resolver_api.c:100
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
int was_queued
Did we add this request to the queue?
Definition: resolver_api.c:162
static struct GNUNET_SCHEDULER_Task * s_task
Task ID of shutdown task; only present while we have a connection to the resolver service...
Definition: resolver_api.c:92
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
static void loopback_resolution(void *cls)
We've been asked to lookup the address for a hostname and were given a variant of "loopback"...
Definition: resolver_api.c:721
static char * hostname
Our hostname; we give this to all the peers we start.
static int check_config()
Check that the resolver service runs on localhost (or equivalent).
Definition: resolver_api.c:189
static struct GNUNET_RESOLVER_RequestHandle * req_head
Head of DLL of requests.
Definition: resolver_api.c:66
static int inet_pton(int af, const char *cp, struct in_addr *buf)
Convert IPv4 address from text to binary form.
void * cls
Closure for the callbacks.
Definition: resolver_api.c:128
#define GNUNET_YES
Definition: gnunet_common.h:80
size_t data_len
Length of the data that follows this struct.
Definition: resolver_api.c:177
Request for the resolver.
Definition: resolver.h:43
uint32_t id
Identifies the request.
Definition: resolver_api.c:149
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:167
#define GNUNET_malloc(size)
Wrapper around malloc.
static void handle_lookup_timeout(void *cls)
A DNS resolution timed out.
Definition: resolver_api.c:867
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_RESOLVER_hostname_resolve()

struct GNUNET_RESOLVER_RequestHandle* GNUNET_RESOLVER_hostname_resolve ( int  af,
struct GNUNET_TIME_Relative  timeout,
GNUNET_RESOLVER_AddressCallback  callback,
void *  cls 
)

Resolve our hostname to an IP address.

Parameters
afAF_INET or AF_INET6; use AF_UNSPEC for "any"
callbackfunction to call with addresses
clsclosure for callback
timeouthow long to try resolving
Returns
handle that can be used to cancel the request, NULL on error

Resolve our hostname to an IP address.

Parameters
afAF_INET or AF_INET6; use AF_UNSPEC for "any"
timeouthow long to try resolving
callbackfunction to call with addresses
clsclosure for callback
Returns
handle that can be used to cancel the request, NULL on error

Definition at line 1220 of file resolver_api.c.

References GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_OS_get_hostname_max_length, GNUNET_RESOLVER_ip_get(), hostname, LOG, and LOG_STRERROR.

1224 {
1226 
1227  if (0 != gethostname (hostname, sizeof (hostname) - 1))
1228  {
1230  "gethostname");
1231  return NULL;
1232  }
1234  "Resolving our hostname `%s'\n",
1235  hostname);
1236  return GNUNET_RESOLVER_ip_get (hostname,
1237  af,
1238  timeout,
1239  callback,
1240  cls);
1241 }
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.
Definition: resolver_api.c:927
#define LOG_STRERROR(kind, syscall)
Definition: resolver_api.c:34
#define LOG(kind,...)
Definition: resolver_api.c:32
#define GNUNET_OS_get_hostname_max_length()
Get maximum string length returned by gethostname()
static char * hostname
Our hostname; we give this to all the peers we start.
Here is the call graph for this function:

◆ GNUNET_RESOLVER_local_fqdn_get()

char* GNUNET_RESOLVER_local_fqdn_get ( void  )

Get local fully qualified domain name.

Returns
local hostname, caller must free

Get local fully qualified domain name.

Returns
fqdn

Definition at line 1134 of file resolver_api.c.

References _, ai, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_OS_get_hostname_max_length, GNUNET_strdup, host, hostname, LOG, LOG_STRERROR, and ret.

Referenced by GNUNET_HOSTLIST_server_start().

1135 {
1137 
1138  if (0 != gethostname (hostname,
1139  sizeof (hostname) - 1))
1140  {
1142  "gethostname");
1143  return NULL;
1144  }
1146  "Resolving our FQDN `%s'\n",
1147  hostname);
1148 #if HAVE_GETADDRINFO
1149  {
1150  struct addrinfo *ai;
1151  int ret;
1152  char *rval;
1153 
1154  if (0 != (ret = getaddrinfo (hostname,
1155  NULL,
1156  NULL,
1157  &ai)))
1158  {
1160  _("Could not resolve our FQDN: %s\n"),
1161  gai_strerror (ret));
1162  return NULL;
1163  }
1164  if (NULL != ai->ai_canonname)
1165  rval = GNUNET_strdup (ai->ai_canonname);
1166  else
1167  rval = GNUNET_strdup (hostname);
1168  freeaddrinfo (ai);
1169  return rval;
1170  }
1171 #elif HAVE_GETHOSTBYNAME2
1172  {
1173  struct hostent *host;
1174 
1175  host = gethostbyname2 (hostname,
1176  AF_INET);
1177  if (NULL == host)
1178  host = gethostbyname2 (hostname,
1179  AF_INET6);
1180  if (NULL == host)
1181  {
1183  _("Could not resolve our FQDN: %s\n"),
1184  hstrerror (h_errno));
1185  return NULL;
1186  }
1187  return GNUNET_strdup (host->h_name);
1188  }
1189 #elif HAVE_GETHOSTBYNAME
1190  {
1191  struct hostent *host;
1192 
1193  host = gethostbyname (hostname);
1194  if (NULL == host)
1195  {
1197  _("Could not resolve our FQDN: %s\n"),
1198  hstrerror (h_errno));
1199  return NULL;
1200  }
1201  return GNUNET_strdup (host->h_name);
1202  }
1203 #else
1204  /* fallback: just hope name is already FQDN */
1205  return GNUNET_strdup (hostname);
1206 #endif
1207 }
static int ret
Final status code.
Definition: gnunet-arm.c:89
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define LOG_STRERROR(kind, syscall)
Definition: resolver_api.c:34
#define LOG(kind,...)
Definition: resolver_api.c:32
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
#define GNUNET_OS_get_hostname_max_length()
Get maximum string length returned by gethostname()
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
GUID host
static char * hostname
Our hostname; we give this to all the peers we start.
Here is the caller graph for this function:

◆ GNUNET_RESOLVER_hostname_get()

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 
)

Perform a reverse DNS lookup.

Parameters
sahost address
salenlength of sa
do_resolveuse GNUNET_NO to return numeric hostname
timeouthow long to try resolving
callbackfunction to call with hostnames
clsclosure for callback
Returns
handle that can be used to cancel the request, NULL on error

Perform a reverse DNS lookup.

Parameters
sahost address
salenlength of host address in sa
do_resolveuse GNUNET_NO to return numeric hostname
timeouthow long to try resolving
callbackfunction to call with hostnames last callback is NULL when finished
clsclosure for callback
Returns
handle that can be used to cancel the request

Definition at line 1059 of file resolver_api.c.

References _, GNUNET_RESOLVER_RequestHandle::af, check_config(), GNUNET_RESOLVER_RequestHandle::cls, GNUNET_RESOLVER_RequestHandle::data_len, GNUNET_RESOLVER_RequestHandle::direction, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert_tail, GNUNET_ERROR_TYPE_ERROR, GNUNET_malloc, GNUNET_memcpy, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_cancel(), GNUNET_TIME_relative_to_absolute(), GNUNET_YES, handle_lookup_timeout(), GNUNET_RESOLVER_RequestHandle::id, last_request_id, LOG, GNUNET_RESOLVER_RequestHandle::name_callback, numeric_reverse(), process_requests(), GNUNET_RESOLVER_RequestHandle::received_response, GNUNET_RESOLVER_RequestHandle::task, GNUNET_RESOLVER_RequestHandle::timeout, and GNUNET_RESOLVER_RequestHandle::was_queued.

Referenced by http_common_dns_reverse_lookup(), run(), tcp_plugin_address_pretty_printer(), and udp_plugin_address_pretty_printer().

1065 {
1066  struct GNUNET_RESOLVER_RequestHandle *rh;
1067  size_t ip_len;
1068  const void *ip;
1069 
1070  if (GNUNET_OK != check_config ())
1071  {
1073  _("Resolver not configured correctly.\n"));
1074  return NULL;
1075  }
1076 
1077  switch (sa->sa_family)
1078  {
1079  case AF_INET:
1080  GNUNET_assert (salen == sizeof (struct sockaddr_in));
1081  ip_len = sizeof (struct in_addr);
1082  ip = &((const struct sockaddr_in*)sa)->sin_addr;
1083  break;
1084  case AF_INET6:
1085  GNUNET_assert (salen == sizeof (struct sockaddr_in6));
1086  ip_len = sizeof (struct in6_addr);
1087  ip = &((const struct sockaddr_in6*)sa)->sin6_addr;
1088  break;
1089  default:
1090  GNUNET_break (0);
1091  return NULL;
1092  }
1093  rh = GNUNET_malloc (sizeof (struct GNUNET_RESOLVER_RequestHandle) + salen);
1094  rh->name_callback = callback;
1095  rh->cls = cls;
1096  rh->af = sa->sa_family;
1097  rh->id = ++last_request_id;
1098  rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1099  GNUNET_memcpy (&rh[1],
1100  ip,
1101  ip_len);
1102  rh->data_len = ip_len;
1103  rh->direction = GNUNET_YES;
1105  if (GNUNET_NO == do_resolve)
1106  {
1108  rh);
1109  return rh;
1110  }
1111  rh->task = GNUNET_SCHEDULER_add_delayed (timeout,
1113  rh);
1115  req_tail,
1116  rh);
1117  rh->was_queued = GNUNET_YES;
1118  if (NULL != s_task)
1119  {
1121  s_task = NULL;
1122  }
1123  process_requests ();
1124  return rh;
1125 }
static struct GNUNET_RESOLVER_RequestHandle * req_tail
Tail of DLL of requests.
Definition: resolver_api.c:71
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static void process_requests()
Process pending requests to the resolver.
Definition: resolver_api.c:421
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define LOG(kind,...)
Definition: resolver_api.c:32
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
GNUNET_RESOLVER_HostnameCallback name_callback
Callback if this is a reverse lookup request, otherwise NULL.
Definition: resolver_api.c:123
static void numeric_reverse(void *cls)
We've been asked to convert an address to a string without a reverse lookup, either because the clien...
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
#define GNUNET_memcpy(dst, src, n)
static uint32_t last_request_id
ID of the last request we sent to the service.
Definition: resolver_api.c:76
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1273
int af
Desired address family.
Definition: resolver_api.c:144
struct GNUNET_TIME_Absolute timeout
When should this request time out?
Definition: resolver_api.c:133
struct GNUNET_SCHEDULER_Task * task
Task handle for making reply callbacks in numeric lookups asynchronous, and for timeout handling...
Definition: resolver_api.c:139
Handle to a request given to the resolver.
Definition: resolver_api.c:100
#define GNUNET_CONTAINER_DLL_insert_tail(head, tail, element)
Insert an element at the tail of a DLL.
int was_queued
Did we add this request to the queue?
Definition: resolver_api.c:162
static struct GNUNET_SCHEDULER_Task * s_task
Task ID of shutdown task; only present while we have a connection to the resolver service...
Definition: resolver_api.c:92
static int check_config()
Check that the resolver service runs on localhost (or equivalent).
Definition: resolver_api.c:189
static struct GNUNET_RESOLVER_RequestHandle * req_head
Head of DLL of requests.
Definition: resolver_api.c:66
void * cls
Closure for the callbacks.
Definition: resolver_api.c:128
#define GNUNET_YES
Definition: gnunet_common.h:80
size_t data_len
Length of the data that follows this struct.
Definition: resolver_api.c:177
uint32_t id
Identifies the request.
Definition: resolver_api.c:149
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:167
int received_response
GNUNET_YES if a response was received
Definition: resolver_api.c:172
#define GNUNET_malloc(size)
Wrapper around malloc.
static void handle_lookup_timeout(void *cls)
A DNS resolution timed out.
Definition: resolver_api.c:867
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_RESOLVER_request_cancel()

void GNUNET_RESOLVER_request_cancel ( struct GNUNET_RESOLVER_RequestHandle rh)

Cancel a request that is still pending with the resolver.

Note that a client MUST NOT cancel a request that has been completed (i.e, the callback has been called to signal timeout or the final result).

Parameters
rhhandle of request to cancel

Definition at line 1253 of file resolver_api.c.

References check_disconnect(), GNUNET_RESOLVER_RequestHandle::direction, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_SYSERR, GNUNET_YES, and LOG.

Referenced by client_disconnect_cb(), connection_client_destroy_impl(), dns_result_parser(), GNS_resolver_lookup_cancel(), GNUNET_CONNECTION_destroy(), GNUNET_NAT_stun_make_request_cancel(), handle_gns_cname_result(), handle_lookup_timeout(), handle_response(), libgnunet_plugin_transport_tcp_done(), and libgnunet_plugin_transport_udp_done().

1254 {
1255  if (GNUNET_NO == rh->direction)
1257  "Asked to cancel request to resolve hostname `%s'.\n",
1258  (const char *) &rh[1]);
1259  if (NULL != rh->task)
1260  {
1262  rh->task = NULL;
1263  }
1264  if (GNUNET_NO == rh->was_transmitted)
1265  {
1266  if (GNUNET_YES == rh->was_queued)
1268  req_tail,
1269  rh);
1270  GNUNET_free (rh);
1271  check_disconnect ();
1272  return;
1273  }
1275  rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
1276  check_disconnect ();
1277 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNUNET_RESOLVER_RequestHandle * req_tail
Tail of DLL of requests.
Definition: resolver_api.c:71
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define LOG(kind,...)
Definition: resolver_api.c:32
int was_transmitted
Has this request been transmitted to the service? GNUNET_YES if transmitted GNUNET_YES if not transmi...
Definition: resolver_api.c:157
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct GNUNET_SCHEDULER_Task * task
Task handle for making reply callbacks in numeric lookups asynchronous, and for timeout handling...
Definition: resolver_api.c:139
int was_queued
Did we add this request to the queue?
Definition: resolver_api.c:162
static struct GNUNET_RESOLVER_RequestHandle * req_head
Head of DLL of requests.
Definition: resolver_api.c:66
static void check_disconnect()
Consider disconnecting if we have no further requests pending.
Definition: resolver_api.c:315
#define GNUNET_YES
Definition: gnunet_common.h:80
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:167
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
Here is the caller graph for this function: