GNUnet debian-0.24.3-29-g453fda2cf
 
Loading...
Searching...
No Matches
gnunet-core.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011, 2012, 2014, 2025 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
27#include "platform.h"
28#include "gnunet_time_lib.h"
29#include "gnunet_util_lib.h"
30#include "gnunet_core_service.h"
31
35static int ret;
36
41
45static int show_conns;
46
51
58static void
59shutdown_task (void *cls)
60{
61 (void) cls;
62 if (NULL != mh)
63 {
65 mh = NULL;
66 }
67}
68
69
79static void
80monitor_cb (void *cls,
81 const struct GNUNET_PeerIdentity *peer,
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}
163
164
173static void
174run (void *cls,
175 char *const *args,
176 const char *cfgfile,
177 const struct GNUNET_CONFIGURATION_Handle *cfg)
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}
212
213
221int
222main (int argc, char *const *argv)
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}
255
256
257/* end of gnunet-core.c */
struct GNUNET_GETOPT_CommandLineOption options[]
Definition 002.c:5
int main()
Program to simulate results from GCP_get_desirability_of_path() for various plausible inputs.
#define gettext_noop(String)
Definition gettext.h:74
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition gnunet-arm.c:108
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 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
static struct GNUNET_CORE_MonitorHandle * mh
Handle to the CORE monitor.
Definition gnunet-core.c:50
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.
struct GNUNET_SCHEDULER_Task * shutdown_task
static int state
The current state of the parser.
static char * res
Currently read line or NULL on EOF.
Core service; the main API for encrypted P2P communications.
Functions related to time.
GNUNET_CORE_KxState
TODO how does this harmonize with CAKE_CRYPTO_ENABLED?
void GNUNET_CORE_monitor_stop(struct GNUNET_CORE_MonitorHandle *mh)
Stop monitoring CORE activity.
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.
@ 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...
#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
@ GNUNET_YES
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition scheduler.c:567
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_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
Handle to a CORE monitoring operation.
Definition of a command line option.
The identity of the host (wraps the signing key of the peer).
Time for absolute times used by GNUnet, in microseconds.