GNUnet  0.19.4
gnunet-peerinfo.c File Reference

Print information about other known peers. More...

Include dependency graph for gnunet-peerinfo.c:

Go to the source code of this file.

Data Structures

struct  AddressRecord
 Record we keep for each printable address. More...
 
struct  PrintContext
 Structure we use to collect printable address information. More...
 

Macros

#define TIMEOUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
 How long until we time out during address lookup? More...
 

Functions

static void state_machine (void *cls)
 Main state machine that goes over all options and runs the next requested function. More...
 
static void dump_pc (struct PrintContext *pc)
 Print the collected address information to the console and free pc. More...
 
static void process_resolved_address (void *cls, const char *address, int res)
 Function to call with a human-readable format of an address. More...
 
static int count_address (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Iterator callback to go over all addresses and count them. More...
 
static int print_address (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Iterator callback to go over all addresses. More...
 
static void print_peer_info (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 Print information about the peer. More...
 
static int count_addr (void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
 Count the number of addresses in the HELLO. More...
 
static void dump_my_hello ()
 Write HELLO of my peer to a file. More...
 
static void print_my_uri (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
 Print URI of the peer. More...
 
static void add_continuation (void *cls)
 Continuation called from GNUNET_PEERINFO_add_peer() More...
 
static int parse_hello_uri (const char *put_uri)
 Parse the PUT URI given at the command line and add it to our peerinfo database. More...
 
static void shutdown_task (void *cls)
 Main state machine that goes over all options and runs the next requested function. More...
 
static void hello_callback (void *cls, const struct GNUNET_MessageHeader *hello)
 Function called with our peer's HELLO message. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 The main function to obtain peer information. More...
 

Variables

static int no_resolve
 Option '-n'. More...
 
static int be_quiet
 Option '-q'. More...
 
static int include_friend_only
 Option '-f'. More...
 
static int get_self
 Option '-s'. More...
 
static int get_uri
 Option. More...
 
static int default_operation
 Option. More...
 
static int get_info
 Option '-i'. More...
 
static char * put_uri
 Option. More...
 
static char * dump_hello
 Option -d. More...
 
static struct GNUNET_PEERINFO_Handlepeerinfo
 Handle to peerinfo service. More...
 
static const struct GNUNET_CONFIGURATION_Handlecfg
 Configuration handle. More...
 
static struct GNUNET_SCHEDULER_Tasktt
 Main state machine task (if active). More...
 
static struct GNUNET_TRANSPORT_HelloGetHandlegh
 Pending GNUNET_TRANSPORT_hello_get() operation. More...
 
static struct GNUNET_PEERINFO_IteratorContextpic
 Current iterator context (if active, otherwise NULL). More...
 
static struct GNUNET_PeerIdentity my_peer_identity
 My peer identity. More...
 
static struct PrintContextpc_head
 Head of list of print contexts. More...
 
static struct PrintContextpc_tail
 Tail of list of print contexts. More...
 
static struct GNUNET_MQ_Envelopeac
 Handle to current GNUNET_PEERINFO_add_peer() operation. More...
 
static struct GNUNET_HELLO_Messagemy_hello
 Hello of this peer (if initialized). More...
 

Detailed Description

Print information about other known peers.

Author
Christian Grothoff
Matthias Wachs

Definition in file gnunet-peerinfo.c.

Macro Definition Documentation

◆ TIMEOUT

How long until we time out during address lookup?

Definition at line 38 of file gnunet-peerinfo.c.

Function Documentation

◆ state_machine()

static void state_machine ( void *  cls)
static

Main state machine that goes over all options and runs the next requested function.

Parameters
clsunused

Definition at line 728 of file gnunet-peerinfo.c.

729 {
730  tt = NULL;
731 
732  if (NULL != put_uri)
733  {
736  {
737  fprintf (stderr, _ ("Invalid URI `%s'\n"), put_uri);
739  }
741  put_uri = NULL;
742  }
743  else if (GNUNET_YES == get_info)
744  {
749  NULL,
751  NULL);
752  }
753  else if (GNUNET_YES == get_self)
754  {
756  if (be_quiet)
757  printf ("%s\n", GNUNET_i2s_full (&my_peer_identity));
758  else
759  printf (_ ("I am peer `%s'.\n"), GNUNET_i2s_full (&my_peer_identity));
761  }
762  else if (GNUNET_YES == get_uri)
763  {
768  &print_my_uri,
769  NULL);
770  get_uri = GNUNET_NO;
771  }
772  else if (GNUNET_YES == default_operation)
773  {
774  /* default operation list all */
778  }
779  else
780  {
782  }
784 }
static int be_quiet
Option '-q'.
static int parse_hello_uri(const char *put_uri)
Parse the PUT URI given at the command line and add it to our peerinfo database.
static void print_my_uri(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
Print URI of the peer.
static char * put_uri
Option.
static struct GNUNET_PEERINFO_IteratorContext * pic
Current iterator context (if active, otherwise NULL).
static int default_operation
Option.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration handle.
static int get_uri
Option.
static int get_info
Option '-i'.
static int get_self
Option '-s'.
static struct GNUNET_PEERINFO_Handle * peerinfo
Handle to peerinfo service.
static struct GNUNET_SCHEDULER_Task * tt
Main state machine task (if active).
static int include_friend_only
Option '-f'.
static void state_machine(void *cls)
Main state machine that goes over all options and runs the next requested function.
static struct GNUNET_PeerIdentity my_peer_identity
My peer identity.
static void print_peer_info(void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_HELLO_Message *hello, const char *err_msg)
Print information about the peer.
void GPI_plugins_load(const struct GNUNET_CONFIGURATION_Handle *cfg)
Load and initialize all plugins.
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
struct GNUNET_PEERINFO_IteratorContext * GNUNET_PEERINFO_iterate(struct GNUNET_PEERINFO_Handle *h, int include_friend_only, const struct GNUNET_PeerIdentity *peer, GNUNET_PEERINFO_Processor callback, void *callback_cls)
Call a method for each known matching host.
Definition: peerinfo_api.c:464
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:562
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1299
#define _(String)
GNU gettext support macro.
Definition: platform.h:177

References _, be_quiet, cfg, default_operation, get_info, get_self, get_uri, GNUNET_free, GNUNET_i2s_full(), GNUNET_NO, GNUNET_PEERINFO_iterate(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_YES, GPI_plugins_load(), include_friend_only, my_peer_identity, parse_hello_uri(), peerinfo, pic, print_my_uri(), print_peer_info(), put_uri, and tt.

Referenced by add_continuation(), dump_pc(), hello_callback(), parse_hello_uri(), print_my_uri(), print_peer_info(), and run().

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

◆ dump_pc()

static void dump_pc ( struct PrintContext pc)
static

Print the collected address information to the console and free pc.

Parameters
pcprinting context

Definition at line 233 of file gnunet-peerinfo.c.

234 {
235  unsigned int i;
236 
237  printf (_ ("%sPeer `%s'\n"),
238  (GNUNET_YES == pc->friend_only) ? "F2F: " : "",
239  GNUNET_i2s_full (&pc->peer));
240  for (i = 0; i < pc->num_addresses; i++)
241  {
242  if (NULL != pc->address_list[i].result)
243  {
244  printf (_ ("\tExpires: %s \t %s\n"),
246  pc->address_list[i].expiration),
247  pc->address_list[i].result);
248  GNUNET_free (pc->address_list[i].result);
249  }
250  }
251  printf ("\n");
252  GNUNET_free (pc->address_list);
254  GNUNET_free (pc);
255  if ((NULL == pc_head) && (NULL == pic))
257 }
static struct PrintContext * pc_head
Head of list of print contexts.
static struct PrintContext * pc_tail
Tail of list of print contexts.
static struct GNUNET_FS_PublishContext * pc
Handle to FS-publishing operation.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:616

References _, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_i2s_full(), GNUNET_SCHEDULER_add_now(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_YES, pc, pc_head, pc_tail, pic, state_machine(), and tt.

Referenced by print_peer_info(), and process_resolved_address().

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

◆ process_resolved_address()

static void process_resolved_address ( void *  cls,
const char *  address,
int  res 
)
static

Function to call with a human-readable format of an address.

Parameters
clsclosure
addressNULL on error, otherwise 0-terminated printable UTF-8 string
resresult of the address to string conversion: if GNUNET_OK: address was valid (conversion to string might still have failed) if GNUNET_SYSERR: address is invalid

Definition at line 274 of file gnunet-peerinfo.c.

275 {
276  struct AddressRecord *ar = cls;
277  struct PrintContext *pc = ar->pc;
278 
279  if (NULL != address)
280  {
281  if (0 != strlen (address))
282  {
283  if (NULL != ar->result)
284  GNUNET_free (ar->result);
285  ar->result = GNUNET_strdup (address);
286  }
287  return;
288  }
289  ar->atsc = NULL;
290  if (GNUNET_SYSERR == res)
292  _ ("Failure: Cannot convert address to string for peer `%s'\n"),
293  GNUNET_i2s (&ar->pc->peer));
294  pc->num_addresses++;
295  if (pc->num_addresses == pc->address_list_size)
296  dump_pc (pc);
297 }
static int res
static char * address
GNS address for this phone.
static void dump_pc(struct PrintContext *pc)
Print the collected address information to the console and free pc.
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
Record we keep for each printable address.
struct PrintContext * pc
Print context this address record belongs to.
struct GNUNET_TRANSPORT_AddressToStringContext * atsc
Current address-to-string context (if active, otherwise NULL).
char * result
Printable address.
Structure we use to collect printable address information.
struct GNUNET_PeerIdentity peer
Identity of the peer.

References _, address, AddressRecord::atsc, dump_pc(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_strdup, GNUNET_SYSERR, pc, AddressRecord::pc, PrintContext::peer, res, and AddressRecord::result.

Referenced by print_address().

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

◆ count_address()

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

Iterator callback to go over all addresses and count them.

Parameters
clsstruct PrintContext * with off to increment
addressthe address
expirationexpiration time
Returns
GNUNET_OK to keep the address and continue

Definition at line 309 of file gnunet-peerinfo.c.

312 {
313  struct PrintContext *pc = cls;
314 
315  pc->off++;
316  return GNUNET_OK;
317 }
@ GNUNET_OK

References GNUNET_OK, and pc.

Referenced by print_peer_info().

Here is the caller graph for this function:

◆ print_address()

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

Iterator callback to go over all addresses.

Parameters
clsclosure
addressthe address
expirationexpiration time
Returns
GNUNET_OK to keep the address and continue

Definition at line 329 of file gnunet-peerinfo.c.

332 {
333  struct PrintContext *pc = cls;
334  struct AddressRecord *ar;
335 
336  GNUNET_assert (0 < pc->off);
337  ar = &pc->address_list[--pc->off];
338  ar->pc = pc;
339  ar->expiration = expiration;
340  GNUNET_asprintf (&ar->result,
341  "%s:%lu:%u",
342  address->transport_name,
343  (unsigned long) address->address_length,
344  address->local_info);
346  address,
347  no_resolve,
348  TIMEOUT,
350  ar);
351  return GNUNET_OK;
352 }
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
static int no_resolve
Option '-n'.
#define TIMEOUT
How long until we time out during address lookup?
static void process_resolved_address(void *cls, const char *address, int res)
Function to call with a human-readable format of an address.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
struct GNUNET_TRANSPORT_AddressToStringContext * GNUNET_TRANSPORT_address_to_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_HELLO_Address *address, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressToStringCallback aluc, void *aluc_cls)
Convert a binary address into a human readable address.
struct GNUNET_TIME_Absolute expiration
Address expiration time.

References address, AddressRecord::atsc, cfg, expiration, AddressRecord::expiration, GNUNET_asprintf(), GNUNET_assert, GNUNET_OK, GNUNET_TRANSPORT_address_to_string(), no_resolve, pc, AddressRecord::pc, process_resolved_address(), AddressRecord::result, and TIMEOUT.

Referenced by print_peer_info().

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

◆ print_peer_info()

static void print_peer_info ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const struct GNUNET_HELLO_Message hello,
const char *  err_msg 
)
static

Print information about the peer.

Currently prints the struct GNUNET_PeerIdentity and the transport address.

Parameters
clsthe struct PrintContext *
peeridentity of the peer
helloaddresses of the peer
err_msgerror message

Definition at line 365 of file gnunet-peerinfo.c.

369 {
370  struct PrintContext *pc;
371  int friend_only;
372 
373  if (NULL == peer)
374  {
375  pic = NULL; /* end of iteration */
376  if (NULL != err_msg)
377  {
378  fprintf (stderr,
379  _ ("Error in communication with PEERINFO service: %s\n"),
380  err_msg);
381  }
382  if (NULL == pc_head)
384  return;
385  }
387  if (NULL != hello)
389  if ((GNUNET_YES == be_quiet) || (NULL == hello))
390  {
391  printf ("%s%s\n",
392  (GNUNET_YES == friend_only) ? "F2F: " : "",
394  return;
395  }
396  pc = GNUNET_new (struct PrintContext);
398  pc->peer = *peer;
399  pc->friend_only = friend_only;
401  if (0 == pc->off)
402  {
403  dump_pc (pc);
404  return;
405  }
406  pc->address_list_size = pc->off;
407  pc->address_list = GNUNET_malloc (sizeof(struct AddressRecord) * pc->off);
409 }
static int count_address(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Iterator callback to go over all addresses and count them.
static int print_address(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Iterator callback to go over all addresses.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
int GNUNET_HELLO_is_friend_only(const struct GNUNET_HELLO_Message *h)
Return HELLO type.
Definition: hello.c:89
struct GNUNET_HELLO_Message * GNUNET_HELLO_iterate_addresses(const struct GNUNET_HELLO_Message *msg, int return_modified, GNUNET_HELLO_AddressIterator it, void *it_cls)
Iterate over all of the addresses in the HELLO.
Definition: hello.c:254
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
int friend_only
Hello was friend only, GNUNET_YES or GNUNET_NO.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References _, be_quiet, count_address(), dump_pc(), PrintContext::friend_only, GNUNET_CONTAINER_DLL_insert, GNUNET_HELLO_is_friend_only(), GNUNET_HELLO_iterate_addresses(), GNUNET_i2s_full(), GNUNET_malloc, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_now(), GNUNET_YES, pc, pc_head, pc_tail, peer, pic, print_address(), state_machine(), and tt.

Referenced by state_machine().

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

◆ count_addr()

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

Count the number of addresses in the HELLO.

Parameters
clspointer to an int * used for the counter
addressan address to count
expiration(unused)
Returns
GNUNET_OK

Definition at line 423 of file gnunet-peerinfo.c.

426 {
427  int *c = cls;
428 
429  (*c)++;
430  return GNUNET_OK;
431 }

References GNUNET_OK.

Referenced by dump_my_hello().

Here is the caller graph for this function:

◆ dump_my_hello()

static void dump_my_hello ( )
static

Write HELLO of my peer to a file.

Parameters
clsthe struct GetUriContext *
peeridentity of the peer (unused)
helloaddresses of the peer
err_msgerror message

Definition at line 443 of file gnunet-peerinfo.c.

444 {
445  unsigned int size;
446  unsigned int c_addr;
447 
449  if (0 == size)
450  {
451  fprintf (stderr, _ ("Failure: Received invalid %s\n"), "HELLO");
452  return;
453  }
454  if (GNUNET_SYSERR ==
456  my_hello,
457  size,
462  {
463  fprintf (stderr,
464  _ ("Failed to write HELLO with %u bytes to file `%s'\n"),
465  size,
466  dump_hello);
467  if (0 != unlink (dump_hello))
470  "unlink",
471  dump_hello);
472  }
473  c_addr = 0;
475 
476  if (! be_quiet)
477  {
478  fprintf (
479  stderr,
480  _ ("Wrote %s HELLO containing %u addresses with %u bytes to file `%s'\n"),
481  (GNUNET_YES == GNUNET_HELLO_is_friend_only (my_hello)) ? "friend-only"
482  : "public",
483  c_addr,
484  size,
485  dump_hello);
486  }
488  dump_hello = NULL;
489 }
static char * dump_hello
Option -d.
static struct GNUNET_HELLO_Message * my_hello
Hello of this peer (if initialized).
static int count_addr(void *cls, const struct GNUNET_HELLO_Address *address, struct GNUNET_TIME_Absolute expiration)
Count the number of addresses in the HELLO.
enum GNUNET_GenericReturnValue GNUNET_DISK_fn_write(const char *fn, const void *buf, size_t buf_size, enum GNUNET_DISK_AccessPermissions mode)
Write a buffer to a file atomically.
Definition: disk.c:725
@ GNUNET_DISK_PERM_USER_READ
Owner can read.
@ GNUNET_DISK_PERM_GROUP_READ
Group can read.
@ GNUNET_DISK_PERM_USER_WRITE
Owner can write.
@ GNUNET_DISK_PERM_OTHER_READ
Everybody can read.
uint16_t GNUNET_HELLO_size(const struct GNUNET_HELLO_Message *hello)
Return the size of the given HELLO message.
Definition: hello.c:630
#define GNUNET_log_strerror_file(level, cmd, filename)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_WARNING
@ GNUNET_ERROR_TYPE_BULK
static unsigned int size
Size of the "table".
Definition: peer.c:68

References _, be_quiet, count_addr(), dump_hello, GNUNET_DISK_fn_write(), GNUNET_DISK_PERM_GROUP_READ, GNUNET_DISK_PERM_OTHER_READ, GNUNET_DISK_PERM_USER_READ, GNUNET_DISK_PERM_USER_WRITE, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_HELLO_is_friend_only(), GNUNET_HELLO_iterate_addresses(), GNUNET_HELLO_size(), GNUNET_log_strerror_file, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, my_hello, and size.

Referenced by hello_callback().

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

◆ print_my_uri()

static void print_my_uri ( void *  cls,
const struct GNUNET_PeerIdentity peer,
const struct GNUNET_HELLO_Message hello,
const char *  err_msg 
)
static

Print URI of the peer.

Parameters
clsthe struct GetUriContext *
peeridentity of the peer (unused)
helloaddresses of the peer
err_msgerror message

Definition at line 504 of file gnunet-peerinfo.c.

508 {
509  char *uri;
510 
511  if (NULL == peer)
512  {
513  pic = NULL;
514  if (NULL != err_msg)
515  fprintf (stderr,
516  _ ("Error in communication with PEERINFO service: %s\n"),
517  err_msg);
519  return;
520  }
521 
522  if (NULL == hello)
523  return;
525  if (NULL != uri)
526  {
527  printf ("%s\n", (const char *) uri);
528  GNUNET_free (uri);
529  }
530 }
struct GNUNET_TRANSPORT_PluginFunctions * GPI_plugins_find(const char *name)
Obtain the plugin API based on a plugin name.
static struct GNUNET_FS_Uri * uri
Value of URI provided on command-line (when not publishing a file but just creating UBlocks to refer ...
char * GNUNET_HELLO_compose_uri(const struct GNUNET_HELLO_Message *hello, GNUNET_HELLO_TransportPluginsFind plugins_find)
Compose a hello URI string from a hello message.
Definition: hello.c:1007

References _, GNUNET_free, GNUNET_HELLO_compose_uri(), GNUNET_SCHEDULER_add_now(), GPI_plugins_find(), peer, pic, state_machine(), tt, and uri.

Referenced by state_machine().

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

◆ add_continuation()

static void add_continuation ( void *  cls)
static

Continuation called from GNUNET_PEERINFO_add_peer()

Parameters
clsclosure, NULL

Definition at line 542 of file gnunet-peerinfo.c.

543 {
544  ac = NULL;
546 }
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.

References ac, GNUNET_SCHEDULER_add_now(), state_machine(), and tt.

Referenced by parse_hello_uri().

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

◆ parse_hello_uri()

static int parse_hello_uri ( const char *  put_uri)
static

Parse the PUT URI given at the command line and add it to our peerinfo database.

Parameters
put_uriURI string to parse
Returns
GNUNET_OK on success, GNUNET_SYSERR if the URI was invalid, GNUNET_NO on other errors

Definition at line 559 of file gnunet-peerinfo.c.

560 {
561  struct GNUNET_HELLO_Message *hello = NULL;
562 
565  &hello,
567 
568  if (NULL != hello)
569  {
570  /* WARNING: this adds the address from URI WITHOUT verification! */
571  if (GNUNET_OK == ret)
573  else
575  GNUNET_free (hello);
576  }
577  return ret;
578 }
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
static void add_continuation(void *cls)
Continuation called from GNUNET_PEERINFO_add_peer()
int GNUNET_HELLO_parse_uri(const char *uri, struct GNUNET_CRYPTO_EddsaPublicKey *pubkey, struct GNUNET_HELLO_Message **hello, GNUNET_HELLO_TransportPluginsFind plugins_find)
Parse a hello URI string to a hello message.
Definition: hello.c:1195
struct GNUNET_MQ_Envelope * GNUNET_PEERINFO_add_peer(struct GNUNET_PEERINFO_Handle *h, const struct GNUNET_HELLO_Message *hello, GNUNET_SCHEDULER_TaskCallback cont, void *cont_cls)
Add a host to the persistent list.
Definition: peerinfo_api.c:530
A HELLO message is used to exchange information about transports with other peers.
struct GNUNET_CRYPTO_EddsaPublicKey public_key

References ac, add_continuation(), GNUNET_free, GNUNET_HELLO_parse_uri(), GNUNET_OK, GNUNET_PEERINFO_add_peer(), GNUNET_SCHEDULER_add_now(), GPI_plugins_find(), my_peer_identity, peerinfo, GNUNET_PeerIdentity::public_key, put_uri, ret, state_machine(), and tt.

Referenced by state_machine().

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

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Main state machine that goes over all options and runs the next requested function.

Parameters
clsunused

Definition at line 591 of file gnunet-peerinfo.c.

592 {
593  struct PrintContext *pc;
594  struct AddressRecord *ar;
595  unsigned int i;
596 
597  if (NULL != ac)
598  {
600  ac = NULL;
601  }
602  if (NULL != tt)
603  {
605  tt = NULL;
606  }
607  if (NULL != pic)
608  {
610  pic = NULL;
611  }
612  if (NULL != gh)
613  {
615  gh = NULL;
616  }
617  while (NULL != (pc = pc_head))
618  {
620  for (i = 0; i < pc->address_list_size; i++)
621  {
622  ar = &pc->address_list[i];
623  GNUNET_free (ar->result);
624  if (NULL != ar->atsc)
625  {
627  ar->atsc = NULL;
628  }
629  }
630  GNUNET_free (pc->address_list);
631  GNUNET_free (pc);
632  }
634  if (NULL != peerinfo)
635  {
637  peerinfo = NULL;
638  }
639  if (NULL != my_hello)
640  {
642  my_hello = NULL;
643  }
644 }
static struct GNUNET_TRANSPORT_HelloGetHandle * gh
Pending GNUNET_TRANSPORT_hello_get() operation.
void GPI_plugins_unload()
Unload all plugins.
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:768
void GNUNET_PEERINFO_iterate_cancel(struct GNUNET_PEERINFO_IteratorContext *ic)
Cancel an iteration over peer information.
Definition: peerinfo_api.c:497
void GNUNET_PEERINFO_disconnect(struct GNUNET_PEERINFO_Handle *h)
Disconnect from the peerinfo service.
Definition: peerinfo_api.c:149
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:975
void GNUNET_TRANSPORT_hello_get_cancel(struct GNUNET_TRANSPORT_HelloGetHandle *ghh)
Stop receiving updates about changes to our HELLO message.
void GNUNET_TRANSPORT_address_to_string_cancel(struct GNUNET_TRANSPORT_AddressToStringContext *alc)
Cancel request for address conversion.

References ac, AddressRecord::atsc, gh, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_send_cancel(), GNUNET_PEERINFO_disconnect(), GNUNET_PEERINFO_iterate_cancel(), GNUNET_SCHEDULER_cancel(), GNUNET_TRANSPORT_address_to_string_cancel(), GNUNET_TRANSPORT_hello_get_cancel(), GPI_plugins_unload(), my_hello, pc, pc_head, pc_tail, peerinfo, pic, AddressRecord::result, and tt.

Referenced by run().

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

◆ hello_callback()

static void hello_callback ( void *  cls,
const struct GNUNET_MessageHeader hello 
)
static

Function called with our peer's HELLO message.

Used to obtain our peer's public key.

Parameters
clsNULL
hellothe HELLO message

Definition at line 655 of file gnunet-peerinfo.c.

656 {
657  if (NULL == hello)
658  {
659  fprintf (stderr, "Failed to get my own HELLO from this peer!\n");
661  return;
662  }
667  gh = NULL;
668  if (NULL != dump_hello)
669  dump_my_hello ();
671 }
static void dump_my_hello()
Write HELLO of my peer to a file.
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:649
struct GNUNET_MessageHeader * GNUNET_copy_message(const struct GNUNET_MessageHeader *msg)
Create a copy of the given message.

References dump_hello, dump_my_hello(), gh, GNUNET_assert, GNUNET_copy_message(), GNUNET_HELLO_get_id(), GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_shutdown(), GNUNET_TRANSPORT_hello_get_cancel(), my_hello, my_peer_identity, state_machine(), and tt.

Referenced by run().

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

◆ run()

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

Main function that will be run by the scheduler.

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

Definition at line 683 of file gnunet-peerinfo.c.

687 {
688  cfg = c;
689  if ((NULL != args[0]) && (NULL == put_uri) &&
690  (args[0] == strcasestr (args[0], "gnunet://hello/")))
691  {
692  put_uri = GNUNET_strdup (args[0]);
693  args++;
694  }
695  if (NULL != args[0])
696  {
697  fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
698  return;
699  }
700  if (NULL == (peerinfo = GNUNET_PEERINFO_connect (cfg)))
701  {
702  fprintf (stderr, "%s", "Could not access PEERINFO service. Exiting.\n");
703  return;
704  }
705  if ((GNUNET_YES == get_self) || (GNUNET_YES == get_uri) ||
706  (NULL != dump_hello))
707  {
711  NULL);
712  }
713  else
714  {
716  }
718 }
static void shutdown_task(void *cls)
Main state machine that goes over all options and runs the next requested function.
static void hello_callback(void *cls, const struct GNUNET_MessageHeader *hello)
Function called with our peer's HELLO message.
struct GNUNET_PEERINFO_Handle * GNUNET_PEERINFO_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the peerinfo service.
Definition: peerinfo_api.c:123
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
Definition: scheduler.c:1334
struct GNUNET_TRANSPORT_HelloGetHandle * GNUNET_TRANSPORT_hello_get(const struct GNUNET_CONFIGURATION_Handle *cfg, enum GNUNET_TRANSPORT_AddressClass ac, GNUNET_TRANSPORT_HelloUpdateCallback rec, void *rec_cls)
Obtain updates on changes to the HELLO message for this peer.
@ GNUNET_TRANSPORT_AC_ANY
Bitmask for "any" address.

References _, consensus-simulation::args, cfg, dump_hello, get_self, get_uri, gh, GNUNET_PEERINFO_connect(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_strdup, GNUNET_TRANSPORT_AC_ANY, GNUNET_TRANSPORT_hello_get(), GNUNET_YES, hello_callback(), peerinfo, put_uri, shutdown_task(), state_machine(), and tt.

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 *const *  argv 
)

The main function to obtain peer information.

Parameters
argcnumber of arguments from the command line
argvcommand line arguments
Returns
0 ok, 1 on error

Definition at line 795 of file gnunet-peerinfo.c.

796 {
799  "numeric",
800  gettext_noop ("don't resolve host names"),
801  &no_resolve),
802 
804  "quiet",
805  gettext_noop (
806  "output only the identity strings"),
807  &be_quiet),
809  "friends",
810  gettext_noop (
811  "include friend-only information"),
813 
815  "self",
816  gettext_noop ("output our own identity only"),
817  &get_self),
818 
820  "info",
821  gettext_noop ("list all known peers"),
822  &get_info),
823 
825  "dump-hello",
826  NULL,
827  gettext_noop ("dump hello to file"),
828  &dump_hello),
829 
831  "get-hello",
832  gettext_noop ("also output HELLO uri(s)"),
833  &get_uri),
834 
836  "put-hello",
837  "HELLO",
838  gettext_noop (
839  "add given HELLO uri to the database"),
840  &put_uri),
841 
843  int ret;
844 
846  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
847  return 2;
848 
849  ret = (GNUNET_OK ==
850  GNUNET_PROGRAM_run (argc,
851  argv,
852  "gnunet-peerinfo",
853  gettext_noop ("Print information about peers."),
854  options,
855  &run,
856  NULL))
857  ? 0
858  : 1;
859  GNUNET_free_nz ((void *) argv);
860  return ret;
861 }
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
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 by the scheduler.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_flag(char shortName, const char *name, const char *description, int *val)
Allow user to specify a flag (which internally means setting an integer to 1/GNUNET_YES/GNUNET_OK.
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.
#define GNUNET_free_nz(ptr)
Wrapper around free.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration,...
Definition: program.c:400
enum GNUNET_GenericReturnValue GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1222
Definition of a command line option.

References be_quiet, default_operation, dump_hello, get_info, get_self, get_uri, gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_GETOPT_option_string(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), GNUNET_YES, include_friend_only, no_resolve, options, put_uri, ret, and run().

Here is the call graph for this function:

Variable Documentation

◆ no_resolve

int no_resolve
static

Option '-n'.

Definition at line 122 of file gnunet-peerinfo.c.

Referenced by main(), and print_address().

◆ be_quiet

int be_quiet
static

Option '-q'.

Definition at line 127 of file gnunet-peerinfo.c.

Referenced by dump_my_hello(), main(), print_peer_info(), and state_machine().

◆ include_friend_only

int include_friend_only
static

◆ get_self

int get_self
static

Option '-s'.

Definition at line 137 of file gnunet-peerinfo.c.

Referenced by main(), run(), and state_machine().

◆ get_uri

int get_uri
static

Option.

Definition at line 142 of file gnunet-peerinfo.c.

Referenced by main(), run(), and state_machine().

◆ default_operation

int default_operation
static

Option.

Definition at line 147 of file gnunet-peerinfo.c.

Referenced by main(), and state_machine().

◆ get_info

int get_info
static

Option '-i'.

Definition at line 152 of file gnunet-peerinfo.c.

Referenced by main(), and state_machine().

◆ put_uri

char* put_uri
static

Option.

Definition at line 157 of file gnunet-peerinfo.c.

Referenced by main(), parse_hello_uri(), run(), and state_machine().

◆ dump_hello

char* dump_hello
static

Option -d.

Definition at line 162 of file gnunet-peerinfo.c.

Referenced by dump_my_hello(), hello_callback(), main(), and run().

◆ peerinfo

struct GNUNET_PEERINFO_Handle* peerinfo
static

Handle to peerinfo service.

Definition at line 167 of file gnunet-peerinfo.c.

Referenced by parse_hello_uri(), run(), shutdown_task(), and state_machine().

◆ cfg

const struct GNUNET_CONFIGURATION_Handle* cfg
static

Configuration handle.

Definition at line 172 of file gnunet-peerinfo.c.

Referenced by print_address(), run(), and state_machine().

◆ tt

struct GNUNET_SCHEDULER_Task* tt
static

Main state machine task (if active).

Definition at line 177 of file gnunet-peerinfo.c.

Referenced by add_continuation(), dump_pc(), hello_callback(), parse_hello_uri(), print_my_uri(), print_peer_info(), run(), shutdown_task(), and state_machine().

◆ gh

◆ pic

struct GNUNET_PEERINFO_IteratorContext* pic
static

Current iterator context (if active, otherwise NULL).

Definition at line 187 of file gnunet-peerinfo.c.

Referenced by dump_pc(), GNUNET_TRANSPORT_monitor_peers_cancel(), print_my_uri(), print_peer_info(), shutdown_task(), and state_machine().

◆ my_peer_identity

struct GNUNET_PeerIdentity my_peer_identity
static

My peer identity.

Definition at line 187 of file gnunet-peerinfo.c.

Referenced by hello_callback(), parse_hello_uri(), and state_machine().

◆ pc_head

struct PrintContext* pc_head
static

Head of list of print contexts.

Definition at line 197 of file gnunet-peerinfo.c.

Referenced by dump_pc(), print_peer_info(), and shutdown_task().

◆ pc_tail

struct PrintContext* pc_tail
static

Tail of list of print contexts.

Definition at line 202 of file gnunet-peerinfo.c.

Referenced by dump_pc(), print_peer_info(), and shutdown_task().

◆ ac

◆ my_hello

struct GNUNET_HELLO_Message* my_hello
static

Hello of this peer (if initialized).

Definition at line 212 of file gnunet-peerinfo.c.

Referenced by dump_my_hello(), hello_callback(), and shutdown_task().