GNUnet  0.10.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.
#define GNUNET_GNSRECORD_TYPE_PHONE
Record type for a phone (of CONVERSATION).
static int ret
Final status code.
Definition: gnunet-arm.c:89
#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:367
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:921
uint32_t data
The data value.
static size_t data_size
Number of bytes in data.
#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.
#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:501
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.
static size_t data_size
Number of bytes in data.
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:953
#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 188 of file plugin_gnsrecord_conversation.c.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

190 {
191  unsigned int i;
192 
193  (void)cls;
194  i = 0;
195  while ((name_map[i].name != NULL) &&
196  (0 != strcasecmp(gns_typename, name_map[i].name)))
197  i++;
198  return name_map[i].number;
199 }
const char * name
static struct @9 name_map[]
Mapping of record type numbers to human-readable record type names.
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 210 of file plugin_gnsrecord_conversation.c.

References name, and name_map.

Referenced by libgnunet_plugin_gnsrecord_conversation_init().

212 {
213  unsigned int i;
214 
215  (void)cls;
216  i = 0;
217  while ((name_map[i].name != NULL) &&
218  (type != name_map[i].number))
219  i++;
220  return name_map[i].name;
221 }
const char * name
static struct @9 name_map[]
Mapping of record type numbers to human-readable record type names.
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 231 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.

232 {
234 
235  (void)cls;
241  return api;
242 }
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 252 of file plugin_gnsrecord_conversation.c.

References GNUNET_GNSRECORD_PluginFunctions::cls, and GNUNET_free.

253 {
255 
256  GNUNET_free(api);
257  return NULL;
258 }
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

Definition at line 172 of file plugin_gnsrecord_conversation.c.

Referenced by check_barrier_status(), check_delete_message(), check_get(), check_get_default_message(), check_lookup_result(), check_monitor_notify(), check_record_result(), check_set(), check_ssl_certificate(), check_watch(), conversation_number_to_typename(), conversation_typename_to_number(), format_help(), GNS_get_tld(), gns_resolve_name(), GNUNET_CREDENTIAL_credential_from_string(), GNUNET_DATACACHE_create(), GNUNET_DISK_directory_scan(), GNUNET_DNSPARSER_parse_query(), GNUNET_DNSPARSER_parse_record(), GNUNET_FS_GETOPT_KEYWORDS(), GNUNET_FS_GETOPT_METADATA(), GNUNET_GETOPT_option_absolute_time(), GNUNET_GETOPT_option_base32_fixed_size(), GNUNET_GETOPT_option_filename(), GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_increment_uint(), GNUNET_GETOPT_option_relative_time(), GNUNET_GETOPT_option_string(), GNUNET_GETOPT_option_uint(), GNUNET_GETOPT_option_uint16(), GNUNET_GETOPT_option_ulong(), GNUNET_JSON_getopt(), GNUNET_JSON_spec_absolute_time(), GNUNET_JSON_spec_absolute_time_nbo(), GNUNET_JSON_spec_boolean(), GNUNET_JSON_spec_fixed(), GNUNET_JSON_spec_json(), GNUNET_JSON_spec_relative_time(), GNUNET_JSON_spec_rsa_public_key(), GNUNET_JSON_spec_rsa_signature(), GNUNET_JSON_spec_string(), GNUNET_JSON_spec_uint16(), GNUNET_JSON_spec_uint32(), GNUNET_JSON_spec_uint64(), GNUNET_JSON_spec_uint8(), GNUNET_JSON_spec_varsize(), GNUNET_NETWORK_socket_accept(), GNUNET_PQ_make_prepare(), GNUNET_PQ_result_spec_absolute_time(), GNUNET_PQ_result_spec_uint16(), GNUNET_PQ_result_spec_uint32(), GNUNET_PQ_result_spec_uint64(), GNUNET_PQ_result_spec_variable_size(), GNUNET_PROGRAM_run2(), handle_barrier_cancel(), handle_barrier_init(), handle_barrier_status(), handle_barrier_wait(), handle_delete_message(), handle_get(), handle_get_default_message(), handle_lookup(), handle_lookup_by_suffix_message(), handle_lookup_message(), handle_lookup_result(), handle_record_result(), handle_set(), handle_watch(), handle_zone_to_name_it(), libgnunet_plugin_ats2_simple_init(), mlp_create_problem_add_address_information(), mlp_create_problem_add_invariant_columns(), mlp_create_problem_add_invariant_rows(), plugin_session_info_cb(), print_entry(), process_lookup_result(), REGEX_TEST_automaton_save_graph_step(), run(), send_ibf(), stun_attr2str(), stun_msg2str(), and translate_dot_plus().

◆ number

uint32_t number

Definition at line 173 of file plugin_gnsrecord_conversation.c.

Referenced by event_cb(), and GNUNET_TESTBED_run().

◆ 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().