GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
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.
 
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.
 
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.
 
int main (int argc, char *const *argv)
 The main function to obtain peer information from CORE.
 

Variables

static int ret
 Return code.
 
static int monitor_connections
 Option -m.
 
static int show_conns
 Option -s.
 
static struct GNUNET_CORE_MonitorHandlemh
 Handle to the CORE monitor.
 

Detailed Description

Print information about other peers known to CORE.

Author
Nathan Evans
Martin Schanzenbach

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:50
void GNUNET_CORE_monitor_stop(struct GNUNET_CORE_MonitorHandle *mh)
Stop monitoring CORE activity.

References GNUNET_CORE_monitor_stop(), and mh.

Here is the call 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 state_str = _ ("Hello sent (I)");
101 break;
102
104 state_str = _ ("Done sent (I)");
105 break;
106
108 state_str = _ ("Awaiting initiation (R)");
109 break;
110
112 state_str = _ ("Hello received (R)");
113 break;
114
116 state_str = _ ("Hello sent (R)");
117 break;
118
120 state_str = _ ("Hello received (I)");
121 break;
122
124 state_str = _ ("Connected (I)");
125 break;
126
128 state_str = _ ("Connected (R)");
129 break;
130
132 /* should never happen, as we immediately send the key */
133 state_str = _ ("idle");
134 break;
135
137 state_str = _ ("disconnected");
138 break;
139
141 return;
142
144 fprintf (stderr,
145 "%s\n",
146 _ ("Connection to CORE service lost (reconnecting)"));
147 return;
148
149 default:
150 state_str = _ ("unknown state");
151 break;
152 }
154 fprintf (stdout,
155 _ ("%24s: %-30s %4s (timeout in %6s)\n"),
156 now_str,
157 state_str,
158 GNUNET_i2s (peer),
161 GNUNET_YES));
162}
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
static int state
The current state of the parser.
@ GNUNET_CORE_KX_PEER_DISCONNECT
Last state of a KX (when it is being terminated).
@ GNUNET_CORE_KX_STATE_RESPONDER_CONNECTED
Connected as responder.
@ GNUNET_CORE_KX_STATE_DOWN
No handshake yet.
@ GNUNET_CORE_KX_STATE_INITIATOR_DONE_SENT
We sent initiator done.
@ 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_INITIATOR_HELLO_RECEIVED
We've received the initiator hello.
@ GNUNET_CORE_KX_STATE_AWAIT_INITIATION
We are awating the initiator hello.
@ GNUNET_CORE_KX_STATE_INITIATOR_CONNECTED
Connected as initiator.
@ GNUNET_CORE_KX_STATE_INITIATOR_HELLO_SENT
We sent the initiator hello.
@ GNUNET_CORE_KX_STATE_RESPONDER_HELLO_RECEIVED
We've received the initiator hello.
@ GNUNET_CORE_KX_STATE_RESPONDER_HELLO_SENT
We sent the responder hello.
@ 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_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:599
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:660
#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_AWAIT_INITIATION, GNUNET_CORE_KX_STATE_DOWN, GNUNET_CORE_KX_STATE_INITIATOR_CONNECTED, GNUNET_CORE_KX_STATE_INITIATOR_DONE_SENT, GNUNET_CORE_KX_STATE_INITIATOR_HELLO_RECEIVED, GNUNET_CORE_KX_STATE_INITIATOR_HELLO_SENT, GNUNET_CORE_KX_STATE_RESPONDER_CONNECTED, GNUNET_CORE_KX_STATE_RESPONDER_HELLO_RECEIVED, GNUNET_CORE_KX_STATE_RESPONDER_HELLO_SENT, 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 174 of file gnunet-core.c.

178{
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 }
196 {
198 {
199 fprintf (stdout,
200 _ ("Monitoring connections. Press CTRL-C to quit.\n\n"));
201 }
203 if (NULL == mh)
204 {
205 fprintf (stderr, "%s", _ ("Failed to connect to CORE service!\n"));
206 ret = 1;
208 }
209 return;
210 }
211}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
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:45
static int ret
Return code.
Definition gnunet-core.c:35
struct GNUNET_SCHEDULER_Task * shutdown_task
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.
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

References _, cfg, GNUNET_CORE_monitor_start(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), mh, monitor_cb(), monitor_connections, ret, show_conns, 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 222 of file gnunet-core.c.

223{
224 int res;
227 'm',
228 "monitor",
230 "provide information about all current connections (continuously)"),
233 's',
234 "connection-status",
236 "Show current connections"
237 ),
238 &show_conns),
240
242 argc,
243 argv,
244 "gnunet-core",
246 "Print information about connected peers."),
247 options,
248 &run,
249 NULL);
250
251 if (GNUNET_OK == res)
252 return ret;
253 return 1;
254}
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.
static char * res
Currently read line or NULL on EOF.
#define GNUNET_GETOPT_OPTION_END
Marker for the end of the list of options.
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.
@ 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(), and show_conns.

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_conns

int show_conns
static

Option -s.

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

Referenced by run(), and shutdown_task().