2 This file is part of GNUnet
3 (C) 2012 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file set/gnunet-set.c
23 * @brief profiling tool for the set service
24 * @author Florian Dold
27 #include "gnunet_common.h"
28 #include "gnunet_applications.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_stream_lib.h"
33 static struct GNUNET_PeerIdentity local_id;
35 static struct GNUNET_CONFIGURATION_Handle *cfg;
37 static struct GNUNET_STREAM_ListenSocket *listen_socket;
39 static struct GNUNET_STREAM_Socket *s1;
41 static struct GNUNET_STREAM_Socket *s2;
44 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
47 GNUNET_STREAM_close (s2);
48 GNUNET_STREAM_close (s1);
49 GNUNET_STREAM_listen_close (listen_socket);
50 GNUNET_CONFIGURATION_destroy (cfg);
54 stream_data_processor (void *cls,
55 enum GNUNET_STREAM_Status status,
64 struct GNUNET_STREAM_Socket *socket,
66 GNUNET_PeerIdentity *initiator)
68 if (NULL == (s2 = socket))
70 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "socket listen failed\n");
74 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "socket listen succesful\n");
75 GNUNET_assert (NULL != socket);
76 GNUNET_assert (0 == memcmp (initiator, &local_id, sizeof (*initiator)));
77 GNUNET_STREAM_read (socket, GNUNET_TIME_UNIT_FOREVER_REL,
78 &stream_data_processor, NULL);
83 open_cb (void *cls, struct GNUNET_STREAM_Socket *socket)
91 s1 = GNUNET_STREAM_open (cfg,
93 GNUNET_APPLICATION_TYPE_SET,
96 GNUNET_STREAM_OPTION_END);
100 * Main function that will be run.
103 * @param args remaining command-line arguments
104 * @param cfgfile name of the configuration file used (for saving, can be NULL!)
105 * @param cfg configuration
108 run (void *cls, char *const *args,
110 const struct GNUNET_CONFIGURATION_Handle *cfg2)
113 cfg = GNUNET_CONFIGURATION_dup (cfg2);
114 GNUNET_CRYPTO_get_host_identity (cfg, &local_id);
116 listen_socket = GNUNET_STREAM_listen (cfg,
117 GNUNET_APPLICATION_TYPE_SET,
120 GNUNET_STREAM_OPTION_SIGNAL_LISTEN_SUCCESS,
122 GNUNET_STREAM_OPTION_END);
123 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
130 main (int argc, char **argv)
132 static const struct GNUNET_GETOPT_CommandLineOption options[] = {
133 GNUNET_GETOPT_OPTION_END
135 GNUNET_PROGRAM_run (argc, argv, "gnunet-set",
137 options, &run, NULL);