GNUnet  0.10.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 108 of file gns_tld_api.c.

References GNUNET_GNS_LookupWithTldRequest::name.

Referenced by GNUNET_GNS_lookup_with_tld().

109 {
110  const char *tld;
111 
112  tld = strrchr (name, (unsigned char) '.');
113  if (NULL == tld)
114  tld = name;
115  else
116  tld++; /* skip the '.' */
117  return tld;
118 }
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 128 of file gns_tld_api.c.

References GNUNET_assert, and GNUNET_GNS_EMPTY_LABEL_AT.

Referenced by GNUNET_GNS_lookup_with_tld().

129 {
130  GNUNET_assert (0 < strlen (name));
131  if ((NULL == tld) || (strlen (name) == strlen (tld)))
132  {
134  }
135  else
136  {
137  GNUNET_assert (strlen (tld) < strlen (name));
138  name[strlen (name) - strlen (tld) - 1] = '\0';
139  }
140 }
#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 151 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().

154 {
155  struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
156 
157  ltr->lr = NULL;
158  ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd);
160 }
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:330
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:70
GNUNET_GNS_LookupResultProcessor2 lookup_proc
processor to call on lookup result
Definition: gns_tld_api.c:55
#define GNUNET_YES
Definition: gnunet_common.h:80
Handle to a lookup request.
Definition: gns_tld_api.c:44
void * lookup_proc_cls
lookup_proc closure
Definition: gns_tld_api.c:65
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 170 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().

172 {
173  ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle,
174  ltr->name,
175  pkey,
176  ltr->type,
177  ltr->options,
179  ltr);
180 }
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:70
uint32_t type
Desired result record type.
Definition: gns_tld_api.c:91
struct GNUNET_GNS_Handle * gns_handle
handle to gns
Definition: gns_tld_api.c:50
enum GNUNET_GNS_LocalOptions options
Lookup options.
Definition: gns_tld_api.c:96
char * name
Domain name we are resolving.
Definition: gns_tld_api.c:60
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:151
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:337
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 193 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().

196 {
197  struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
199 
200  ltr->id_co = NULL;
201  if (NULL == priv)
202  {
203  /* no matching ego found */
204  ltr->lookup_proc (ltr->lookup_proc_cls, GNUNET_NO, 0, NULL);
205  return;
206  }
207  /* Final case: TLD matches one of our egos */
208  if (0 == strcmp (ltr->name, ego_name))
209  {
210  /* name matches ego name perfectly, only "@" remains */
211  strcpy (ltr->name, GNUNET_GNS_EMPTY_LABEL_AT);
212  }
213  else
214  {
215  GNUNET_assert (strlen (ego_name) < strlen (ltr->name));
216  ltr->name[strlen (ltr->name) - strlen (ego_name) - 1] = '\0';
217  }
218  /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */
219  if (NULL == strchr (ltr->name, (unsigned char) '.'))
221  else
225 }
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.
static char * ego_name
Name of our ego.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_IDENTITY_EgoSuffixLookup * id_co
Lookup an ego with the identity service.
Definition: gns_tld_api.c:75
enum GNUNET_GNS_LocalOptions options
Lookup options.
Definition: gns_tld_api.c:96
Never look in the DHT, keep request to local cache.
char * name
Domain name we are resolving.
Definition: gns_tld_api.c:60
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:241
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:55
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:170
Handle to a lookup request.
Definition: gns_tld_api.c:44
void * lookup_proc_cls
lookup_proc closure
Definition: gns_tld_api.c:65
Here is the call graph for this function:
Here is the caller graph for this function: