GNUnet 0.21.1
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_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...
 
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 37 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.

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

References name.

Referenced by GNUNET_GNS_lookup_with_tld().

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.

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.

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

152{
153 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
154
155 ltr->lr = NULL;
158}
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:44
GNUNET_GNS_LookupResultProcessor2 lookup_proc
processor to call on lookup result
Definition: gns_tld_api.c:53
void * lookup_proc_cls
lookup_proc closure
Definition: gns_tld_api.c:63
struct GNUNET_GNS_LookupRequest * lr
Underlying GNS lookup.
Definition: gns_tld_api.c:68

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

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

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

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}
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:168
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:73

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: