summaryrefslogtreecommitdiff
path: root/src/peerinfo/perf_peerinfo_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/peerinfo/perf_peerinfo_api.c')
-rw-r--r--src/peerinfo/perf_peerinfo_api.c150
1 files changed, 75 insertions, 75 deletions
diff --git a/src/peerinfo/perf_peerinfo_api.c b/src/peerinfo/perf_peerinfo_api.c
index d56e0c558..b9317478c 100644
--- a/src/peerinfo/perf_peerinfo_api.c
+++ b/src/peerinfo/perf_peerinfo_api.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file peerinfo/perf_peerinfo_api.c 22 * @file peerinfo/perf_peerinfo_api.c
@@ -48,40 +48,40 @@ static struct GNUNET_SCHEDULER_Task *tt;
48 48
49 49
50static void 50static void
51do_shutdown (void *cls) 51do_shutdown(void *cls)
52{ 52{
53 if (NULL != tt) 53 if (NULL != tt)
54 { 54 {
55 GNUNET_SCHEDULER_cancel (tt); 55 GNUNET_SCHEDULER_cancel(tt);
56 tt = NULL; 56 tt = NULL;
57 } 57 }
58 for (unsigned int i = 0; i < NUM_REQUESTS; i++) 58 for (unsigned int i = 0; i < NUM_REQUESTS; i++)
59 if (NULL != ic[i]) 59 if (NULL != ic[i])
60 GNUNET_PEERINFO_iterate_cancel (ic[i]); 60 GNUNET_PEERINFO_iterate_cancel(ic[i]);
61 GNUNET_PEERINFO_disconnect (h); 61 GNUNET_PEERINFO_disconnect(h);
62 h = NULL; 62 h = NULL;
63} 63}
64 64
65 65
66static void 66static void
67do_timeout (void *cls) 67do_timeout(void *cls)
68{ 68{
69 tt = NULL; 69 tt = NULL;
70 GNUNET_SCHEDULER_shutdown (); 70 GNUNET_SCHEDULER_shutdown();
71} 71}
72 72
73 73
74static int 74static int
75check_it (void *cls, 75check_it(void *cls,
76 const struct GNUNET_HELLO_Address *address, 76 const struct GNUNET_HELLO_Address *address,
77 struct GNUNET_TIME_Absolute expiration) 77 struct GNUNET_TIME_Absolute expiration)
78{ 78{
79 return GNUNET_OK; 79 return GNUNET_OK;
80} 80}
81 81
82 82
83static ssize_t 83static ssize_t
84address_generator (void *cls, size_t max, void *buf) 84address_generator(void *cls, size_t max, void *buf)
85{ 85{
86 size_t *agc = cls; 86 size_t *agc = cls;
87 ssize_t ret; 87 ssize_t ret;
@@ -91,100 +91,100 @@ address_generator (void *cls, size_t max, void *buf)
91 if (*agc == 0) 91 if (*agc == 0)
92 return GNUNET_SYSERR; /* Done */ 92 return GNUNET_SYSERR; /* Done */
93 93
94 GNUNET_asprintf (&caddress, "Address%d", *agc); 94 GNUNET_asprintf(&caddress, "Address%d", *agc);
95 address.peer = pid; 95 address.peer = pid;
96 address.address_length = strlen (caddress) + 1; 96 address.address_length = strlen(caddress) + 1;
97 address.address = caddress; 97 address.address = caddress;
98 address.transport_name = "peerinfotest"; 98 address.transport_name = "peerinfotest";
99 ret = 99 ret =
100 GNUNET_HELLO_add_address (&address, 100 GNUNET_HELLO_add_address(&address,
101 GNUNET_TIME_relative_to_absolute 101 GNUNET_TIME_relative_to_absolute
102 (GNUNET_TIME_UNIT_HOURS), buf, max); 102 (GNUNET_TIME_UNIT_HOURS), buf, max);
103 GNUNET_free (caddress); 103 GNUNET_free(caddress);
104 *agc = 0; 104 *agc = 0;
105 return ret; 105 return ret;
106} 106}
107 107
108 108
109static void 109static void
110add_peer (size_t i) 110add_peer(size_t i)
111{ 111{
112 struct GNUNET_HELLO_Message *h2; 112 struct GNUNET_HELLO_Message *h2;
113 113
114 memset (&pid, i, sizeof (pid)); 114 memset(&pid, i, sizeof(pid));
115 h2 = GNUNET_HELLO_create (&pid.public_key, 115 h2 = GNUNET_HELLO_create(&pid.public_key,
116 &address_generator, 116 &address_generator,
117 &i, 117 &i,
118 GNUNET_NO); 118 GNUNET_NO);
119 GNUNET_PEERINFO_add_peer (h, h2, NULL, NULL); 119 GNUNET_PEERINFO_add_peer(h, h2, NULL, NULL);
120 GNUNET_free (h2); 120 GNUNET_free(h2);
121} 121}
122 122
123 123
124static void 124static void
125process (void *cls, 125process(void *cls,
126 const struct GNUNET_PeerIdentity *peer, 126 const struct GNUNET_PeerIdentity *peer,
127 const struct GNUNET_HELLO_Message *hello, 127 const struct GNUNET_HELLO_Message *hello,
128 const char *err_msg) 128 const char *err_msg)
129{ 129{
130 struct GNUNET_PEERINFO_IteratorContext **icp = cls; 130 struct GNUNET_PEERINFO_IteratorContext **icp = cls;
131 131
132 if (NULL == peer) 132 if (NULL == peer)
133 { 133 {
134 *icp = NULL; 134 *icp = NULL;
135 return; 135 return;
136 } 136 }
137 numpeers++; 137 numpeers++;
138 if (0 && (NULL != hello) ) 138 if (0 && (NULL != hello))
139 GNUNET_HELLO_iterate_addresses (hello, 139 GNUNET_HELLO_iterate_addresses(hello,
140 GNUNET_NO, 140 GNUNET_NO,
141 &check_it, 141 &check_it,
142 NULL); 142 NULL);
143} 143}
144 144
145 145
146static void 146static void
147run (void *cls, 147run(void *cls,
148 const struct GNUNET_CONFIGURATION_Handle *cfg, 148 const struct GNUNET_CONFIGURATION_Handle *cfg,
149 struct GNUNET_TESTING_Peer *peer) 149 struct GNUNET_TESTING_Peer *peer)
150{ 150{
151 h = GNUNET_PEERINFO_connect (cfg); 151 h = GNUNET_PEERINFO_connect(cfg);
152 GNUNET_assert (h != NULL); 152 GNUNET_assert(h != NULL);
153 for (unsigned int i = 0; i < NUM_REQUESTS; i++) 153 for (unsigned int i = 0; i < NUM_REQUESTS; i++)
154 { 154 {
155 add_peer (i); 155 add_peer(i);
156 ic[i] = GNUNET_PEERINFO_iterate (h, 156 ic[i] = GNUNET_PEERINFO_iterate(h,
157 GNUNET_YES, 157 GNUNET_YES,
158 NULL, 158 NULL,
159 &process, 159 &process,
160 &ic[i]); 160 &ic[i]);
161 } 161 }
162 tt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 162 tt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS,
163 5), 163 5),
164 &do_timeout, 164 &do_timeout,
165 NULL); 165 NULL);
166 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, 166 GNUNET_SCHEDULER_add_shutdown(&do_shutdown,
167 NULL); 167 NULL);
168} 168}
169 169
170 170
171int 171int
172main (int argc, 172main(int argc,
173 char *argv[]) 173 char *argv[])
174{ 174{
175 if (0 != GNUNET_TESTING_service_run ("perf-gnunet-peerinfo", 175 if (0 != GNUNET_TESTING_service_run("perf-gnunet-peerinfo",
176 "peerinfo", 176 "peerinfo",
177 "test_peerinfo_api_data.conf", 177 "test_peerinfo_api_data.conf",
178 &run, NULL)) 178 &run, NULL))
179 return 1; 179 return 1;
180 fprintf (stderr, 180 fprintf(stderr,
181 "Received %u/%u calls before timeout\n", 181 "Received %u/%u calls before timeout\n",
182 numpeers, 182 numpeers,
183 NUM_REQUESTS * NUM_REQUESTS / 2); 183 NUM_REQUESTS * NUM_REQUESTS / 2);
184 GAUGER ("PEERINFO", 184 GAUGER("PEERINFO",
185 "Peerinfo lookups", 185 "Peerinfo lookups",
186 numpeers / 5, 186 numpeers / 5,
187 "peers/s"); 187 "peers/s");
188 return 0; 188 return 0;
189} 189}
190 190