clean up for configs
[oweals/gnunet.git] / src / peerinfo / perf_peerinfo_api.c
1 /*
2      This file is part of GNUnet.
3      (C) 2004, 2009, 2010 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 3, 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 peerinfo/perf_peerinfo_api.c
23  * @brief testcase for peerinfo_api.c, hopefully hammer the peerinfo service
24  * @author Nathan Evans
25  */
26
27 #include "platform.h"
28 #include "gnunet_hello_lib.h"
29 #include "gnunet_util_lib.h"
30 #include "gnunet_testing_lib.h"
31 #include "gnunet_peerinfo_service.h"
32 #include "peerinfo.h"
33 #include <gauger.h>
34
35 #define START_SERVICE 1
36
37 #define NUM_REQUESTS 5000
38
39 static struct GNUNET_PEERINFO_IteratorContext *ic[NUM_REQUESTS];
40
41 static struct GNUNET_PEERINFO_Handle *h;
42
43 static unsigned int numpeers;
44
45 static struct GNUNET_PeerIdentity pid;
46
47
48 static int
49 check_it (void *cls, const struct GNUNET_HELLO_Address *address,
50           struct GNUNET_TIME_Absolute expiration)
51 {
52   return GNUNET_OK;
53 }
54
55
56 static size_t
57 address_generator (void *cls, size_t max, void *buf)
58 {
59   size_t *agc = cls;
60   size_t ret;
61   char *caddress;
62   struct GNUNET_HELLO_Address address;
63
64   if (*agc == 0)
65     return 0;
66
67   GNUNET_asprintf (&caddress, "Address%d", *agc);
68   address.peer = pid;
69   address.address_length = strlen (caddress) + 1;
70   address.address = caddress;
71   address.transport_name = "peerinfotest";
72   ret =
73       GNUNET_HELLO_add_address (&address,
74                                 GNUNET_TIME_relative_to_absolute
75                                 (GNUNET_TIME_UNIT_HOURS), buf, max);
76   GNUNET_free (caddress);
77   *agc = 0;
78   return ret;
79 }
80
81
82 static void
83 add_peer (size_t i)
84 {
85   struct GNUNET_HELLO_Message *h2;
86
87   memset (&pid, i, sizeof (pid));
88   h2 = GNUNET_HELLO_create (&pid.public_key, &address_generator, &i, GNUNET_NO);
89   GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL);
90   GNUNET_free (h2);
91 }
92
93
94 static void
95 process (void *cls, const struct GNUNET_PeerIdentity *peer,
96          const struct GNUNET_HELLO_Message *hello, const char *err_msg)
97 {
98   if (NULL != peer)
99   {
100     numpeers++;
101     if (0 && (hello != NULL))
102       GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &check_it, NULL);
103
104   }
105 }
106
107
108 static void
109 run (void *cls,
110      const struct GNUNET_CONFIGURATION_Handle *cfg,
111      struct GNUNET_TESTING_Peer *peer)
112 {
113   size_t i;
114
115   h = GNUNET_PEERINFO_connect (cfg);
116   GNUNET_assert (h != NULL);
117   for (i = 0; i < NUM_REQUESTS; i++)
118   {
119     add_peer (i);
120     ic[i] =
121         GNUNET_PEERINFO_iterate (h, GNUNET_YES, NULL,
122                                  GNUNET_TIME_relative_multiply
123                                  (GNUNET_TIME_UNIT_SECONDS, 30), &process, cls);
124   }
125 }
126
127
128 int
129 main (int argc, char *argv[])
130 {
131   if (0 != GNUNET_TESTING_service_run ("perf-gnunet-peerinfo",
132                                        "peerinfo",
133                                        "test_peerinfo_api_data.conf",
134                                        &run, NULL))
135     return 1;
136   FPRINTF (stderr, "Received %u/%u calls before timeout\n", numpeers,
137            NUM_REQUESTS * NUM_REQUESTS / 2);
138   GAUGER ("PEERINFO", "Peerinfo lookups", numpeers / 30, "peers/s");
139   return 0;
140 }
141
142 /* end of perf_peerinfo_api.c */