GNUnet 0.21.1
gns_tld_api.c File Reference

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

#include "gnunet_common.h"
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_identity_service.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_PublicKey *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_PrivateKey *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...
 
enum GNUNET_GenericReturnValue GNUNET_GNS_parse_ztld (const char *name, struct GNUNET_CRYPTO_PublicKey *ztld_key)
 Try to parse the zTLD into a public key. 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.

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}
static char * name
Name (label) of the records to list.

References name.

Referenced by GNUNET_GNS_lookup_with_tld(), and GNUNET_GNS_parse_ztld().

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.

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.

References GNUNET_assert, GNUNET_GNS_EMPTY_LABEL_AT, and name.

Referenced by GNUNET_GNS_lookup_with_tld().

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.

153{
154 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
155
156 ltr->lr = NULL;
159}
static unsigned int rd_count
Number of records for currently parsed set.
static struct GNUNET_GNSRECORD_Data rd[50]
The record data under a single label.
void * GNUNET_GNS_lookup_with_tld_cancel(struct GNUNET_GNS_LookupWithTldRequest *ltr)
Cancel pending lookup request.
Definition: gns_tld_api.c:331
@ GNUNET_YES
Handle to a lookup request.
Definition: gns_tld_api.c:45
GNUNET_GNS_LookupResultProcessor2 lookup_proc
processor to call on lookup result
Definition: gns_tld_api.c:54
void * lookup_proc_cls
lookup_proc closure
Definition: gns_tld_api.c:64
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:69

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

Referenced by lookup_with_public_key().

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_PublicKey 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.

171{
172 ltr->lr = GNUNET_GNS_lookup (ltr->gns_handle,
173 ltr->name,
174 pkey,
175 ltr->type,
176 ltr->options,
178 ltr);
179}
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
static char * pkey
Public key of the zone to look in, in ASCII.
struct GNUNET_GNS_LookupRequest * GNUNET_GNS_lookup(struct GNUNET_GNS_Handle *handle, const char *name, const struct GNUNET_CRYPTO_PublicKey *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:421
enum GNUNET_GNS_LocalOptions options
Lookup options.
Definition: gns_tld_api.c:95
uint32_t type
Desired result record type.
Definition: gns_tld_api.c:90
char * name
Domain name we are resolving.
Definition: gns_tld_api.c:59
struct GNUNET_GNS_Handle * gns_handle
handle to gns
Definition: gns_tld_api.c:49

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

Referenced by GNUNET_GNS_lookup_with_tld(), and identity_zone_cb().

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_PrivateKey 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
ego_namename of the ego

Definition at line 192 of file gns_tld_api.c.

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}
static void lookup_with_public_key(struct GNUNET_GNS_LookupWithTldRequest *ltr, const struct GNUNET_CRYPTO_PublicKey *pkey)
Perform the actual resolution, starting with the zone identified by the given public key.
Definition: gns_tld_api.c:169
char * ego_name
@ GNUNET_GNS_LO_NO_DHT
Never look in the DHT, keep request to local cache.
@ GNUNET_GNS_LO_LOCAL_MASTER
For the rightmost label, only look in the cache (it is our local namestore), for the others,...
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_key_get_public(const struct GNUNET_CRYPTO_PrivateKey *privkey, struct GNUNET_CRYPTO_PublicKey *key)
Retrieves the public key representation of a private key.
Definition: crypto_pkey.c:602
@ GNUNET_NO
An identity key as per LSD0001.
struct GNUNET_IDENTITY_EgoSuffixLookup * id_co
Lookup an ego with the identity service.
Definition: gns_tld_api.c:74

References ego_name, GNUNET_assert, GNUNET_CRYPTO_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, GNUNET_GNS_LookupWithTldRequest::options, and pkey.

Referenced by GNUNET_GNS_lookup_with_tld().

Here is the call graph for this function:
Here is the caller graph for this function: