GNUnet 0.21.2
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 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 (e.g. More...
 
static const char * conversation_number_to_typename (void *cls, uint32_t type)
 Convert a type number to the corresponding type string (e.g. 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.

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 {
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
81 "%s-%s",
82 s,
83 pkey);
84 GNUNET_free (s);
86 return ret;
87 }
88
89 default:
90 return NULL;
91 }
92}
static int ret
Final status code.
Definition: gnunet-arm.c:94
static char * data
The data to insert into the dht.
static char * pkey
Public key of the zone to look in, in ASCII.
static uint32_t type
Type string converted to DNS type value.
static size_t data_size
Number of bytes in data.
#define GNUNET_log(kind,...)
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:254
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
@ GNUNET_ERROR_TYPE_ERROR
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_free(ptr)
Wrapper around free.
char * GNUNET_STRINGS_data_to_string_alloc(const void *buf, size_t size)
Return the base32crockford encoding of the given buffer.
Definition: strings.c:764
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define GNUNET_GNSRECORD_TYPE_PHONE
Endpoint for conversation.
A phone record specifies which peer is hosting a given user and may also specify the phone line that ...
struct GNUNET_HashCode line_port
Phone line (CADET port) to connect to.
struct GNUNET_PeerIdentity peer
Identity of the peer hosting the phone service.
uint32_t version
Version of the phone record, for now always one.
A 512-bit hashcode.
struct GNUNET_CRYPTO_EddsaPublicKey public_key

References _, data, data_size, 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, type, and GNUNET_CONVERSATION_PhoneRecord::version.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

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.

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[104];
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;
158 return GNUNET_OK;
159 }
160
161 default:
162 return GNUNET_SYSERR;
163 }
164}
enum GNUNET_GenericReturnValue 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:360
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
enum GNUNET_GenericReturnValue 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:789
The identity of the host (wraps the signing key of the peer).

References _, data, data_size, 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, GNUNET_PeerIdentity::public_key, GNUNET_CONVERSATION_PhoneRecord::reserved, type, and GNUNET_CONVERSATION_PhoneRecord::version.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

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 (e.g.

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

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}
const char * name
static struct @7 name_map[]
Mapping of record type numbers to human-readable record type names.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

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 to the corresponding type string (e.g.

1 to "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.

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}

References name, name_map, and type.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

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.

233{
235
236 (void) cls;
242 return api;
243}
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.
static const char * conversation_number_to_typename(void *cls, uint32_t type)
Convert a type number to the corresponding type string (e.g.
static uint32_t conversation_typename_to_number(void *cls, const char *gns_typename)
Convert a type name (e.g.
Each plugin is required to return a pointer to a struct of this type as the return value from its ent...
GNUNET_GNSRECORD_TypenameToNumberFunction typename_to_number
Typename to number.
GNUNET_GNSRECORD_NumberToTypenameFunction number_to_typename
Number to typename.
GNUNET_GNSRECORD_ValueToStringFunction value_to_string
Conversion to string.
void * cls
Closure for all of the callbacks.
GNUNET_GNSRECORD_StringToValueFunction string_to_value
Conversion to binary.

References GNUNET_GNSRECORD_PluginFunctions::cls, 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.

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.

254{
256
257 GNUNET_free (api);
258 return NULL;
259}

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

Variable Documentation

◆ name

const char* name

◆ number

uint32_t number

Definition at line 174 of file plugin_gnsrecord_conversation.c.

◆ 

struct { ... } name_map[]
Initial value:
= {
{ NULL, UINT32_MAX }
}

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

Referenced by conversation_number_to_typename(), and conversation_typename_to_number().