-comments
[oweals/gnunet.git] / src / set / gnunet-set-bug.c
1 /*
2       This file is part of GNUnet
3       (C) 2012 Christian Grothoff (and other contributing authors)
4
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.
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       General Public License for more details.
14
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.
19  */
20
21 /**
22  * @file set/gnunet-set.c
23  * @brief profiling tool for the set service
24  * @author Florian Dold
25  */
26 #include "platform.h"
27 #include "gnunet_common.h"
28 #include "gnunet_applications.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_stream_lib.h"
31
32
33 static struct GNUNET_PeerIdentity local_id;
34
35 static struct GNUNET_STREAM_ListenSocket *listen_socket;
36
37 static struct GNUNET_STREAM_Socket *s1;
38
39
40
41 static size_t
42 stream_data_processor (void *cls,
43                        enum GNUNET_STREAM_Status status,
44                        const void *data,
45                        size_t size)
46 {
47   return size;
48 }
49
50 static int
51 listen_cb (void *cls,
52            struct GNUNET_STREAM_Socket *socket,
53            const struct 
54            GNUNET_PeerIdentity *initiator)
55 {
56   if (NULL == socket)
57   {
58     GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "socket listen failed\n");
59     return GNUNET_NO;
60   }
61
62   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "socket listen succesful\n");
63   GNUNET_assert (NULL != socket);
64   GNUNET_assert (0 == memcmp (initiator, &local_id, sizeof (*initiator)));
65   GNUNET_STREAM_read (socket, GNUNET_TIME_UNIT_FOREVER_REL, 
66                       stream_data_processor, NULL);
67   return GNUNET_YES;
68 }
69
70 static void
71 open_cb (void *cls, struct GNUNET_STREAM_Socket *socket)
72 {
73 }
74
75 /**
76  * Main function that will be run.
77  *
78  * @param cls closure
79  * @param args remaining command-line arguments
80  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
81  * @param cfg configuration
82  */
83 static void
84 run (void *cls, char *const *args,
85      const char *cfgfile,
86      const struct GNUNET_CONFIGURATION_Handle *cfg)
87 {
88
89   GNUNET_CRYPTO_get_host_identity (cfg, &local_id);
90
91   listen_socket = GNUNET_STREAM_listen (cfg,
92                                         GNUNET_APPLICATION_TYPE_SET,
93                                         listen_cb,
94                                         NULL,
95                                         NULL);
96
97   s1 = GNUNET_STREAM_open (cfg,
98                            &local_id,
99                            GNUNET_APPLICATION_TYPE_SET,
100                            open_cb,
101                            NULL,
102                            NULL);
103 }
104
105
106
107 int
108 main (int argc, char **argv)
109 {
110    static const struct GNUNET_GETOPT_CommandLineOption options[] = {
111       GNUNET_GETOPT_OPTION_END
112   };
113   GNUNET_PROGRAM_run (argc, argv, "gnunet-set",
114                       "help",
115                       options, &run, NULL);
116   return 0;
117 }
118