GNUnet 0.22.2
gnunet-core.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011, 2012, 2014 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
26#include "platform.h"
27#include "gnunet_time_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_core_service.h"
30#include "gnunet_util_lib.h"
31
35static int ret;
36
41
45static int show_pid;
46
50static int show_conns;
51
56
61
66
73static void
74shutdown_task (void *cls)
75{
76 (void) cls;
77 if (NULL != mh)
78 {
80 mh = NULL;
81 }
82}
83
84
94static void
95monitor_cb (void *cls,
96 const struct GNUNET_PeerIdentity *peer,
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}
162
163
172static void
173run (void *cls,
174 char *const *args,
175 const char *cfgfile,
176 const struct GNUNET_CONFIGURATION_Handle *cfg)
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}
243
244
252int
253main (int argc, char *const *argv)
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}
293
294
295/* end of gnunet-core.c */
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 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 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 struct GNUNET_CORE_MonitorHandle * mh
Handle to the CORE monitor.
Definition: gnunet-core.c:55
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 int show_pid
Option -i.
Definition: gnunet-core.c:45
int main(int argc, char *const *argv)
The main function to obtain peer information from CORE.
Definition: gnunet-core.c:253
static char * res
Currently read line or NULL on EOF.
enum State state
current state of profiling
Core service; the main API for encrypted P2P communications.
Functions related to time.
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.
GNUNET_CORE_KxState
State machine for our P2P encryption handshake.
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_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,...
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
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_log(kind,...)
@ GNUNET_OK
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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.
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: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:178
Handle to a CORE monitoring operation.
Private ECC key encoded for transmission.
Definition of a command line option.
The identity of the host (wraps the signing key of the peer).
struct GNUNET_CRYPTO_EddsaPublicKey public_key
Time for absolute times used by GNUnet, in microseconds.