GNUnet  0.10.x
gnunet-peerstore.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C)
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_util_lib.h"
29 
30 static int ret;
31 
32 /*
33  * Handle to PEERSTORE service
34  */
36 
37 
43 static void
44 shutdown_task (void *cls)
45 {
46  if (NULL != peerstore_handle)
47  {
48  GNUNET_PEERSTORE_disconnect (peerstore_handle, GNUNET_YES);
49  peerstore_handle = NULL;
50  }
51 }
52 
53 
62 static void
63 run (void *cls,
64  char *const *args,
65  const char *cfgfile,
66  const struct GNUNET_CONFIGURATION_Handle *cfg)
67 {
69  NULL);
70  peerstore_handle = GNUNET_PEERSTORE_connect (cfg);
71  GNUNET_assert (NULL != peerstore_handle);
72  ret = 0;
73 }
74 
75 
83 int
84 main (int argc, char *const *argv)
85 {
86  static const struct GNUNET_GETOPT_CommandLineOption options[] = {
88  };
89  return (GNUNET_OK ==
90  GNUNET_PROGRAM_run (argc, argv, "gnunet-peerstore [options [value]]",
91  gettext_noop ("peerstore"), options, &run,
92  NULL)) ? ret : 1;
93 }
94 
95 /* end of gnunet-peerstore.c */
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, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1293
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
Definition of a command line option.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
int main(int argc, char *const *argv)
The main function to peerstore.
void GNUNET_PEERSTORE_disconnect(struct GNUNET_PEERSTORE_Handle *h, int sync_first)
Disconnect from the PEERSTORE service.
static struct GNUNET_PEERSTORE_Handle * peerstore_handle
Handle to the PEERSTORE service.
Definition: peerstore_api.c:40
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
struct GNUNET_PEERSTORE_Handle * GNUNET_PEERSTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the PEERSTORE service.
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.
configuration data
Definition: configuration.c:85
int GNUNET_PROGRAM_run(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, parse options).
Definition: program.c:361
#define GNUNET_YES
Definition: gnunet_common.h:80
static int ret
static void shutdown_task(void *cls)
Run on shutdown.
#define gettext_noop(String)
Definition: gettext.h:69