GNUnet  0.10.x
Data Structures | Functions | Variables
gnunet-service-gns.c File Reference

GNU Name System (main service) More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_dns_service.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_dht_service.h"
#include "gnunet_namecache_service.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_gns_service.h"
#include "gnunet_statistics_service.h"
#include "gns.h"
#include "gnunet-service-gns_resolver.h"
#include "gnunet-service-gns_interceptor.h"
#include "gnunet_protocols.h"
Include dependency graph for gnunet-service-gns.c:

Go to the source code of this file.

Data Structures

struct  ClientLookupHandle
 Handle to a lookup operation from client via API. More...
 
struct  GnsClient
 Information we track per connected client. More...
 
struct  GNS_TopLevelDomain
 Representation of a TLD, mapping the respective TLD string (i.e. More...
 

Functions

int GNS_find_tld (const char *tld_str, struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
 Find GNS zone belonging to TLD tld. More...
 
const char * GNS_get_tld (const char *name)
 Obtain the TLD of the given name. More...
 
static void shutdown_task (void *cls)
 Task run during shutdown. More...
 
static void client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *client, void *app_ctx)
 Called whenever a client is disconnected. More...
 
static void * client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *client, struct GNUNET_MQ_Handle *mq)
 Add a client to our list of active clients. More...
 
static void send_lookup_response (void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Reply to client with the result from our lookup. More...
 
static int check_lookup (void *cls, const struct LookupMessage *l_msg)
 Checks a GNUNET_MESSAGE_TYPE_GNS_LOOKUP message. More...
 
static void handle_lookup (void *cls, const struct LookupMessage *sh_msg)
 Handle lookup requests from client. More...
 
static void read_service_conf (void *cls, const char *section, const char *option, const char *value)
 Reads the configuration and populates TLDs. More...
 
static void run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
 Process GNS requests. More...
 
 GNUNET_SERVICE_MAIN ("gns", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(lookup, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, struct LookupMessage, NULL), GNUNET_MQ_handler_end())
 Define "main" method using service macro. More...
 

Variables

static struct GNUNET_DHT_Handledht_handle
 Our handle to the DHT. More...
 
static struct GNUNET_NAMECACHE_Handlenamecache_handle
 Our handle to the namecache service. More...
 
static int v6_enabled
 GNUNET_YES if ipv6 is supported More...
 
static int v4_enabled
 GNUNET_YES if ipv4 is supported More...
 
static struct GNUNET_STATISTICS_Handlestatistics
 Handle to the statistics service. More...
 
static struct GNS_TopLevelDomaintld_head
 Head of DLL of TLDs we map to GNS zones. More...
 
static struct GNS_TopLevelDomaintld_tail
 Tail of DLL of TLDs we map to GNS zones. More...
 

Detailed Description

GNU Name System (main service)

Author
Martin Schanzenbach
Christian Grothoff

Definition in file gnunet-service-gns.c.

Function Documentation

◆ GNS_find_tld()

int GNS_find_tld ( const char *  tld_str,
struct GNUNET_CRYPTO_EcdsaPublicKey pkey 
)

Find GNS zone belonging to TLD tld.

Parameters
tld_strtop-level domain to look up
[out]pkeypublic key to set
Returns
GNUNET_YES if tld was found GNUNET_NO if not

Definition at line 176 of file gnunet-service-gns.c.

References GNUNET_GNSRECORD_zkey_to_pkey(), GNUNET_NO, GNUNET_OK, GNUNET_YES, and GNS_TopLevelDomain::tld.

Referenced by handle_dns_request().

178 {
179  if ('\0' == *tld_str)
180  return GNUNET_NO;
181  for (struct GNS_TopLevelDomain *tld = tld_head;
182  NULL != tld;
183  tld = tld->next)
184  {
185  if (0 == strcasecmp(tld_str,
186  tld->tld))
187  {
188  *pkey = tld->pkey;
189  return GNUNET_YES;
190  }
191  }
192  if (GNUNET_OK ==
193  GNUNET_GNSRECORD_zkey_to_pkey(tld_str + 1,
194  pkey))
195  return GNUNET_YES; /* TLD string *was* the public key */
196  return GNUNET_NO;
197 }
struct GNS_TopLevelDomain * next
Kept in a DLL, as there are unlikely enough of these to warrant a hash map.
static struct GNS_TopLevelDomain * tld_head
Head of DLL of TLDs we map to GNS zones.
int GNUNET_GNSRECORD_zkey_to_pkey(const char *zkey, struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Convert an absolute domain name to the respective public key.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Representation of a TLD, mapping the respective TLD string (i.e.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNS_get_tld()

const char* GNS_get_tld ( const char *  name)

Obtain the TLD of the given name.

Parameters
namea name
Returns
the part of name after the last ".", or name if name does not contain a "."

Definition at line 208 of file gnunet-service-gns.c.

References name, and GNS_TopLevelDomain::tld.

Referenced by handle_dns_request(), and recursive_gns2dns_resolution().

209 {
210  const char *tld;
211 
212  tld = strrchr(name,
213  (unsigned char)'.');
214  if (NULL == tld)
215  tld = name;
216  else
217  tld++; /* skip the '.' */
218  return tld;
219 }
const char * name
Here is the caller graph for this function:

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run during shutdown.

Parameters
clsunused, NULL

Definition at line 228 of file gnunet-service-gns.c.

References GNS_interceptor_done(), GNS_resolver_done(), GNUNET_CONTAINER_DLL_remove, GNUNET_DHT_disconnect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NAMECACHE_disconnect(), GNUNET_NO, GNUNET_STATISTICS_destroy(), and GNS_TopLevelDomain::tld.

Referenced by run().

229 {
230  struct GNS_TopLevelDomain *tld;
231 
232  (void)cls;
234  "Shutting down!\n");
237  if (NULL != statistics)
238  {
240  GNUNET_NO);
241  statistics = NULL;
242  }
243  if (NULL != namecache_handle)
244  {
246  namecache_handle = NULL;
247  }
248  if (NULL != dht_handle)
249  {
251  dht_handle = NULL;
252  }
253  while (NULL != (tld = tld_head))
254  {
256  tld_tail,
257  tld);
258  GNUNET_free(tld->tld);
259  GNUNET_free(tld);
260  }
261 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
static struct GNS_TopLevelDomain * tld_head
Head of DLL of TLDs we map to GNS zones.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static struct GNUNET_DHT_Handle * dht_handle
Our handle to the DHT.
static struct GNUNET_NAMECACHE_Handle * namecache_handle
Our handle to the namecache service.
static struct GNS_TopLevelDomain * tld_tail
Tail of DLL of TLDs we map to GNS zones.
void GNS_interceptor_done()
Disconnect from interceptor.
void GNS_resolver_done()
Shutdown resolver.
void GNUNET_DHT_disconnect(struct GNUNET_DHT_Handle *handle)
Shutdown connection with the DHT service.
Definition: dht_api.c:913
Representation of a TLD, mapping the respective TLD string (i.e.
#define GNUNET_log(kind,...)
char * tld
Top-level domain as a string, including leading ".".
void GNUNET_NAMECACHE_disconnect(struct GNUNET_NAMECACHE_Handle *h)
Disconnect from the namecache service (and free associated resources).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_disconnect_cb()

static void client_disconnect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
void *  app_ctx 
)
static

Called whenever a client is disconnected.

Parameters
clsclosure
clientidentification of the client
app_ctxclient

Definition at line 272 of file gnunet-service-gns.c.

References GnsClient::clh_head, GnsClient::clh_tail, ClientLookupHandle::gc, GNS_resolver_lookup_cancel(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, and ClientLookupHandle::lookup.

Referenced by run().

275 {
276  struct ClientLookupHandle *clh;
277  struct GnsClient *gc = app_ctx;
278 
279  (void)cls;
281  "Client %p disconnected\n",
282  client);
283  while (NULL != (clh = gc->clh_head))
284  {
285  if (NULL != clh->lookup)
288  gc->clh_tail,
289  clh);
290  GNUNET_free(clh);
291  }
292  GNUNET_free(gc);
293 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
void GNS_resolver_lookup_cancel(struct GNS_ResolverHandle *rh)
Cancel active resolution (i.e.
struct GNS_ResolverHandle * lookup
Active handle for the lookup.
Handle to a lookup operation from client via API.
Information we track per connected client.
struct ClientLookupHandle * clh_head
Head of the DLL.
#define GNUNET_log(kind,...)
struct ClientLookupHandle * clh_tail
Tail of the DLL.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ client_connect_cb()

static void* client_connect_cb ( void *  cls,
struct GNUNET_SERVICE_Client client,
struct GNUNET_MQ_Handle mq 
)
static

Add a client to our list of active clients.

Parameters
clsNULL
clientclient to add
mqmessage queue for client
Returns
internal namestore client structure for this client

Definition at line 305 of file gnunet-service-gns.c.

References GnsClient::client, ClientLookupHandle::gc, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, mq, and GnsClient::mq.

Referenced by run().

308 {
309  struct GnsClient *gc;
310 
311  (void)cls;
313  "Client %p connected\n",
314  client);
315  gc = GNUNET_new(struct GnsClient);
316  gc->client = client;
317  gc->mq = mq;
318  return gc;
319 }
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_MQ_Handle * mq
The MQ.
struct GNUNET_SERVICE_Client * client
The client.
Information we track per connected client.
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
Here is the caller graph for this function:

◆ send_lookup_response()

static void send_lookup_response ( void *  cls,
uint32_t  rd_count,
const struct GNUNET_GNSRECORD_Data rd 
)
static

Reply to client with the result from our lookup.

Parameters
clsthe closure (our client lookup handle)
rd_countthe number of records in rd
rdthe record data

Definition at line 330 of file gnunet-service-gns.c.

References GnsClient::clh_head, GnsClient::clh_tail, GnsClient::client, env, ClientLookupHandle::gc, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_GNSRECORD_records_get_size(), GNUNET_GNSRECORD_records_serialize(), GNUNET_log, GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SERVICE_client_drop(), GNUNET_SERVICE_client_get_mq(), GNUNET_STATISTICS_update(), LookupResultMessage::id, len, LookupResultMessage::rd_count, and ClientLookupHandle::request_id.

Referenced by handle_lookup().

333 {
334  struct ClientLookupHandle *clh = cls;
335  struct GnsClient *gc = clh->gc;
336  struct GNUNET_MQ_Envelope *env;
337  struct LookupResultMessage *rmsg;
338  ssize_t len;
339 
341  "Sending LOOKUP_RESULT message with %u results\n",
342  (unsigned int)rd_count);
344  rd);
345  if (len < 0)
346  {
347  GNUNET_break(0);
349  return;
350  }
351  if (len > UINT16_MAX - sizeof(*rmsg))
352  {
353  GNUNET_break(0);
355  return;
356  }
357  env = GNUNET_MQ_msg_extra(rmsg,
358  len,
360  rmsg->id = clh->request_id;
361  rmsg->rd_count = htonl(rd_count);
362  GNUNET_assert(len ==
364  rd,
365  len,
366  (char*)&rmsg[1]));
368  env);
370  gc->clh_tail,
371  clh);
372  GNUNET_free(clh);
374  "Completed lookups", 1,
375  GNUNET_NO);
377  "Records resolved",
378  rd_count,
379  GNUNET_NO);
380 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
Message from GNS service to client: new results.
Definition: gns.h:75
GNUNET_NETWORK_STRUCT_END ssize_t GNUNET_GNSRECORD_records_get_size(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Calculate how many bytes we will need to serialize the given records.
uint32_t rd_count
The number of records contained in response.
Definition: gns.h:89
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2424
ssize_t GNUNET_GNSRECORD_records_serialize(unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, size_t dest_size, char *dest)
Serialize the given records to the given destination buffer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_GNS_LOOKUP_RESULT
Service response to name resolution request from client.
#define GNUNET_NO
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
struct GNUNET_SERVICE_Client * client
The client.
uint32_t request_id
request id
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
uint32_t id
Unique identifier for this request (for key collisions).
Definition: gns.h:84
struct GnsClient * gc
Client handle.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
Definition: service.c:2315
Handle to a lookup operation from client via API.
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
Information we track per connected client.
struct ClientLookupHandle * clh_head
Head of the DLL.
#define GNUNET_log(kind,...)
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:351
struct ClientLookupHandle * clh_tail
Tail of the DLL.
#define GNUNET_free(ptr)
Wrapper around free.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_lookup()

static int check_lookup ( void *  cls,
const struct LookupMessage l_msg 
)
static

Checks a GNUNET_MESSAGE_TYPE_GNS_LOOKUP message.

Parameters
clsclient sending the message
l_msgmessage of type struct LookupMessage
Returns
GNUNET_OK if l_msg is well-formed

Definition at line 391 of file gnunet-service-gns.c.

References GNUNET_break, GNUNET_DNSPARSER_MAX_NAME_LENGTH, GNUNET_MQ_check_zero_termination, GNUNET_OK, GNUNET_SYSERR, LookupMessage::header, and GNUNET_MessageHeader::size.

393 {
394  size_t nlen;
395 
396  (void)cls;
398  nlen = ntohs(l_msg->header.size) - sizeof(struct LookupMessage);
400  {
401  GNUNET_break(0);
402  return GNUNET_SYSERR;
403  }
404  return GNUNET_OK;
405 }
Message from client to GNS service to lookup records.
Definition: gns.h:36
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_MessageHeader header
Header of type GNUNET_MESSAGE_TYPE_GNS_LOOKUP.
Definition: gns.h:40
#define GNUNET_DNSPARSER_MAX_NAME_LENGTH
Maximum length of a name in DNS.
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76

◆ handle_lookup()

static void handle_lookup ( void *  cls,
const struct LookupMessage sh_msg 
)
static

Handle lookup requests from client.

Parameters
clsthe closure
clientthe client
messagethe message

Definition at line 416 of file gnunet-service-gns.c.

References GnsClient::clh_head, GnsClient::clh_tail, GnsClient::client, ClientLookupHandle::gc, GNS_resolver_lookup(), GNUNET_CONTAINER_DLL_insert, GNUNET_DNSPARSER_MAX_NAME_LENGTH, GNUNET_DNSPARSER_TYPE_A, GNUNET_DNSPARSER_TYPE_AAAA, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_STATISTICS_update(), GNUNET_STRINGS_utf8_tolower(), LookupMessage::id, ClientLookupHandle::lookup, name, LookupMessage::options, ClientLookupHandle::request_id, send_lookup_response(), LookupMessage::type, v4_enabled, v6_enabled, and LookupMessage::zone.

418 {
419  struct GnsClient *gc = cls;
421  struct ClientLookupHandle *clh;
422  char *nameptr = name;
423  const char *utf_in;
424 
426  utf_in = (const char *)&sh_msg[1];
428  nameptr);
430  "Received LOOKUP `%s' message\n",
431  name);
432  clh = GNUNET_new(struct ClientLookupHandle);
434  gc->clh_tail,
435  clh);
436  clh->gc = gc;
437  clh->request_id = sh_msg->id;
438  if ((GNUNET_DNSPARSER_TYPE_A == ntohl(sh_msg->type)) &&
439  (GNUNET_OK != v4_enabled))
440  {
442  "LOOKUP: Query for A record but AF_INET not supported!");
444  0,
445  NULL);
446  return;
447  }
448  if ((GNUNET_DNSPARSER_TYPE_AAAA == ntohl(sh_msg->type)) &&
449  (GNUNET_OK != v6_enabled))
450  {
452  "LOOKUP: Query for AAAA record but AF_INET6 not supported!");
454  0,
455  NULL);
456  return;
457  }
458  clh->lookup = GNS_resolver_lookup(&sh_msg->zone,
459  ntohl(sh_msg->type),
460  name,
461  (enum GNUNET_GNS_LocalOptions)ntohs(sh_msg->options),
462  &send_lookup_response, clh);
464  "Lookup attempts",
465  1, GNUNET_NO);
466 }
uint32_t id
Unique identifier for this request (for key collisions).
Definition: gns.h:45
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_CRYPTO_EcdsaPublicKey zone
Zone that is to be used for lookup.
Definition: gns.h:50
GNUNET_GNS_LocalOptions
Options for the GNS lookup.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
int32_t type
the type of record to look up
Definition: gns.h:66
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static int v6_enabled
GNUNET_YES if ipv6 is supported
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
struct GNUNET_SERVICE_Client * client
The client.
uint32_t request_id
request id
#define GNUNET_DNSPARSER_MAX_NAME_LENGTH
Maximum length of a name in DNS.
struct GnsClient * gc
Client handle.
static int v4_enabled
GNUNET_YES if ipv4 is supported
struct GNS_ResolverHandle * lookup
Active handle for the lookup.
Handle to a lookup operation from client via API.
int16_t options
Local options for where to look for results (an enum GNUNET_GNS_LocalOptions in NBO).
Definition: gns.h:56
const char * name
struct GNS_ResolverHandle * GNS_resolver_lookup(const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t record_type, const char *name, enum GNUNET_GNS_LocalOptions options, GNS_ResultProcessor proc, void *proc_cls)
Lookup of a record in a specific zone calls lookup result processor on result.
Information we track per connected client.
#define GNUNET_DNSPARSER_TYPE_AAAA
struct ClientLookupHandle * clh_head
Head of the DLL.
#define GNUNET_log(kind,...)
static void send_lookup_response(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Reply to client with the result from our lookup.
#define GNUNET_DNSPARSER_TYPE_A
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
Definition: service.c:2234
struct ClientLookupHandle * clh_tail
Tail of the DLL.
void GNUNET_STRINGS_utf8_tolower(const char *input, char *output)
Convert the utf-8 input string to lower case.
Definition: strings.c:552
Here is the call graph for this function:

◆ read_service_conf()

static void read_service_conf ( void *  cls,
const char *  section,
const char *  option,
const char *  value 
)
static

Reads the configuration and populates TLDs.

Parameters
clsunused
sectionname of section in config, always "gns"
optionname of the option, TLDs start with "."
valuevalue for the option, public key for TLDs

Definition at line 478 of file gnunet-service-gns.c.

References _, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_ERROR, GNUNET_log_config_invalid(), GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_string_to_data(), pk, GNS_TopLevelDomain::pkey, and GNS_TopLevelDomain::tld.

Referenced by run().

482 {
484  struct GNS_TopLevelDomain *tld;
485 
486  (void)cls;
487  (void)section;
488  if (option[0] != '.')
489  return;
490  if (GNUNET_OK !=
492  strlen(value),
493  &pk,
494  sizeof(pk)))
495  {
497  section,
498  option,
499  _("Properly base32-encoded public key required"));
500  return;
501  }
502  tld = GNUNET_new(struct GNS_TopLevelDomain);
503  tld->tld = GNUNET_strdup(&option[1]);
504  tld->pkey = pk;
506  tld_tail,
507  tld);
508 }
static struct GNUNET_CRYPTO_EddsaPrivateKey * pk
Private key of this peer.
static struct GNS_TopLevelDomain * tld_head
Head of DLL of TLDs we map to GNS zones.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct GNUNET_CRYPTO_EcdsaPublicKey pkey
Public key associated with the tld.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_log_config_invalid(enum GNUNET_ErrorType kind, const char *section, const char *option, const char *required)
Log error message about invalid configuration option value.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static char * section
Name of the section.
Definition: gnunet-config.c:33
static char * value
Value of the record to add/remove.
static struct GNS_TopLevelDomain * tld_tail
Tail of DLL of TLDs we map to GNS zones.
static char * option
Name of the option.
Definition: gnunet-config.c:38
Representation of a TLD, mapping the respective TLD string (i.e.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
char * tld
Top-level domain as a string, including leading ".".
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:953
Here is the call graph for this function:
Here is the caller graph for this function:

◆ run()

static void run ( void *  cls,
const struct GNUNET_CONFIGURATION_Handle c,
struct GNUNET_SERVICE_Handle service 
)
static

Process GNS requests.

Parameters
clsclosure
serverthe initialized server
cconfiguration to use

Definition at line 519 of file gnunet-service-gns.c.

References _, client_connect_cb(), client_disconnect_cb(), GNS_interceptor_init(), GNS_resolver_init(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_CONFIGURATION_iterate_section_values(), GNUNET_DHT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_NAMECACHE_connect(), GNUNET_NETWORK_test_pf(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_SERVICE_MAIN(), GNUNET_SERVICE_OPTION_NONE, GNUNET_STATISTICS_create(), GNUNET_SYSERR, GNUNET_YES, ClientLookupHandle::lookup, read_service_conf(), shutdown_task(), v4_enabled, and v6_enabled.

522 {
523  unsigned long long max_parallel_bg_queries = 16;
524 
526  "gns",
528  NULL);
532  if (NULL == namecache_handle)
533  {
535  _("Failed to connect to the namecache!\n"));
537  return;
538  }
539  if (GNUNET_OK ==
541  "gns",
542  "MAX_PARALLEL_BACKGROUND_QUERIES",
543  &max_parallel_bg_queries))
544  {
546  "Number of allowed parallel background queries: %llu\n",
547  max_parallel_bg_queries);
548  }
550  (unsigned int)max_parallel_bg_queries);
551  if (NULL == dht_handle)
552  {
554  _("Could not connect to DHT!\n"));
556  NULL);
557  return;
558  }
560  dht_handle,
561  c,
562  max_parallel_bg_queries);
563  if ((GNUNET_YES ==
565  "gns",
566  "INTERCEPT_DNS")) &&
567  (GNUNET_SYSERR ==
569  {
570  GNUNET_break(0);
572  NULL);
573  return;
574  }
576  c);
578  NULL);
579 }
struct GNUNET_NAMECACHE_Handle * GNUNET_NAMECACHE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namecache service.
int GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_iterate_section_values(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, GNUNET_CONFIGURATION_Iterator iter, void *iter_cls)
Iterate over values of a section in the configuration.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1284
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
static int v6_enabled
GNUNET_YES if ipv6 is supported
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
int GNS_interceptor_init(const struct GNUNET_CONFIGURATION_Handle *c)
Initialized the interceptor.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
static struct GNUNET_STATISTICS_Handle * statistics
Handle to the statistics service.
static void shutdown_task(void *cls)
Task run during shutdown.
static struct GNUNET_DHT_Handle * dht_handle
Our handle to the DHT.
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
static struct GNUNET_NAMECACHE_Handle * namecache_handle
Our handle to the namecache service.
static int v4_enabled
GNUNET_YES if ipv4 is supported
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_DHT_Handle * GNUNET_DHT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned int ht_len)
Initialize the connection with the DHT service.
Definition: dht_api.c:885
void GNS_resolver_init(struct GNUNET_NAMECACHE_Handle *nc, struct GNUNET_DHT_Handle *dht, const struct GNUNET_CONFIGURATION_Handle *c, unsigned long long max_bg_queries)
Initialize the resolver.
static void read_service_conf(void *cls, const char *section, const char *option, const char *value)
Reads the configuration and populates TLDs.
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
int GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
int GNUNET_NETWORK_test_pf(int pf)
Test if the given protocol family is supported by this system.
Definition: network.c:78
Here is the call graph for this function:

◆ GNUNET_SERVICE_MAIN()

GNUNET_SERVICE_MAIN ( "gns"  ,
GNUNET_SERVICE_OPTION_NONE  ,
run,
client_connect_cb,
client_disconnect_cb,
NULL  ,
GNUNET_MQ_hd_var_size(lookup, GNUNET_MESSAGE_TYPE_GNS_LOOKUP, struct LookupMessage, NULL)  ,
GNUNET_MQ_handler_end()   
)

Define "main" method using service macro.

Referenced by run().

Here is the caller graph for this function:

Variable Documentation

◆ dht_handle

struct GNUNET_DHT_Handle* dht_handle
static

Our handle to the DHT.

Definition at line 135 of file gnunet-service-gns.c.

◆ namecache_handle

struct GNUNET_NAMECACHE_Handle* namecache_handle
static

Our handle to the namecache service.

Definition at line 140 of file gnunet-service-gns.c.

◆ v6_enabled

int v6_enabled
static

GNUNET_YES if ipv6 is supported

Definition at line 145 of file gnunet-service-gns.c.

Referenced by handle_lookup(), and run().

◆ v4_enabled

int v4_enabled
static

GNUNET_YES if ipv4 is supported

Definition at line 150 of file gnunet-service-gns.c.

Referenced by handle_lookup(), and run().

◆ statistics

struct GNUNET_STATISTICS_Handle* statistics
static

Handle to the statistics service.

Definition at line 155 of file gnunet-service-gns.c.

◆ tld_head

struct GNS_TopLevelDomain* tld_head
static

Head of DLL of TLDs we map to GNS zones.

Definition at line 160 of file gnunet-service-gns.c.

◆ tld_tail

struct GNS_TopLevelDomain* tld_tail
static

Tail of DLL of TLDs we map to GNS zones.

Definition at line 165 of file gnunet-service-gns.c.