GNUnet 0.22.2
gnunet-core.c File Reference

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

#include "platform.h"
#include "gnunet_time_lib.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 ret
 Return code. More...
 
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...
 
static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
 Peer private key. More...
 
static struct GNUNET_PeerIdentity my_full_id
 Peer identity. 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 74 of file gnunet-core.c.

75{
76 (void) cls;
77 if (NULL != mh)
78 {
80 mh = NULL;
81 }
82}
static struct GNUNET_CORE_MonitorHandle * mh
Handle to the CORE monitor.
Definition: gnunet-core.c:55
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 95 of file gnunet-core.c.

99{
101 const char *now_str;
102 const char *state_str;
103
104 (void) cls;
105 if (((NULL == peer) || (GNUNET_CORE_KX_ITERATION_FINISHED == state)) &&
107 {
109 return;
110 }
111
112 switch (state)
113 {
115 /* should never happen, as we immediately send the key */
116 state_str = _ ("fresh connection");
117 break;
118
120 state_str = _ ("key sent");
121 break;
122
124 state_str = _ ("key received");
125 break;
126
128 state_str = _ ("connection established");
129 break;
130
132 state_str = _ ("rekeying");
133 break;
134
136 state_str = _ ("disconnected");
137 break;
138
140 return;
141
143 fprintf (stderr,
144 "%s\n",
145 _ ("Connection to CORE service lost (reconnecting)"));
146 return;
147
148 default:
149 state_str = _ ("unknown state");
150 break;
151 }
153 fprintf (stdout,
154 _ ("%24s: %-30s %4s (timeout in %6s)\n"),
155 now_str,
156 state_str,
157 GNUNET_i2s (peer),
160 GNUNET_YES));
161}
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:118
static int monitor_connections
Option -m.
Definition: gnunet-core.c:40
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:406
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:579
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:640
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
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 173 of file gnunet-core.c.

177{
178 char *keyfile;
179 (void) cls;
180 (void) cfgfile;
181
182 if (NULL != args[0])
183 {
184 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
185 return;
186 }
188 {
189 fprintf (stderr, "%s", _ ("No argument given.\n"));
190 ret = 1;
192 return;
193 }
195 if (GNUNET_OK !=
197 "PEER",
198 "PRIVATE_KEY",
199 &keyfile))
200 {
201 GNUNET_log (
203 _ ("Core service is lacking HOSTKEY configuration setting. Exiting.\n"));
205 ret = 1;
206 return;
207 }
208 if (GNUNET_SYSERR ==
212 {
214 "Failed to read peer's private key!\n");
216 ret = 1;
217 GNUNET_free (keyfile);
218 return;
219 }
220 GNUNET_free (keyfile);
222 if (show_pid)
223 fprintf (stdout,
224 _ ("Current local peer identity: %s\n"),
227 {
229 {
230 fprintf (stdout,
231 _ ("Monitoring connections. Press CTRL-C to quit.\n\n"));
232 }
234 if (NULL == mh)
235 {
236 fprintf (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
237 ret = 1;
239 }
240 return;
241 }
242}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:108
static struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
Peer private key.
Definition: gnunet-core.c:60
static struct GNUNET_PeerIdentity my_full_id
Peer identity.
Definition: gnunet-core.c:65
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:95
static int show_conns
Option -s.
Definition: gnunet-core.c:50
static void shutdown_task(void *cls)
Task run in monitor mode when the user presses CTRL-C to abort.
Definition: gnunet-core.c:74
static int ret
Return code.
Definition: gnunet-core.c:35
static int show_pid
Option -i.
Definition: gnunet-core.c:45
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:201
#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:1339
struct GNUNET_CRYPTO_EddsaPublicKey public_key

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, my_full_id, my_private_key, GNUNET_PeerIdentity::public_key, ret, 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 253 of file gnunet-core.c.

254{
255 int res;
258 'm',
259 "monitor",
261 "provide information about all current connections (continuously)"),
264 'i',
265 "show-identity",
267 "Show our current peer identity"
268 ),
269 &show_pid),
271 's',
272 "connection-status",
274 "Show current connections"
275 ),
276 &show_conns),
278
280 argc,
281 argv,
282 "gnunet-core",
284 "Print information about connected peers."),
285 options,
286 &run,
287 NULL);
288
289 if (GNUNET_OK == res)
290 return ret;
291 return 1;
292}
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:74
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:173
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.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(const struct GNUNET_OS_ProjectData *pd, 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:407
Definition of a command line option.

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

Here is the call graph for this function:

Variable Documentation

◆ ret

int ret
static

Return code.

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

Referenced by main(), and run().

◆ monitor_connections

int monitor_connections
static

Option -m.

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

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

◆ show_pid

int show_pid
static

Option -i.

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

Referenced by main(), and run().

◆ show_conns

int show_conns
static

Option -s.

Definition at line 50 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 55 of file gnunet-core.c.

Referenced by run(), and shutdown_task().

◆ my_private_key

struct GNUNET_CRYPTO_EddsaPrivateKey my_private_key
static

◆ my_full_id