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 252 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().

253 {
254  GNUNET_assert(NULL != cfg);
256  resolver_cfg = cfg;
257 }
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 264 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().

265 {
267 
268  while (NULL != (rh = req_head))
269  {
272  req_tail,
273  rh);
274  GNUNET_free(rh);
275  }
276  if (NULL != mq)
277  {
279  "Disconnecting from DNS service\n");
281  mq = NULL;
282  }
283  if (NULL != r_task)
284  {
286  r_task = NULL;
287  }
288  if (NULL != s_task)
289  {
291  s_task = NULL;
292  }
293 }
#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:155
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:821
#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:956
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 933 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, 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().

938 {
940  size_t slen;
941  struct in_addr v4;
942  struct in6_addr v6;
943 
944  slen = strlen(hostname) + 1;
945  if (slen + sizeof(struct GNUNET_RESOLVER_GetMessage) >=
947  {
948  GNUNET_break(0);
949  return NULL;
950  }
952  "Trying to resolve hostname `%s'.\n",
953  hostname);
954  rh = GNUNET_malloc(sizeof(struct GNUNET_RESOLVER_RequestHandle) + slen);
955  rh->af = af;
956  rh->id = ++last_request_id;
957  rh->addr_callback = callback;
958  rh->cls = callback_cls;
959  GNUNET_memcpy(&rh[1],
960  hostname,
961  slen);
962  rh->data_len = slen;
964  rh->direction = GNUNET_NO;
965  /* first, check if this is a numeric address */
966  if (((1 == inet_pton(AF_INET,
967  hostname,
968  &v4)) &&
969  ((af == AF_INET) ||
970  (af == AF_UNSPEC))) ||
971  ((1 == inet_pton(AF_INET6,
972  hostname,
973  &v6)) &&
974  ((af == AF_INET6) ||
975  (af == AF_UNSPEC))))
976  {
978  rh);
979  return rh;
980  }
981  /* then, check if this is a loopback address */
982  for (unsigned int i = 0;
983  NULL != loopback[i];
984  i++)
985  if (0 == strcasecmp(loopback[i],
986  hostname))
987  {
989  rh);
990  return rh;
991  }
992  if (GNUNET_OK != check_config())
993  {
994  GNUNET_free(rh);
995  return NULL;
996  }
997  rh->task = GNUNET_SCHEDULER_add_delayed(timeout,
999  rh);
1001  req_tail,
1002  rh);
1003  rh->was_queued = GNUNET_YES;
1004  if (NULL != s_task)
1005  {
1007  s_task = NULL;
1008  }
1009  process_requests();
1010  return rh;
1011 }
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:115
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:246
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_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:1237
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:1264
int af
Desired address family.
Definition: resolver_api.c:142
struct GNUNET_TIME_Absolute timeout
When should this request time out?
Definition: resolver_api.c:131
struct GNUNET_SCHEDULER_Task * task
Task handle for making reply callbacks in numeric lookups asynchronous, and for timeout handling...
Definition: resolver_api.c:137
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:160
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:187
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:126
#define GNUNET_YES
Definition: gnunet_common.h:77
size_t data_len
Length of the data that follows this struct.
Definition: resolver_api.c:175
Request for the resolver.
Definition: resolver.h:43
uint32_t id
Identifies the request.
Definition: resolver_api.c:147
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:165
#define GNUNET_malloc(size)
Wrapper around malloc.
static void handle_lookup_timeout(void *cls)
A DNS resolution timed out.
Definition: resolver_api.c:873
#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:956
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 1228 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.

1232 {
1234 
1235  if (0 != gethostname(hostname, sizeof(hostname) - 1))
1236  {
1238  "gethostname");
1239  return NULL;
1240  }
1242  "Resolving our hostname `%s'\n",
1243  hostname);
1244  return GNUNET_RESOLVER_ip_get(hostname,
1245  af,
1246  timeout,
1247  callback,
1248  cls);
1249 }
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:933
#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 1142 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, hostname, LOG, LOG_STRERROR, and ret.

Referenced by GNUNET_HOSTLIST_server_start().

1143 {
1145 
1146  if (0 != gethostname(hostname,
1147  sizeof(hostname) - 1))
1148  {
1150  "gethostname");
1151  return NULL;
1152  }
1154  "Resolving our FQDN `%s'\n",
1155  hostname);
1156 #if HAVE_GETADDRINFO
1157  {
1158  struct addrinfo *ai;
1159  int ret;
1160  char *rval;
1161 
1162  if (0 != (ret = getaddrinfo(hostname,
1163  NULL,
1164  NULL,
1165  &ai)))
1166  {
1168  _("Could not resolve our FQDN: %s\n"),
1169  gai_strerror(ret));
1170  return NULL;
1171  }
1172  if (NULL != ai->ai_canonname)
1173  rval = GNUNET_strdup(ai->ai_canonname);
1174  else
1175  rval = GNUNET_strdup(hostname);
1176  freeaddrinfo(ai);
1177  return rval;
1178  }
1179 #elif HAVE_GETHOSTBYNAME2
1180  {
1181  struct hostent *host;
1182 
1183  host = gethostbyname2(hostname,
1184  AF_INET);
1185  if (NULL == host)
1186  host = gethostbyname2(hostname,
1187  AF_INET6);
1188  if (NULL == host)
1189  {
1191  _("Could not resolve our FQDN: %s\n"),
1192  hstrerror(h_errno));
1193  return NULL;
1194  }
1195  return GNUNET_strdup(host->h_name);
1196  }
1197 #elif HAVE_GETHOSTBYNAME
1198  {
1199  struct hostent *host;
1200 
1201  host = gethostbyname(hostname);
1202  if (NULL == host)
1203  {
1205  _("Could not resolve our FQDN: %s\n"),
1206  hstrerror(h_errno));
1207  return NULL;
1208  }
1209  return GNUNET_strdup(host->h_name);
1210  }
1211 #else
1212  /* fallback: just hope name is already FQDN */
1213  return GNUNET_strdup(hostname);
1214 #endif
1215 }
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:181
#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.
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 1065 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().

1071 {
1072  struct GNUNET_RESOLVER_RequestHandle *rh;
1073  size_t ip_len;
1074  const void *ip;
1075 
1076  if (GNUNET_OK != check_config())
1077  {
1079  _("Resolver not configured correctly.\n"));
1080  return NULL;
1081  }
1082 
1083  switch (sa->sa_family)
1084  {
1085  case AF_INET:
1086  GNUNET_assert(salen == sizeof(struct sockaddr_in));
1087  ip_len = sizeof(struct in_addr);
1088  ip = &((const struct sockaddr_in*)sa)->sin_addr;
1089  break;
1090 
1091  case AF_INET6:
1092  GNUNET_assert(salen == sizeof(struct sockaddr_in6));
1093  ip_len = sizeof(struct in6_addr);
1094  ip = &((const struct sockaddr_in6*)sa)->sin6_addr;
1095  break;
1096 
1097  default:
1098  GNUNET_break(0);
1099  return NULL;
1100  }
1101  rh = GNUNET_malloc(sizeof(struct GNUNET_RESOLVER_RequestHandle) + salen);
1102  rh->name_callback = callback;
1103  rh->cls = cls;
1104  rh->af = sa->sa_family;
1105  rh->id = ++last_request_id;
1107  GNUNET_memcpy(&rh[1],
1108  ip,
1109  ip_len);
1110  rh->data_len = ip_len;
1111  rh->direction = GNUNET_YES;
1113  if (GNUNET_NO == do_resolve)
1114  {
1116  rh);
1117  return rh;
1118  }
1119  rh->task = GNUNET_SCHEDULER_add_delayed(timeout,
1121  rh);
1123  req_tail,
1124  rh);
1125  rh->was_queued = GNUNET_YES;
1126  if (NULL != s_task)
1127  {
1129  s_task = NULL;
1130  }
1131  process_requests();
1132  return rh;
1133 }
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:246
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:181
GNUNET_RESOLVER_HostnameCallback name_callback
Callback if this is a reverse lookup request, otherwise NULL.
Definition: resolver_api.c:121
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:1237
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:1264
int af
Desired address family.
Definition: resolver_api.c:142
struct GNUNET_TIME_Absolute timeout
When should this request time out?
Definition: resolver_api.c:131
struct GNUNET_SCHEDULER_Task * task
Task handle for making reply callbacks in numeric lookups asynchronous, and for timeout handling...
Definition: resolver_api.c:137
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:160
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:187
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:126
#define GNUNET_YES
Definition: gnunet_common.h:77
size_t data_len
Length of the data that follows this struct.
Definition: resolver_api.c:175
uint32_t id
Identifies the request.
Definition: resolver_api.c:147
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:165
int received_response
GNUNET_YES if a response was received
Definition: resolver_api.c:170
#define GNUNET_malloc(size)
Wrapper around malloc.
static void handle_lookup_timeout(void *cls)
A DNS resolution timed out.
Definition: resolver_api.c:873
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:956
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 1261 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().

1262 {
1263  if (GNUNET_NO == rh->direction)
1265  "Asked to cancel request to resolve hostname `%s'.\n",
1266  (const char *)&rh[1]);
1267  if (NULL != rh->task)
1268  {
1270  rh->task = NULL;
1271  }
1272  if (GNUNET_NO == rh->was_transmitted)
1273  {
1274  if (GNUNET_YES == rh->was_queued)
1276  req_tail,
1277  rh);
1278  GNUNET_free(rh);
1279  check_disconnect();
1280  return;
1281  }
1283  rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
1284  check_disconnect();
1285 }
#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:78
#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:155
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_SCHEDULER_Task * task
Task handle for making reply callbacks in numeric lookups asynchronous, and for timeout handling...
Definition: resolver_api.c:137
int was_queued
Did we add this request to the queue?
Definition: resolver_api.c:160
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:313
#define GNUNET_YES
Definition: gnunet_common.h:77
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:165
#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:956
Here is the call graph for this function:
Here is the caller graph for this function: