GNUnet debian-0.24.3-23-g589b01d60
gnunet-pils.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 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
26#include "platform.h"
27#include "gnunet_time_lib.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_pils_service.h"
30
34static int ret;
35
39static int once;
40
44static struct GNUNET_PILS_Handle *pils;
45
52static void
53shutdown_task (void *cls)
54{
55 (void) cls;
56 if (NULL != pils)
57 {
59 pils = NULL;
60 }
61}
62
63void
64pid_change_cb (void *cls,
65 const struct GNUNET_HELLO_Parser *hparser,
66 const struct GNUNET_HashCode *addr_hash)
67{
68 printf ("%s\n",
70 if (once)
72}
73
82static void
83run (void *cls,
84 char *const *args,
85 const char *cfgfile,
86 const struct GNUNET_CONFIGURATION_Handle *cfg)
87{
88 (void) cls;
89 (void) cfgfile;
90
91 if (NULL != args[0])
92 {
93 fprintf (stderr, _ ("Invalid command line argument `%s'\n"), args[0]);
94 return;
95 }
98 if (NULL == pils)
99 {
100 fprintf (stderr, "%s", _ ("Unable to connect to service.\n"));
101 ret = 1;
103 return;
104 }
105}
106
107
115int
116main (int argc, char *const *argv)
117{
118 int res;
120 {
122 '1',
123 "once",
125 "Show our current peer identity and exit"
126 ),
127 &once),
129
131 argc,
132 argv,
133 "gnunet-pils",
135 "Print information about our peer identity."),
136 options,
137 &run,
138 NULL);
139
140 if (GNUNET_OK == res)
141 return ret;
142 return 1;
143}
144
145
146/* 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 char * res
Currently read line or NULL on EOF.
static void shutdown_task(void *cls)
Task run in monitor mode when the user presses CTRL-C to abort.
Definition: gnunet-pils.c:53
static int ret
Return code.
Definition: gnunet-pils.c:34
static int once
Option -i.
Definition: gnunet-pils.c:39
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-pils.c:83
int main(int argc, char *const *argv)
The main function to obtain peer information from PILS.
Definition: gnunet-pils.c:116
void pid_change_cb(void *cls, const struct GNUNET_HELLO_Parser *hparser, const struct GNUNET_HashCode *addr_hash)
Definition: gnunet-pils.c:64
static struct GNUNET_PILS_Handle * pils
Handle to PILS.
Definition: gnunet-pils.c:44
struct GNUNET_PILS_Handle * GNUNET_PILS_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_PILS_PidChangeCallback pid_change_cb, void *cls)
Connect to the PILS service.
Definition: pils_api.c:367
void GNUNET_PILS_disconnect(struct GNUNET_PILS_Handle *handle)
Disconnect from the PILS service.
Definition: pils_api.c:390
Functions related to time.
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_PeerIdentity * GNUNET_HELLO_parser_get_id(const struct GNUNET_HELLO_Parser *parser)
Get the PeerIdentity for this builder.
Definition: hello-uri.c:353
@ GNUNET_OK
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
#define _(String)
GNU gettext support macro.
Definition: platform.h:179
Definition of a command line option.
Context for parsing HELLOs.
Definition: hello-uri.c:232
A 512-bit hashcode.
A handle for the PILS service.
Definition: pils_api.c:82