GNUnet 0.21.1
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 int show_pid
 Option -i. More...
 
static int show_conns
 Option -s. 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 59 of file gnunet-core.c.

60{
61 (void) cls;
62 if (NULL != mh)
63 {
65 mh = NULL;
66 }
67}
static struct GNUNET_CORE_MonitorHandle * mh
Handle to the CORE monitor.
Definition: gnunet-core.c:49
void GNUNET_CORE_monitor_stop(struct GNUNET_CORE_MonitorHandle *mh)
Stop monitoring CORE activity.

References GNUNET_CORE_monitor_stop(), and mh.

Referenced by run().

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 80 of file gnunet-core.c.

84{
86 const char *now_str;
87 const char *state_str;
88
89 (void) cls;
90 if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) &&
92 {
94 return;
95 }
96
97 switch (state)
98 {
100 /* should never happen, as we immediately send the key */
101 state_str = _ ("fresh connection");
102 break;
103
105 state_str = _ ("key sent");
106 break;
107
109 state_str = _ ("key received");
110 break;
111
113 state_str = _ ("connection established");
114 break;
115
117 state_str = _ ("rekeying");
118 break;
119
121 state_str = _ ("disconnected");
122 break;
123
125 return;
126
128 fprintf (stderr,
129 "%s\n",
130 _ ("Connection to CORE service lost (reconnecting)"));
131 return;
132
133 default:
134 state_str = _ ("unknown state");
135 break;
136 }
138 fprintf (stdout,
139 _ ("%24s: %-30s %4s (timeout in %6s)\n"),
140 now_str,
141 state_str,
142 GNUNET_i2s (peer),
145 GNUNET_YES));
146}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:119
static int monitor_connections
Option -m.
Definition: gnunet-core.c:34
enum State state
current state of profiling
@ GNUNET_CORE_KX_PEER_DISCONNECT
Last state of a KX (when it is being terminated).
@ GNUNET_CORE_KX_STATE_UP
The other peer has confirmed our session key + PING with a PONG message encrypted with their session ...
@ GNUNET_CORE_KX_STATE_DOWN
No handshake yet.
@ GNUNET_CORE_KX_CORE_DISCONNECT
This is not a state in a peer's state machine, but a special value used with the GNUNET_CORE_MonitorC...
@ GNUNET_CORE_KX_STATE_KEY_SENT
We've sent our session key.
@ GNUNET_CORE_KX_STATE_KEY_RECEIVED
We've received the other peers session key.
@ GNUNET_CORE_KX_ITERATION_FINISHED
This is not a state in a peer's state machine, but a special value used with the GNUNET_CORE_MonitorC...
@ GNUNET_CORE_KX_STATE_REKEY_SENT
We're rekeying (or had a timeout), so we have sent the other peer our new ephemeral key,...
@ GNUNET_YES
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:567
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:405
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:570
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:111
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:617
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Time for absolute times used by GNUnet, in microseconds.

References _, 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, monitor_connections, state, and timeout.

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 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 158 of file gnunet-core.c.

162{
165 char *keyfile;
166 (void) cls;
167 (void) cfgfile;
168 if (NULL != args[0])
169 {
170 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
171 return;
172 }
173 if (GNUNET_OK !=
175 "PEER",
176 "PRIVATE_KEY",
177 &keyfile))
178 {
179 GNUNET_log (
181 _ ("Core service is lacking HOSTKEY configuration setting. Exiting.\n"));
183 return;
184 }
185 if (GNUNET_SYSERR ==
188 &pk))
189 {
191 "Failed to read peer's private key!\n");
193 GNUNET_free (keyfile);
194 return;
195 }
197 if (show_pid)
198 fprintf (stdout,
199 _ ("Current local peer identity: %s\n"),
202 {
204 if (NULL == mh)
205 {
206 fprintf (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
207 return;
208 }
209 }
211 {
212 fprintf (stderr, "%s", _ ("No argument given.\n"));
213 return;
214 }
216}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
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:80
static int show_conns
Option -s.
Definition: gnunet-core.c:44
static void shutdown_task(void *cls)
Task run in monitor mode when the user presses CTRL-C to abort.
Definition: gnunet-core.c:59
static int show_pid
Option -i.
Definition: gnunet-core.c:39
struct GNUNET_CRYPTO_PrivateKey pk
Private key from command line option, or NULL.
static struct GNUNET_CRYPTO_EddsaPublicKey pub
Definition: gnunet-scrypt.c:47
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_filename(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be the name of a file or directory.
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.
enum GNUNET_GenericReturnValue GNUNET_CRYPTO_eddsa_key_from_file(const char *filename, int do_create, struct GNUNET_CRYPTO_EddsaPrivateKey *pkey)
Create a new private key by reading it from a file.
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
#define GNUNET_log(kind,...)
@ GNUNET_OK
@ GNUNET_SYSERR
const char * GNUNET_i2s_full(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_free(ptr)
Wrapper around free.
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:1340
Private ECC key encoded for transmission.
Public ECC key (always for curve Ed25519) encoded in a format suitable for network transmission and E...
The identity of the host (wraps the signing key of the peer).

References _, consensus-simulation::args, cfg, GNUNET_CONFIGURATION_get_value_filename(), GNUNET_CORE_monitor_start(), GNUNET_CRYPTO_eddsa_key_from_file(), GNUNET_CRYPTO_eddsa_key_get_public(), GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_i2s_full(), GNUNET_log, GNUNET_OK, GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_SYSERR, GNUNET_YES, mh, monitor_cb(), monitor_connections, pk, pub, show_conns, show_pid, and shutdown_task().

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 from CORE.

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

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

228{
229 int res;
232 'm',
233 "monitor",
235 "provide information about all current connections (continuously)"),
238 'i',
239 "show-identity",
241 "Show our current peer identity"
242 ),
243 &show_pid),
245 's',
246 "connection-status",
248 "Show current connections"
249 ),
250 &show_conns),
252
253 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
254 return 2;
255 res = GNUNET_PROGRAM_run (argc,
256 argv,
257 "gnunet-core",
259 "Print information about connected peers."),
260 options,
261 &run,
262 NULL);
263
264 GNUNET_free_nz ((void *) argv);
265 if (GNUNET_OK == res)
266 return 0;
267 return 1;
268}
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 *cfg)
Main function that will be run by the scheduler.
Definition: gnunet-core.c:158
static char * res
Currently read line or NULL on EOF.
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.
#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:1230
Definition of a command line option.

References gettext_noop, GNUNET_free_nz, GNUNET_GETOPT_OPTION_END, GNUNET_GETOPT_option_flag(), GNUNET_OK, GNUNET_PROGRAM_run(), GNUNET_STRINGS_get_utf8_args(), monitor_connections, options, res, run(), show_conns, and show_pid.

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(), monitor_cb(), and run().

◆ show_pid

int show_pid
static

Option -i.

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

Referenced by main(), and run().

◆ show_conns

int show_conns
static

Option -s.

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

Referenced by main(), and run().

◆ mh

struct GNUNET_CORE_MonitorHandle* mh
static

Handle to the CORE monitor.

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

Referenced by run(), and shutdown_task().