GNUnet  0.10.x
Functions | Variables
gnunet-core.c File Reference

Print information about other peers known to CORE. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_core_service.h"
Include dependency graph for gnunet-core.c:

Go to the source code of this file.

Functions

static void shutdown_task (void *cls)
 Task run in monitor mode when the user presses CTRL-C to abort. More...
 
static void monitor_cb (void *cls, const struct GNUNET_PeerIdentity *peer, enum GNUNET_CORE_KxState state, struct GNUNET_TIME_Absolute timeout)
 Function called to notify core users that another peer changed its state with us. More...
 
static void run (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
 Main function that will be run by the scheduler. More...
 
int main (int argc, char *const *argv)
 The main function to obtain peer information from CORE. More...
 

Variables

static int monitor_connections
 Option -m. More...
 
static struct GNUNET_CORE_MonitorHandlemh
 Handle to the CORE monitor. More...
 

Detailed Description

Print information about other peers known to CORE.

Author
Nathan Evans

Definition in file gnunet-core.c.

Function Documentation

◆ shutdown_task()

static void shutdown_task ( void *  cls)
static

Task run in monitor mode when the user presses CTRL-C to abort.

Stops monitoring activity.

Parameters
clsNULL

Definition at line 49 of file gnunet-core.c.

References GNUNET_CORE_monitor_stop().

Referenced by run().

50 {
51  (void) cls;
52  if (NULL != mh)
53  {
55  mh = NULL;
56  }
57 }
static struct GNUNET_CORE_MonitorHandle * mh
Handle to the CORE monitor.
Definition: gnunet-core.c:39
void GNUNET_CORE_monitor_stop(struct GNUNET_CORE_MonitorHandle *mh)
Stop monitoring CORE activity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ monitor_cb()

static void monitor_cb ( void *  cls,
const struct GNUNET_PeerIdentity peer,
enum GNUNET_CORE_KxState  state,
struct GNUNET_TIME_Absolute  timeout 
)
static

Function called to notify core users that another peer changed its state with us.

Parameters
clsclosure
peerthe peer that changed state
statenew state of the peer
timeouttimeout for the new state

Definition at line 70 of file gnunet-core.c.

References _, FPRINTF, GNUNET_CORE_KX_CORE_DISCONNECT, GNUNET_CORE_KX_ITERATION_FINISHED, GNUNET_CORE_KX_PEER_DISCONNECT, GNUNET_CORE_KX_STATE_DOWN, GNUNET_CORE_KX_STATE_KEY_RECEIVED, GNUNET_CORE_KX_STATE_KEY_SENT, GNUNET_CORE_KX_STATE_REKEY_SENT, GNUNET_CORE_KX_STATE_UP, GNUNET_i2s(), GNUNET_NO, GNUNET_SCHEDULER_shutdown(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_remaining(), GNUNET_YES, and monitor_connections.

Referenced by run().

74 {
76  const char *now_str;
77  const char *state_str;
78 
79  (void) cls;
80  if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) &&
82  {
84  return;
85  }
86 
87  switch (state)
88  {
90  /* should never happen, as we immediately send the key */
91  state_str = _ ("fresh connection");
92  break;
94  state_str = _ ("key sent");
95  break;
97  state_str = _ ("key received");
98  break;
100  state_str = _ ("connection established");
101  break;
103  state_str = _ ("rekeying");
104  break;
106  state_str = _ ("disconnected");
107  break;
109  return;
111  FPRINTF (stderr,
112  "%s\n",
113  _ ("Connection to CORE service lost (reconnecting)"));
114  return;
115  default:
116  state_str = _ ("unknown state");
117  break;
118  }
120  FPRINTF (stdout,
121  _ ("%24s: %-30s %4s (timeout in %6s)\n"),
122  now_str,
123  state_str,
124  GNUNET_i2s (peer),
127  GNUNET_YES));
128 }
#define FPRINTF
Definition: plibc.h:683
#define GNUNET_NO
Definition: gnunet_common.h:81
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:524
We've received the other peers session key.
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
enum State state
current state of profiling
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:727
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
This is not a state in a peer's state machine, but a special value used with the GNUNET_CORE_MonitorC...
The other peer has confirmed our session key + PING with a PONG message encrypted with their session ...
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
Last state of a KX (when it is being terminated).
Time for absolute times used by GNUnet, in microseconds.
#define GNUNET_YES
Definition: gnunet_common.h:80
We've sent our session key.
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:792
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
This is not a state in a peer's state machine, but a special value used with the GNUNET_CORE_MonitorC...
static int monitor_connections
Option -m.
Definition: gnunet-core.c:34
We're rekeying (or had a timeout), so we have sent the other peer our new ephemeral key...
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 cfg 
)
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!)
cfgconfiguration

Definition at line 140 of file gnunet-core.c.

References _, FPRINTF, GNUNET_CORE_monitor_start(), GNUNET_SCHEDULER_add_shutdown(), monitor_cb(), and shutdown_task().

Referenced by main().

144 {
145  (void) cls;
146  (void) cfgfile;
147  if (NULL != args[0])
148  {
149  FPRINTF (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
150  return;
151  }
152  mh = GNUNET_CORE_monitor_start (cfg, &monitor_cb, NULL);
153  if (NULL == mh)
154  {
155  FPRINTF (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
156  return;
157  }
159 }
#define FPRINTF
Definition: plibc.h:683
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
static struct GNUNET_CORE_MonitorHandle * mh
Handle to the CORE monitor.
Definition: gnunet-core.c:39
#define _(String)
GNU gettext support macro.
Definition: platform.h:208
static void monitor_cb(void *cls, const struct GNUNET_PeerIdentity *peer, enum GNUNET_CORE_KxState state, struct GNUNET_TIME_Absolute timeout)
Function called to notify core users that another peer changed its state with us. ...
Definition: gnunet-core.c:70
static void shutdown_task(void *cls)
Task run in monitor mode when the user presses CTRL-C to abort.
Definition: gnunet-core.c:49
struct GNUNET_CORE_MonitorHandle * GNUNET_CORE_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CORE_MonitorCallback peer_cb, void *peer_cb_cls)
Monitor connectivity and KX status of all peers known to CORE.
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 from CORE.

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

Definition at line 170 of file gnunet-core.c.

References gettext_noop, GNUNET_free, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), monitor_connections, res, and run().

171 {
172  int res;
175  'm',
176  "monitor",
177  gettext_noop (
178  "provide information about all current connections (continuously)"),
181 
182  if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
183  return 2;
184  res = GNUNET_PROGRAM_run (argc,
185  argv,
186  "gnunet-core",
187  gettext_noop (
188  "Print information about connected peers."),
189  options,
190  &run,
191  NULL);
192 
193  GNUNET_free ((void *) argv);
194  if (GNUNET_OK == res)
195  return 0;
196  return 1;
197 }
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1521
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run by the scheduler.
Definition: gnunet-core.c:140
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static int res
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.
int 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, parse options).
Definition: program.c:361
#define GNUNET_free(ptr)
Wrapper around free.
static int monitor_connections
Option -m.
Definition: gnunet-core.c:34
#define gettext_noop(String)
Definition: gettext.h:69
Here is the call graph for this function:

Variable Documentation

◆ monitor_connections

int monitor_connections
static

Option -m.

Definition at line 34 of file gnunet-core.c.

Referenced by main(), and monitor_cb().

◆ mh

struct GNUNET_CORE_MonitorHandle* mh
static

Handle to the CORE monitor.

Definition at line 39 of file gnunet-core.c.