GNUnet 0.21.1
gnunet-hello.c File Reference

change HELLO files to never expire More...

#include "platform.h"
#include "gnunet_protocols.h"
#include "gnunet_hello_uri_lib.h"
#include "gnunet_transport_plugin.h"
Include dependency graph for gnunet-hello.c:

Go to the source code of this file.

Data Structures

struct  AddContext
 Closure for add_to_buf(). More...
struct  TransportPlugin
 Entry in doubly-linked list of all of our plugins. More...


static void plugins_load (const struct GNUNET_CONFIGURATION_Handle *cfg)
static int add_to_builder (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
static int add_to_buf (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Add the given address with infinite expiration to the buffer. More...
static ssize_t add_from_hello (void *cls, size_t max, void *buf)
 Add addresses from the address list to the HELLO. More...
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run without the scheduler. More...
int main (int argc, char *argv[])


static int address_count
static struct GNUNET_CRYPTO_EddsaPrivateKeymy_private_key
 Our private key. More...
struct GNUNET_PeerIdentity my_full_id
 Local peer own ID. More...
static char * hello_file
 The file with hello in old style which we like to replace with the new one. More...
static struct TransportPluginplugins_head
 Head of DLL of all loaded plugins. More...
static struct TransportPluginplugins_tail
 Head of DLL of all loaded plugins. More...

Detailed Description

change HELLO files to never expire

Christian Grothoff

Definition in file gnunet-hello.c.

Function Documentation

◆ plugins_load()

static void plugins_load ( const struct GNUNET_CONFIGURATION_Handle cfg)

Definition at line 119 of file gnunet-hello.c.

121 struct TransportPlugin *plug;
122 struct TransportPlugin *next;
123 char *libname;
124 char *plugs;
125 char *pos;
127 if (NULL != plugins_head)
128 return; /* already loaded */
129 if (GNUNET_OK !=
130 GNUNET_CONFIGURATION_get_value_string (cfg, "TRANSPORT", "PLUGINS",
131 &plugs))
132 return;
133 fprintf (stdout,"Starting transport plugins `%s'\n",
134 plugs);
135 for (pos = strtok (plugs, " "); pos != NULL; pos = strtok (NULL, " "))
136 {
137 fprintf (stdout,"Loading `%s' transport plugin\n",
138 pos);
139 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_%s", pos);
140 plug = GNUNET_new (struct TransportPlugin);
141 plug->short_name = GNUNET_strdup (pos);
142 plug->lib_name = libname;
143 plug->env.cfg = cfg;
144 plug->env.cls = plug->short_name;
146 }
147 GNUNET_free (plugs);
149 while (next != NULL)
150 {
151 plug = next;
152 next = plug->next;
153 plug->api = GNUNET_PLUGIN_load (plug->lib_name, &plug->env);
154 if (plug->api == NULL)
155 {
156 fprintf (stdout,"Failed to load transport plugin for `%s'\n",
157 plug->lib_name);
159 GNUNET_free (plug->short_name);
160 GNUNET_free (plug->lib_name);
161 GNUNET_free (plug);
162 }
163 }
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static struct TransportPlugin * plugins_head
Head of DLL of all loaded plugins.
Definition: gnunet-hello.c:111
static struct TransportPlugin * plugins_tail
Head of DLL of all loaded plugins.
Definition: gnunet-hello.c:116
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
void * GNUNET_PLUGIN_load(const char *library_name, void *arg)
Setup plugin (runs the "init" callback and returns whatever "init" returned).
Definition: plugin.c:198
Entry in doubly-linked list of all of our plugins.
Definition: gnunet-hello.c:57
char * lib_name
Name of the library (e.g.
Definition: gnunet-hello.c:82
struct GNUNET_TRANSPORT_PluginEnvironment env
Environment this transport service is using for this plugin.
Definition: gnunet-hello.c:88
struct TransportPlugin * next
This is a doubly-linked list.
Definition: gnunet-hello.c:61
char * short_name
Short name for the plugin (e.g.
Definition: gnunet-hello.c:77
struct GNUNET_TRANSPORT_PluginFunctions * api
API of the transport as returned by the plugin's initialization function.
Definition: gnunet-hello.c:72

References TransportPlugin::api, cfg, TransportPlugin::env, GNUNET_asprintf(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_PLUGIN_load(), GNUNET_strdup, TransportPlugin::lib_name, TransportPlugin::next, plugins_head, plugins_tail, and TransportPlugin::short_name.

Referenced by run().

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

◆ add_to_builder()

static int add_to_builder ( void *  cls,
const struct GNUNET_HELLO_Address *  address,
struct GNUNET_TIME_Absolute  expiration 

Definition at line 168 of file gnunet-hello.c.

172 struct GNUNET_HELLO_Builder *builder= cls;
173 struct TransportPlugin *pos = plugins_head;
174 const char *addr;
175 char *uri;
177 while (NULL != pos)
178 {
180 "short_name: %s transport_name: %s\n",
181 pos->short_name,
182 address->transport_name);
183 if (0 == strcmp (address->transport_name, pos->short_name))
184 {
186 "short_name: %s transport_name: %s are the same\n",
187 pos->short_name,
188 address->transport_name);
189 addr = strchr (strchr (pos->api->address_to_string (pos, address, address->address_length), '.')+1, '.') + 1;
190 }
191 pos = pos->next;
192 }
195 "Hello address string: %s\n",
196 addr);
197 GNUNET_asprintf (&uri, "%s://%s", address->transport_name, addr);
199 "Hello address uri string: %s\n",
200 uri);
202 uri);
static char * address
GNS address for this phone.
static struct HostSet * builder
NULL if we are not currently iterating over peer information.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
enum GNUNET_GenericReturnValue GNUNET_HELLO_builder_add_address(struct GNUNET_HELLO_Builder *builder, const char *address)
Add individual address to the builder.
Definition: hello-uri.c:835
#define GNUNET_log(kind,...)
Context for building (or parsing) HELLO URIs.
Definition: hello-uri.c:205

References address, TransportPlugin::api, builder, GNUNET_asprintf(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_builder_add_address(), GNUNET_log, TransportPlugin::next, plugins_head, TransportPlugin::short_name, and uri.

Referenced by run().

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

◆ add_to_buf()

static int add_to_buf ( void *  cls,
const struct GNUNET_HELLO_Address *  address,
struct GNUNET_TIME_Absolute  expiration 

Add the given address with infinite expiration to the buffer.

addressaddress to add
expirationold expiration
GNUNET_OK keep iterating

Definition at line 215 of file gnunet-hello.c.

219 struct AddContext *ac = cls;
220 size_t ret;
222 ret = GNUNET_HELLO_add_address (address,
224 ac->buf,
225 ac->max);
227 ac->buf += ret;
228 ac->max -= ret;
229 ac->ret += ret;
231 return GNUNET_OK;
static int ret
Final status code.
Definition: gnunet-arm.c:94
static int address_count
Definition: gnunet-hello.c:91
Constant used to specify "forever".
Closure for add_to_buf().
Definition: gnunet-hello.c:34
size_t ret
Number of bytes added so far.
Definition: gnunet-hello.c:48
char * buf
Where to add.
Definition: gnunet-hello.c:38
size_t max
Maximum number of bytes left.
Definition: gnunet-hello.c:43

References address, address_count, AddContext::buf, GNUNET_OK, GNUNET_TIME_UNIT_FOREVER_ABS, AddContext::max, ret, and AddContext::ret.

Referenced by add_from_hello().

Here is the caller graph for this function:

◆ add_from_hello()

static ssize_t add_from_hello ( void *  cls,
size_t  max,
void *  buf 

Add addresses from the address list to the HELLO.

clsthe HELLO with the addresses to add
maxmaximum space available
bufwhere to add the addresses
number of bytes added, 0 to terminate

Definition at line 244 of file gnunet-hello.c.

246 struct GNUNET_HELLO_Message **orig = cls;
247 struct AddContext ac;
249 if (NULL == *orig)
250 return GNUNET_SYSERR; /* already done */
251 ac.buf = buf;
252 ac.max = max;
253 ac.ret = 0;
255 NULL ==
256 GNUNET_HELLO_iterate_addresses (*orig, GNUNET_NO, &add_to_buf, &ac));
257 *orig = NULL;
258 return ac.ret;
static int add_to_buf(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Add the given address with infinite expiration to the buffer.
Definition: gnunet-hello.c:215
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define max(x, y)

References add_to_buf(), AddContext::buf, GNUNET_assert, GNUNET_NO, GNUNET_SYSERR, AddContext::max, max, and AddContext::ret.

Here is the call graph for this function:

◆ run()

static void run ( void *  cls,
char *const *  args,
const char *  cfgfile,
const struct GNUNET_CONFIGURATION_Handle c 

Main function that will be run without the scheduler.

argsremaining command-line arguments
cfgfilename of the configuration file used (for saving, can be NULL!)

Definition at line 271 of file gnunet-hello.c.

277 struct GNUNET_HELLO_Message *orig;
278 struct GNUNET_HELLO_Message *result;
280 uint64_t fsize;
281 ssize_t size_written;
283 char *url;
284 const struct GNUNET_MessageHeader *msg;
285 struct GNUNET_MQ_Envelope *env;
287 plugins_load (c);
288 address_count = 0;
294 fprintf (stdout,"We are peer %s\n", GNUNET_i2s (&my_full_id));
296 GNUNET_log_setup ("gnunet-hello", "DEBUG", NULL);
298 if (GNUNET_OK !=
300 {
301 fprintf (stderr,
302 _ ("Error accessing file `%s': %s\n"),
304 strerror (errno));
305 return;
306 }
307 if (fsize > 65536)
308 {
309 fprintf (stderr, _ ("File `%s' is too big to be a HELLO\n"), hello_file);
310 return;
311 }
312 if (fsize < sizeof(struct GNUNET_MessageHeader))
313 {
314 fprintf (stderr, _ ("File `%s' is too small to be a HELLO\n"), hello_file);
315 return;
316 }
320 if (NULL == fh)
321 {
322 fprintf (stderr,
323 _ ("Error opening file `%s': %s\n"),
325 strerror (errno));
326 return;
327 }
328 {
329 char buf[fsize] GNUNET_ALIGN;
331 GNUNET_assert (fsize == GNUNET_DISK_file_read (fh, buf, fsize));
333 orig = (struct GNUNET_HELLO_Message *) buf;
334 if ((fsize < GNUNET_HELLO_size (orig)) ||
335 (GNUNET_OK != GNUNET_HELLO_get_id (orig, &pid)))
336 {
337 fprintf (stderr,
338 _ ("Did not find well-formed HELLO in file `%s'\n"),
339 hello_file);
340 return;
341 }
342 {
343 char *pids;
346 fprintf (stdout, "Processing HELLO for peer `%s'\n", pids);
347 GNUNET_free (pids);
348 }
349 /* result = GNUNET_HELLO_create (&pid.public_key, */
350 /* &add_from_hello, */
351 /* &orig, */
352 /* GNUNET_HELLO_is_friend_only (orig)); */
356 NULL ==
357 GNUNET_HELLO_iterate_addresses ((const struct GNUNET_HELLO_Message *) orig, GNUNET_NO, &add_to_builder, builder));
359 fprintf (stdout,"url: %s\n", url);
364 //GNUNET_assert (NULL != result);
365 GNUNET_assert (NULL != msg);
366 fh =
371 if (NULL == fh)
372 {
373 fprintf (stderr,
374 _ ("Error opening file `%s': %s\n"),
376 strerror (errno));
378 return;
379 }
380 //fsize = GNUNET_HELLO_size (result);
381 size_written = GNUNET_DISK_file_write (fh, msg, ntohs (msg->size));
382 if (ntohs (msg->size) != size_written)
383 {
384 fprintf (stderr,
385 _ ("Error writing HELLO to file `%s': %s expected size %u size written %u\n"),
387 strerror (errno));
388 (void) GNUNET_DISK_file_close (fh);
389 return;
390 }
392 }
393 fprintf (stderr,
394 _ ("Modified %u addresses, wrote %u bytes\n"),
396 (unsigned int) ntohs (msg->size));
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
struct GNUNET_PeerIdentity my_full_id
Local peer own ID.
Definition: gnunet-hello.c:101
static int add_to_builder(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Definition: gnunet-hello.c:168
static char * hello_file
The file with hello in old style which we like to replace with the new one.
Definition: gnunet-hello.c:106
static struct GNUNET_CRYPTO_EddsaPrivateKey * my_private_key
Our private key.
Definition: gnunet-hello.c:96
static void plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg)
Definition: gnunet-hello.c:119
static int result
Global testing status.
static struct GNUNET_DISK_FileHandle * fh
File handle to STDIN, for reading restart/quit commands.
static struct GNUNET_PeerIdentity pid
Identity of the peer we transmit to / connect to.
void GNUNET_CRYPTO_eddsa_key_get_public(const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_CRYPTO_EddsaPublicKey *pub)
Extract the public key for the given private key.
Definition: crypto_ecc.c:198
struct GNUNET_CRYPTO_EddsaPrivateKey * GNUNET_CRYPTO_eddsa_key_create_from_configuration(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create a new private key by reading our peer's key from the file specified in the configuration.
struct GNUNET_DISK_FileHandle * GNUNET_DISK_file_open(const char *fn, enum GNUNET_DISK_OpenFlags flags, enum GNUNET_DISK_AccessPermissions perm)
Open a file.
Definition: disk.c:1237
ssize_t GNUNET_DISK_file_write(const struct GNUNET_DISK_FileHandle *h, const void *buffer, size_t n)
Write a buffer to a file.
Definition: disk.c:686
enum GNUNET_GenericReturnValue GNUNET_DISK_file_size(const char *filename, uint64_t *size, int include_symbolic_links, int single_file_mode)
Get the size of the file (or directory) of the given file (in bytes).
Definition: disk.c:221
enum GNUNET_GenericReturnValue GNUNET_DISK_file_close(struct GNUNET_DISK_FileHandle *h)
Close an open file.
Definition: disk.c:1308
ssize_t GNUNET_DISK_file_read(const struct GNUNET_DISK_FileHandle *h, void *result, size_t len)
Read the contents of a binary file into a buffer.
Definition: disk.c:622
Open the file for reading.
Open the file for writing.
Truncate file if it exists.
Owner can read.
Owner can write.
void GNUNET_HELLO_builder_free(struct GNUNET_HELLO_Builder *builder)
Release resources of a builder.
Definition: hello-uri.c:373
struct GNUNET_HELLO_Builder * GNUNET_HELLO_builder_new(const struct GNUNET_PeerIdentity *pid)
Allocate builder.
Definition: hello-uri.c:355
char * GNUNET_HELLO_builder_to_url(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv)
Generate GNUnet HELLO URI from a builder.
Definition: hello-uri.c:717
struct GNUNET_MQ_Envelope * GNUNET_HELLO_builder_to_env(const struct GNUNET_HELLO_Builder *builder, const struct GNUNET_CRYPTO_EddsaPrivateKey *priv, struct GNUNET_TIME_Relative expiration_time)
Generate envelope with GNUnet HELLO message (including peer ID) from a builder.
Definition: hello-uri.c:631
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:252
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
enum GNUNET_GenericReturnValue GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
const struct GNUNET_MessageHeader * GNUNET_MQ_env_get_msg(const struct GNUNET_MQ_Envelope *env)
Obtain message contained in envelope.
Definition: mq.c:879
Constant used to specify "forever".
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Handle used to access files (and pipes).
Header for all communications.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key

References _, add_to_builder(), address_count, builder, env, fh, GNUNET_ALIGN, GNUNET_assert, GNUNET_CRYPTO_eddsa_key_create_from_configuration(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_CRYPTO_eddsa_public_key_to_string(), GNUNET_DISK_file_close(), GNUNET_DISK_file_open(), GNUNET_DISK_file_read(), GNUNET_DISK_file_size(), GNUNET_DISK_file_write(), GNUNET_DISK_OPEN_READ, GNUNET_DISK_OPEN_TRUNCATE, GNUNET_DISK_OPEN_WRITE, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_free, GNUNET_HELLO_builder_free(), GNUNET_HELLO_builder_new(), GNUNET_HELLO_builder_to_env(), GNUNET_HELLO_builder_to_url(), GNUNET_i2s(), GNUNET_log_setup(), GNUNET_MQ_env_get_msg(), GNUNET_NO, GNUNET_OK, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, hello_file, msg, my_full_id, my_private_key, pid, plugins_load(), GNUNET_PeerIdentity::public_key, result, and GNUNET_MessageHeader::size.

Referenced by main().

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

◆ main()

int main ( int  argc,
char *  argv[] 

Definition at line 402 of file gnunet-hello.c.

406 "hello-file",
408 gettext_noop ("Hello file to read"),
409 &hello_file),
411 int ret;
413 ret = (GNUNET_OK ==
415 argv,
416 "gnunet-peerinfo",
417 gettext_noop ("Print information about peers."),
418 options,
419 &run,
420 NULL,
422 return ret;
Definition: 002.c:13
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
#define gettext_noop(String)
Definition: gettext.h:70
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
Main function that will be run without the scheduler.
Definition: gnunet-hello.c:271
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run2(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls, int run_without_scheduler)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:132
Definition of a command line option.

References gettext_noop, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_string(), GNUNET_OK, GNUNET_PROGRAM_run2(), GNUNET_YES, hello_file, options, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ address_count

int address_count

Definition at line 91 of file gnunet-hello.c.

Referenced by add_to_buf(), and run().

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey* my_private_key

◆ my_full_id

◆ hello_file

char* hello_file

The file with hello in old style which we like to replace with the new one.

Definition at line 106 of file gnunet-hello.c.

Referenced by main(), and run().

◆ plugins_head

struct TransportPlugin* plugins_head

Head of DLL of all loaded plugins.

Definition at line 111 of file gnunet-hello.c.

Referenced by add_to_builder(), and plugins_load().

◆ plugins_tail

struct TransportPlugin* plugins_tail

Head of DLL of all loaded plugins.

Definition at line 116 of file gnunet-hello.c.

Referenced by plugins_load().