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

References GNUNET_GNS_LookupWithTldRequest::name.

Referenced by GNUNET_GNS_lookup_with_tld().

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

References GNUNET_assert, and GNUNET_GNS_EMPTY_LABEL_AT.

Referenced by GNUNET_GNS_lookup_with_tld().

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

152 {
153  struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
154 
155  ltr->lr = NULL;
156  ltr->lookup_proc(ltr->lookup_proc_cls, GNUNET_YES, rd_count, rd);
158 }
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:328
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:68
GNUNET_GNS_LookupResultProcessor2 lookup_proc
processor to call on lookup result
Definition: gns_tld_api.c:53
#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:63
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 168 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().

170 {
171  ltr->lr = GNUNET_GNS_lookup(ltr->gns_handle,
172  ltr->name,
173  pkey,
174  ltr->type,
175  ltr->options,
177  ltr);
178 }
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:68
uint32_t type
Desired result record type.
Definition: gns_tld_api.c:89
struct GNUNET_GNS_Handle * gns_handle
handle to gns
Definition: gns_tld_api.c:48
enum GNUNET_GNS_LocalOptions options
Lookup options.
Definition: gns_tld_api.c:94
char * name
Domain name we are resolving.
Definition: gns_tld_api.c:58
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:149
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:334
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 191 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().

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