GNUnet  0.11.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 257 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().

258 {
259  GNUNET_assert (NULL != cfg);
261  resolver_cfg = cfg;
262 }
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
static struct GNUNET_TIME_Relative backoff
How long should we wait to reconnect?
Definition: resolver_api.c:83
#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:57
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
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 269 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().

270 {
272 
273  while (NULL != (rh = req_head))
274  {
277  req_tail,
278  rh);
279  GNUNET_free (rh);
280  }
281  if (NULL != mq)
282  {
284  "Disconnecting from DNS service\n");
286  mq = NULL;
287  }
288  if (NULL != r_task)
289  {
291  r_task = NULL;
292  }
293  if (NULL != s_task)
294  {
296  s_task = NULL;
297  }
298 }
#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:88
static struct GNUNET_RESOLVER_RequestHandle * req_tail
Tail of DLL of requests.
Definition: resolver_api.c:73
#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:158
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
Handle to a request given to the resolver.
Definition: resolver_api.c:102
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:94
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:63
static struct GNUNET_RESOLVER_RequestHandle * req_head
Head of DLL of requests.
Definition: resolver_api.c:68
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:966
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 939 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().

944 {
946  size_t slen;
947  struct in_addr v4;
948  struct in6_addr v6;
949 
950  slen = strlen (hostname) + 1;
951  if (slen + sizeof(struct GNUNET_RESOLVER_GetMessage) >=
953  {
954  GNUNET_break (0);
955  return NULL;
956  }
958  "Trying to resolve hostname `%s'.\n",
959  hostname);
960  rh = GNUNET_malloc (sizeof(struct GNUNET_RESOLVER_RequestHandle) + slen);
961  rh->af = af;
962  rh->id = ++last_request_id;
963  rh->addr_callback = callback;
964  rh->cls = callback_cls;
965  GNUNET_memcpy (&rh[1],
966  hostname,
967  slen);
968  rh->data_len = slen;
970  rh->direction = GNUNET_NO;
971  /* first, check if this is a numeric address */
972  if (((1 == inet_pton (AF_INET,
973  hostname,
974  &v4)) &&
975  ((af == AF_INET) ||
976  (af == AF_UNSPEC))) ||
977  ((1 == inet_pton (AF_INET6,
978  hostname,
979  &v6)) &&
980  ((af == AF_INET6) ||
981  (af == AF_UNSPEC))))
982  {
984  rh);
985  return rh;
986  }
987  /* then, check if this is a loopback address */
988  for (unsigned int i = 0;
989  NULL != loopback[i];
990  i++)
991  if (0 == strcasecmp (loopback[i],
992  hostname))
993  {
995  rh);
996  return rh;
997  }
998  if (GNUNET_OK != check_config ())
999  {
1000  GNUNET_free (rh);
1001  return NULL;
1002  }
1003  rh->task = GNUNET_SCHEDULER_add_delayed (timeout,
1005  rh);
1007  req_tail,
1008  rh);
1009  rh->was_queued = GNUNET_YES;
1010  if (NULL != s_task)
1011  {
1013  s_task = NULL;
1014  }
1015  process_requests ();
1016  return rh;
1017 }
static struct GNUNET_RESOLVER_RequestHandle * req_tail
Tail of DLL of requests.
Definition: resolver_api.c:73
GNUNET_RESOLVER_AddressCallback addr_callback
Callback if this is an name resolution request, otherwise NULL.
Definition: resolver_api.c:118
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:651
#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:426
#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:1253
static const char * loopback[]
Possible hostnames for "loopback".
Definition: resolver_api.c:47
static uint32_t last_request_id
ID of the last request we sent to the service.
Definition: resolver_api.c:78
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:1280
int af
Desired address family.
Definition: resolver_api.c:145
struct GNUNET_TIME_Absolute timeout
When should this request time out?
Definition: resolver_api.c:134
struct GNUNET_SCHEDULER_Task * task
Task handle for making reply callbacks in numeric lookups asynchronous, and for timeout handling...
Definition: resolver_api.c:140
Handle to a request given to the resolver.
Definition: resolver_api.c:102
#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:163
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:94
#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:727
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:190
static struct GNUNET_RESOLVER_RequestHandle * req_head
Head of DLL of requests.
Definition: resolver_api.c:68
void * cls
Closure for the callbacks.
Definition: resolver_api.c:129
#define GNUNET_YES
Definition: gnunet_common.h:77
size_t data_len
Length of the data that follows this struct.
Definition: resolver_api.c:178
Request for the resolver.
Definition: resolver.h:43
uint32_t id
Identifies the request.
Definition: resolver_api.c:150
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:168
#define GNUNET_malloc(size)
Wrapper around malloc.
static void handle_lookup_timeout(void *cls)
A DNS resolution timed out.
Definition: resolver_api.c:879
#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:966
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 1234 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.

1238 {
1240 
1241  if (0 != gethostname (hostname, sizeof(hostname) - 1))
1242  {
1244  "gethostname");
1245  return NULL;
1246  }
1248  "Resolving our hostname `%s'\n",
1249  hostname);
1250  return GNUNET_RESOLVER_ip_get (hostname,
1251  af,
1252  timeout,
1253  callback,
1254  cls);
1255 }
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:939
#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 1148 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().

1149 {
1151 
1152  if (0 != gethostname (hostname,
1153  sizeof(hostname) - 1))
1154  {
1156  "gethostname");
1157  return NULL;
1158  }
1160  "Resolving our FQDN `%s'\n",
1161  hostname);
1162 #if HAVE_GETADDRINFO
1163  {
1164  struct addrinfo *ai;
1165  int ret;
1166  char *rval;
1167 
1168  if (0 != (ret = getaddrinfo (hostname,
1169  NULL,
1170  NULL,
1171  &ai)))
1172  {
1174  _ ("Could not resolve our FQDN: %s\n"),
1175  gai_strerror (ret));
1176  return NULL;
1177  }
1178  if (NULL != ai->ai_canonname)
1179  rval = GNUNET_strdup (ai->ai_canonname);
1180  else
1181  rval = GNUNET_strdup (hostname);
1182  freeaddrinfo (ai);
1183  return rval;
1184  }
1185 #elif HAVE_GETHOSTBYNAME2
1186  {
1187  struct hostent *host;
1188 
1189  host = gethostbyname2 (hostname,
1190  AF_INET);
1191  if (NULL == host)
1192  host = gethostbyname2 (hostname,
1193  AF_INET6);
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 #elif HAVE_GETHOSTBYNAME
1204  {
1205  struct hostent *host;
1206 
1207  host = gethostbyname (hostname);
1208  if (NULL == host)
1209  {
1211  _ ("Could not resolve our FQDN: %s\n"),
1212  hstrerror (h_errno));
1213  return NULL;
1214  }
1215  return GNUNET_strdup (host->h_name);
1216  }
1217 #else
1218  /* fallback: just hope name is already FQDN */
1219  return GNUNET_strdup (hostname);
1220 #endif
1221 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#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 1071 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().

1077 {
1078  struct GNUNET_RESOLVER_RequestHandle *rh;
1079  size_t ip_len;
1080  const void *ip;
1081 
1082  if (GNUNET_OK != check_config ())
1083  {
1085  _ ("Resolver not configured correctly.\n"));
1086  return NULL;
1087  }
1088 
1089  switch (sa->sa_family)
1090  {
1091  case AF_INET:
1092  GNUNET_assert (salen == sizeof(struct sockaddr_in));
1093  ip_len = sizeof(struct in_addr);
1094  ip = &((const struct sockaddr_in*) sa)->sin_addr;
1095  break;
1096 
1097  case AF_INET6:
1098  GNUNET_assert (salen == sizeof(struct sockaddr_in6));
1099  ip_len = sizeof(struct in6_addr);
1100  ip = &((const struct sockaddr_in6*) sa)->sin6_addr;
1101  break;
1102 
1103  default:
1104  GNUNET_break (0);
1105  return NULL;
1106  }
1107  rh = GNUNET_malloc (sizeof(struct GNUNET_RESOLVER_RequestHandle) + salen);
1108  rh->name_callback = callback;
1109  rh->cls = cls;
1110  rh->af = sa->sa_family;
1111  rh->id = ++last_request_id;
1112  rh->timeout = GNUNET_TIME_relative_to_absolute (timeout);
1113  GNUNET_memcpy (&rh[1],
1114  ip,
1115  ip_len);
1116  rh->data_len = ip_len;
1117  rh->direction = GNUNET_YES;
1119  if (GNUNET_NO == do_resolve)
1120  {
1122  rh);
1123  return rh;
1124  }
1125  rh->task = GNUNET_SCHEDULER_add_delayed (timeout,
1127  rh);
1129  req_tail,
1130  rh);
1131  rh->was_queued = GNUNET_YES;
1132  if (NULL != s_task)
1133  {
1135  s_task = NULL;
1136  }
1137  process_requests ();
1138  return rh;
1139 }
static struct GNUNET_RESOLVER_RequestHandle * req_tail
Tail of DLL of requests.
Definition: resolver_api.c:73
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:426
#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:124
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:1253
static uint32_t last_request_id
ID of the last request we sent to the service.
Definition: resolver_api.c:78
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:1280
int af
Desired address family.
Definition: resolver_api.c:145
struct GNUNET_TIME_Absolute timeout
When should this request time out?
Definition: resolver_api.c:134
struct GNUNET_SCHEDULER_Task * task
Task handle for making reply callbacks in numeric lookups asynchronous, and for timeout handling...
Definition: resolver_api.c:140
Handle to a request given to the resolver.
Definition: resolver_api.c:102
#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:163
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:94
static int check_config()
Check that the resolver service runs on localhost (or equivalent).
Definition: resolver_api.c:190
static struct GNUNET_RESOLVER_RequestHandle * req_head
Head of DLL of requests.
Definition: resolver_api.c:68
void * cls
Closure for the callbacks.
Definition: resolver_api.c:129
#define GNUNET_YES
Definition: gnunet_common.h:77
size_t data_len
Length of the data that follows this struct.
Definition: resolver_api.c:178
uint32_t id
Identifies the request.
Definition: resolver_api.c:150
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:168
int received_response
GNUNET_YES if a response was received
Definition: resolver_api.c:173
#define GNUNET_malloc(size)
Wrapper around malloc.
static void handle_lookup_timeout(void *cls)
A DNS resolution timed out.
Definition: resolver_api.c:879
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:966
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 1267 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().

1268 {
1269  if (GNUNET_NO == rh->direction)
1271  "Asked to cancel request to resolve hostname `%s'.\n",
1272  (const char *) &rh[1]);
1273  if (NULL != rh->task)
1274  {
1276  rh->task = NULL;
1277  }
1278  if (GNUNET_NO == rh->was_transmitted)
1279  {
1280  if (GNUNET_YES == rh->was_queued)
1282  req_tail,
1283  rh);
1284  GNUNET_free (rh);
1285  check_disconnect ();
1286  return;
1287  }
1289  rh->was_transmitted = GNUNET_SYSERR; /* mark as cancelled */
1290  check_disconnect ();
1291 }
#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:73
#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:158
#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:140
int was_queued
Did we add this request to the queue?
Definition: resolver_api.c:163
static struct GNUNET_RESOLVER_RequestHandle * req_head
Head of DLL of requests.
Definition: resolver_api.c:68
static void check_disconnect()
Consider disconnecting if we have no further requests pending.
Definition: resolver_api.c:318
#define GNUNET_YES
Definition: gnunet_common.h:77
int direction
Desired direction (IP to name or name to IP)
Definition: resolver_api.c:168
#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:966
Here is the call graph for this function:
Here is the caller graph for this function: