GNUnet  0.11.x
Data Structures | Macros | Functions
gns_tld_api.c File Reference

library to access the GNS service, including TLD lookup More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_identity_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_dht_service.h"
#include "gns.h"
#include "gns_api.h"
Include dependency graph for gns_tld_api.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_GNS_LookupWithTldRequest
 Handle to a lookup request. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "gns-tld-api", __VA_ARGS__)
 

Functions

static const char * get_tld (const char *name)
 Obtain the TLD of the given name. More...
 
static void eat_tld (char *name, const char *tld)
 Eat the "TLD" (last bit) of the given name. More...
 
static void process_lookup_result (void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
 Function called with the result of a GNS lookup. More...
 
static void lookup_with_public_key (struct GNUNET_GNS_LookupWithTldRequest *ltr, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
 Perform the actual resolution, starting with the zone identified by the given public key. More...
 
static void identity_zone_cb (void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, const char *ego_name)
 Method called to with the ego we are to use for the lookup, when the ego is determined by a name. More...
 
struct GNUNET_GNS_LookupWithTldRequestGNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle, const char *name, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor2 proc, void *proc_cls)
 Perform an asynchronous lookup operation on the GNS, determining the zone using the TLD of the given name and the current configuration to resolve TLDs to zones. More...
 
void * GNUNET_GNS_lookup_with_tld_cancel (struct GNUNET_GNS_LookupWithTldRequest *ltr)
 Cancel pending lookup request. More...
 

Detailed Description

library to access the GNS service, including TLD lookup

Author
Martin Schanzenbach
Christian Grothoff

Definition in file gns_tld_api.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from (kind, "gns-tld-api", __VA_ARGS__)

Definition at line 38 of file gns_tld_api.c.

Function Documentation

◆ get_tld()

static const char* get_tld ( const char *  name)
static

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 107 of file gns_tld_api.c.

References GNUNET_GNS_LookupWithTldRequest::name.

Referenced by GNUNET_GNS_lookup_with_tld().

108 {
109  const char *tld;
110 
111  tld = strrchr (name, (unsigned char) '.');
112  if (NULL == tld)
113  tld = name;
114  else
115  tld++; /* skip the '.' */
116  return tld;
117 }
const char * name
Here is the caller graph for this function:

◆ eat_tld()

static void eat_tld ( char *  name,
const char *  tld 
)
static

Eat the "TLD" (last bit) of the given name.

Parameters
[in,out]namea name
tldwhat to eat (can be more than just the tld)

Definition at line 127 of file gns_tld_api.c.

References GNUNET_assert, and GNUNET_GNS_EMPTY_LABEL_AT.

Referenced by GNUNET_GNS_lookup_with_tld().

128 {
129  GNUNET_assert (0 < strlen (name));
130  if ((NULL == tld) || (strlen (name) == strlen (tld)))
131  {
133  }
134  else
135  {
136  GNUNET_assert (strlen (tld) < strlen (name));
137  name[strlen (name) - strlen (tld) - 1] = '\0';
138  }
139 }
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
const char * name
Here is the caller graph for this function:

◆ process_lookup_result()

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

Function called with the result of a GNS lookup.

Parameters
clsa struct GNUNET_GNS_LookupWithTldRequest *
rd_countnumber of records returned
rdarray of rd_count records with the results

Definition at line 150 of file gns_tld_api.c.

References GNUNET_GNS_lookup_with_tld_cancel(), GNUNET_YES, GNUNET_GNS_LookupWithTldRequest::lookup_proc, GNUNET_GNS_LookupWithTldRequest::lookup_proc_cls, and GNUNET_GNS_LookupWithTldRequest::lr.

Referenced by lookup_with_public_key().

153 {
154  struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
155 
156  ltr->lr = NULL;
157  ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd);
159 }
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:329
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:69
GNUNET_GNS_LookupResultProcessor2 lookup_proc
processor to call on lookup result
Definition: gns_tld_api.c:54
#define GNUNET_YES
Definition: gnunet_common.h:77
Handle to a lookup request.
Definition: gns_tld_api.c:44
void * lookup_proc_cls
lookup_proc closure
Definition: gns_tld_api.c:64
Here is the call graph for this function:
Here is the caller graph for this function:

◆ lookup_with_public_key()

static void lookup_with_public_key ( struct GNUNET_GNS_LookupWithTldRequest ltr,
const struct GNUNET_CRYPTO_EcdsaPublicKey pkey 
)
static

Perform the actual resolution, starting with the zone identified by the given public key.

Parameters
pkeypublic key to use for the zone, can be NULL

Definition at line 169 of file gns_tld_api.c.

References GNUNET_GNS_LookupWithTldRequest::gns_handle, GNUNET_GNS_lookup(), GNUNET_GNS_LookupWithTldRequest::lr, GNUNET_GNS_LookupWithTldRequest::name, GNUNET_GNS_LookupWithTldRequest::options, process_lookup_result(), and GNUNET_GNS_LookupWithTldRequest::type.

Referenced by GNUNET_GNS_lookup_with_tld(), and identity_zone_cb().

171 {
172  ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle,
173  ltr->name,
174  pkey,
175  ltr->type,
176  ltr->options,
178  ltr);
179 }
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:69
uint32_t type
Desired result record type.
Definition: gns_tld_api.c:90
struct GNUNET_GNS_Handle * gns_handle
handle to gns
Definition: gns_tld_api.c:49
enum GNUNET_GNS_LocalOptions options
Lookup options.
Definition: gns_tld_api.c:95
char * name
Domain name we are resolving.
Definition: gns_tld_api.c:59
static void process_lookup_result(void *cls, uint32_t rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Function called with the result of a GNS lookup.
Definition: gns_tld_api.c:150
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_EcdsaPublicKey *zone, uint32_t type, enum GNUNET_GNS_LocalOptions options, GNUNET_GNS_LookupResultProcessor proc, void *proc_cls)
Perform an asynchronous lookup operation on the GNS.
Definition: gns_api.c:336
Here is the call graph for this function:
Here is the caller graph for this function:

◆ identity_zone_cb()

static void identity_zone_cb ( void *  cls,
const struct GNUNET_CRYPTO_EcdsaPrivateKey priv,
const char *  ego_name 
)
static

Method called to with the ego we are to use for the lookup, when the ego is determined by a name.

Parameters
clsa struct GNUNET_GNS_LookupWithTldRequest *
egoego handle, NULL at the end of the iteration
ctxcontext we could store data to associate with ego
namename of the ego

Definition at line 192 of file gns_tld_api.c.

References GNUNET_assert, GNUNET_CRYPTO_ecdsa_key_get_public(), GNUNET_GNS_EMPTY_LABEL_AT, GNUNET_GNS_LO_LOCAL_MASTER, GNUNET_GNS_LO_NO_DHT, GNUNET_NO, GNUNET_GNS_LookupWithTldRequest::id_co, GNUNET_GNS_LookupWithTldRequest::lookup_proc, GNUNET_GNS_LookupWithTldRequest::lookup_proc_cls, lookup_with_public_key(), GNUNET_GNS_LookupWithTldRequest::name, and GNUNET_GNS_LookupWithTldRequest::options.

Referenced by GNUNET_GNS_lookup_with_tld().

195 {
196  struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
198 
199  ltr->id_co = NULL;
200  if (NULL == priv)
201  {
202  /* no matching ego found */
203  ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL);
204  return;
205  }
206  /* Final case: TLD matches one of our egos */
207  if (0 == strcmp (ltr->name, ego_name))
208  {
209  /* name matches ego name perfectly, only "@" remains */
210  strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT);
211  }
212  else
213  {
214  GNUNET_assert (strlen (ego_name) < strlen (ltr->name));
215  ltr->name[strlen (ltr->name) - strlen (ego_name) - 1] = '\0';
216  }
217  /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */
218  if (NULL == strchr (ltr->name, (unsigned char) '.'))
220  else
224 }
For the rightmost label, only look in the cache (it is our local namestore), for the others...
static char * pkey
Public key of the zone to look in, in ASCII.
#define GNUNET_GNS_EMPTY_LABEL_AT
String we use to indicate an empty label (top-level entry in the zone).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
struct GNUNET_IDENTITY_EgoSuffixLookup * id_co
Lookup an ego with the identity service.
Definition: gns_tld_api.c:74
enum GNUNET_GNS_LocalOptions options
Lookup options.
Definition: gns_tld_api.c:95
Never look in the DHT, keep request to local cache.
char * name
Domain name we are resolving.
Definition: gns_tld_api.c:59
void GNUNET_CRYPTO_ecdsa_key_get_public(const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:239
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
GNUNET_GNS_LookupResultProcessor2 lookup_proc
processor to call on lookup result
Definition: gns_tld_api.c:54
static void lookup_with_public_key(struct GNUNET_GNS_LookupWithTldRequest *ltr, const struct GNUNET_CRYPTO_EcdsaPublicKey *pkey)
Perform the actual resolution, starting with the zone identified by the given public key...
Definition: gns_tld_api.c:169
Handle to a lookup request.
Definition: gns_tld_api.c:44
static char * ego_name
ego
Definition: gnunet-abd.c:117
void * lookup_proc_cls
lookup_proc closure
Definition: gns_tld_api.c:64
Here is the call graph for this function:
Here is the caller graph for this function: