GNUnet  0.11.x
Functions | Variables
plugin_gnsrecord_conversation.c File Reference

gnsrecord plugin to provide the API for fundamental GNS records This includes the VPN record because GNS resolution is expected to understand VPN records and (if needed) map the result to A/AAAA. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_gnsrecord_lib.h"
#include "gnunet_conversation_service.h"
#include "gnunet_gnsrecord_plugin.h"
Include dependency graph for plugin_gnsrecord_conversation.c:

Go to the source code of this file.

Functions

static char * conversation_value_to_string (void *cls, uint32_t type, const void *data, size_t data_size)
 Convert the 'value' of a record to a string. More...
 
static int conversation_string_to_value (void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
 Convert human-readable version of a 'value' of a record to the binary representation. More...
 
static uint32_t conversation_typename_to_number (void *cls, const char *gns_typename)
 Convert a type name (i.e. More...
 
static const char * conversation_number_to_typename (void *cls, uint32_t type)
 Convert a type number (i.e. More...
 
void * libgnunet_plugin_gnsrecord_conversation_init (void *cls)
 Entry point for the plugin. More...
 
void * libgnunet_plugin_gnsrecord_conversation_done (void *cls)
 Exit point from the plugin. More...
 

Variables

struct {
   const char *   name
 
   uint32_t   number
 
name_map []
 Mapping of record type numbers to human-readable record type names. More...
 

Detailed Description

gnsrecord plugin to provide the API for fundamental GNS records This includes the VPN record because GNS resolution is expected to understand VPN records and (if needed) map the result to A/AAAA.

Author
Christian Grothoff

Definition in file plugin_gnsrecord_conversation.c.

Function Documentation

◆ conversation_value_to_string()

static char* conversation_value_to_string ( void *  cls,
uint32_t  type,
const void *  data,
size_t  data_size 
)
static

Convert the 'value' of a record to a string.

Parameters
clsclosure, unused
typetype of the record
datavalue in binary encoding
data_sizenumber of bytes in data
Returns
NULL on error, otherwise human-readable representation of the value

Definition at line 47 of file plugin_gnsrecord_conversation.c.

References _, data, GNUNET_asprintf(), GNUNET_break_op, GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNSRECORD_TYPE_PHONE, GNUNET_log, GNUNET_STRINGS_data_to_string_alloc(), GNUNET_CONVERSATION_PhoneRecord::line_port, GNUNET_CONVERSATION_PhoneRecord::peer, pkey, GNUNET_PeerIdentity::public_key, ret, and GNUNET_CONVERSATION_PhoneRecord::version.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

51 {
52  char *s;
53 
54  (void) cls;
55  switch (type)
56  {
58  {
59  const struct GNUNET_CONVERSATION_PhoneRecord *pr;
60  char *ret;
61  char *pkey;
62 
63  if (data_size != sizeof(struct GNUNET_CONVERSATION_PhoneRecord))
64  {
65  GNUNET_break_op (0);
66  return NULL;
67  }
68  pr = data;
69  if (1 != ntohl (pr->version))
70  {
72  _ ("PHONE version %u not supported\n"),
73  ntohl (pr->version));
74  return NULL;
75  }
78  sizeof(struct GNUNET_HashCode));
79 
80  GNUNET_asprintf (&ret,
81  "%s-%s",
82  s,
83  pkey);
84  GNUNET_free (s);
85  GNUNET_free (pkey);
86  return ret;
87  }
88 
89  default:
90  return NULL;
91  }
92 }
struct GNUNET_PeerIdentity peer
Identity of the peer hosting the phone service.
static char * pkey
Public key of the zone to look in, in ASCII.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_GNSRECORD_TYPE_PHONE
Record type for a phone (of CONVERSATION).
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
A phone record specifies which peer is hosting a given user and may also specify the phone line that ...
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
char * GNUNET_CRYPTO_eddsa_public_key_to_string(const struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a public key to a string.
Definition: crypto_ecc.c:365
A 512-bit hashcode.
uint32_t version
Version of the phone record, for now always one.
#define GNUNET_log(kind,...)
struct GNUNET_HashCode line_port
Phone line (CADET port) to connect to.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:920
uint32_t data
The data value.
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conversation_string_to_value()

static int conversation_string_to_value ( void *  cls,
uint32_t  type,
const char *  s,
void **  data,
size_t *  data_size 
)
static

Convert human-readable version of a 'value' of a record to the binary representation.

Parameters
clsclosure, unused
typetype of the record
shuman-readable string
dataset to value in binary encoding (will be allocated)
data_sizeset to number of bytes in data
Returns
GNUNET_OK on success

Definition at line 107 of file plugin_gnsrecord_conversation.c.

References _, GNUNET_break, GNUNET_CRYPTO_eddsa_public_key_from_string(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_GNSRECORD_TYPE_PHONE, GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_STRINGS_string_to_data(), GNUNET_SYSERR, GNUNET_CONVERSATION_PhoneRecord::line_port, GNUNET_CONVERSATION_PhoneRecord::peer, peer, GNUNET_PeerIdentity::public_key, GNUNET_CONVERSATION_PhoneRecord::reserved, and GNUNET_CONVERSATION_PhoneRecord::version.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

112 {
113  (void) cls;
114  if (NULL == s)
115  {
116  GNUNET_break (0);
117  return GNUNET_SYSERR;
118  }
119  switch (type)
120  {
122  {
124  char line_port[103];
125  const char *dash;
126  struct GNUNET_PeerIdentity peer;
127 
128  if ((NULL == (dash = strchr (s, '-'))) ||
129  (1 != sscanf (s, "%103s-", line_port)) ||
130  (GNUNET_OK !=
132  strlen (dash + 1),
133  &peer.public_key)))
134  {
136  _ ("Unable to parse PHONE record `%s'\n"),
137  s);
138  return GNUNET_SYSERR;
139  }
141  pr->version = htonl (1);
142  pr->reserved = htonl (0);
143  if (GNUNET_OK !=
145  strlen (line_port),
146  &pr->line_port,
147  sizeof(struct GNUNET_HashCode)))
148  {
150  _ ("Unable to parse PHONE record `%s'\n"),
151  s);
152  GNUNET_free (pr);
153  return GNUNET_SYSERR;
154  }
155  pr->peer = peer;
156  *data = pr;
157  *data_size = sizeof(struct GNUNET_CONVERSATION_PhoneRecord);
158  return GNUNET_OK;
159  }
160 
161  default:
162  return GNUNET_SYSERR;
163  }
164 }
struct GNUNET_PeerIdentity peer
Identity of the peer hosting the phone service.
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_GNSRECORD_TYPE_PHONE
Record type for a phone (of CONVERSATION).
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
A phone record specifies which peer is hosting a given user and may also specify the phone line that ...
A 512-bit hashcode.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint32_t version
Version of the phone record, for now always one.
int GNUNET_CRYPTO_eddsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:499
The identity of the host (wraps the signing key of the peer).
#define GNUNET_log(kind,...)
struct GNUNET_HashCode line_port
Phone line (CADET port) to connect to.
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
uint32_t data
The data value.
int GNUNET_STRINGS_string_to_data(const char *enc, size_t enclen, void *out, size_t out_size)
Convert CrockfordBase32 encoding back to data.
Definition: strings.c:952
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ conversation_typename_to_number()

static uint32_t conversation_typename_to_number ( void *  cls,
const char *  gns_typename 
)
static

Convert a type name (i.e.

"AAAA") to the corresponding number.

Parameters
clsclosure, unused
gns_typenamename to convert
Returns
corresponding number, UINT32_MAX on error

Definition at line 189 of file plugin_gnsrecord_conversation.c.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

191 {
192  unsigned int i;
193 
194  (void) cls;
195  i = 0;
196  while ((name_map[i].name != NULL) &&
197  (0 != strcasecmp (gns_typename, name_map[i].name)))
198  i++;
199  return name_map[i].number;
200 }
static struct @7 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
Here is the caller graph for this function:

◆ conversation_number_to_typename()

static const char* conversation_number_to_typename ( void *  cls,
uint32_t  type 
)
static

Convert a type number (i.e.

1) to the corresponding type string (i.e. "A")

Parameters
clsclosure, unused
typenumber of a type to convert
Returns
corresponding typestring, NULL on error

Definition at line 211 of file plugin_gnsrecord_conversation.c.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

213 {
214  unsigned int i;
215 
216  (void) cls;
217  i = 0;
218  while ((name_map[i].name != NULL) &&
219  (type != name_map[i].number))
220  i++;
221  return name_map[i].name;
222 }
static struct @7 name_map[]
Mapping of record type numbers to human-readable record type names.
const char * name
enum GNUNET_TESTBED_UnderlayLinkModelType type
the type of this model
Here is the caller graph for this function:

◆ libgnunet_plugin_gnsrecord_conversation_init()

void* libgnunet_plugin_gnsrecord_conversation_init ( void *  cls)

Entry point for the plugin.

Parameters
clsNULL
Returns
the exported block API

Definition at line 232 of file plugin_gnsrecord_conversation.c.

References conversation_number_to_typename(), conversation_string_to_value(), conversation_typename_to_number(), conversation_value_to_string(), GNUNET_new, GNUNET_GNSRECORD_PluginFunctions::number_to_typename, GNUNET_GNSRECORD_PluginFunctions::string_to_value, GNUNET_GNSRECORD_PluginFunctions::typename_to_number, and GNUNET_GNSRECORD_PluginFunctions::value_to_string.

233 {
235 
236  (void) cls;
242  return api;
243 }
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
static const char * conversation_number_to_typename(void *cls, uint32_t type)
Convert a type number (i.e.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
static uint32_t conversation_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (i.e.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.
void * cls
Closure for all of the callbacks.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static int conversation_string_to_value(void *cls, uint32_t type, const char *s, void **data, size_t *data_size)
Convert human-readable version of a 'value' of a record to the binary representation.
static char * conversation_value_to_string(void *cls, uint32_t type, const void *data, size_t data_size)
Convert the 'value' of a record to a string.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
Here is the call graph for this function:

◆ libgnunet_plugin_gnsrecord_conversation_done()

void* libgnunet_plugin_gnsrecord_conversation_done ( void *  cls)

Exit point from the plugin.

Parameters
clsthe return value from libgnunet_plugin_block_test_init
Returns
NULL

Definition at line 253 of file plugin_gnsrecord_conversation.c.

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

254 {
256 
257  GNUNET_free (api);
258  return NULL;
259 }
void * cls
Closure for all of the callbacks.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
#define GNUNET_free(ptr)
Wrapper around free.

Variable Documentation

◆ name

const char* name

◆ number

uint32_t number

Definition at line 174 of file plugin_gnsrecord_conversation.c.

◆ name_map

struct { ... } name_map[]
Initial value:
= {
{ NULL, UINT32_MAX }
}
#define GNUNET_GNSRECORD_TYPE_PHONE
Record type for a phone (of CONVERSATION).

Mapping of record type numbers to human-readable record type names.

Referenced by conversation_number_to_typename(), and conversation_typename_to_number().