diff options
Diffstat (limited to 'src/rps')
-rw-r--r-- | src/rps/Makefile.am | 24 | ||||
-rw-r--r-- | src/rps/gnunet-rps-profiler.c | 2853 | ||||
-rw-r--r-- | src/rps/gnunet-rps.c | 35 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps.c | 1325 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_custommap.c | 22 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_custommap.h | 18 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.c | 19 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler.h | 18 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler_elem.c | 18 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_sampler_elem.h | 18 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_view.c | 26 | ||||
-rw-r--r-- | src/rps/gnunet-service-rps_view.h | 18 | ||||
-rw-r--r-- | src/rps/rps-test_util.c | 261 | ||||
-rw-r--r-- | src/rps/rps-test_util.h | 27 | ||||
-rw-r--r-- | src/rps/rps.conf.in | 4 | ||||
-rw-r--r-- | src/rps/rps.h | 18 | ||||
-rw-r--r-- | src/rps/rps_api.c | 18 | ||||
-rw-r--r-- | src/rps/test_rps.c | 188 | ||||
-rw-r--r-- | src/rps/test_rps.conf | 76 | ||||
-rw-r--r-- | src/rps/test_rps_api.c | 18 | ||||
-rw-r--r-- | src/rps/test_service_rps_custommap.c | 18 | ||||
-rw-r--r-- | src/rps/test_service_rps_sampler_elem.c | 18 | ||||
-rw-r--r-- | src/rps/test_service_rps_view.c | 18 |
23 files changed, 4010 insertions, 1048 deletions
diff --git a/src/rps/Makefile.am b/src/rps/Makefile.am index b5f712268..d477ade92 100644 --- a/src/rps/Makefile.am +++ b/src/rps/Makefile.am | |||
@@ -83,17 +83,18 @@ check_PROGRAMS = \ | |||
83 | test_rps_churn | 83 | test_rps_churn |
84 | endif | 84 | endif |
85 | 85 | ||
86 | rps_test_src = \ | ||
87 | test_rps.c \ | ||
88 | rps-test_util.h rps-test_util.c \ | ||
89 | gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c | ||
90 | |||
86 | ld_rps_test_lib = \ | 91 | ld_rps_test_lib = \ |
87 | libgnunetrps.la \ | 92 | libgnunetrps.la \ |
88 | $(top_builddir)/src/util/libgnunetutil.la \ | 93 | $(top_builddir)/src/util/libgnunetutil.la \ |
94 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
89 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | 95 | $(top_builddir)/src/testbed/libgnunettestbed.la \ |
90 | -lm | 96 | -lm |
91 | 97 | ||
92 | rps_test_src = \ | ||
93 | test_rps.c \ | ||
94 | rps-test_util.h rps-test_util.c \ | ||
95 | gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c | ||
96 | |||
97 | if ENABLE_TEST_RUN | 98 | if ENABLE_TEST_RUN |
98 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; | 99 | AM_TESTS_ENVIRONMENT=export GNUNET_PREFIX=$${GNUNET_PREFIX:-@libdir@};export PATH=$${GNUNET_PREFIX:-@prefix@}/bin:$$PATH;unset XDG_DATA_HOME;unset XDG_CONFIG_HOME; |
99 | TESTS = $(check_PROGRAMS) | 100 | TESTS = $(check_PROGRAMS) |
@@ -140,10 +141,19 @@ test_rps_seed_big_LDADD = $(ld_rps_test_lib) | |||
140 | test_rps_churn_SOURCES = $(rps_test_src) | 141 | test_rps_churn_SOURCES = $(rps_test_src) |
141 | test_rps_churn_LDADD = $(ld_rps_test_lib) | 142 | test_rps_churn_LDADD = $(ld_rps_test_lib) |
142 | 143 | ||
143 | gnunet_rps_profiler_SOURCES = $(rps_test_src) | 144 | gnunet_rps_profiler_SOURCES = \ |
145 | gnunet-service-rps_sampler_elem.h gnunet-service-rps_sampler_elem.c \ | ||
146 | rps-test_util.h rps-test_util.c \ | ||
147 | gnunet-rps-profiler.c | ||
148 | |||
149 | |||
144 | gnunet_rps_profiler_LDADD = \ | 150 | gnunet_rps_profiler_LDADD = \ |
145 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | 151 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ |
146 | $(ld_rps_test_lib) | 152 | libgnunetrps.la \ |
153 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
154 | $(top_builddir)/src/testbed/libgnunettestbed.la \ | ||
155 | -lm | ||
156 | |||
147 | 157 | ||
148 | EXTRA_DIST = \ | 158 | EXTRA_DIST = \ |
149 | test_rps.conf | 159 | test_rps.conf |
diff --git a/src/rps/gnunet-rps-profiler.c b/src/rps/gnunet-rps-profiler.c new file mode 100644 index 000000000..277688b56 --- /dev/null +++ b/src/rps/gnunet-rps-profiler.c | |||
@@ -0,0 +1,2853 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2009, 2012 GNUnet e.V. | ||
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 | /** | ||
19 | * @file rps/test_rps.c | ||
20 | * @brief Testcase for the random peer sampling service. Starts | ||
21 | * a peergroup with a given number of peers, then waits to | ||
22 | * receive size pushes/pulls from each peer. Expects to wait | ||
23 | * for one message from each peer. | ||
24 | */ | ||
25 | #include "platform.h" | ||
26 | //#include "rps_test_lib.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_testbed_service.h" | ||
29 | |||
30 | #include "gnunet_rps_service.h" | ||
31 | #include "rps-test_util.h" | ||
32 | #include "gnunet-service-rps_sampler_elem.h" | ||
33 | |||
34 | #include <inttypes.h> | ||
35 | |||
36 | |||
37 | #define BIT(n) (1 << (n)) | ||
38 | |||
39 | /** | ||
40 | * How many peers do we start? | ||
41 | */ | ||
42 | static uint32_t num_peers; | ||
43 | |||
44 | /** | ||
45 | * @brief numer of bits required to represent the largest peer id | ||
46 | */ | ||
47 | static unsigned bits_needed; | ||
48 | |||
49 | /** | ||
50 | * How long do we run the test? | ||
51 | */ | ||
52 | static struct GNUNET_TIME_Relative duration; | ||
53 | |||
54 | /** | ||
55 | * When do we do a hard shutdown? | ||
56 | */ | ||
57 | static struct GNUNET_TIME_Relative timeout; | ||
58 | |||
59 | |||
60 | /** | ||
61 | * Portion of malicious peers | ||
62 | */ | ||
63 | static double portion = .1; | ||
64 | |||
65 | /** | ||
66 | * Type of malicious peer to test | ||
67 | */ | ||
68 | static unsigned int mal_type = 0; | ||
69 | |||
70 | /** | ||
71 | * Handles to all of the running peers | ||
72 | */ | ||
73 | static struct GNUNET_TESTBED_Peer **testbed_peers; | ||
74 | |||
75 | enum STAT_TYPE | ||
76 | { | ||
77 | STAT_TYPE_ROUNDS, /* 0 */ | ||
78 | STAT_TYPE_BLOCKS, /* 1 */ | ||
79 | STAT_TYPE_BLOCKS_MANY_PUSH, /* 2 */ | ||
80 | STAT_TYPE_BLOCKS_NO_PUSH, /* 3 */ | ||
81 | STAT_TYPE_BLOCKS_NO_PULL, /* 4 */ | ||
82 | STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL, /* 5 */ | ||
83 | STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL, /* 6 */ | ||
84 | STAT_TYPE_ISSUED_PUSH_SEND, /* 7 */ | ||
85 | STAT_TYPE_ISSUED_PULL_REQ, /* 8 */ | ||
86 | STAT_TYPE_ISSUED_PULL_REP, /* 9 */ | ||
87 | STAT_TYPE_SENT_PUSH_SEND, /* 10 */ | ||
88 | STAT_TYPE_SENT_PULL_REQ, /* 11 */ | ||
89 | STAT_TYPE_SENT_PULL_REP, /* 12 */ | ||
90 | STAT_TYPE_RECV_PUSH_SEND, /* 13 */ | ||
91 | STAT_TYPE_RECV_PULL_REQ, /* 14 */ | ||
92 | STAT_TYPE_RECV_PULL_REP, /* 15 */ | ||
93 | STAT_TYPE_MAX, /* 16 */ | ||
94 | }; | ||
95 | |||
96 | struct STATcls | ||
97 | { | ||
98 | struct RPSPeer *rps_peer; | ||
99 | enum STAT_TYPE stat_type; | ||
100 | }; | ||
101 | |||
102 | |||
103 | /** | ||
104 | * @brief Converts string representation to the corresponding #STAT_TYPE enum. | ||
105 | * | ||
106 | * @param stat_str string representation of statistics specifier | ||
107 | * | ||
108 | * @return corresponding enum | ||
109 | */ | ||
110 | enum STAT_TYPE stat_str_2_type (const char *stat_str) | ||
111 | { | ||
112 | if (0 == strncmp ("# rounds blocked - no pull replies", stat_str, strlen ("# rounds blocked - no pull replies"))) | ||
113 | { | ||
114 | return STAT_TYPE_BLOCKS_NO_PULL; | ||
115 | } | ||
116 | else if (0 == strncmp ("# rounds blocked - too many pushes, no pull replies", stat_str, strlen ("# rounds blocked - too many pushes, no pull replies"))) | ||
117 | { | ||
118 | return STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL; | ||
119 | } | ||
120 | else if (0 == strncmp ("# rounds blocked - too many pushes", stat_str, strlen ("# rounds blocked - too many pushes"))) | ||
121 | { | ||
122 | return STAT_TYPE_BLOCKS_MANY_PUSH; | ||
123 | } | ||
124 | else if (0 == strncmp ("# rounds blocked - no pushes, no pull replies", stat_str, strlen ("# rounds blocked - no pushes, no pull replies"))) | ||
125 | { | ||
126 | return STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL; | ||
127 | } | ||
128 | else if (0 == strncmp ("# rounds blocked - no pushes", stat_str, strlen ("# rounds blocked - no pushes"))) | ||
129 | { | ||
130 | return STAT_TYPE_BLOCKS_NO_PUSH; | ||
131 | } | ||
132 | else if (0 == strncmp ("# rounds blocked", stat_str, strlen ("# rounds blocked"))) | ||
133 | { | ||
134 | return STAT_TYPE_BLOCKS; | ||
135 | } | ||
136 | else if (0 == strncmp ("# rounds", stat_str, strlen ("# rounds"))) | ||
137 | { | ||
138 | return STAT_TYPE_ROUNDS; | ||
139 | } | ||
140 | else if (0 == strncmp ("# push send issued", stat_str, strlen ("# push send issued"))) | ||
141 | { | ||
142 | return STAT_TYPE_ISSUED_PUSH_SEND; | ||
143 | } | ||
144 | else if (0 == strncmp ("# pull request send issued", stat_str, strlen ("# pull request send issued"))) | ||
145 | { | ||
146 | return STAT_TYPE_ISSUED_PULL_REQ; | ||
147 | } | ||
148 | else if (0 == strncmp ("# pull reply send issued", stat_str, strlen ("# pull reply send issued"))) | ||
149 | { | ||
150 | return STAT_TYPE_ISSUED_PULL_REP; | ||
151 | } | ||
152 | else if (0 == strncmp ("# pushes sent", stat_str, strlen ("# pushes sent"))) | ||
153 | { | ||
154 | return STAT_TYPE_SENT_PUSH_SEND; | ||
155 | } | ||
156 | else if (0 == strncmp ("# pull requests sent", stat_str, strlen ("# pull requests sent"))) | ||
157 | { | ||
158 | return STAT_TYPE_SENT_PULL_REQ; | ||
159 | } | ||
160 | else if (0 == strncmp ("# pull replys sent", stat_str, strlen ("# pull replys sent"))) | ||
161 | { | ||
162 | return STAT_TYPE_SENT_PULL_REP; | ||
163 | } | ||
164 | else if (0 == strncmp ("# push message received", stat_str, strlen ("# push message received"))) | ||
165 | { | ||
166 | return STAT_TYPE_RECV_PUSH_SEND; | ||
167 | } | ||
168 | else if (0 == strncmp ("# pull request message received", stat_str, strlen ("# pull request message received"))) | ||
169 | { | ||
170 | return STAT_TYPE_RECV_PULL_REQ; | ||
171 | } | ||
172 | else if (0 == strncmp ("# pull reply messages received", stat_str, strlen ("# pull reply messages received"))) | ||
173 | { | ||
174 | return STAT_TYPE_RECV_PULL_REP; | ||
175 | } | ||
176 | return STAT_TYPE_MAX; | ||
177 | } | ||
178 | |||
179 | |||
180 | /** | ||
181 | * @brief Converts #STAT_TYPE enum to the equivalent string representation that | ||
182 | * is stored with the statistics service. | ||
183 | * | ||
184 | * @param stat_type #STAT_TYPE enum | ||
185 | * | ||
186 | * @return string representation that matches statistics value | ||
187 | */ | ||
188 | char* stat_type_2_str (enum STAT_TYPE stat_type) | ||
189 | { | ||
190 | switch (stat_type) | ||
191 | { | ||
192 | case STAT_TYPE_ROUNDS: | ||
193 | return "# rounds"; | ||
194 | case STAT_TYPE_BLOCKS: | ||
195 | return "# rounds blocked"; | ||
196 | case STAT_TYPE_BLOCKS_MANY_PUSH: | ||
197 | return "# rounds blocked - too many pushes"; | ||
198 | case STAT_TYPE_BLOCKS_NO_PUSH: | ||
199 | return "# rounds blocked - no pushes"; | ||
200 | case STAT_TYPE_BLOCKS_NO_PULL: | ||
201 | return "# rounds blocked - no pull replies"; | ||
202 | case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: | ||
203 | return "# rounds blocked - too many pushes, no pull replies"; | ||
204 | case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: | ||
205 | return "# rounds blocked - no pushes, no pull replies"; | ||
206 | case STAT_TYPE_ISSUED_PUSH_SEND: | ||
207 | return "# push send issued"; | ||
208 | case STAT_TYPE_ISSUED_PULL_REQ: | ||
209 | return "# pull request send issued"; | ||
210 | case STAT_TYPE_ISSUED_PULL_REP: | ||
211 | return "# pull reply send issued"; | ||
212 | case STAT_TYPE_SENT_PUSH_SEND: | ||
213 | return "# pushes sent"; | ||
214 | case STAT_TYPE_SENT_PULL_REQ: | ||
215 | return "# pull requests sent"; | ||
216 | case STAT_TYPE_SENT_PULL_REP: | ||
217 | return "# pull replys sent"; | ||
218 | case STAT_TYPE_RECV_PUSH_SEND: | ||
219 | return "# push message received"; | ||
220 | case STAT_TYPE_RECV_PULL_REQ: | ||
221 | return "# pull request message received"; | ||
222 | case STAT_TYPE_RECV_PULL_REP: | ||
223 | return "# pull reply messages received"; | ||
224 | case STAT_TYPE_MAX: | ||
225 | default: | ||
226 | return "ERROR"; | ||
227 | ; | ||
228 | } | ||
229 | } | ||
230 | |||
231 | |||
232 | /** | ||
233 | * @brief Indicates whether peer should go off- or online | ||
234 | */ | ||
235 | enum PEER_ONLINE_DELTA { | ||
236 | /** | ||
237 | * @brief Indicates peer going online | ||
238 | */ | ||
239 | PEER_GO_ONLINE = 1, | ||
240 | /** | ||
241 | * @brief Indicates peer going offline | ||
242 | */ | ||
243 | PEER_GO_OFFLINE = -1, | ||
244 | }; | ||
245 | |||
246 | /** | ||
247 | * Operation map entry | ||
248 | */ | ||
249 | struct OpListEntry | ||
250 | { | ||
251 | /** | ||
252 | * DLL next ptr | ||
253 | */ | ||
254 | struct OpListEntry *next; | ||
255 | |||
256 | /** | ||
257 | * DLL prev ptr | ||
258 | */ | ||
259 | struct OpListEntry *prev; | ||
260 | |||
261 | /** | ||
262 | * The testbed operation | ||
263 | */ | ||
264 | struct GNUNET_TESTBED_Operation *op; | ||
265 | |||
266 | /** | ||
267 | * Depending on whether we start or stop RPS service at the peer, set this to | ||
268 | * #PEER_GO_ONLINE (1) or #PEER_GO_OFFLINE (-1) | ||
269 | */ | ||
270 | enum PEER_ONLINE_DELTA delta; | ||
271 | |||
272 | /** | ||
273 | * Index of the regarding peer | ||
274 | */ | ||
275 | unsigned int index; | ||
276 | }; | ||
277 | |||
278 | /** | ||
279 | * OpList DLL head | ||
280 | */ | ||
281 | static struct OpListEntry *oplist_head; | ||
282 | |||
283 | /** | ||
284 | * OpList DLL tail | ||
285 | */ | ||
286 | static struct OpListEntry *oplist_tail; | ||
287 | |||
288 | |||
289 | /** | ||
290 | * A pending reply: A request was sent and the reply is pending. | ||
291 | */ | ||
292 | struct PendingReply | ||
293 | { | ||
294 | /** | ||
295 | * DLL next,prev ptr | ||
296 | */ | ||
297 | struct PendingReply *next; | ||
298 | struct PendingReply *prev; | ||
299 | |||
300 | /** | ||
301 | * Handle to the request we are waiting for | ||
302 | */ | ||
303 | struct GNUNET_RPS_Request_Handle *req_handle; | ||
304 | |||
305 | /** | ||
306 | * The peer that requested | ||
307 | */ | ||
308 | struct RPSPeer *rps_peer; | ||
309 | }; | ||
310 | |||
311 | |||
312 | /** | ||
313 | * A pending request: A request was not made yet but is scheduled for later. | ||
314 | */ | ||
315 | struct PendingRequest | ||
316 | { | ||
317 | /** | ||
318 | * DLL next,prev ptr | ||
319 | */ | ||
320 | struct PendingRequest *next; | ||
321 | struct PendingRequest *prev; | ||
322 | |||
323 | /** | ||
324 | * Handle to the request we are waiting for | ||
325 | */ | ||
326 | struct GNUNET_SCHEDULER_Task *request_task; | ||
327 | |||
328 | /** | ||
329 | * The peer that requested | ||
330 | */ | ||
331 | struct RPSPeer *rps_peer; | ||
332 | }; | ||
333 | |||
334 | |||
335 | /** | ||
336 | * Information we track for each peer. | ||
337 | */ | ||
338 | struct RPSPeer | ||
339 | { | ||
340 | /** | ||
341 | * Index of the peer. | ||
342 | */ | ||
343 | unsigned int index; | ||
344 | |||
345 | /** | ||
346 | * Handle for RPS connect operation. | ||
347 | */ | ||
348 | struct GNUNET_TESTBED_Operation *op; | ||
349 | |||
350 | /** | ||
351 | * Handle to RPS service. | ||
352 | */ | ||
353 | struct GNUNET_RPS_Handle *rps_handle; | ||
354 | |||
355 | /** | ||
356 | * ID of the peer. | ||
357 | */ | ||
358 | struct GNUNET_PeerIdentity *peer_id; | ||
359 | |||
360 | /** | ||
361 | * A request handle to check for an request | ||
362 | */ | ||
363 | //struct GNUNET_RPS_Request_Handle *req_handle; | ||
364 | |||
365 | /** | ||
366 | * Peer on- or offline? | ||
367 | */ | ||
368 | int online; | ||
369 | |||
370 | /** | ||
371 | * Number of Peer IDs to request during the whole test | ||
372 | */ | ||
373 | unsigned int num_ids_to_request; | ||
374 | |||
375 | /** | ||
376 | * Pending requests DLL | ||
377 | */ | ||
378 | struct PendingRequest *pending_req_head; | ||
379 | struct PendingRequest *pending_req_tail; | ||
380 | |||
381 | /** | ||
382 | * Number of pending requests | ||
383 | */ | ||
384 | unsigned int num_pending_reqs; | ||
385 | |||
386 | /** | ||
387 | * Pending replies DLL | ||
388 | */ | ||
389 | struct PendingReply *pending_rep_head; | ||
390 | struct PendingReply *pending_rep_tail; | ||
391 | |||
392 | /** | ||
393 | * Number of pending replies | ||
394 | */ | ||
395 | unsigned int num_pending_reps; | ||
396 | |||
397 | /** | ||
398 | * Number of received PeerIDs | ||
399 | */ | ||
400 | unsigned int num_recv_ids; | ||
401 | |||
402 | /** | ||
403 | * Pending operation on that peer | ||
404 | */ | ||
405 | const struct OpListEntry *entry_op_manage; | ||
406 | |||
407 | /** | ||
408 | * Testbed operation to connect to statistics service | ||
409 | */ | ||
410 | struct GNUNET_TESTBED_Operation *stat_op; | ||
411 | |||
412 | /** | ||
413 | * Handle to the statistics service | ||
414 | */ | ||
415 | struct GNUNET_STATISTICS_Handle *stats_h; | ||
416 | |||
417 | /** | ||
418 | * @brief flags to indicate which statistics values have been already | ||
419 | * collected from the statistics service. | ||
420 | * Used to check whether we are able to shutdown. | ||
421 | */ | ||
422 | uint32_t stat_collected_flags; | ||
423 | |||
424 | /** | ||
425 | * @brief File name of the file the stats are finally written to | ||
426 | */ | ||
427 | const char *file_name_stats; | ||
428 | |||
429 | /** | ||
430 | * @brief File name of the file the stats are finally written to | ||
431 | */ | ||
432 | const char *file_name_probs; | ||
433 | |||
434 | /** | ||
435 | * @brief The current view | ||
436 | */ | ||
437 | struct GNUNET_PeerIdentity *cur_view; | ||
438 | |||
439 | /** | ||
440 | * @brief Number of peers in the #cur_view. | ||
441 | */ | ||
442 | uint32_t cur_view_count; | ||
443 | |||
444 | /** | ||
445 | * @brief Number of occurrences in other peer's view | ||
446 | */ | ||
447 | uint32_t count_in_views; | ||
448 | |||
449 | /** | ||
450 | * @brief statistics values | ||
451 | */ | ||
452 | uint64_t stats[STAT_TYPE_MAX]; | ||
453 | /** | ||
454 | * @brief Handle for the statistics get request | ||
455 | */ | ||
456 | struct GNUNET_STATISTICS_GetHandle *h_stat_get[STAT_TYPE_MAX]; | ||
457 | }; | ||
458 | |||
459 | /** | ||
460 | * Information for all the peers. | ||
461 | */ | ||
462 | static struct RPSPeer *rps_peers; | ||
463 | |||
464 | /** | ||
465 | * Peermap to get the index of a given peer ID quick. | ||
466 | */ | ||
467 | static struct GNUNET_CONTAINER_MultiPeerMap *peer_map; | ||
468 | |||
469 | /** | ||
470 | * IDs of the peers. | ||
471 | */ | ||
472 | static struct GNUNET_PeerIdentity *rps_peer_ids; | ||
473 | |||
474 | /** | ||
475 | * ID of the targeted peer. | ||
476 | */ | ||
477 | static struct GNUNET_PeerIdentity *target_peer; | ||
478 | |||
479 | /** | ||
480 | * ID of the peer that requests for the evaluation. | ||
481 | */ | ||
482 | static struct RPSPeer *eval_peer; | ||
483 | |||
484 | /** | ||
485 | * Number of online peers. | ||
486 | */ | ||
487 | static unsigned int num_peers_online; | ||
488 | |||
489 | /** | ||
490 | * @brief The added sizes of the peer's views | ||
491 | */ | ||
492 | static unsigned int view_sizes; | ||
493 | |||
494 | /** | ||
495 | * Return value from 'main'. | ||
496 | */ | ||
497 | static int ok; | ||
498 | |||
499 | /** | ||
500 | * Identifier for the task that runs after the test to collect results | ||
501 | */ | ||
502 | static struct GNUNET_SCHEDULER_Task *post_test_task; | ||
503 | |||
504 | /** | ||
505 | * Identifier for the shutdown task | ||
506 | */ | ||
507 | static struct GNUNET_SCHEDULER_Task *shutdown_task; | ||
508 | |||
509 | |||
510 | /** | ||
511 | * Identifier for the churn task that runs periodically | ||
512 | */ | ||
513 | static struct GNUNET_SCHEDULER_Task *churn_task; | ||
514 | |||
515 | /** | ||
516 | * Called to initialise the given RPSPeer | ||
517 | */ | ||
518 | typedef void (*InitPeer) (struct RPSPeer *rps_peer); | ||
519 | |||
520 | /** | ||
521 | * @brief Called directly after connecting to the service | ||
522 | * | ||
523 | * @param rps_peer Specific peer the function is called on | ||
524 | * @param h the handle to the rps service | ||
525 | */ | ||
526 | typedef void (*PreTest) (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h); | ||
527 | |||
528 | /** | ||
529 | * @brief Executes functions to test the api/service for a given peer | ||
530 | * | ||
531 | * Called from within #rps_connect_complete_cb () | ||
532 | * Implemented by #churn_test_cb, #profiler_cb, #mal_cb, #single_req_cb, | ||
533 | * #delay_req_cb, #seed_big_cb, #single_peer_seed_cb, #seed_cb, #req_cancel_cb | ||
534 | * | ||
535 | * @param rps_peer the peer the task runs on | ||
536 | */ | ||
537 | typedef void (*MainTest) (struct RPSPeer *rps_peer); | ||
538 | |||
539 | /** | ||
540 | * Callback called once the requested random peers are available | ||
541 | */ | ||
542 | typedef void (*ReplyHandle) (void *cls, | ||
543 | uint64_t n, | ||
544 | const struct GNUNET_PeerIdentity *recv_peers); | ||
545 | |||
546 | /** | ||
547 | * Called directly before disconnecting from the service | ||
548 | */ | ||
549 | typedef void (*PostTest) (struct RPSPeer *peer); | ||
550 | |||
551 | /** | ||
552 | * Function called after disconnect to evaluate test success | ||
553 | */ | ||
554 | typedef int (*EvaluationCallback) (void); | ||
555 | |||
556 | /** | ||
557 | * @brief Do we have Churn? | ||
558 | */ | ||
559 | enum OPTION_CHURN { | ||
560 | /** | ||
561 | * @brief If we have churn this is set | ||
562 | */ | ||
563 | HAVE_CHURN, | ||
564 | /** | ||
565 | * @brief If we have no churn this is set | ||
566 | */ | ||
567 | HAVE_NO_CHURN, | ||
568 | }; | ||
569 | |||
570 | /** | ||
571 | * @brief Is it ok to quit the test before the timeout? | ||
572 | */ | ||
573 | enum OPTION_QUICK_QUIT { | ||
574 | /** | ||
575 | * @brief It is ok for the test to quit before the timeout triggers | ||
576 | */ | ||
577 | HAVE_QUICK_QUIT, | ||
578 | |||
579 | /** | ||
580 | * @brief It is NOT ok for the test to quit before the timeout triggers | ||
581 | */ | ||
582 | HAVE_NO_QUICK_QUIT, | ||
583 | }; | ||
584 | |||
585 | /** | ||
586 | * @brief Do we collect statistics at the end? | ||
587 | */ | ||
588 | enum OPTION_COLLECT_STATISTICS { | ||
589 | /** | ||
590 | * @brief We collect statistics at the end | ||
591 | */ | ||
592 | COLLECT_STATISTICS, | ||
593 | |||
594 | /** | ||
595 | * @brief We do not collect statistics at the end | ||
596 | */ | ||
597 | NO_COLLECT_STATISTICS, | ||
598 | }; | ||
599 | |||
600 | /** | ||
601 | * @brief Do we collect views during run? | ||
602 | */ | ||
603 | enum OPTION_COLLECT_VIEW { | ||
604 | /** | ||
605 | * @brief We collect view during run | ||
606 | */ | ||
607 | COLLECT_VIEW, | ||
608 | |||
609 | /** | ||
610 | * @brief We do not collect the view during run | ||
611 | */ | ||
612 | NO_COLLECT_VIEW, | ||
613 | }; | ||
614 | |||
615 | /** | ||
616 | * Structure to define a single test | ||
617 | */ | ||
618 | struct SingleTestRun | ||
619 | { | ||
620 | /** | ||
621 | * Name of the test | ||
622 | */ | ||
623 | char *name; | ||
624 | |||
625 | /** | ||
626 | * Called with a single peer in order to initialise that peer | ||
627 | */ | ||
628 | InitPeer init_peer; | ||
629 | |||
630 | /** | ||
631 | * Called directly after connecting to the service | ||
632 | */ | ||
633 | PreTest pre_test; | ||
634 | |||
635 | /** | ||
636 | * Main function for each peer | ||
637 | */ | ||
638 | MainTest main_test; | ||
639 | |||
640 | /** | ||
641 | * Callback called once the requested peers are available | ||
642 | */ | ||
643 | ReplyHandle reply_handle; | ||
644 | |||
645 | /** | ||
646 | * Called directly before disconnecting from the service | ||
647 | */ | ||
648 | PostTest post_test; | ||
649 | |||
650 | /** | ||
651 | * Function to evaluate the test results | ||
652 | */ | ||
653 | EvaluationCallback eval_cb; | ||
654 | |||
655 | /** | ||
656 | * Request interval | ||
657 | */ | ||
658 | uint32_t request_interval; | ||
659 | |||
660 | /** | ||
661 | * Number of Requests to make. | ||
662 | */ | ||
663 | uint32_t num_requests; | ||
664 | |||
665 | /** | ||
666 | * Run with (-out) churn | ||
667 | */ | ||
668 | enum OPTION_CHURN have_churn; | ||
669 | |||
670 | /** | ||
671 | * Quit test before timeout? | ||
672 | */ | ||
673 | enum OPTION_QUICK_QUIT have_quick_quit; | ||
674 | |||
675 | /** | ||
676 | * Collect statistics at the end? | ||
677 | */ | ||
678 | enum OPTION_COLLECT_STATISTICS have_collect_statistics; | ||
679 | |||
680 | /** | ||
681 | * Collect view during run? | ||
682 | */ | ||
683 | enum OPTION_COLLECT_VIEW have_collect_view; | ||
684 | |||
685 | /** | ||
686 | * @brief Mark which values from the statistics service to collect at the end | ||
687 | * of the run | ||
688 | */ | ||
689 | uint32_t stat_collect_flags; | ||
690 | } cur_test_run; | ||
691 | |||
692 | /** | ||
693 | * Did we finish the test? | ||
694 | */ | ||
695 | static int post_test; | ||
696 | |||
697 | /** | ||
698 | * Are we shutting down? | ||
699 | */ | ||
700 | static int in_shutdown; | ||
701 | |||
702 | /** | ||
703 | * Append arguments to file | ||
704 | */ | ||
705 | static void | ||
706 | tofile_ (const char *file_name, const char *line) | ||
707 | { | ||
708 | struct GNUNET_DISK_FileHandle *f; | ||
709 | /* char output_buffer[512]; */ | ||
710 | size_t size; | ||
711 | /* int size; */ | ||
712 | size_t size2; | ||
713 | |||
714 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | ||
715 | GNUNET_DISK_OPEN_APPEND | | ||
716 | GNUNET_DISK_OPEN_WRITE | | ||
717 | GNUNET_DISK_OPEN_CREATE, | ||
718 | GNUNET_DISK_PERM_USER_READ | | ||
719 | GNUNET_DISK_PERM_USER_WRITE | | ||
720 | GNUNET_DISK_PERM_GROUP_READ | | ||
721 | GNUNET_DISK_PERM_OTHER_READ))) | ||
722 | { | ||
723 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
724 | "Not able to open file %s\n", | ||
725 | file_name); | ||
726 | return; | ||
727 | } | ||
728 | /* size = GNUNET_snprintf (output_buffer, | ||
729 | sizeof (output_buffer), | ||
730 | "%llu %s\n", | ||
731 | GNUNET_TIME_absolute_get ().abs_value_us, | ||
732 | line); | ||
733 | if (0 > size) | ||
734 | { | ||
735 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
736 | "Failed to write string to buffer (size: %i)\n", | ||
737 | size); | ||
738 | return; | ||
739 | } */ | ||
740 | |||
741 | size = strlen (line) * sizeof (char); | ||
742 | |||
743 | size2 = GNUNET_DISK_file_write (f, line, size); | ||
744 | if (size != size2) | ||
745 | { | ||
746 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
747 | "Unable to write to file! (Size: %lu, size2: %lu)\n", | ||
748 | size, | ||
749 | size2); | ||
750 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
751 | { | ||
752 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
753 | "Unable to close file\n"); | ||
754 | } | ||
755 | return; | ||
756 | } | ||
757 | |||
758 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
759 | { | ||
760 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
761 | "Unable to close file\n"); | ||
762 | } | ||
763 | } | ||
764 | |||
765 | /** | ||
766 | * This function is used to facilitate writing important information to disk | ||
767 | */ | ||
768 | #define tofile(file_name, ...) do {\ | ||
769 | char tmp_buf[512];\ | ||
770 | int size;\ | ||
771 | size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\ | ||
772 | if (0 > size)\ | ||
773 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING,\ | ||
774 | "Failed to create tmp_buf\n");\ | ||
775 | else\ | ||
776 | tofile_(file_name,tmp_buf);\ | ||
777 | } while (0); | ||
778 | |||
779 | |||
780 | /** | ||
781 | * Write the ids and their according index in the given array to a file | ||
782 | * Unused | ||
783 | */ | ||
784 | /* static void | ||
785 | ids_to_file (char *file_name, | ||
786 | struct GNUNET_PeerIdentity *peer_ids, | ||
787 | unsigned int num_peer_ids) | ||
788 | { | ||
789 | unsigned int i; | ||
790 | |||
791 | for (i=0 ; i < num_peer_ids ; i++) | ||
792 | { | ||
793 | to_file (file_name, | ||
794 | "%u\t%s", | ||
795 | i, | ||
796 | GNUNET_i2s_full (&peer_ids[i])); | ||
797 | } | ||
798 | } */ | ||
799 | |||
800 | /** | ||
801 | * Test the success of a single test | ||
802 | */ | ||
803 | static int | ||
804 | evaluate (void) | ||
805 | { | ||
806 | unsigned int i; | ||
807 | int tmp_ok; | ||
808 | |||
809 | tmp_ok = 1; | ||
810 | |||
811 | for (i = 0; i < num_peers; i++) | ||
812 | { | ||
813 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
814 | "%u. peer [%s] received %u of %u expected peer_ids: %i\n", | ||
815 | i, | ||
816 | GNUNET_i2s (rps_peers[i].peer_id), | ||
817 | rps_peers[i].num_recv_ids, | ||
818 | rps_peers[i].num_ids_to_request, | ||
819 | (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids)); | ||
820 | tmp_ok &= (rps_peers[i].num_ids_to_request == rps_peers[i].num_recv_ids); | ||
821 | } | ||
822 | return tmp_ok? 0 : 1; | ||
823 | } | ||
824 | |||
825 | |||
826 | /** | ||
827 | * Creates an oplist entry and adds it to the oplist DLL | ||
828 | */ | ||
829 | static struct OpListEntry * | ||
830 | make_oplist_entry () | ||
831 | { | ||
832 | struct OpListEntry *entry; | ||
833 | |||
834 | entry = GNUNET_new (struct OpListEntry); | ||
835 | GNUNET_CONTAINER_DLL_insert_tail (oplist_head, oplist_tail, entry); | ||
836 | return entry; | ||
837 | } | ||
838 | |||
839 | |||
840 | /** | ||
841 | * @brief Checks if given peer already received its statistics value from the | ||
842 | * statistics service. | ||
843 | * | ||
844 | * @param rps_peer the peer to check for | ||
845 | * | ||
846 | * @return #GNUNET_YES if so | ||
847 | * #GNUNET_NO otherwise | ||
848 | */ | ||
849 | static int check_statistics_collect_completed_single_peer ( | ||
850 | const struct RPSPeer *rps_peer) | ||
851 | { | ||
852 | if (cur_test_run.stat_collect_flags != | ||
853 | (cur_test_run.stat_collect_flags & | ||
854 | rps_peer->stat_collected_flags)) | ||
855 | { | ||
856 | return GNUNET_NO; | ||
857 | } | ||
858 | return GNUNET_YES; | ||
859 | } | ||
860 | /** | ||
861 | * @brief Checks if all peers already received their statistics value from the | ||
862 | * statistics service. | ||
863 | * | ||
864 | * @return #GNUNET_YES if so | ||
865 | * #GNUNET_NO otherwise | ||
866 | */ | ||
867 | static int check_statistics_collect_completed () | ||
868 | { | ||
869 | uint32_t i; | ||
870 | |||
871 | for (i = 0; i < num_peers; i++) | ||
872 | { | ||
873 | if (GNUNET_NO == check_statistics_collect_completed_single_peer (&rps_peers[i])) | ||
874 | { | ||
875 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
876 | "At least Peer %" PRIu32 " did not yet receive all statistics values\n", | ||
877 | i); | ||
878 | return GNUNET_NO; | ||
879 | } | ||
880 | } | ||
881 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
882 | "All peers received their statistics values\n"); | ||
883 | return GNUNET_YES; | ||
884 | } | ||
885 | |||
886 | static void | ||
887 | rps_disconnect_adapter (void *cls, | ||
888 | void *op_result); | ||
889 | |||
890 | static void | ||
891 | cancel_pending_req (struct PendingRequest *pending_req) | ||
892 | { | ||
893 | struct RPSPeer *rps_peer; | ||
894 | |||
895 | rps_peer = pending_req->rps_peer; | ||
896 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | ||
897 | rps_peer->pending_req_tail, | ||
898 | pending_req); | ||
899 | rps_peer->num_pending_reqs--; | ||
900 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
901 | "Cancelling pending rps get request\n"); | ||
902 | GNUNET_SCHEDULER_cancel (pending_req->request_task); | ||
903 | GNUNET_free (pending_req); | ||
904 | } | ||
905 | |||
906 | static void | ||
907 | cancel_request (struct PendingReply *pending_rep) | ||
908 | { | ||
909 | struct RPSPeer *rps_peer; | ||
910 | |||
911 | rps_peer = pending_rep->rps_peer; | ||
912 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | ||
913 | rps_peer->pending_rep_tail, | ||
914 | pending_rep); | ||
915 | rps_peer->num_pending_reps--; | ||
916 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
917 | "Cancelling rps get reply\n"); | ||
918 | GNUNET_RPS_request_cancel (pending_rep->req_handle); | ||
919 | GNUNET_free (pending_rep); | ||
920 | } | ||
921 | |||
922 | void | ||
923 | clean_peer (unsigned peer_index) | ||
924 | { | ||
925 | struct PendingRequest *pending_req; | ||
926 | |||
927 | while (NULL != (pending_req = rps_peers[peer_index].pending_req_head)) | ||
928 | { | ||
929 | cancel_pending_req (pending_req); | ||
930 | } | ||
931 | pending_req = rps_peers[peer_index].pending_req_head; | ||
932 | rps_disconnect_adapter (&rps_peers[peer_index], | ||
933 | &rps_peers[peer_index].rps_handle); | ||
934 | for (unsigned stat_type = STAT_TYPE_ROUNDS; | ||
935 | stat_type < STAT_TYPE_MAX; | ||
936 | stat_type++) | ||
937 | { | ||
938 | if (NULL != rps_peers[peer_index].h_stat_get[stat_type]) | ||
939 | { | ||
940 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
941 | "(%u) did not yet receive stat value for `%s'\n", | ||
942 | rps_peers[peer_index].index, | ||
943 | stat_type_2_str (stat_type)); | ||
944 | GNUNET_STATISTICS_get_cancel ( | ||
945 | rps_peers[peer_index].h_stat_get[stat_type]); | ||
946 | } | ||
947 | } | ||
948 | if (NULL != rps_peers[peer_index].op) | ||
949 | { | ||
950 | GNUNET_TESTBED_operation_done (rps_peers[peer_index].op); | ||
951 | rps_peers[peer_index].op = NULL; | ||
952 | } | ||
953 | } | ||
954 | |||
955 | /** | ||
956 | * Task run on timeout to shut everything down. | ||
957 | */ | ||
958 | static void | ||
959 | shutdown_op (void *cls) | ||
960 | { | ||
961 | unsigned int i; | ||
962 | struct OpListEntry *entry; | ||
963 | |||
964 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
965 | "Shutdown task scheduled, going down.\n"); | ||
966 | in_shutdown = GNUNET_YES; | ||
967 | |||
968 | if (NULL != shutdown_task) | ||
969 | { | ||
970 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
971 | shutdown_task = NULL; | ||
972 | } | ||
973 | if (NULL != post_test_task) | ||
974 | { | ||
975 | GNUNET_SCHEDULER_cancel (post_test_task); | ||
976 | post_test_task = NULL; | ||
977 | } | ||
978 | if (NULL != churn_task) | ||
979 | { | ||
980 | GNUNET_SCHEDULER_cancel (churn_task); | ||
981 | churn_task = NULL; | ||
982 | } | ||
983 | entry = oplist_head; | ||
984 | while (NULL != (entry = oplist_head)) | ||
985 | { | ||
986 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
987 | "Operation still pending on shutdown (%u)\n", | ||
988 | entry->index); | ||
989 | GNUNET_TESTBED_operation_done (entry->op); | ||
990 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | ||
991 | GNUNET_free (entry); | ||
992 | } | ||
993 | for (i = 0; i < num_peers; i++) | ||
994 | { | ||
995 | clean_peer (i); | ||
996 | } | ||
997 | } | ||
998 | |||
999 | static void | ||
1000 | trigger_shutdown (void *cls) | ||
1001 | { | ||
1002 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
1003 | "Shutdown was triggerd by timeout, going down.\n"); | ||
1004 | shutdown_task = NULL; | ||
1005 | GNUNET_SCHEDULER_shutdown (); | ||
1006 | } | ||
1007 | |||
1008 | |||
1009 | /** | ||
1010 | * Task run after #duration to collect statistics and potentially shut down. | ||
1011 | */ | ||
1012 | static void | ||
1013 | post_test_op (void *cls) | ||
1014 | { | ||
1015 | unsigned int i; | ||
1016 | |||
1017 | post_test_task = NULL; | ||
1018 | post_test = GNUNET_YES; | ||
1019 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1020 | "Post test task scheduled.\n"); | ||
1021 | if (NULL != churn_task) | ||
1022 | { | ||
1023 | GNUNET_SCHEDULER_cancel (churn_task); | ||
1024 | churn_task = NULL; | ||
1025 | } | ||
1026 | for (i = 0; i < num_peers; i++) | ||
1027 | { | ||
1028 | if (NULL != rps_peers[i].op) | ||
1029 | { | ||
1030 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | ||
1031 | rps_peers[i].op = NULL; | ||
1032 | } | ||
1033 | if (NULL != cur_test_run.post_test) | ||
1034 | { | ||
1035 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | ||
1036 | cur_test_run.post_test (&rps_peers[i]); | ||
1037 | } | ||
1038 | } | ||
1039 | /* If we do not collect statistics, shut down directly */ | ||
1040 | if (NO_COLLECT_STATISTICS == cur_test_run.have_collect_statistics || | ||
1041 | GNUNET_YES == check_statistics_collect_completed()) | ||
1042 | { | ||
1043 | GNUNET_SCHEDULER_cancel (shutdown_task); | ||
1044 | shutdown_task = NULL; | ||
1045 | GNUNET_SCHEDULER_shutdown (); | ||
1046 | } | ||
1047 | } | ||
1048 | |||
1049 | |||
1050 | /** | ||
1051 | * Seed peers. | ||
1052 | */ | ||
1053 | static void | ||
1054 | seed_peers (void *cls) | ||
1055 | { | ||
1056 | struct RPSPeer *peer = cls; | ||
1057 | unsigned int amount; | ||
1058 | unsigned int i; | ||
1059 | |||
1060 | // TODO if malicious don't seed mal peers | ||
1061 | amount = round (.5 * num_peers); | ||
1062 | |||
1063 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n"); | ||
1064 | for (i = 0 ; i < amount ; i++) | ||
1065 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n", | ||
1066 | i, | ||
1067 | GNUNET_i2s (&rps_peer_ids[i])); | ||
1068 | |||
1069 | GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids); | ||
1070 | } | ||
1071 | |||
1072 | |||
1073 | /** | ||
1074 | * Get the id of peer i. | ||
1075 | */ | ||
1076 | void | ||
1077 | info_cb (void *cb_cls, | ||
1078 | struct GNUNET_TESTBED_Operation *op, | ||
1079 | const struct GNUNET_TESTBED_PeerInformation *pinfo, | ||
1080 | const char *emsg) | ||
1081 | { | ||
1082 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; | ||
1083 | |||
1084 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1085 | { | ||
1086 | return; | ||
1087 | } | ||
1088 | |||
1089 | if (NULL == pinfo || NULL != emsg) | ||
1090 | { | ||
1091 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg); | ||
1092 | GNUNET_TESTBED_operation_done (entry->op); | ||
1093 | return; | ||
1094 | } | ||
1095 | |||
1096 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1097 | "Peer %u is %s\n", | ||
1098 | entry->index, | ||
1099 | GNUNET_i2s (pinfo->result.id)); | ||
1100 | |||
1101 | rps_peer_ids[entry->index] = *(pinfo->result.id); | ||
1102 | rps_peers[entry->index].peer_id = &rps_peer_ids[entry->index]; | ||
1103 | |||
1104 | GNUNET_assert (GNUNET_OK == | ||
1105 | GNUNET_CONTAINER_multipeermap_put (peer_map, | ||
1106 | &rps_peer_ids[entry->index], | ||
1107 | &rps_peers[entry->index], | ||
1108 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | ||
1109 | tofile ("/tmp/rps/peer_ids", | ||
1110 | "%u\t%s\n", | ||
1111 | entry->index, | ||
1112 | GNUNET_i2s_full (&rps_peer_ids[entry->index])); | ||
1113 | |||
1114 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | ||
1115 | GNUNET_TESTBED_operation_done (entry->op); | ||
1116 | GNUNET_free (entry); | ||
1117 | } | ||
1118 | |||
1119 | |||
1120 | /** | ||
1121 | * Callback to be called when RPS service connect operation is completed | ||
1122 | * | ||
1123 | * @param cls the callback closure from functions generating an operation | ||
1124 | * @param op the operation that has been finished | ||
1125 | * @param ca_result the RPS service handle returned from rps_connect_adapter | ||
1126 | * @param emsg error message in case the operation has failed; will be NULL if | ||
1127 | * operation has executed successfully. | ||
1128 | */ | ||
1129 | static void | ||
1130 | rps_connect_complete_cb (void *cls, | ||
1131 | struct GNUNET_TESTBED_Operation *op, | ||
1132 | void *ca_result, | ||
1133 | const char *emsg) | ||
1134 | { | ||
1135 | struct RPSPeer *rps_peer = cls; | ||
1136 | struct GNUNET_RPS_Handle *rps = ca_result; | ||
1137 | |||
1138 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1139 | { | ||
1140 | return; | ||
1141 | } | ||
1142 | |||
1143 | rps_peer->rps_handle = rps; | ||
1144 | rps_peer->online = GNUNET_YES; | ||
1145 | num_peers_online++; | ||
1146 | |||
1147 | GNUNET_assert (op == rps_peer->op); | ||
1148 | if (NULL != emsg) | ||
1149 | { | ||
1150 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1151 | "Failed to connect to RPS service: %s\n", | ||
1152 | emsg); | ||
1153 | ok = 1; | ||
1154 | GNUNET_SCHEDULER_shutdown (); | ||
1155 | return; | ||
1156 | } | ||
1157 | |||
1158 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1159 | "Started client successfully (%u)\n", | ||
1160 | rps_peer->index); | ||
1161 | |||
1162 | cur_test_run.main_test (rps_peer); | ||
1163 | } | ||
1164 | |||
1165 | |||
1166 | /** | ||
1167 | * Adapter function called to establish a connection to | ||
1168 | * the RPS service. | ||
1169 | * | ||
1170 | * @param cls closure | ||
1171 | * @param cfg configuration of the peer to connect to; will be available until | ||
1172 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
1173 | * from GNUNET_TESTBED_service_connect() | ||
1174 | * @return service handle to return in 'op_result', NULL on error | ||
1175 | */ | ||
1176 | static void * | ||
1177 | rps_connect_adapter (void *cls, | ||
1178 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1179 | { | ||
1180 | struct GNUNET_RPS_Handle *h; | ||
1181 | |||
1182 | h = GNUNET_RPS_connect (cfg); | ||
1183 | |||
1184 | if (NULL != cur_test_run.pre_test) | ||
1185 | cur_test_run.pre_test (cls, h); | ||
1186 | |||
1187 | return h; | ||
1188 | } | ||
1189 | |||
1190 | /** | ||
1191 | * Called to open a connection to the peer's statistics | ||
1192 | * | ||
1193 | * @param cls peer context | ||
1194 | * @param cfg configuration of the peer to connect to; will be available until | ||
1195 | * GNUNET_TESTBED_operation_done() is called on the operation returned | ||
1196 | * from GNUNET_TESTBED_service_connect() | ||
1197 | * @return service handle to return in 'op_result', NULL on error | ||
1198 | */ | ||
1199 | static void * | ||
1200 | stat_connect_adapter (void *cls, | ||
1201 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
1202 | { | ||
1203 | struct RPSPeer *peer = cls; | ||
1204 | |||
1205 | peer->stats_h = GNUNET_STATISTICS_create ("rps-profiler", cfg); | ||
1206 | return peer->stats_h; | ||
1207 | } | ||
1208 | |||
1209 | /** | ||
1210 | * Called to disconnect from peer's statistics service | ||
1211 | * | ||
1212 | * @param cls peer context | ||
1213 | * @param op_result service handle returned from the connect adapter | ||
1214 | */ | ||
1215 | static void | ||
1216 | stat_disconnect_adapter (void *cls, void *op_result) | ||
1217 | { | ||
1218 | struct RPSPeer *peer = cls; | ||
1219 | |||
1220 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | ||
1221 | // (peer->stats_h, "core", "# peers connected", | ||
1222 | // stat_iterator, peer)); | ||
1223 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch_cancel | ||
1224 | // (peer->stats_h, "nse", "# peers connected", | ||
1225 | // stat_iterator, peer)); | ||
1226 | GNUNET_STATISTICS_destroy (op_result, GNUNET_NO); | ||
1227 | peer->stats_h = NULL; | ||
1228 | } | ||
1229 | |||
1230 | /** | ||
1231 | * Called after successfully opening a connection to a peer's statistics | ||
1232 | * service; we register statistics monitoring for CORE and NSE here. | ||
1233 | * | ||
1234 | * @param cls the callback closure from functions generating an operation | ||
1235 | * @param op the operation that has been finished | ||
1236 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
1237 | * @param emsg error message in case the operation has failed; will be NULL if | ||
1238 | * operation has executed successfully. | ||
1239 | */ | ||
1240 | static void | ||
1241 | stat_complete_cb (void *cls, struct GNUNET_TESTBED_Operation *op, | ||
1242 | void *ca_result, const char *emsg ) | ||
1243 | { | ||
1244 | //struct GNUNET_STATISTICS_Handle *sh = ca_result; | ||
1245 | //struct RPSPeer *peer = (struct RPSPeer *) cls; | ||
1246 | |||
1247 | if (NULL != emsg) | ||
1248 | { | ||
1249 | GNUNET_break (0); | ||
1250 | return; | ||
1251 | } | ||
1252 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch | ||
1253 | // (sh, "core", "# peers connected", | ||
1254 | // stat_iterator, peer)); | ||
1255 | //GNUNET_break (GNUNET_OK == GNUNET_STATISTICS_watch | ||
1256 | // (sh, "nse", "# peers connected", | ||
1257 | // stat_iterator, peer)); | ||
1258 | } | ||
1259 | |||
1260 | |||
1261 | /** | ||
1262 | * Adapter function called to destroy connection to | ||
1263 | * RPS service. | ||
1264 | * | ||
1265 | * @param cls closure | ||
1266 | * @param op_result service handle returned from the connect adapter | ||
1267 | */ | ||
1268 | static void | ||
1269 | rps_disconnect_adapter (void *cls, | ||
1270 | void *op_result) | ||
1271 | { | ||
1272 | struct RPSPeer *peer = cls; | ||
1273 | struct GNUNET_RPS_Handle *h = op_result; | ||
1274 | struct PendingReply *pending_rep; | ||
1275 | |||
1276 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1277 | "disconnect_adapter (%u)\n", | ||
1278 | peer->index); | ||
1279 | GNUNET_assert (NULL != peer); | ||
1280 | if (NULL != peer->rps_handle) | ||
1281 | { | ||
1282 | while (NULL != (pending_rep = peer->pending_rep_head)) | ||
1283 | { | ||
1284 | cancel_request (pending_rep); | ||
1285 | } | ||
1286 | GNUNET_assert (h == peer->rps_handle); | ||
1287 | GNUNET_RPS_disconnect (h); | ||
1288 | peer->rps_handle = NULL; | ||
1289 | } | ||
1290 | } | ||
1291 | |||
1292 | |||
1293 | /*********************************************************************** | ||
1294 | * Definition of tests | ||
1295 | ***********************************************************************/ | ||
1296 | |||
1297 | /** | ||
1298 | * Callback to call on receipt of a reply | ||
1299 | * | ||
1300 | * @param cls closure | ||
1301 | * @param n number of peers | ||
1302 | * @param recv_peers the received peers | ||
1303 | */ | ||
1304 | static void | ||
1305 | default_reply_handle (void *cls, | ||
1306 | uint64_t n, | ||
1307 | const struct GNUNET_PeerIdentity *recv_peers) | ||
1308 | { | ||
1309 | struct RPSPeer *rps_peer; | ||
1310 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | ||
1311 | unsigned int i; | ||
1312 | |||
1313 | rps_peer = pending_rep->rps_peer; | ||
1314 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_rep_head, | ||
1315 | rps_peer->pending_rep_tail, | ||
1316 | pending_rep); | ||
1317 | rps_peer->num_pending_reps--; | ||
1318 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1319 | "[%s] got %" PRIu64 " peers:\n", | ||
1320 | GNUNET_i2s (rps_peer->peer_id), | ||
1321 | n); | ||
1322 | |||
1323 | for (i = 0; i < n; i++) | ||
1324 | { | ||
1325 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1326 | "%u: %s\n", | ||
1327 | i, | ||
1328 | GNUNET_i2s (&recv_peers[i])); | ||
1329 | |||
1330 | rps_peer->num_recv_ids++; | ||
1331 | } | ||
1332 | |||
1333 | if (GNUNET_YES != post_test) return; | ||
1334 | if (HAVE_QUICK_QUIT != cur_test_run.have_quick_quit) return; | ||
1335 | if (0 == evaluate()) | ||
1336 | { | ||
1337 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1338 | "Test succeeded before end of duration\n"); | ||
1339 | if (NULL != post_test_task) GNUNET_SCHEDULER_cancel (post_test_task); | ||
1340 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); | ||
1341 | GNUNET_assert (NULL != post_test_task); | ||
1342 | } | ||
1343 | } | ||
1344 | |||
1345 | /** | ||
1346 | * Request random peers. | ||
1347 | */ | ||
1348 | static void | ||
1349 | request_peers (void *cls) | ||
1350 | { | ||
1351 | struct PendingRequest *pending_req = cls; | ||
1352 | struct RPSPeer *rps_peer; | ||
1353 | struct PendingReply *pending_rep; | ||
1354 | |||
1355 | rps_peer = pending_req->rps_peer; | ||
1356 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); | ||
1357 | GNUNET_CONTAINER_DLL_remove (rps_peer->pending_req_head, | ||
1358 | rps_peer->pending_req_tail, | ||
1359 | pending_req); | ||
1360 | rps_peer->num_pending_reqs--; | ||
1361 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) return; | ||
1362 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1363 | "Requesting one peer\n"); | ||
1364 | pending_rep = GNUNET_new (struct PendingReply); | ||
1365 | pending_rep->rps_peer = rps_peer; | ||
1366 | pending_rep->req_handle = GNUNET_RPS_request_peers (rps_peer->rps_handle, | ||
1367 | 1, | ||
1368 | cur_test_run.reply_handle, | ||
1369 | pending_rep); | ||
1370 | GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_rep_head, | ||
1371 | rps_peer->pending_rep_tail, | ||
1372 | pending_rep); | ||
1373 | rps_peer->num_pending_reps++; | ||
1374 | } | ||
1375 | |||
1376 | |||
1377 | /** | ||
1378 | * Schedule requests for peer @a rps_peer that have neither been scheduled, nor | ||
1379 | * issued, nor replied | ||
1380 | */ | ||
1381 | void | ||
1382 | schedule_missing_requests (struct RPSPeer *rps_peer) | ||
1383 | { | ||
1384 | unsigned int i; | ||
1385 | struct PendingRequest *pending_req; | ||
1386 | |||
1387 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1388 | "Scheduling %u - %u missing requests\n", | ||
1389 | rps_peer->num_ids_to_request, | ||
1390 | rps_peer->num_pending_reqs + rps_peer->num_pending_reps); | ||
1391 | GNUNET_assert (rps_peer->num_pending_reqs + rps_peer->num_pending_reps <= | ||
1392 | rps_peer->num_ids_to_request); | ||
1393 | for (i = rps_peer->num_pending_reqs + rps_peer->num_pending_reps; | ||
1394 | i < rps_peer->num_ids_to_request; i++) | ||
1395 | { | ||
1396 | pending_req = GNUNET_new (struct PendingRequest); | ||
1397 | pending_req->rps_peer = rps_peer; | ||
1398 | pending_req->request_task = GNUNET_SCHEDULER_add_delayed ( | ||
1399 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
1400 | cur_test_run.request_interval * i), | ||
1401 | request_peers, | ||
1402 | pending_req); | ||
1403 | GNUNET_CONTAINER_DLL_insert_tail (rps_peer->pending_req_head, | ||
1404 | rps_peer->pending_req_tail, | ||
1405 | pending_req); | ||
1406 | rps_peer->num_pending_reqs++; | ||
1407 | } | ||
1408 | } | ||
1409 | |||
1410 | void | ||
1411 | cancel_pending_req_rep (struct RPSPeer *rps_peer) | ||
1412 | { | ||
1413 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1414 | "Cancelling all (pending) requests.\n"); | ||
1415 | while (NULL != rps_peer->pending_req_head) | ||
1416 | cancel_pending_req (rps_peer->pending_req_head); | ||
1417 | GNUNET_assert (0 == rps_peer->num_pending_reqs); | ||
1418 | while (NULL != rps_peer->pending_rep_head) | ||
1419 | cancel_request (rps_peer->pending_rep_head); | ||
1420 | GNUNET_assert (0 == rps_peer->num_pending_reps); | ||
1421 | } | ||
1422 | |||
1423 | /*********************************** | ||
1424 | * MALICIOUS | ||
1425 | ***********************************/ | ||
1426 | |||
1427 | /** | ||
1428 | * Initialise only non-mal RPSPeers | ||
1429 | */ | ||
1430 | static void mal_init_peer (struct RPSPeer *rps_peer) | ||
1431 | { | ||
1432 | if (rps_peer->index >= round (portion * num_peers)) | ||
1433 | rps_peer->num_ids_to_request = 1; | ||
1434 | } | ||
1435 | |||
1436 | |||
1437 | /** | ||
1438 | * @brief Set peers to (non-)malicious before execution | ||
1439 | * | ||
1440 | * Of signature #PreTest | ||
1441 | * | ||
1442 | * @param rps_peer the peer to set (non-) malicious | ||
1443 | * @param h the handle to the service | ||
1444 | */ | ||
1445 | static void | ||
1446 | mal_pre (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | ||
1447 | { | ||
1448 | #ifdef ENABLE_MALICIOUS | ||
1449 | uint32_t num_mal_peers; | ||
1450 | |||
1451 | GNUNET_assert ( (1 >= portion) && | ||
1452 | (0 < portion) ); | ||
1453 | num_mal_peers = round (portion * num_peers); | ||
1454 | |||
1455 | if (rps_peer->index < num_mal_peers) | ||
1456 | { | ||
1457 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1458 | "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n", | ||
1459 | rps_peer->index, | ||
1460 | GNUNET_i2s (rps_peer->peer_id), | ||
1461 | num_mal_peers); | ||
1462 | |||
1463 | GNUNET_RPS_act_malicious (h, mal_type, num_mal_peers, | ||
1464 | rps_peer_ids, target_peer); | ||
1465 | } | ||
1466 | #endif /* ENABLE_MALICIOUS */ | ||
1467 | } | ||
1468 | |||
1469 | static void | ||
1470 | mal_cb (struct RPSPeer *rps_peer) | ||
1471 | { | ||
1472 | uint32_t num_mal_peers; | ||
1473 | |||
1474 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1475 | { | ||
1476 | return; | ||
1477 | } | ||
1478 | |||
1479 | #ifdef ENABLE_MALICIOUS | ||
1480 | GNUNET_assert ( (1 >= portion) && | ||
1481 | (0 < portion) ); | ||
1482 | num_mal_peers = round (portion * num_peers); | ||
1483 | |||
1484 | if (rps_peer->index >= num_mal_peers) | ||
1485 | { /* It's useless to ask a malicious peer about a random sample - | ||
1486 | it's not sampling */ | ||
1487 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | ||
1488 | seed_peers, rps_peer); | ||
1489 | schedule_missing_requests (rps_peer); | ||
1490 | } | ||
1491 | #endif /* ENABLE_MALICIOUS */ | ||
1492 | } | ||
1493 | |||
1494 | /*********************************** | ||
1495 | * CHURN | ||
1496 | ***********************************/ | ||
1497 | |||
1498 | static void | ||
1499 | churn (void *cls); | ||
1500 | |||
1501 | /** | ||
1502 | * @brief Starts churn | ||
1503 | * | ||
1504 | * Has signature of #MainTest | ||
1505 | * | ||
1506 | * This is not implemented too nicely as this is called for each peer, but we | ||
1507 | * only need to call it once. (Yes we check that we only schedule the task | ||
1508 | * once.) | ||
1509 | * | ||
1510 | * @param rps_peer The peer it's called for | ||
1511 | */ | ||
1512 | static void | ||
1513 | churn_test_cb (struct RPSPeer *rps_peer) | ||
1514 | { | ||
1515 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1516 | { | ||
1517 | return; | ||
1518 | } | ||
1519 | |||
1520 | /* Start churn */ | ||
1521 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) | ||
1522 | { | ||
1523 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1524 | "Starting churn task\n"); | ||
1525 | churn_task = GNUNET_SCHEDULER_add_delayed ( | ||
1526 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | ||
1527 | churn, | ||
1528 | NULL); | ||
1529 | } else { | ||
1530 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1531 | "Not starting churn task\n"); | ||
1532 | } | ||
1533 | |||
1534 | schedule_missing_requests (rps_peer); | ||
1535 | } | ||
1536 | |||
1537 | /*********************************** | ||
1538 | * PROFILER | ||
1539 | ***********************************/ | ||
1540 | |||
1541 | /** | ||
1542 | * Callback to be called when RPS service is started or stopped at peers | ||
1543 | * | ||
1544 | * @param cls NULL | ||
1545 | * @param op the operation handle | ||
1546 | * @param emsg NULL on success; otherwise an error description | ||
1547 | */ | ||
1548 | static void | ||
1549 | churn_cb (void *cls, | ||
1550 | struct GNUNET_TESTBED_Operation *op, | ||
1551 | const char *emsg) | ||
1552 | { | ||
1553 | // FIXME | ||
1554 | struct OpListEntry *entry = cls; | ||
1555 | |||
1556 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1557 | { | ||
1558 | return; | ||
1559 | } | ||
1560 | |||
1561 | GNUNET_TESTBED_operation_done (entry->op); | ||
1562 | if (NULL != emsg) | ||
1563 | { | ||
1564 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to start/stop RPS at a peer\n"); | ||
1565 | GNUNET_SCHEDULER_shutdown (); | ||
1566 | return; | ||
1567 | } | ||
1568 | GNUNET_assert (0 != entry->delta); | ||
1569 | |||
1570 | num_peers_online += entry->delta; | ||
1571 | |||
1572 | if (PEER_GO_OFFLINE == entry->delta) | ||
1573 | { /* Peer hopefully just went offline */ | ||
1574 | if (GNUNET_YES != rps_peers[entry->index].online) | ||
1575 | { | ||
1576 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1577 | "peer %s was expected to go offline but is still marked as online\n", | ||
1578 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
1579 | GNUNET_break (0); | ||
1580 | } | ||
1581 | else | ||
1582 | { | ||
1583 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1584 | "peer %s probably went offline as expected\n", | ||
1585 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
1586 | } | ||
1587 | rps_peers[entry->index].online = GNUNET_NO; | ||
1588 | } | ||
1589 | |||
1590 | else if (PEER_GO_ONLINE < entry->delta) | ||
1591 | { /* Peer hopefully just went online */ | ||
1592 | if (GNUNET_NO != rps_peers[entry->index].online) | ||
1593 | { | ||
1594 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
1595 | "peer %s was expected to go online but is still marked as offline\n", | ||
1596 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
1597 | GNUNET_break (0); | ||
1598 | } | ||
1599 | else | ||
1600 | { | ||
1601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1602 | "peer %s probably went online as expected\n", | ||
1603 | GNUNET_i2s (rps_peers[entry->index].peer_id)); | ||
1604 | if (NULL != cur_test_run.pre_test) | ||
1605 | { | ||
1606 | cur_test_run.pre_test (&rps_peers[entry->index], | ||
1607 | rps_peers[entry->index].rps_handle); | ||
1608 | schedule_missing_requests (&rps_peers[entry->index]); | ||
1609 | } | ||
1610 | } | ||
1611 | rps_peers[entry->index].online = GNUNET_YES; | ||
1612 | } | ||
1613 | else | ||
1614 | { | ||
1615 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1616 | "Invalid value for delta: %i\n", entry->delta); | ||
1617 | GNUNET_break (0); | ||
1618 | } | ||
1619 | |||
1620 | GNUNET_CONTAINER_DLL_remove (oplist_head, oplist_tail, entry); | ||
1621 | rps_peers[entry->index].entry_op_manage = NULL; | ||
1622 | GNUNET_free (entry); | ||
1623 | //if (num_peers_in_round[current_round] == peers_running) | ||
1624 | // run_round (); | ||
1625 | } | ||
1626 | |||
1627 | /** | ||
1628 | * @brief Set the rps-service up or down for a specific peer | ||
1629 | * | ||
1630 | * @param i index of action | ||
1631 | * @param j index of peer | ||
1632 | * @param delta (#PEER_ONLINE_DELTA) down (-1) or up (1) | ||
1633 | * @param prob_go_on_off the probability of the action | ||
1634 | */ | ||
1635 | static void | ||
1636 | manage_service_wrapper (unsigned int i, unsigned int j, | ||
1637 | enum PEER_ONLINE_DELTA delta, | ||
1638 | double prob_go_on_off) | ||
1639 | { | ||
1640 | struct OpListEntry *entry = NULL; | ||
1641 | uint32_t prob; | ||
1642 | |||
1643 | /* make sure that management operation is not already scheduled */ | ||
1644 | if (NULL != rps_peers[j].entry_op_manage) | ||
1645 | { | ||
1646 | return; | ||
1647 | } | ||
1648 | |||
1649 | prob = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1650 | UINT32_MAX); | ||
1651 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1652 | "%u. selected peer (%u: %s) is %s.\n", | ||
1653 | i, | ||
1654 | j, | ||
1655 | GNUNET_i2s (rps_peers[j].peer_id), | ||
1656 | (PEER_GO_ONLINE == delta) ? "online" : "offline"); | ||
1657 | if (prob < prob_go_on_off * UINT32_MAX) | ||
1658 | { | ||
1659 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1660 | "%s goes %s\n", | ||
1661 | GNUNET_i2s (rps_peers[j].peer_id), | ||
1662 | (PEER_GO_OFFLINE == delta) ? "offline" : "online"); | ||
1663 | |||
1664 | if (PEER_GO_OFFLINE == delta) | ||
1665 | cancel_pending_req_rep (&rps_peers[j]); | ||
1666 | entry = make_oplist_entry (); | ||
1667 | entry->delta = delta; | ||
1668 | entry->index = j; | ||
1669 | entry->op = GNUNET_TESTBED_peer_manage_service (NULL, | ||
1670 | testbed_peers[j], | ||
1671 | "rps", | ||
1672 | &churn_cb, | ||
1673 | entry, | ||
1674 | (PEER_GO_OFFLINE == delta) ? 0 : 1); | ||
1675 | rps_peers[j].entry_op_manage = entry; | ||
1676 | } | ||
1677 | } | ||
1678 | |||
1679 | |||
1680 | static void | ||
1681 | churn (void *cls) | ||
1682 | { | ||
1683 | unsigned int i; | ||
1684 | unsigned int j; | ||
1685 | double portion_online; | ||
1686 | unsigned int *permut; | ||
1687 | double prob_go_offline; | ||
1688 | double portion_go_online; | ||
1689 | double portion_go_offline; | ||
1690 | |||
1691 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1692 | { | ||
1693 | return; | ||
1694 | } | ||
1695 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1696 | "Churn function executing\n"); | ||
1697 | |||
1698 | churn_task = NULL; /* Should be invalid by now */ | ||
1699 | |||
1700 | /* Compute the probability for an online peer to go offline | ||
1701 | * this round */ | ||
1702 | portion_online = num_peers_online * 1.0 / num_peers; | ||
1703 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1704 | "Portion online: %f\n", | ||
1705 | portion_online); | ||
1706 | portion_go_online = ((1 - portion_online) * .5 * .66); | ||
1707 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1708 | "Portion that should go online: %f\n", | ||
1709 | portion_go_online); | ||
1710 | portion_go_offline = (portion_online + portion_go_online) - .75; | ||
1711 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1712 | "Portion that probably goes offline: %f\n", | ||
1713 | portion_go_offline); | ||
1714 | prob_go_offline = portion_go_offline / (portion_online * .5); | ||
1715 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1716 | "Probability of a selected online peer to go offline: %f\n", | ||
1717 | prob_go_offline); | ||
1718 | |||
1719 | permut = GNUNET_CRYPTO_random_permute (GNUNET_CRYPTO_QUALITY_WEAK, | ||
1720 | (unsigned int) num_peers); | ||
1721 | |||
1722 | /* Go over 50% randomly chosen peers */ | ||
1723 | for (i = 0; i < .5 * num_peers; i++) | ||
1724 | { | ||
1725 | j = permut[i]; | ||
1726 | |||
1727 | /* If online, shut down with certain probability */ | ||
1728 | if (GNUNET_YES == rps_peers[j].online) | ||
1729 | { | ||
1730 | manage_service_wrapper (i, j, -1, prob_go_offline); | ||
1731 | } | ||
1732 | |||
1733 | /* If offline, restart with certain probability */ | ||
1734 | else if (GNUNET_NO == rps_peers[j].online) | ||
1735 | { | ||
1736 | manage_service_wrapper (i, j, 1, 0.66); | ||
1737 | } | ||
1738 | } | ||
1739 | |||
1740 | GNUNET_free (permut); | ||
1741 | |||
1742 | churn_task = GNUNET_SCHEDULER_add_delayed ( | ||
1743 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2), | ||
1744 | churn, | ||
1745 | NULL); | ||
1746 | } | ||
1747 | |||
1748 | |||
1749 | /** | ||
1750 | * Initialise given RPSPeer | ||
1751 | */ | ||
1752 | static void profiler_init_peer (struct RPSPeer *rps_peer) | ||
1753 | { | ||
1754 | if (num_peers - 1 == rps_peer->index) | ||
1755 | { | ||
1756 | rps_peer->num_ids_to_request = cur_test_run.num_requests; | ||
1757 | } else { | ||
1758 | rps_peer->num_ids_to_request = 0; | ||
1759 | } | ||
1760 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "peer shall request %i peers\n", | ||
1761 | rps_peer->num_ids_to_request); | ||
1762 | } | ||
1763 | |||
1764 | |||
1765 | /** | ||
1766 | * Callback to call on receipt of a reply | ||
1767 | * | ||
1768 | * @param cls closure | ||
1769 | * @param n number of peers | ||
1770 | * @param recv_peers the received peers | ||
1771 | */ | ||
1772 | static void | ||
1773 | profiler_reply_handle (void *cls, | ||
1774 | uint64_t n, | ||
1775 | const struct GNUNET_PeerIdentity *recv_peers) | ||
1776 | { | ||
1777 | struct RPSPeer *rps_peer; | ||
1778 | struct RPSPeer *rcv_rps_peer; | ||
1779 | char *file_name; | ||
1780 | char *file_name_dh; | ||
1781 | char *file_name_dhr; | ||
1782 | char *file_name_dhru; | ||
1783 | unsigned int i; | ||
1784 | struct PendingReply *pending_rep = (struct PendingReply *) cls; | ||
1785 | |||
1786 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "profiler_reply_handle()\n"); | ||
1787 | rps_peer = pending_rep->rps_peer; | ||
1788 | file_name = "/tmp/rps/received_ids"; | ||
1789 | file_name_dh = "/tmp/rps/diehard_input"; | ||
1790 | file_name_dhr = "/tmp/rps/diehard_input_raw"; | ||
1791 | file_name_dhru = "/tmp/rps/diehard_input_raw_aligned"; | ||
1792 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1793 | "[%s] got %" PRIu64 " peers:\n", | ||
1794 | GNUNET_i2s (rps_peer->peer_id), | ||
1795 | n); | ||
1796 | for (i = 0; i < n; i++) | ||
1797 | { | ||
1798 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1799 | "%u: %s\n", | ||
1800 | i, | ||
1801 | GNUNET_i2s (&recv_peers[i])); | ||
1802 | tofile (file_name, | ||
1803 | "%s\n", | ||
1804 | GNUNET_i2s_full (&recv_peers[i])); | ||
1805 | rcv_rps_peer = GNUNET_CONTAINER_multipeermap_get (peer_map, &recv_peers[i]); | ||
1806 | GNUNET_assert (NULL != rcv_rps_peer); | ||
1807 | tofile (file_name_dh, | ||
1808 | "%" PRIu32 "\n", | ||
1809 | (uint32_t) rcv_rps_peer->index); | ||
1810 | to_file_raw (file_name_dhr, | ||
1811 | (char *) &rcv_rps_peer->index, | ||
1812 | sizeof (uint32_t)); | ||
1813 | to_file_raw_unaligned (file_name_dhru, | ||
1814 | (char *) &rcv_rps_peer->index, | ||
1815 | sizeof (uint32_t), | ||
1816 | bits_needed); | ||
1817 | } | ||
1818 | default_reply_handle (cls, n, recv_peers); | ||
1819 | } | ||
1820 | |||
1821 | |||
1822 | static void | ||
1823 | profiler_cb (struct RPSPeer *rps_peer) | ||
1824 | { | ||
1825 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
1826 | { | ||
1827 | return; | ||
1828 | } | ||
1829 | |||
1830 | /* Start churn */ | ||
1831 | if (HAVE_CHURN == cur_test_run.have_churn && NULL == churn_task) | ||
1832 | { | ||
1833 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1834 | "Starting churn task\n"); | ||
1835 | churn_task = GNUNET_SCHEDULER_add_delayed ( | ||
1836 | GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), | ||
1837 | churn, | ||
1838 | NULL); | ||
1839 | } else { | ||
1840 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1841 | "Not starting churn task\n"); | ||
1842 | } | ||
1843 | |||
1844 | /* Only request peer ids at one peer. | ||
1845 | * (It's the before-last because last one is target of the focussed attack.) | ||
1846 | */ | ||
1847 | if (eval_peer == rps_peer) | ||
1848 | schedule_missing_requests (rps_peer); | ||
1849 | } | ||
1850 | |||
1851 | /** | ||
1852 | * Function called from #profiler_eval with a filename. | ||
1853 | * | ||
1854 | * @param cls closure | ||
1855 | * @param filename complete filename (absolute path) | ||
1856 | * @return #GNUNET_OK to continue to iterate, | ||
1857 | * #GNUNET_NO to stop iteration with no error, | ||
1858 | * #GNUNET_SYSERR to abort iteration with error! | ||
1859 | */ | ||
1860 | int | ||
1861 | file_name_cb (void *cls, const char *filename) | ||
1862 | { | ||
1863 | if (NULL != strstr (filename, "sampler_el")) | ||
1864 | { | ||
1865 | struct RPS_SamplerElement *s_elem; | ||
1866 | struct GNUNET_CRYPTO_AuthKey auth_key; | ||
1867 | const char *key_char; | ||
1868 | uint32_t i; | ||
1869 | |||
1870 | key_char = filename + 20; /* Length of "/tmp/rps/sampler_el-" */ | ||
1871 | tofile (filename, "--------------------------\n"); | ||
1872 | |||
1873 | auth_key = string_to_auth_key (key_char); | ||
1874 | s_elem = RPS_sampler_elem_create (); | ||
1875 | RPS_sampler_elem_set (s_elem, auth_key); | ||
1876 | |||
1877 | for (i = 0; i < num_peers; i++) | ||
1878 | { | ||
1879 | RPS_sampler_elem_next (s_elem, &rps_peer_ids[i]); | ||
1880 | } | ||
1881 | RPS_sampler_elem_destroy (s_elem); | ||
1882 | } | ||
1883 | return GNUNET_OK; | ||
1884 | } | ||
1885 | |||
1886 | /** | ||
1887 | * This is run after the test finished. | ||
1888 | * | ||
1889 | * Compute all perfect samples. | ||
1890 | */ | ||
1891 | int | ||
1892 | profiler_eval (void) | ||
1893 | { | ||
1894 | /* Compute perfect sample for each sampler element */ | ||
1895 | if (-1 == GNUNET_DISK_directory_scan ("/tmp/rps/", file_name_cb, NULL)) | ||
1896 | { | ||
1897 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Scan of directory failed\n"); | ||
1898 | } | ||
1899 | |||
1900 | return evaluate (); | ||
1901 | } | ||
1902 | |||
1903 | static uint32_t fac (uint32_t x) | ||
1904 | { | ||
1905 | if (1 >= x) | ||
1906 | { | ||
1907 | return x; | ||
1908 | } | ||
1909 | return x * fac (x - 1); | ||
1910 | } | ||
1911 | |||
1912 | static uint32_t binom (uint32_t n, uint32_t k) | ||
1913 | { | ||
1914 | //GNUNET_assert (n >= k); | ||
1915 | if (k > n) return 0; | ||
1916 | if (0 > n) return 0; | ||
1917 | if (0 > k) return 0; | ||
1918 | if (0 == k) return 1; | ||
1919 | return fac (n) | ||
1920 | / | ||
1921 | fac(k) * fac(n - k); | ||
1922 | } | ||
1923 | |||
1924 | /** | ||
1925 | * @brief is b in view of a? | ||
1926 | * | ||
1927 | * @param a | ||
1928 | * @param b | ||
1929 | * | ||
1930 | * @return | ||
1931 | */ | ||
1932 | static int is_in_view (uint32_t a, uint32_t b) | ||
1933 | { | ||
1934 | uint32_t i; | ||
1935 | for (i = 0; i < rps_peers[a].cur_view_count; i++) | ||
1936 | { | ||
1937 | if (0 == memcmp (rps_peers[b].peer_id, | ||
1938 | &rps_peers[a].cur_view[i], | ||
1939 | sizeof (struct GNUNET_PeerIdentity))) | ||
1940 | { | ||
1941 | return GNUNET_YES; | ||
1942 | } | ||
1943 | } | ||
1944 | return GNUNET_NO; | ||
1945 | } | ||
1946 | |||
1947 | static uint32_t get_idx_of_pid (const struct GNUNET_PeerIdentity *pid) | ||
1948 | { | ||
1949 | uint32_t i; | ||
1950 | |||
1951 | for (i = 0; i < num_peers; i++) | ||
1952 | { | ||
1953 | if (0 == memcmp (pid, | ||
1954 | rps_peers[i].peer_id, | ||
1955 | sizeof (struct GNUNET_PeerIdentity))) | ||
1956 | { | ||
1957 | return i; | ||
1958 | } | ||
1959 | } | ||
1960 | //return 0; /* Should not happen - make compiler happy */ | ||
1961 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1962 | "No known _PeerIdentity %s!\n", | ||
1963 | GNUNET_i2s_full (pid)); | ||
1964 | GNUNET_assert (0); | ||
1965 | } | ||
1966 | |||
1967 | /** | ||
1968 | * @brief Counts number of peers in view of a that have b in their view | ||
1969 | * | ||
1970 | * @param a | ||
1971 | * @param uint32_tb | ||
1972 | * | ||
1973 | * @return | ||
1974 | */ | ||
1975 | static uint32_t count_containing_views (uint32_t a, uint32_t b) | ||
1976 | { | ||
1977 | uint32_t i; | ||
1978 | uint32_t peer_idx; | ||
1979 | uint32_t count = 0; | ||
1980 | |||
1981 | for (i = 0; i < rps_peers[a].cur_view_count; i++) | ||
1982 | { | ||
1983 | peer_idx = get_idx_of_pid (&rps_peers[a].cur_view[i]); | ||
1984 | if (GNUNET_YES == is_in_view (peer_idx, b)) | ||
1985 | { | ||
1986 | count++; | ||
1987 | } | ||
1988 | } | ||
1989 | return count; | ||
1990 | } | ||
1991 | |||
1992 | /** | ||
1993 | * @brief Computes the probability for each other peer to be selected by the | ||
1994 | * sampling process based on the views of all peers | ||
1995 | * | ||
1996 | * @param peer_idx index of the peer that is about to sample | ||
1997 | */ | ||
1998 | static void compute_probabilities (uint32_t peer_idx) | ||
1999 | { | ||
2000 | //double probs[num_peers] = { 0 }; | ||
2001 | double probs[num_peers]; | ||
2002 | size_t probs_as_str_size = (num_peers * 10 + 1) * sizeof (char); | ||
2003 | char *probs_as_str = GNUNET_malloc (probs_as_str_size); | ||
2004 | char *probs_as_str_cpy; | ||
2005 | uint32_t i; | ||
2006 | double prob_push; | ||
2007 | double prob_pull; | ||
2008 | uint32_t view_size; | ||
2009 | uint32_t cont_views; | ||
2010 | uint32_t number_of_being_in_pull_events; | ||
2011 | int tmp; | ||
2012 | uint32_t count_non_zero_prob = 0; | ||
2013 | |||
2014 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2015 | "Computing probabilities for peer %" PRIu32 "\n", peer_idx); | ||
2016 | /* Firstly without knowledge of old views */ | ||
2017 | for (i = 0; i < num_peers; i++) | ||
2018 | { | ||
2019 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2020 | "\tfor peer %" PRIu32 ":\n", i); | ||
2021 | view_size = rps_peers[i].cur_view_count; | ||
2022 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2023 | "\t\tview_size: %" PRIu32 "\n", view_size); | ||
2024 | /* For peer i the probability of being sampled is | ||
2025 | * evenly distributed among all possibly observed peers. */ | ||
2026 | /* We could have observed a peer in three cases: | ||
2027 | * 1. peer sent a push | ||
2028 | * 2. peer was contained in a pull reply | ||
2029 | * 3. peer was in history (sampler) - ignored for now */ | ||
2030 | /* 1. Probability of having received a push from peer i */ | ||
2031 | if ((GNUNET_YES == is_in_view (i, peer_idx)) && | ||
2032 | (1 <= (0.45 * view_size))) | ||
2033 | { | ||
2034 | if (0 == binom (view_size, 0.45 * view_size)) prob_push = 0; | ||
2035 | else | ||
2036 | { | ||
2037 | prob_push = 1.0 * binom (0.45 * view_size, 1) | ||
2038 | / | ||
2039 | binom (view_size, 0.45 * view_size); | ||
2040 | } | ||
2041 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2042 | "\t\t%" PRIu32 " is in %" PRIu32 "'s view, prob: %f\n", | ||
2043 | peer_idx, | ||
2044 | i, | ||
2045 | prob_push); | ||
2046 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2047 | "\t\tposs choices from view: %" PRIu32 ", containing i: %" PRIu32 "\n", | ||
2048 | binom (view_size, 0.45 * view_size), | ||
2049 | binom (0.45 * view_size, 1)); | ||
2050 | } else { | ||
2051 | prob_push = 0; | ||
2052 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2053 | "\t\t%" PRIu32 " is not in %" PRIu32 "'s view, prob: 0\n", | ||
2054 | peer_idx, | ||
2055 | i); | ||
2056 | } | ||
2057 | /* 2. Probability of peer i being contained in pulls */ | ||
2058 | view_size = rps_peers[peer_idx].cur_view_count; | ||
2059 | cont_views = count_containing_views (peer_idx, i); | ||
2060 | number_of_being_in_pull_events = | ||
2061 | (binom (view_size, 0.45 * view_size) - | ||
2062 | binom (view_size - cont_views, 0.45 * view_size)); | ||
2063 | if (0 != number_of_being_in_pull_events) | ||
2064 | { | ||
2065 | prob_pull = number_of_being_in_pull_events | ||
2066 | / | ||
2067 | (1.0 * binom (view_size, 0.45 * view_size)); | ||
2068 | } else | ||
2069 | { | ||
2070 | prob_pull = 0; | ||
2071 | } | ||
2072 | probs[i] = prob_push + prob_pull - (prob_push * prob_pull); | ||
2073 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2074 | "\t\t%" PRIu32 " has %" PRIu32 " of %" PRIu32 | ||
2075 | " peers in its view who know %" PRIu32 " prob: %f\n", | ||
2076 | peer_idx, | ||
2077 | cont_views, | ||
2078 | view_size, | ||
2079 | i, | ||
2080 | prob_pull); | ||
2081 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2082 | "\t\tnumber of possible pull combinations: %" PRIu32 "\n", | ||
2083 | binom (view_size, 0.45 * view_size)); | ||
2084 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2085 | "\t\tnumber of possible pull combinations without %" PRIu32 | ||
2086 | ": %" PRIu32 "\n", | ||
2087 | i, | ||
2088 | binom (view_size - cont_views, 0.45 * view_size)); | ||
2089 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2090 | "\t\tnumber of possible pull combinations with %" PRIu32 | ||
2091 | ": %" PRIu32 "\n", | ||
2092 | i, | ||
2093 | number_of_being_in_pull_events); | ||
2094 | |||
2095 | if (0 != probs[i]) count_non_zero_prob++; | ||
2096 | } | ||
2097 | /* normalize */ | ||
2098 | if (0 != count_non_zero_prob) | ||
2099 | { | ||
2100 | for (i = 0; i < num_peers; i++) | ||
2101 | { | ||
2102 | probs[i] = probs[i] * (1.0 / count_non_zero_prob); | ||
2103 | } | ||
2104 | } else { | ||
2105 | for (i = 0; i < num_peers; i++) | ||
2106 | { | ||
2107 | probs[i] = 0; | ||
2108 | } | ||
2109 | } | ||
2110 | /* str repr */ | ||
2111 | for (i = 0; i < num_peers; i++) | ||
2112 | { | ||
2113 | probs_as_str_cpy = GNUNET_strndup (probs_as_str, probs_as_str_size); | ||
2114 | tmp = GNUNET_snprintf (probs_as_str, | ||
2115 | probs_as_str_size, | ||
2116 | "%s %7.6f", probs_as_str_cpy, probs[i]); | ||
2117 | GNUNET_free (probs_as_str_cpy); | ||
2118 | GNUNET_assert (0 <= tmp); | ||
2119 | } | ||
2120 | |||
2121 | to_file_w_len (rps_peers[peer_idx].file_name_probs, | ||
2122 | probs_as_str_size, | ||
2123 | probs_as_str); | ||
2124 | GNUNET_free (probs_as_str); | ||
2125 | } | ||
2126 | |||
2127 | /** | ||
2128 | * @brief This counts the number of peers in which views a given peer occurs. | ||
2129 | * | ||
2130 | * It also stores this value in the rps peer. | ||
2131 | * | ||
2132 | * @param peer_idx the index of the peer to count the representation | ||
2133 | * | ||
2134 | * @return the number of occurrences | ||
2135 | */ | ||
2136 | static uint32_t count_peer_in_views_2 (uint32_t peer_idx) | ||
2137 | { | ||
2138 | uint32_t i, j; | ||
2139 | uint32_t count = 0; | ||
2140 | |||
2141 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | ||
2142 | { | ||
2143 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ | ||
2144 | { | ||
2145 | if (0 == memcmp (rps_peers[peer_idx].peer_id, | ||
2146 | &rps_peers[i].cur_view[j], | ||
2147 | sizeof (struct GNUNET_PeerIdentity))) | ||
2148 | { | ||
2149 | count++; | ||
2150 | break; | ||
2151 | } | ||
2152 | } | ||
2153 | } | ||
2154 | rps_peers[peer_idx].count_in_views = count; | ||
2155 | return count; | ||
2156 | } | ||
2157 | |||
2158 | static uint32_t cumulated_view_sizes () | ||
2159 | { | ||
2160 | uint32_t i; | ||
2161 | |||
2162 | view_sizes = 0; | ||
2163 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | ||
2164 | { | ||
2165 | view_sizes += rps_peers[i].cur_view_count; | ||
2166 | } | ||
2167 | return view_sizes; | ||
2168 | } | ||
2169 | |||
2170 | static void count_peer_in_views (uint32_t *count_peers) | ||
2171 | { | ||
2172 | uint32_t i, j; | ||
2173 | |||
2174 | for (i = 0; i < num_peers; i++) /* Peer in which view is counted */ | ||
2175 | { | ||
2176 | for (j = 0; j < rps_peers[i].cur_view_count; j++) /* entry in view */ | ||
2177 | { | ||
2178 | if (0 == memcmp (rps_peers[i].peer_id, | ||
2179 | &rps_peers[i].cur_view[j], | ||
2180 | sizeof (struct GNUNET_PeerIdentity))) | ||
2181 | { | ||
2182 | count_peers[i]++; | ||
2183 | } | ||
2184 | } | ||
2185 | } | ||
2186 | } | ||
2187 | |||
2188 | void compute_diversity () | ||
2189 | { | ||
2190 | uint32_t i; | ||
2191 | /* ith entry represents the numer of occurrences in other peer's views */ | ||
2192 | uint32_t *count_peers = GNUNET_new_array (num_peers, uint32_t); | ||
2193 | uint32_t views_total_size; | ||
2194 | double expected; | ||
2195 | /* deviation from expected number of peers */ | ||
2196 | double *deviation = GNUNET_new_array (num_peers, double); | ||
2197 | |||
2198 | views_total_size = 0; | ||
2199 | expected = 0; | ||
2200 | |||
2201 | /* For each peer count its representation in other peer's views*/ | ||
2202 | for (i = 0; i < num_peers; i++) /* Peer to count */ | ||
2203 | { | ||
2204 | views_total_size += rps_peers[i].cur_view_count; | ||
2205 | count_peer_in_views (count_peers); | ||
2206 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2207 | "Counted representation of %" PRIu32 "th peer [%s]: %" PRIu32"\n", | ||
2208 | i, | ||
2209 | GNUNET_i2s (rps_peers[i].peer_id), | ||
2210 | count_peers[i]); | ||
2211 | } | ||
2212 | |||
2213 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2214 | "size of all views combined: %" PRIu32 "\n", | ||
2215 | views_total_size); | ||
2216 | expected = ((double) 1/num_peers) * views_total_size; | ||
2217 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2218 | "Expected number of occurrences of each peer in all views: %f\n", | ||
2219 | expected); | ||
2220 | for (i = 0; i < num_peers; i++) /* Peer to count */ | ||
2221 | { | ||
2222 | deviation[i] = expected - count_peers[i]; | ||
2223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2224 | "Deviation from expectation: %f\n", deviation[i]); | ||
2225 | } | ||
2226 | GNUNET_free (count_peers); | ||
2227 | GNUNET_free (deviation); | ||
2228 | } | ||
2229 | |||
2230 | void print_view_sizes() | ||
2231 | { | ||
2232 | uint32_t i; | ||
2233 | |||
2234 | for (i = 0; i < num_peers; i++) /* Peer to count */ | ||
2235 | { | ||
2236 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2237 | "View size of %" PRIu32 ". [%s] is %" PRIu32 "\n", | ||
2238 | i, | ||
2239 | GNUNET_i2s (rps_peers[i].peer_id), | ||
2240 | rps_peers[i].cur_view_count); | ||
2241 | } | ||
2242 | } | ||
2243 | |||
2244 | void all_views_updated_cb() | ||
2245 | { | ||
2246 | compute_diversity(); | ||
2247 | print_view_sizes(); | ||
2248 | } | ||
2249 | |||
2250 | void view_update_cb (void *cls, | ||
2251 | uint64_t view_size, | ||
2252 | const struct GNUNET_PeerIdentity *peers) | ||
2253 | { | ||
2254 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2255 | "View was updated (%" PRIu64 ")\n", view_size); | ||
2256 | struct RPSPeer *rps_peer = (struct RPSPeer *) cls; | ||
2257 | to_file ("/tmp/rps/view_sizes.txt", | ||
2258 | "%" PRIu64 " %" PRIu32 "", | ||
2259 | rps_peer->index, | ||
2260 | view_size); | ||
2261 | for (int i = 0; i < view_size; i++) | ||
2262 | { | ||
2263 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2264 | "\t%s\n", GNUNET_i2s (&peers[i])); | ||
2265 | } | ||
2266 | GNUNET_array_grow (rps_peer->cur_view, | ||
2267 | rps_peer->cur_view_count, | ||
2268 | view_size); | ||
2269 | //*rps_peer->cur_view = *peers; | ||
2270 | GNUNET_memcpy (rps_peer->cur_view, | ||
2271 | peers, | ||
2272 | view_size * sizeof (struct GNUNET_PeerIdentity)); | ||
2273 | to_file ("/tmp/rps/count_in_views.txt", | ||
2274 | "%" PRIu64 " %" PRIu32 "", | ||
2275 | rps_peer->index, | ||
2276 | count_peer_in_views_2 (rps_peer->index)); | ||
2277 | cumulated_view_sizes(); | ||
2278 | if (0 != view_size) | ||
2279 | { | ||
2280 | to_file ("/tmp/rps/repr.txt", | ||
2281 | "%" PRIu64 /* index */ | ||
2282 | " %" PRIu32 /* occurrence in views */ | ||
2283 | " %" PRIu32 /* view sizes */ | ||
2284 | " %f" /* fraction of repr in views */ | ||
2285 | " %f" /* average view size */ | ||
2286 | " %f" /* prob of occurrence in view slot */ | ||
2287 | " %f" "", /* exp frac of repr in views */ | ||
2288 | rps_peer->index, | ||
2289 | count_peer_in_views_2 (rps_peer->index), | ||
2290 | view_sizes, | ||
2291 | count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ | ||
2292 | view_sizes / (view_size * 1.0), /* average view size */ | ||
2293 | 1.0 /view_size, /* prob of occurrence in view slot */ | ||
2294 | (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ | ||
2295 | ); | ||
2296 | } | ||
2297 | compute_probabilities (rps_peer->index); | ||
2298 | all_views_updated_cb(); | ||
2299 | } | ||
2300 | |||
2301 | static void | ||
2302 | pre_profiler (struct RPSPeer *rps_peer, struct GNUNET_RPS_Handle *h) | ||
2303 | { | ||
2304 | rps_peer->file_name_probs = | ||
2305 | store_prefix_file_name (rps_peer->peer_id, "probs"); | ||
2306 | GNUNET_RPS_view_request (h, 0, view_update_cb, rps_peer); | ||
2307 | } | ||
2308 | |||
2309 | void write_final_stats (void){ | ||
2310 | uint64_t sums[STAT_TYPE_MAX] = { 0 }; | ||
2311 | |||
2312 | for (uint32_t i = 0; i < num_peers; i++) | ||
2313 | { | ||
2314 | to_file ("/tmp/rps/final_stats.csv", | ||
2315 | ", %" PRIu32 ", " /* index */ | ||
2316 | "%s, %" /* id */ | ||
2317 | PRIu64 ", %" /* rounds */ | ||
2318 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* blocking */ | ||
2319 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* issued */ | ||
2320 | PRIu64 ", %" PRIu64 ", %" PRIu64 ", %" /* sent */ | ||
2321 | PRIu64 ", %" PRIu64 ", %" PRIu64 /* recv */, | ||
2322 | i, | ||
2323 | GNUNET_i2s (rps_peers[i].peer_id), | ||
2324 | rps_peers[i].stats[STAT_TYPE_ROUNDS], | ||
2325 | rps_peers[i].stats[STAT_TYPE_BLOCKS], | ||
2326 | rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH], | ||
2327 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH], | ||
2328 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PULL], | ||
2329 | rps_peers[i].stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], | ||
2330 | rps_peers[i].stats[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], | ||
2331 | rps_peers[i].stats[STAT_TYPE_ISSUED_PUSH_SEND], | ||
2332 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REQ], | ||
2333 | rps_peers[i].stats[STAT_TYPE_ISSUED_PULL_REP], | ||
2334 | rps_peers[i].stats[STAT_TYPE_SENT_PUSH_SEND], | ||
2335 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REQ], | ||
2336 | rps_peers[i].stats[STAT_TYPE_SENT_PULL_REP], | ||
2337 | rps_peers[i].stats[STAT_TYPE_RECV_PUSH_SEND], | ||
2338 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REQ], | ||
2339 | rps_peers[i].stats[STAT_TYPE_RECV_PULL_REP]); | ||
2340 | for (uint32_t stat_type = STAT_TYPE_ROUNDS; | ||
2341 | stat_type < STAT_TYPE_MAX; | ||
2342 | stat_type++) | ||
2343 | { | ||
2344 | sums[stat_type] += rps_peers[i].stats[stat_type]; | ||
2345 | } | ||
2346 | } | ||
2347 | to_file ("/tmp/rps/final_stats.dat", | ||
2348 | "SUM %" | ||
2349 | PRIu64 " %" /* rounds */ | ||
2350 | PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64 " %" /* blocking */ | ||
2351 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* issued */ | ||
2352 | PRIu64 " %" PRIu64 " %" PRIu64 " %" /* sent */ | ||
2353 | PRIu64 " %" PRIu64 " %" PRIu64 /* recv */, | ||
2354 | sums[STAT_TYPE_ROUNDS], | ||
2355 | sums[STAT_TYPE_BLOCKS], | ||
2356 | sums[STAT_TYPE_BLOCKS_MANY_PUSH], | ||
2357 | sums[STAT_TYPE_BLOCKS_NO_PUSH], | ||
2358 | sums[STAT_TYPE_BLOCKS_NO_PULL], | ||
2359 | sums[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL], | ||
2360 | sums[STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL], | ||
2361 | sums[STAT_TYPE_ISSUED_PUSH_SEND], | ||
2362 | sums[STAT_TYPE_ISSUED_PULL_REQ], | ||
2363 | sums[STAT_TYPE_ISSUED_PULL_REP], | ||
2364 | sums[STAT_TYPE_SENT_PUSH_SEND], | ||
2365 | sums[STAT_TYPE_SENT_PULL_REQ], | ||
2366 | sums[STAT_TYPE_SENT_PULL_REP], | ||
2367 | sums[STAT_TYPE_RECV_PUSH_SEND], | ||
2368 | sums[STAT_TYPE_RECV_PULL_REQ], | ||
2369 | sums[STAT_TYPE_RECV_PULL_REP]); | ||
2370 | } | ||
2371 | |||
2372 | /** | ||
2373 | * Continuation called by #GNUNET_STATISTICS_get() functions. | ||
2374 | * | ||
2375 | * Remembers that this specific statistics value was received for this peer. | ||
2376 | * Checks whether all peers received their statistics yet. | ||
2377 | * Issues the shutdown. | ||
2378 | * | ||
2379 | * @param cls closure | ||
2380 | * @param success #GNUNET_OK if statistics were | ||
2381 | * successfully obtained, #GNUNET_SYSERR if not. | ||
2382 | */ | ||
2383 | void | ||
2384 | post_test_shutdown_ready_cb (void *cls, | ||
2385 | int success) | ||
2386 | { | ||
2387 | struct STATcls *stat_cls = (struct STATcls *) cls; | ||
2388 | struct RPSPeer *rps_peer = stat_cls->rps_peer; | ||
2389 | |||
2390 | rps_peer->h_stat_get[stat_cls->stat_type] = NULL; | ||
2391 | if (GNUNET_OK == success) | ||
2392 | { | ||
2393 | /* set flag that we we got the value */ | ||
2394 | rps_peer->stat_collected_flags |= BIT(stat_cls->stat_type); | ||
2395 | } else { | ||
2396 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
2397 | "Peer %u did not receive statistics value\n", | ||
2398 | rps_peer->index); | ||
2399 | GNUNET_free (stat_cls); | ||
2400 | GNUNET_break (0); | ||
2401 | return; | ||
2402 | } | ||
2403 | |||
2404 | if (NULL != rps_peer->stat_op && | ||
2405 | GNUNET_YES == check_statistics_collect_completed_single_peer (rps_peer)) | ||
2406 | { | ||
2407 | GNUNET_TESTBED_operation_done (rps_peer->stat_op); | ||
2408 | } | ||
2409 | |||
2410 | //write_final_stats (); | ||
2411 | if (GNUNET_YES == check_statistics_collect_completed()) | ||
2412 | { | ||
2413 | write_final_stats (); | ||
2414 | GNUNET_free (stat_cls); | ||
2415 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2416 | "Shutting down\n"); | ||
2417 | GNUNET_SCHEDULER_shutdown (); | ||
2418 | } else { | ||
2419 | GNUNET_free (stat_cls); | ||
2420 | } | ||
2421 | } | ||
2422 | |||
2423 | /** | ||
2424 | * Callback function to process statistic values. | ||
2425 | * | ||
2426 | * @param cls closure | ||
2427 | * @param subsystem name of subsystem that created the statistic | ||
2428 | * @param name the name of the datum | ||
2429 | * @param value the current value | ||
2430 | * @param is_persistent #GNUNET_YES if the value is persistent, #GNUNET_NO if not | ||
2431 | * @return #GNUNET_OK to continue, #GNUNET_SYSERR to abort iteration | ||
2432 | */ | ||
2433 | int | ||
2434 | stat_iterator (void *cls, | ||
2435 | const char *subsystem, | ||
2436 | const char *name, | ||
2437 | uint64_t value, | ||
2438 | int is_persistent) | ||
2439 | { | ||
2440 | const struct STATcls *stat_cls = (const struct STATcls *) cls; | ||
2441 | struct RPSPeer *rps_peer = (struct RPSPeer *) stat_cls->rps_peer; | ||
2442 | |||
2443 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got stat value: %s - %" PRIu64 "\n", | ||
2444 | //stat_type_2_str (stat_cls->stat_type), | ||
2445 | name, | ||
2446 | value); | ||
2447 | to_file (rps_peer->file_name_stats, | ||
2448 | "%s: %" PRIu64 "\n", | ||
2449 | name, | ||
2450 | value); | ||
2451 | switch (stat_str_2_type (name)) | ||
2452 | { | ||
2453 | case STAT_TYPE_ROUNDS: | ||
2454 | rps_peer->stats[STAT_TYPE_ROUNDS] = value; | ||
2455 | break; | ||
2456 | case STAT_TYPE_BLOCKS: | ||
2457 | rps_peer->stats[STAT_TYPE_BLOCKS] = value; | ||
2458 | break; | ||
2459 | case STAT_TYPE_BLOCKS_MANY_PUSH: | ||
2460 | rps_peer->stats[STAT_TYPE_BLOCKS_MANY_PUSH] = value; | ||
2461 | break; | ||
2462 | case STAT_TYPE_BLOCKS_NO_PUSH: | ||
2463 | rps_peer->stats[STAT_TYPE_BLOCKS_NO_PUSH] = value; | ||
2464 | break; | ||
2465 | case STAT_TYPE_BLOCKS_NO_PULL: | ||
2466 | rps_peer->stats[STAT_TYPE_BLOCKS_NO_PULL] = value; | ||
2467 | break; | ||
2468 | case STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL: | ||
2469 | rps_peer->stats[STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL] = value; | ||
2470 | break; | ||
2471 | case STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL: | ||
2472 | rps_peer->stats[STAT_TYPE_BLOCKS] = value; | ||
2473 | break; | ||
2474 | case STAT_TYPE_ISSUED_PUSH_SEND: | ||
2475 | rps_peer->stats[STAT_TYPE_ISSUED_PUSH_SEND] = value; | ||
2476 | break; | ||
2477 | case STAT_TYPE_ISSUED_PULL_REQ: | ||
2478 | rps_peer->stats[STAT_TYPE_ISSUED_PULL_REQ] = value; | ||
2479 | break; | ||
2480 | case STAT_TYPE_ISSUED_PULL_REP: | ||
2481 | rps_peer->stats[STAT_TYPE_ISSUED_PULL_REP] = value; | ||
2482 | break; | ||
2483 | case STAT_TYPE_SENT_PUSH_SEND: | ||
2484 | rps_peer->stats[STAT_TYPE_SENT_PUSH_SEND] = value; | ||
2485 | break; | ||
2486 | case STAT_TYPE_SENT_PULL_REQ: | ||
2487 | rps_peer->stats[STAT_TYPE_SENT_PULL_REQ] = value; | ||
2488 | break; | ||
2489 | case STAT_TYPE_SENT_PULL_REP: | ||
2490 | rps_peer->stats[STAT_TYPE_SENT_PULL_REP] = value; | ||
2491 | break; | ||
2492 | case STAT_TYPE_RECV_PUSH_SEND: | ||
2493 | rps_peer->stats[STAT_TYPE_RECV_PUSH_SEND] = value; | ||
2494 | break; | ||
2495 | case STAT_TYPE_RECV_PULL_REQ: | ||
2496 | rps_peer->stats[STAT_TYPE_RECV_PULL_REQ] = value; | ||
2497 | break; | ||
2498 | case STAT_TYPE_RECV_PULL_REP: | ||
2499 | rps_peer->stats[STAT_TYPE_RECV_PULL_REP] = value; | ||
2500 | break; | ||
2501 | case STAT_TYPE_MAX: | ||
2502 | default: | ||
2503 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2504 | "Unknown statistics string: %s\n", | ||
2505 | name); | ||
2506 | break; | ||
2507 | } | ||
2508 | return GNUNET_OK; | ||
2509 | } | ||
2510 | |||
2511 | void post_profiler (struct RPSPeer *rps_peer) | ||
2512 | { | ||
2513 | if (COLLECT_STATISTICS != cur_test_run.have_collect_statistics) | ||
2514 | { | ||
2515 | return; | ||
2516 | } | ||
2517 | |||
2518 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2519 | "Going to request statistic values with mask 0x%" PRIx32 "\n", | ||
2520 | cur_test_run.stat_collect_flags); | ||
2521 | |||
2522 | struct STATcls *stat_cls; | ||
2523 | uint32_t stat_type; | ||
2524 | for (stat_type = STAT_TYPE_ROUNDS; | ||
2525 | stat_type < STAT_TYPE_MAX; | ||
2526 | stat_type++) | ||
2527 | { | ||
2528 | if (BIT(stat_type) & cur_test_run.stat_collect_flags) | ||
2529 | { | ||
2530 | stat_cls = GNUNET_malloc (sizeof (struct STATcls)); | ||
2531 | stat_cls->rps_peer = rps_peer; | ||
2532 | stat_cls->stat_type = stat_type; | ||
2533 | rps_peer->file_name_stats = | ||
2534 | store_prefix_file_name (rps_peer->peer_id, "stats"); | ||
2535 | rps_peer->h_stat_get[stat_type] = GNUNET_STATISTICS_get ( | ||
2536 | rps_peer->stats_h, | ||
2537 | "rps", | ||
2538 | stat_type_2_str (stat_type), | ||
2539 | post_test_shutdown_ready_cb, | ||
2540 | stat_iterator, | ||
2541 | (struct STATcls *) stat_cls); | ||
2542 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2543 | "Requested statistics for %s (peer %" PRIu32 ")\n", | ||
2544 | stat_type_2_str (stat_type), | ||
2545 | rps_peer->index); | ||
2546 | } | ||
2547 | } | ||
2548 | } | ||
2549 | |||
2550 | |||
2551 | /*********************************************************************** | ||
2552 | * /Definition of tests | ||
2553 | ***********************************************************************/ | ||
2554 | |||
2555 | |||
2556 | /** | ||
2557 | * Actual "main" function for the testcase. | ||
2558 | * | ||
2559 | * @param cls closure | ||
2560 | * @param h the run handle | ||
2561 | * @param n_peers number of peers in 'peers' | ||
2562 | * @param peers handle to peers run in the testbed | ||
2563 | * @param links_succeeded the number of overlay link connection attempts that | ||
2564 | * succeeded | ||
2565 | * @param links_failed the number of overlay link connection attempts that | ||
2566 | * failed | ||
2567 | */ | ||
2568 | static void | ||
2569 | test_run (void *cls, | ||
2570 | struct GNUNET_TESTBED_RunHandle *h, | ||
2571 | unsigned int n_peers, | ||
2572 | struct GNUNET_TESTBED_Peer **peers, | ||
2573 | unsigned int links_succeeded, | ||
2574 | unsigned int links_failed) | ||
2575 | { | ||
2576 | unsigned int i; | ||
2577 | struct OpListEntry *entry; | ||
2578 | |||
2579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "RUN was called\n"); | ||
2580 | |||
2581 | /* Check whether we timed out */ | ||
2582 | if (n_peers != num_peers || | ||
2583 | NULL == peers || | ||
2584 | 0 == links_succeeded) | ||
2585 | { | ||
2586 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Going down due to args (eg. timeout)\n"); | ||
2587 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tn_peers: %u\n", n_peers); | ||
2588 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tnum_peers: %" PRIu32 "\n", num_peers); | ||
2589 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tpeers: %p\n", peers); | ||
2590 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tlinks_succeeded: %u\n", links_succeeded); | ||
2591 | GNUNET_SCHEDULER_shutdown (); | ||
2592 | return; | ||
2593 | } | ||
2594 | |||
2595 | |||
2596 | /* Initialize peers */ | ||
2597 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "going to initialise peers\n"); | ||
2598 | testbed_peers = peers; | ||
2599 | num_peers_online = 0; | ||
2600 | for (i = 0; i < num_peers; i++) | ||
2601 | { | ||
2602 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "initialising %u\n", i); | ||
2603 | entry = make_oplist_entry (); | ||
2604 | entry->index = i; | ||
2605 | rps_peers[i].index = i; | ||
2606 | if (NULL != cur_test_run.init_peer) | ||
2607 | cur_test_run.init_peer (&rps_peers[i]); | ||
2608 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | ||
2609 | { | ||
2610 | rps_peers->cur_view_count = 0; | ||
2611 | rps_peers->cur_view = NULL; | ||
2612 | } | ||
2613 | entry->op = GNUNET_TESTBED_peer_get_information (peers[i], | ||
2614 | GNUNET_TESTBED_PIT_IDENTITY, | ||
2615 | &info_cb, | ||
2616 | entry); | ||
2617 | } | ||
2618 | |||
2619 | /* Bring peers up */ | ||
2620 | GNUNET_assert (num_peers == n_peers); | ||
2621 | for (i = 0; i < n_peers; i++) | ||
2622 | { | ||
2623 | rps_peers[i].index = i; | ||
2624 | rps_peers[i].op = | ||
2625 | GNUNET_TESTBED_service_connect (&rps_peers[i], | ||
2626 | peers[i], | ||
2627 | "rps", | ||
2628 | &rps_connect_complete_cb, | ||
2629 | &rps_peers[i], | ||
2630 | &rps_connect_adapter, | ||
2631 | &rps_disconnect_adapter, | ||
2632 | &rps_peers[i]); | ||
2633 | /* Connect all peers to statistics service */ | ||
2634 | if (COLLECT_STATISTICS == cur_test_run.have_collect_statistics) | ||
2635 | { | ||
2636 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2637 | "Connecting to statistics service\n"); | ||
2638 | rps_peers[i].stat_op = | ||
2639 | GNUNET_TESTBED_service_connect (NULL, | ||
2640 | peers[i], | ||
2641 | "statistics", | ||
2642 | stat_complete_cb, | ||
2643 | &rps_peers[i], | ||
2644 | &stat_connect_adapter, | ||
2645 | &stat_disconnect_adapter, | ||
2646 | &rps_peers[i]); | ||
2647 | } | ||
2648 | } | ||
2649 | |||
2650 | if (NULL != churn_task) | ||
2651 | GNUNET_SCHEDULER_cancel (churn_task); | ||
2652 | post_test_task = GNUNET_SCHEDULER_add_delayed (duration, &post_test_op, NULL); | ||
2653 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "timeout for shutdown is %lu\n", timeout.rel_value_us/1000000); | ||
2654 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, | ||
2655 | &trigger_shutdown, | ||
2656 | NULL); | ||
2657 | GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); | ||
2658 | } | ||
2659 | |||
2660 | |||
2661 | /** | ||
2662 | * Entry point for the testcase, sets up the testbed. | ||
2663 | * | ||
2664 | * @param argc unused | ||
2665 | * @param argv unused | ||
2666 | */ | ||
2667 | static void | ||
2668 | run (void *cls, | ||
2669 | char *const *args, | ||
2670 | const char *cfgfile, | ||
2671 | const struct GNUNET_CONFIGURATION_Handle *cfg) | ||
2672 | { | ||
2673 | //int ret_value; | ||
2674 | |||
2675 | /* Defaults for tests */ | ||
2676 | churn_task = NULL; | ||
2677 | |||
2678 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); | ||
2679 | cur_test_run.name = "test-rps-profiler"; | ||
2680 | if (0 == num_peers) num_peers = 10; | ||
2681 | mal_type = 3; | ||
2682 | cur_test_run.init_peer = profiler_init_peer; | ||
2683 | //cur_test_run.pre_test = mal_pre; | ||
2684 | cur_test_run.pre_test = pre_profiler; | ||
2685 | cur_test_run.main_test = profiler_cb; | ||
2686 | cur_test_run.reply_handle = profiler_reply_handle; | ||
2687 | cur_test_run.eval_cb = profiler_eval; | ||
2688 | cur_test_run.post_test = post_profiler; | ||
2689 | cur_test_run.request_interval = 2; | ||
2690 | if (0 == cur_test_run.num_requests) cur_test_run.num_requests = 5; | ||
2691 | //cur_test_run.have_churn = HAVE_CHURN; | ||
2692 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2693 | cur_test_run.have_quick_quit = HAVE_QUICK_QUIT; | ||
2694 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; | ||
2695 | cur_test_run.stat_collect_flags = BIT(STAT_TYPE_ROUNDS) | | ||
2696 | BIT(STAT_TYPE_BLOCKS) | | ||
2697 | BIT(STAT_TYPE_BLOCKS_MANY_PUSH) | | ||
2698 | BIT(STAT_TYPE_BLOCKS_NO_PUSH) | | ||
2699 | BIT(STAT_TYPE_BLOCKS_NO_PULL) | | ||
2700 | BIT(STAT_TYPE_BLOCKS_MANY_PUSH_NO_PULL) | | ||
2701 | BIT(STAT_TYPE_BLOCKS_NO_PUSH_NO_PULL) | | ||
2702 | BIT(STAT_TYPE_ISSUED_PUSH_SEND) | | ||
2703 | BIT(STAT_TYPE_ISSUED_PULL_REQ) | | ||
2704 | BIT(STAT_TYPE_ISSUED_PULL_REP) | | ||
2705 | BIT(STAT_TYPE_SENT_PUSH_SEND) | | ||
2706 | BIT(STAT_TYPE_SENT_PULL_REQ) | | ||
2707 | BIT(STAT_TYPE_SENT_PULL_REP) | | ||
2708 | BIT(STAT_TYPE_RECV_PUSH_SEND) | | ||
2709 | BIT(STAT_TYPE_RECV_PULL_REQ) | | ||
2710 | BIT(STAT_TYPE_RECV_PULL_REP); | ||
2711 | cur_test_run.have_collect_view = COLLECT_VIEW; | ||
2712 | |||
2713 | /* 'Clean' directory */ | ||
2714 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | ||
2715 | GNUNET_DISK_directory_create ("/tmp/rps/"); | ||
2716 | if (0 == duration.rel_value_us) | ||
2717 | { | ||
2718 | if (0 == timeout.rel_value_us) | ||
2719 | { | ||
2720 | duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 90); | ||
2721 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2722 | (90 * 1.2) + | ||
2723 | (0.01 * num_peers)); | ||
2724 | } | ||
2725 | else | ||
2726 | { | ||
2727 | duration = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2728 | (timeout.rel_value_us/1000000) | ||
2729 | * 0.75); | ||
2730 | } | ||
2731 | } | ||
2732 | else | ||
2733 | { | ||
2734 | if (0 == timeout.rel_value_us) | ||
2735 | { | ||
2736 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2737 | ((duration.rel_value_us/1000000) | ||
2738 | * 1.2) + (0.01 * num_peers)); | ||
2739 | } | ||
2740 | } | ||
2741 | GNUNET_assert (duration.rel_value_us < timeout.rel_value_us); | ||
2742 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2743 | "duration is %lus\n", | ||
2744 | duration.rel_value_us/1000000); | ||
2745 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2746 | "timeout is %lus\n", | ||
2747 | timeout.rel_value_us/1000000); | ||
2748 | |||
2749 | /* Compute number of bits for representing largest peer id */ | ||
2750 | for (bits_needed = 1; (1 << bits_needed) < num_peers; bits_needed++) | ||
2751 | ; | ||
2752 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2753 | "Need %u bits to represent %" PRIu32 " peers\n", | ||
2754 | bits_needed, | ||
2755 | num_peers); | ||
2756 | |||
2757 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); | ||
2758 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); | ||
2759 | rps_peer_ids = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | ||
2760 | if ( (2 == mal_type) || | ||
2761 | (3 == mal_type)) | ||
2762 | target_peer = &rps_peer_ids[num_peers - 2]; | ||
2763 | if (profiler_eval == cur_test_run.eval_cb) | ||
2764 | eval_peer = &rps_peers[num_peers - 1]; /* FIXME: eval_peer could be a | ||
2765 | malicious peer if not careful | ||
2766 | with the malicious portion */ | ||
2767 | |||
2768 | ok = 1; | ||
2769 | GNUNET_TESTBED_run (NULL, | ||
2770 | cfg, | ||
2771 | num_peers, | ||
2772 | 0, /* event mask */ | ||
2773 | NULL, | ||
2774 | NULL, | ||
2775 | &test_run, | ||
2776 | NULL); | ||
2777 | } | ||
2778 | |||
2779 | /** | ||
2780 | * Entry point for the testcase, sets up the testbed. | ||
2781 | * | ||
2782 | * @param argc unused | ||
2783 | * @param argv unused | ||
2784 | * @return 0 on success | ||
2785 | */ | ||
2786 | int | ||
2787 | main (int argc, char *argv[]) | ||
2788 | { | ||
2789 | int ret_value; | ||
2790 | struct GNUNET_GETOPT_CommandLineOption options[] = { | ||
2791 | GNUNET_GETOPT_option_uint ('n', | ||
2792 | "num-peers", | ||
2793 | "COUNT", | ||
2794 | gettext_noop ("number of peers to start"), | ||
2795 | &num_peers), | ||
2796 | |||
2797 | GNUNET_GETOPT_option_relative_time ('d', | ||
2798 | "duration", | ||
2799 | "DURATION", | ||
2800 | gettext_noop ("duration of the profiling"), | ||
2801 | &duration), | ||
2802 | |||
2803 | GNUNET_GETOPT_option_relative_time ('t', | ||
2804 | "timeout", | ||
2805 | "TIMEOUT", | ||
2806 | gettext_noop ("timeout for the profiling"), | ||
2807 | &timeout), | ||
2808 | |||
2809 | GNUNET_GETOPT_option_uint ('r', | ||
2810 | "num-requests", | ||
2811 | "COUNT", | ||
2812 | gettext_noop ("number of PeerIDs to request"), | ||
2813 | &cur_test_run.num_requests), | ||
2814 | |||
2815 | GNUNET_GETOPT_OPTION_END | ||
2816 | }; | ||
2817 | |||
2818 | //if (GNUNET_OK != | ||
2819 | // GNUNET_STRINGS_get_utf8_args (argc, argv, | ||
2820 | // &argc, &argv)) | ||
2821 | // return 2; | ||
2822 | ret_value = 0; | ||
2823 | if (GNUNET_OK != | ||
2824 | GNUNET_PROGRAM_run (argc, | ||
2825 | argv, | ||
2826 | "gnunet-rps-profiler", | ||
2827 | gettext_noop ("Measure quality and performance of the RPS service."), | ||
2828 | options, | ||
2829 | &run, | ||
2830 | NULL)) | ||
2831 | { | ||
2832 | ret_value = 1; | ||
2833 | } | ||
2834 | if (GNUNET_OK != ret_value) | ||
2835 | { | ||
2836 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
2837 | "Test did not run successfully!\n"); | ||
2838 | } | ||
2839 | |||
2840 | ret_value = cur_test_run.eval_cb(); | ||
2841 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | ||
2842 | { | ||
2843 | GNUNET_array_grow (rps_peers->cur_view, | ||
2844 | rps_peers->cur_view_count, | ||
2845 | 0); | ||
2846 | } | ||
2847 | GNUNET_free (rps_peers); | ||
2848 | GNUNET_free (rps_peer_ids); | ||
2849 | GNUNET_CONTAINER_multipeermap_destroy (peer_map); | ||
2850 | return ret_value; | ||
2851 | } | ||
2852 | |||
2853 | /* end of test_rps.c */ | ||
diff --git a/src/rps/gnunet-rps.c b/src/rps/gnunet-rps.c index 8de588568..b3785a733 100644 --- a/src/rps/gnunet-rps.c +++ b/src/rps/gnunet-rps.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -152,12 +150,21 @@ run (void *cls, | |||
152 | static struct GNUNET_PeerIdentity zero_pid; | 150 | static struct GNUNET_PeerIdentity zero_pid; |
153 | 151 | ||
154 | rps_handle = GNUNET_RPS_connect (cfg); | 152 | rps_handle = GNUNET_RPS_connect (cfg); |
153 | if (NULL == rps_handle) | ||
154 | { | ||
155 | FPRINTF (stderr, "Failed to connect to the rps service\n"); | ||
156 | return; | ||
157 | } | ||
155 | 158 | ||
156 | if ((0 == memcmp (&zero_pid, &peer_id, sizeof (peer_id))) && | 159 | if ((0 == memcmp (&zero_pid, &peer_id, sizeof (peer_id))) && |
157 | (!view_update)) | 160 | (!view_update)) |
158 | { /* Request n PeerIDs */ | 161 | { /* Request n PeerIDs */ |
159 | /* If number was specified use it, else request single peer. */ | 162 | /* If number was specified use it, else request single peer. */ |
160 | num_peers = (NULL == args[0]) ? 1 : atoi (args[0]); | 163 | if (NULL == args[0] || |
164 | 0 == sscanf (args[0], "%lu", &num_peers)) | ||
165 | { | ||
166 | num_peers = 1; | ||
167 | } | ||
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 168 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
162 | "Requesting %" PRIu64 " PeerIDs\n", num_peers); | 169 | "Requesting %" PRIu64 " PeerIDs\n", num_peers); |
163 | req_handle = GNUNET_RPS_request_peers (rps_handle, num_peers, reply_handle, NULL); | 170 | req_handle = GNUNET_RPS_request_peers (rps_handle, num_peers, reply_handle, NULL); |
@@ -165,7 +172,11 @@ run (void *cls, | |||
165 | } else if (view_update) | 172 | } else if (view_update) |
166 | { | 173 | { |
167 | /* Get updates of view */ | 174 | /* Get updates of view */ |
168 | num_view_updates = (NULL == args[0]) ? 0 : atoi (args[0]); | 175 | if (NULL == args[0] || |
176 | 0 == sscanf (args[0], "%lu", &num_view_updates)) | ||
177 | { | ||
178 | num_view_updates = 0; | ||
179 | } | ||
169 | GNUNET_RPS_view_request (rps_handle, num_view_updates, view_update_handle, NULL); | 180 | GNUNET_RPS_view_request (rps_handle, num_view_updates, view_update_handle, NULL); |
170 | if (0 != num_view_updates) | 181 | if (0 != num_view_updates) |
171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 182 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index eb47903e0..1f155b14f 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2013-2015 GNUnet e.V. | 3 | Copyright (C) 2013-2015 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -70,7 +68,14 @@ static struct GNUNET_STATISTICS_Handle *stats; | |||
70 | */ | 68 | */ |
71 | static struct GNUNET_PeerIdentity own_identity; | 69 | static struct GNUNET_PeerIdentity own_identity; |
72 | 70 | ||
71 | static int in_shutdown = GNUNET_NO; | ||
73 | 72 | ||
73 | /** | ||
74 | * @brief Port used for cadet. | ||
75 | * | ||
76 | * Don't compute multiple times through making it global | ||
77 | */ | ||
78 | static struct GNUNET_HashCode port; | ||
74 | 79 | ||
75 | /*********************************************************************** | 80 | /*********************************************************************** |
76 | * Old gnunet-service-rps_peers.c | 81 | * Old gnunet-service-rps_peers.c |
@@ -79,7 +84,7 @@ static struct GNUNET_PeerIdentity own_identity; | |||
79 | /** | 84 | /** |
80 | * Set a peer flag of given peer context. | 85 | * Set a peer flag of given peer context. |
81 | */ | 86 | */ |
82 | #define set_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask)) | 87 | #define SET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) |= (mask)) |
83 | 88 | ||
84 | /** | 89 | /** |
85 | * Get peer flag of given peer context. | 90 | * Get peer flag of given peer context. |
@@ -90,12 +95,7 @@ static struct GNUNET_PeerIdentity own_identity; | |||
90 | /** | 95 | /** |
91 | * Unset flag of given peer context. | 96 | * Unset flag of given peer context. |
92 | */ | 97 | */ |
93 | #define unset_peer_flag(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) | 98 | #define UNSET_PEER_FLAG(peer_ctx, mask) ((peer_ctx->peer_flags) &= ~(mask)) |
94 | |||
95 | /** | ||
96 | * Set a channel flag of given channel context. | ||
97 | */ | ||
98 | #define set_channel_flag(channel_flags, mask) ((*channel_flags) |= (mask)) | ||
99 | 99 | ||
100 | /** | 100 | /** |
101 | * Get channel flag of given channel context. | 101 | * Get channel flag of given channel context. |
@@ -160,6 +160,11 @@ struct PendingMessage | |||
160 | }; | 160 | }; |
161 | 161 | ||
162 | /** | 162 | /** |
163 | * @brief Context for a channel | ||
164 | */ | ||
165 | struct ChannelCtx; | ||
166 | |||
167 | /** | ||
163 | * Struct used to keep track of other peer's status | 168 | * Struct used to keep track of other peer's status |
164 | * | 169 | * |
165 | * This is stored in a multipeermap. | 170 | * This is stored in a multipeermap. |
@@ -177,22 +182,12 @@ struct PeerContext | |||
177 | /** | 182 | /** |
178 | * Channel open to client. | 183 | * Channel open to client. |
179 | */ | 184 | */ |
180 | struct GNUNET_CADET_Channel *send_channel; | 185 | struct ChannelCtx *send_channel_ctx; |
181 | |||
182 | /** | ||
183 | * Flags to the sending channel | ||
184 | */ | ||
185 | uint32_t *send_channel_flags; | ||
186 | 186 | ||
187 | /** | 187 | /** |
188 | * Channel open from client. | 188 | * Channel open from client. |
189 | */ | 189 | */ |
190 | struct GNUNET_CADET_Channel *recv_channel; // unneeded? | 190 | struct ChannelCtx *recv_channel_ctx; |
191 | |||
192 | /** | ||
193 | * Flags to the receiving channel | ||
194 | */ | ||
195 | uint32_t *recv_channel_flags; | ||
196 | 191 | ||
197 | /** | 192 | /** |
198 | * Array of pending operations on this peer. | 193 | * Array of pending operations on this peer. |
@@ -239,7 +234,7 @@ struct PeerContext | |||
239 | 234 | ||
240 | /** | 235 | /** |
241 | * This is pobably followed by 'statistical' data (when we first saw | 236 | * This is pobably followed by 'statistical' data (when we first saw |
242 | * him, how did we get his ID, how many pushes (in a timeinterval), | 237 | * it, how did we get its ID, how many pushes (in a timeinterval), |
243 | * ...) | 238 | * ...) |
244 | */ | 239 | */ |
245 | }; | 240 | }; |
@@ -261,6 +256,35 @@ struct PeersIteratorCls | |||
261 | }; | 256 | }; |
262 | 257 | ||
263 | /** | 258 | /** |
259 | * @brief Context for a channel | ||
260 | */ | ||
261 | struct ChannelCtx | ||
262 | { | ||
263 | /** | ||
264 | * @brief Meant to be used in a DLL | ||
265 | */ | ||
266 | struct ChannelCtx *next; | ||
267 | struct ChannelCtx *prev; | ||
268 | |||
269 | /** | ||
270 | * @brief The channel itself | ||
271 | */ | ||
272 | struct GNUNET_CADET_Channel *channel; | ||
273 | |||
274 | /** | ||
275 | * @brief The peer context associated with the channel | ||
276 | */ | ||
277 | struct PeerContext *peer_ctx; | ||
278 | |||
279 | /** | ||
280 | * @brief When channel destruction needs to be delayed (because it is called | ||
281 | * from within the cadet routine of another channel destruction) this task | ||
282 | * refers to the respective _SCHEDULER_Task. | ||
283 | */ | ||
284 | struct GNUNET_SCHEDULER_Task *destruction_task; | ||
285 | }; | ||
286 | |||
287 | /** | ||
264 | * @brief Hashmap of valid peers. | 288 | * @brief Hashmap of valid peers. |
265 | */ | 289 | */ |
266 | static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; | 290 | static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers; |
@@ -287,7 +311,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *peer_map; | |||
287 | static struct GNUNET_CADET_Handle *cadet_handle; | 311 | static struct GNUNET_CADET_Handle *cadet_handle; |
288 | 312 | ||
289 | 313 | ||
290 | |||
291 | /** | 314 | /** |
292 | * @brief Get the #PeerContext associated with a peer | 315 | * @brief Get the #PeerContext associated with a peer |
293 | * | 316 | * |
@@ -308,8 +331,28 @@ get_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
308 | return ctx; | 331 | return ctx; |
309 | } | 332 | } |
310 | 333 | ||
311 | int | 334 | /** |
312 | Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer); | 335 | * @brief Check whether we have information about the given peer. |
336 | * | ||
337 | * FIXME probably deprecated. Make this the new _online. | ||
338 | * | ||
339 | * @param peer peer in question | ||
340 | * | ||
341 | * @return #GNUNET_YES if peer is known | ||
342 | * #GNUNET_NO if peer is not knwon | ||
343 | */ | ||
344 | static int | ||
345 | check_peer_known (const struct GNUNET_PeerIdentity *peer) | ||
346 | { | ||
347 | if (NULL != peer_map) | ||
348 | { | ||
349 | return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); | ||
350 | } else | ||
351 | { | ||
352 | return GNUNET_NO; | ||
353 | } | ||
354 | } | ||
355 | |||
313 | 356 | ||
314 | /** | 357 | /** |
315 | * @brief Create a new #PeerContext and insert it into the peer map | 358 | * @brief Create a new #PeerContext and insert it into the peer map |
@@ -324,12 +367,10 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
324 | struct PeerContext *ctx; | 367 | struct PeerContext *ctx; |
325 | int ret; | 368 | int ret; |
326 | 369 | ||
327 | GNUNET_assert (GNUNET_NO == Peers_check_peer_known (peer)); | 370 | GNUNET_assert (GNUNET_NO == check_peer_known (peer)); |
328 | 371 | ||
329 | ctx = GNUNET_new (struct PeerContext); | 372 | ctx = GNUNET_new (struct PeerContext); |
330 | ctx->peer_id = *peer; | 373 | ctx->peer_id = *peer; |
331 | ctx->send_channel_flags = GNUNET_new (uint32_t); | ||
332 | ctx->recv_channel_flags = GNUNET_new (uint32_t); | ||
333 | ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, | 374 | ret = GNUNET_CONTAINER_multipeermap_put (peer_map, peer, ctx, |
334 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 375 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
335 | GNUNET_assert (GNUNET_OK == ret); | 376 | GNUNET_assert (GNUNET_OK == ret); |
@@ -347,18 +388,13 @@ create_peer_ctx (const struct GNUNET_PeerIdentity *peer) | |||
347 | static struct PeerContext * | 388 | static struct PeerContext * |
348 | create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer) | 389 | create_or_get_peer_ctx (const struct GNUNET_PeerIdentity *peer) |
349 | { | 390 | { |
350 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 391 | if (GNUNET_NO == check_peer_known (peer)) |
351 | { | 392 | { |
352 | return create_peer_ctx (peer); | 393 | return create_peer_ctx (peer); |
353 | } | 394 | } |
354 | return get_peer_ctx (peer); | 395 | return get_peer_ctx (peer); |
355 | } | 396 | } |
356 | 397 | ||
357 | void | ||
358 | Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | ||
359 | |||
360 | void | ||
361 | Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | ||
362 | 398 | ||
363 | /** | 399 | /** |
364 | * @brief Check whether we have a connection to this @a peer | 400 | * @brief Check whether we have a connection to this @a peer |
@@ -370,27 +406,27 @@ Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlag | |||
370 | * @return #GNUNET_YES if we are connected | 406 | * @return #GNUNET_YES if we are connected |
371 | * #GNUNET_NO otherwise | 407 | * #GNUNET_NO otherwise |
372 | */ | 408 | */ |
373 | int | 409 | static int |
374 | Peers_check_connected (const struct GNUNET_PeerIdentity *peer) | 410 | check_connected (const struct GNUNET_PeerIdentity *peer) |
375 | { | 411 | { |
376 | const struct PeerContext *peer_ctx; | 412 | struct PeerContext *peer_ctx; |
377 | 413 | ||
378 | /* If we don't know about this peer we don't know whether it's online */ | 414 | /* If we don't know about this peer we don't know whether it's online */ |
379 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 415 | if (GNUNET_NO == check_peer_known (peer)) |
380 | { | 416 | { |
381 | return GNUNET_NO; | 417 | return GNUNET_NO; |
382 | } | 418 | } |
383 | /* Get the context */ | 419 | /* Get the context */ |
384 | peer_ctx = get_peer_ctx (peer); | 420 | peer_ctx = get_peer_ctx (peer); |
385 | /* If we have no channel to this peer we don't know whether it's online */ | 421 | /* If we have no channel to this peer we don't know whether it's online */ |
386 | if ( (NULL == peer_ctx->send_channel) && | 422 | if ( (NULL == peer_ctx->send_channel_ctx) && |
387 | (NULL == peer_ctx->recv_channel) ) | 423 | (NULL == peer_ctx->recv_channel_ctx) ) |
388 | { | 424 | { |
389 | Peers_unset_peer_flag (peer, Peers_ONLINE); | 425 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
390 | return GNUNET_NO; | 426 | return GNUNET_NO; |
391 | } | 427 | } |
392 | /* Otherwise (if we have a channel, we know that it's online */ | 428 | /* Otherwise (if we have a channel, we know that it's online */ |
393 | Peers_set_peer_flag (peer, Peers_ONLINE); | 429 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
394 | return GNUNET_YES; | 430 | return GNUNET_YES; |
395 | } | 431 | } |
396 | 432 | ||
@@ -499,6 +535,8 @@ add_valid_peer (const struct GNUNET_PeerIdentity *peer) | |||
499 | return ret; | 535 | return ret; |
500 | } | 536 | } |
501 | 537 | ||
538 | static void | ||
539 | remove_pending_message (struct PendingMessage *pending_msg, int cancel); | ||
502 | 540 | ||
503 | /** | 541 | /** |
504 | * @brief Set the peer flag to living and | 542 | * @brief Set the peer flag to living and |
@@ -527,12 +565,12 @@ set_peer_live (struct PeerContext *peer_ctx) | |||
527 | GNUNET_i2s (&peer_ctx->peer_id)); | 565 | GNUNET_i2s (&peer_ctx->peer_id)); |
528 | // TODO wait until cadet sets mq->cancel_impl | 566 | // TODO wait until cadet sets mq->cancel_impl |
529 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | 567 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); |
530 | GNUNET_free (peer_ctx->liveliness_check_pending); | 568 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); |
531 | peer_ctx->liveliness_check_pending = NULL; | 569 | peer_ctx->liveliness_check_pending = NULL; |
532 | } | 570 | } |
533 | 571 | ||
534 | (void) add_valid_peer (peer); | 572 | (void) add_valid_peer (peer); |
535 | set_peer_flag (peer_ctx, Peers_ONLINE); | 573 | SET_PEER_FLAG (peer_ctx, Peers_ONLINE); |
536 | 574 | ||
537 | /* Call pending operations */ | 575 | /* Call pending operations */ |
538 | for (i = 0; i < peer_ctx->num_pending_ops; i++) | 576 | for (i = 0; i < peer_ctx->num_pending_ops; i++) |
@@ -569,6 +607,46 @@ handle_peer_pull_reply (void *cls, | |||
569 | 607 | ||
570 | /* End declaration of handlers */ | 608 | /* End declaration of handlers */ |
571 | 609 | ||
610 | /** | ||
611 | * @brief Allocate memory for a new channel context and insert it into DLL | ||
612 | * | ||
613 | * @param peer_ctx context of the according peer | ||
614 | * | ||
615 | * @return The channel context | ||
616 | */ | ||
617 | static struct ChannelCtx * | ||
618 | add_channel_ctx (struct PeerContext *peer_ctx) | ||
619 | { | ||
620 | struct ChannelCtx *channel_ctx; | ||
621 | channel_ctx = GNUNET_new (struct ChannelCtx); | ||
622 | channel_ctx->peer_ctx = peer_ctx; | ||
623 | return channel_ctx; | ||
624 | } | ||
625 | |||
626 | |||
627 | /** | ||
628 | * @brief Free memory and NULL pointers. | ||
629 | * | ||
630 | * @param channel_ctx The channel context. | ||
631 | */ | ||
632 | static void | ||
633 | remove_channel_ctx (struct ChannelCtx *channel_ctx) | ||
634 | { | ||
635 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; | ||
636 | |||
637 | if (channel_ctx == peer_ctx->send_channel_ctx) | ||
638 | { | ||
639 | GNUNET_free (channel_ctx); | ||
640 | peer_ctx->send_channel_ctx = NULL; | ||
641 | peer_ctx->mq = NULL; | ||
642 | } | ||
643 | else if (channel_ctx == peer_ctx->recv_channel_ctx) | ||
644 | { | ||
645 | GNUNET_free (channel_ctx); | ||
646 | peer_ctx->recv_channel_ctx = NULL; | ||
647 | } | ||
648 | } | ||
649 | |||
572 | 650 | ||
573 | /** | 651 | /** |
574 | * @brief Get the channel of a peer. If not existing, create. | 652 | * @brief Get the channel of a peer. If not existing, create. |
@@ -580,7 +658,6 @@ struct GNUNET_CADET_Channel * | |||
580 | get_channel (const struct GNUNET_PeerIdentity *peer) | 658 | get_channel (const struct GNUNET_PeerIdentity *peer) |
581 | { | 659 | { |
582 | struct PeerContext *peer_ctx; | 660 | struct PeerContext *peer_ctx; |
583 | struct GNUNET_HashCode port; | ||
584 | struct GNUNET_PeerIdentity *ctx_peer; | 661 | struct GNUNET_PeerIdentity *ctx_peer; |
585 | /* There exists a copy-paste-clone in run() */ | 662 | /* There exists a copy-paste-clone in run() */ |
586 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { | 663 | struct GNUNET_MQ_MessageHandler cadet_handlers[] = { |
@@ -605,28 +682,27 @@ get_channel (const struct GNUNET_PeerIdentity *peer) | |||
605 | 682 | ||
606 | 683 | ||
607 | peer_ctx = get_peer_ctx (peer); | 684 | peer_ctx = get_peer_ctx (peer); |
608 | if (NULL == peer_ctx->send_channel) | 685 | if (NULL == peer_ctx->send_channel_ctx) |
609 | { | 686 | { |
610 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 687 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
611 | "Trying to establish channel to peer %s\n", | 688 | "Trying to establish channel to peer %s\n", |
612 | GNUNET_i2s (peer)); | 689 | GNUNET_i2s (peer)); |
613 | GNUNET_CRYPTO_hash (GNUNET_APPLICATION_PORT_RPS, | ||
614 | strlen (GNUNET_APPLICATION_PORT_RPS), | ||
615 | &port); | ||
616 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); | 690 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); |
617 | *ctx_peer = *peer; | 691 | *ctx_peer = *peer; |
618 | peer_ctx->send_channel = | 692 | peer_ctx->send_channel_ctx = add_channel_ctx (peer_ctx); |
693 | peer_ctx->send_channel_ctx->channel = | ||
619 | GNUNET_CADET_channel_create (cadet_handle, | 694 | GNUNET_CADET_channel_create (cadet_handle, |
620 | (struct GNUNET_PeerIdentity *) ctx_peer, /* context */ | 695 | peer_ctx->send_channel_ctx, /* context */ |
621 | peer, | 696 | peer, |
622 | &port, | 697 | &port, |
623 | GNUNET_CADET_OPTION_RELIABLE, | 698 | GNUNET_CADET_OPTION_RELIABLE, |
624 | NULL, /* WindowSize handler */ | 699 | NULL, /* WindowSize handler */ |
625 | cleanup_destroyed_channel, /* Disconnect handler */ | 700 | &cleanup_destroyed_channel, /* Disconnect handler */ |
626 | cadet_handlers); | 701 | cadet_handlers); |
627 | } | 702 | } |
628 | GNUNET_assert (NULL != peer_ctx->send_channel); | 703 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx); |
629 | return peer_ctx->send_channel; | 704 | GNUNET_assert (NULL != peer_ctx->send_channel_ctx->channel); |
705 | return peer_ctx->send_channel_ctx->channel; | ||
630 | } | 706 | } |
631 | 707 | ||
632 | 708 | ||
@@ -653,56 +729,6 @@ get_mq (const struct GNUNET_PeerIdentity *peer) | |||
653 | return peer_ctx->mq; | 729 | return peer_ctx->mq; |
654 | } | 730 | } |
655 | 731 | ||
656 | |||
657 | /** | ||
658 | * @brief This is called in response to the first message we sent as a | ||
659 | * liveliness check. | ||
660 | * | ||
661 | * @param cls #PeerContext of peer with pending liveliness check | ||
662 | */ | ||
663 | static void | ||
664 | mq_liveliness_check_successful (void *cls) | ||
665 | { | ||
666 | struct PeerContext *peer_ctx = cls; | ||
667 | |||
668 | if (NULL != peer_ctx->liveliness_check_pending) | ||
669 | { | ||
670 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
671 | "Liveliness check for peer %s was successfull\n", | ||
672 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
673 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
674 | peer_ctx->liveliness_check_pending = NULL; | ||
675 | set_peer_live (peer_ctx); | ||
676 | } | ||
677 | } | ||
678 | |||
679 | /** | ||
680 | * Issue a check whether peer is live | ||
681 | * | ||
682 | * @param peer_ctx the context of the peer | ||
683 | */ | ||
684 | static void | ||
685 | check_peer_live (struct PeerContext *peer_ctx) | ||
686 | { | ||
687 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
688 | "Get informed about peer %s getting live\n", | ||
689 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
690 | |||
691 | struct GNUNET_MQ_Handle *mq; | ||
692 | struct GNUNET_MQ_Envelope *ev; | ||
693 | |||
694 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | ||
695 | peer_ctx->liveliness_check_pending = GNUNET_new (struct PendingMessage); | ||
696 | peer_ctx->liveliness_check_pending->ev = ev; | ||
697 | peer_ctx->liveliness_check_pending->peer_ctx = peer_ctx; | ||
698 | peer_ctx->liveliness_check_pending->type = "Check liveliness"; | ||
699 | mq = get_mq (&peer_ctx->peer_id); | ||
700 | GNUNET_MQ_notify_sent (ev, | ||
701 | mq_liveliness_check_successful, | ||
702 | peer_ctx); | ||
703 | GNUNET_MQ_send (mq, ev); | ||
704 | } | ||
705 | |||
706 | /** | 732 | /** |
707 | * @brief Add an envelope to a message passed to mq to list of pending messages | 733 | * @brief Add an envelope to a message passed to mq to list of pending messages |
708 | * | 734 | * |
@@ -757,6 +783,54 @@ remove_pending_message (struct PendingMessage *pending_msg, int cancel) | |||
757 | 783 | ||
758 | 784 | ||
759 | /** | 785 | /** |
786 | * @brief This is called in response to the first message we sent as a | ||
787 | * liveliness check. | ||
788 | * | ||
789 | * @param cls #PeerContext of peer with pending liveliness check | ||
790 | */ | ||
791 | static void | ||
792 | mq_liveliness_check_successful (void *cls) | ||
793 | { | ||
794 | struct PeerContext *peer_ctx = cls; | ||
795 | |||
796 | if (NULL != peer_ctx->liveliness_check_pending) | ||
797 | { | ||
798 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
799 | "Liveliness check for peer %s was successfull\n", | ||
800 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
801 | remove_pending_message (peer_ctx->liveliness_check_pending, GNUNET_YES); | ||
802 | peer_ctx->liveliness_check_pending = NULL; | ||
803 | set_peer_live (peer_ctx); | ||
804 | } | ||
805 | } | ||
806 | |||
807 | /** | ||
808 | * Issue a check whether peer is live | ||
809 | * | ||
810 | * @param peer_ctx the context of the peer | ||
811 | */ | ||
812 | static void | ||
813 | check_peer_live (struct PeerContext *peer_ctx) | ||
814 | { | ||
815 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
816 | "Get informed about peer %s getting live\n", | ||
817 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
818 | |||
819 | struct GNUNET_MQ_Handle *mq; | ||
820 | struct GNUNET_MQ_Envelope *ev; | ||
821 | |||
822 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_CHECK_LIVE); | ||
823 | peer_ctx->liveliness_check_pending = | ||
824 | insert_pending_message (&peer_ctx->peer_id, ev, "Check liveliness"); | ||
825 | mq = get_mq (&peer_ctx->peer_id); | ||
826 | GNUNET_MQ_notify_sent (ev, | ||
827 | mq_liveliness_check_successful, | ||
828 | peer_ctx); | ||
829 | GNUNET_MQ_send (mq, ev); | ||
830 | } | ||
831 | |||
832 | |||
833 | /** | ||
760 | * @brief Check whether function of type #PeerOp was already scheduled | 834 | * @brief Check whether function of type #PeerOp was already scheduled |
761 | * | 835 | * |
762 | * The array with pending operations will probably never grow really big, so | 836 | * The array with pending operations will probably never grow really big, so |
@@ -782,8 +856,155 @@ check_operation_scheduled (const struct GNUNET_PeerIdentity *peer, | |||
782 | return GNUNET_NO; | 856 | return GNUNET_NO; |
783 | } | 857 | } |
784 | 858 | ||
785 | int | 859 | |
786 | Peers_remove_peer (const struct GNUNET_PeerIdentity *peer); | 860 | /** |
861 | * @brief Callback for scheduler to destroy a channel | ||
862 | * | ||
863 | * @param cls Context of the channel | ||
864 | */ | ||
865 | static void | ||
866 | destroy_channel (struct ChannelCtx *channel_ctx) | ||
867 | { | ||
868 | struct GNUNET_CADET_Channel *channel; | ||
869 | |||
870 | if (NULL != channel_ctx->destruction_task) | ||
871 | { | ||
872 | GNUNET_SCHEDULER_cancel (channel_ctx->destruction_task); | ||
873 | channel_ctx->destruction_task = NULL; | ||
874 | } | ||
875 | GNUNET_assert (channel_ctx->channel != NULL); | ||
876 | channel = channel_ctx->channel; | ||
877 | channel_ctx->channel = NULL; | ||
878 | GNUNET_CADET_channel_destroy (channel); | ||
879 | remove_channel_ctx (channel_ctx); | ||
880 | } | ||
881 | |||
882 | |||
883 | /** | ||
884 | * @brief Destroy a cadet channel. | ||
885 | * | ||
886 | * This satisfies the function signature of #GNUNET_SCHEDULER_TaskCallback. | ||
887 | * | ||
888 | * @param cls | ||
889 | */ | ||
890 | static void | ||
891 | destroy_channel_cb (void *cls) | ||
892 | { | ||
893 | struct ChannelCtx *channel_ctx = cls; | ||
894 | |||
895 | channel_ctx->destruction_task = NULL; | ||
896 | destroy_channel (channel_ctx); | ||
897 | } | ||
898 | |||
899 | |||
900 | /** | ||
901 | * @brief Schedule the destruction of a channel for immediately afterwards. | ||
902 | * | ||
903 | * In case a channel is to be destroyed from within the callback to the | ||
904 | * destruction of another channel (send channel), we cannot call | ||
905 | * GNUNET_CADET_channel_destroy directly, but need to use this scheduling | ||
906 | * construction. | ||
907 | * | ||
908 | * @param channel_ctx channel to be destroyed. | ||
909 | */ | ||
910 | static void | ||
911 | schedule_channel_destruction (struct ChannelCtx *channel_ctx) | ||
912 | { | ||
913 | GNUNET_assert (NULL == | ||
914 | channel_ctx->destruction_task); | ||
915 | GNUNET_assert (NULL != | ||
916 | channel_ctx->channel); | ||
917 | channel_ctx->destruction_task = | ||
918 | GNUNET_SCHEDULER_add_now (&destroy_channel_cb, | ||
919 | channel_ctx); | ||
920 | } | ||
921 | |||
922 | |||
923 | /** | ||
924 | * @brief Remove peer | ||
925 | * | ||
926 | * @param peer the peer to clean | ||
927 | * @return #GNUNET_YES if peer was removed | ||
928 | * #GNUNET_NO otherwise | ||
929 | */ | ||
930 | static int | ||
931 | destroy_peer (struct PeerContext *peer_ctx) | ||
932 | { | ||
933 | GNUNET_assert (NULL != peer_ctx); | ||
934 | GNUNET_assert (NULL != peer_map); | ||
935 | if (GNUNET_NO == | ||
936 | GNUNET_CONTAINER_multipeermap_contains (peer_map, | ||
937 | &peer_ctx->peer_id)) | ||
938 | { | ||
939 | return GNUNET_NO; | ||
940 | } | ||
941 | SET_PEER_FLAG (peer_ctx, Peers_TO_DESTROY); | ||
942 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
943 | "Going to remove peer %s\n", | ||
944 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
945 | UNSET_PEER_FLAG (peer_ctx, Peers_ONLINE); | ||
946 | |||
947 | /* Clear list of pending operations */ | ||
948 | // TODO this probably leaks memory | ||
949 | // ('only' the cls to the function. Not sure what to do with it) | ||
950 | GNUNET_array_grow (peer_ctx->pending_ops, | ||
951 | peer_ctx->num_pending_ops, | ||
952 | 0); | ||
953 | /* Remove all pending messages */ | ||
954 | while (NULL != peer_ctx->pending_messages_head) | ||
955 | { | ||
956 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
957 | "Removing unsent %s\n", | ||
958 | peer_ctx->pending_messages_head->type); | ||
959 | /* Cancle pending message, too */ | ||
960 | if ( (NULL != peer_ctx->liveliness_check_pending) && | ||
961 | (0 == memcmp (peer_ctx->pending_messages_head, | ||
962 | peer_ctx->liveliness_check_pending, | ||
963 | sizeof (struct PendingMessage))) ) | ||
964 | { | ||
965 | // TODO this may leak memory | ||
966 | peer_ctx->liveliness_check_pending = NULL; | ||
967 | } | ||
968 | remove_pending_message (peer_ctx->pending_messages_head, | ||
969 | GNUNET_YES); | ||
970 | } | ||
971 | |||
972 | /* If we are still waiting for notification whether this peer is live | ||
973 | * cancel the according task */ | ||
974 | if (NULL != peer_ctx->liveliness_check_pending) | ||
975 | { | ||
976 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
977 | "Removing pending liveliness check for peer %s\n", | ||
978 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
979 | // TODO wait until cadet sets mq->cancel_impl | ||
980 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | ||
981 | remove_pending_message (peer_ctx->liveliness_check_pending, | ||
982 | GNUNET_YES); | ||
983 | peer_ctx->liveliness_check_pending = NULL; | ||
984 | } | ||
985 | |||
986 | if (NULL != peer_ctx->send_channel_ctx) | ||
987 | { | ||
988 | /* This is possibly called from within channel destruction */ | ||
989 | schedule_channel_destruction (peer_ctx->send_channel_ctx); | ||
990 | } | ||
991 | if (NULL != peer_ctx->recv_channel_ctx) | ||
992 | { | ||
993 | /* This is possibly called from within channel destruction */ | ||
994 | schedule_channel_destruction (peer_ctx->recv_channel_ctx); | ||
995 | } | ||
996 | |||
997 | if (GNUNET_YES != | ||
998 | GNUNET_CONTAINER_multipeermap_remove_all (peer_map, | ||
999 | &peer_ctx->peer_id)) | ||
1000 | { | ||
1001 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1002 | "removing peer from peer_map failed\n"); | ||
1003 | } | ||
1004 | GNUNET_free (peer_ctx); | ||
1005 | return GNUNET_YES; | ||
1006 | } | ||
1007 | |||
787 | 1008 | ||
788 | /** | 1009 | /** |
789 | * Iterator over hash map entries. Deletes all contexts of peers. | 1010 | * Iterator over hash map entries. Deletes all contexts of peers. |
@@ -799,7 +1020,7 @@ peermap_clear_iterator (void *cls, | |||
799 | const struct GNUNET_PeerIdentity *key, | 1020 | const struct GNUNET_PeerIdentity *key, |
800 | void *value) | 1021 | void *value) |
801 | { | 1022 | { |
802 | Peers_remove_peer (key); | 1023 | destroy_peer (get_peer_ctx (key)); |
803 | return GNUNET_YES; | 1024 | return GNUNET_YES; |
804 | } | 1025 | } |
805 | 1026 | ||
@@ -1043,14 +1264,12 @@ restore_valid_peers () | |||
1043 | * @param cadet_h cadet handle | 1264 | * @param cadet_h cadet handle |
1044 | * @param own_id own peer identity | 1265 | * @param own_id own peer identity |
1045 | */ | 1266 | */ |
1046 | void | 1267 | static void |
1047 | Peers_initialise (char* fn_valid_peers, | 1268 | initialise_peers (char* fn_valid_peers, |
1048 | struct GNUNET_CADET_Handle *cadet_h, | 1269 | struct GNUNET_CADET_Handle *cadet_h) |
1049 | const struct GNUNET_PeerIdentity *own_id) | ||
1050 | { | 1270 | { |
1051 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); | 1271 | filename_valid_peers = GNUNET_strdup (fn_valid_peers); |
1052 | cadet_handle = cadet_h; | 1272 | cadet_handle = cadet_h; |
1053 | own_identity = *own_id; | ||
1054 | peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 1273 | peer_map = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
1055 | valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); | 1274 | valid_peers = GNUNET_CONTAINER_multipeermap_create (4, GNUNET_NO); |
1056 | restore_valid_peers (); | 1275 | restore_valid_peers (); |
@@ -1058,14 +1277,14 @@ Peers_initialise (char* fn_valid_peers, | |||
1058 | 1277 | ||
1059 | 1278 | ||
1060 | /** | 1279 | /** |
1061 | * @brief Delete storage of peers that was created with #Peers_initialise () | 1280 | * @brief Delete storage of peers that was created with #initialise_peers () |
1062 | */ | 1281 | */ |
1063 | void | 1282 | static void |
1064 | Peers_terminate () | 1283 | peers_terminate () |
1065 | { | 1284 | { |
1066 | if (GNUNET_SYSERR == | 1285 | if (GNUNET_SYSERR == |
1067 | GNUNET_CONTAINER_multipeermap_iterate (peer_map, | 1286 | GNUNET_CONTAINER_multipeermap_iterate (peer_map, |
1068 | peermap_clear_iterator, | 1287 | &peermap_clear_iterator, |
1069 | NULL)) | 1288 | NULL)) |
1070 | { | 1289 | { |
1071 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1290 | LOG (GNUNET_ERROR_TYPE_WARNING, |
@@ -1075,7 +1294,9 @@ Peers_terminate () | |||
1075 | peer_map = NULL; | 1294 | peer_map = NULL; |
1076 | store_valid_peers (); | 1295 | store_valid_peers (); |
1077 | GNUNET_free (filename_valid_peers); | 1296 | GNUNET_free (filename_valid_peers); |
1297 | filename_valid_peers = NULL; | ||
1078 | GNUNET_CONTAINER_multipeermap_destroy (valid_peers); | 1298 | GNUNET_CONTAINER_multipeermap_destroy (valid_peers); |
1299 | valid_peers = NULL; | ||
1079 | } | 1300 | } |
1080 | 1301 | ||
1081 | 1302 | ||
@@ -1109,9 +1330,9 @@ valid_peer_iterator (void *cls, | |||
1109 | * @return the number of key value pairs processed, | 1330 | * @return the number of key value pairs processed, |
1110 | * #GNUNET_SYSERR if it aborted iteration | 1331 | * #GNUNET_SYSERR if it aborted iteration |
1111 | */ | 1332 | */ |
1112 | int | 1333 | static int |
1113 | Peers_get_valid_peers (PeersIterator iterator, | 1334 | get_valid_peers (PeersIterator iterator, |
1114 | void *it_cls) | 1335 | void *it_cls) |
1115 | { | 1336 | { |
1116 | struct PeersIteratorCls *cls; | 1337 | struct PeersIteratorCls *cls; |
1117 | int ret; | 1338 | int ret; |
@@ -1136,14 +1357,12 @@ Peers_get_valid_peers (PeersIterator iterator, | |||
1136 | * @param peer the new #GNUNET_PeerIdentity | 1357 | * @param peer the new #GNUNET_PeerIdentity |
1137 | * | 1358 | * |
1138 | * @return #GNUNET_YES if peer was inserted | 1359 | * @return #GNUNET_YES if peer was inserted |
1139 | * #GNUNET_NO otherwise (if peer was already known or | 1360 | * #GNUNET_NO otherwise |
1140 | * peer was #own_identity) | ||
1141 | */ | 1361 | */ |
1142 | int | 1362 | static int |
1143 | Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) | 1363 | insert_peer (const struct GNUNET_PeerIdentity *peer) |
1144 | { | 1364 | { |
1145 | if ( (GNUNET_YES == Peers_check_peer_known (peer)) || | 1365 | if (GNUNET_YES == check_peer_known (peer)) |
1146 | (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) ) | ||
1147 | { | 1366 | { |
1148 | return GNUNET_NO; /* We already know this peer - nothing to do */ | 1367 | return GNUNET_NO; /* We already know this peer - nothing to do */ |
1149 | } | 1368 | } |
@@ -1151,8 +1370,30 @@ Peers_insert_peer (const struct GNUNET_PeerIdentity *peer) | |||
1151 | return GNUNET_YES; | 1370 | return GNUNET_YES; |
1152 | } | 1371 | } |
1153 | 1372 | ||
1154 | int | 1373 | |
1155 | Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags); | 1374 | /** |
1375 | * @brief Check whether flags on a peer are set. | ||
1376 | * | ||
1377 | * @param peer the peer to check the flag of | ||
1378 | * @param flags the flags to check | ||
1379 | * | ||
1380 | * @return #GNUNET_SYSERR if peer is not known | ||
1381 | * #GNUNET_YES if all given flags are set | ||
1382 | * #GNUNET_NO otherwise | ||
1383 | */ | ||
1384 | static int | ||
1385 | check_peer_flag (const struct GNUNET_PeerIdentity *peer, | ||
1386 | enum Peers_PeerFlags flags) | ||
1387 | { | ||
1388 | struct PeerContext *peer_ctx; | ||
1389 | |||
1390 | if (GNUNET_NO == check_peer_known (peer)) | ||
1391 | { | ||
1392 | return GNUNET_SYSERR; | ||
1393 | } | ||
1394 | peer_ctx = get_peer_ctx (peer); | ||
1395 | return check_peer_flag_set (peer_ctx, flags); | ||
1396 | } | ||
1156 | 1397 | ||
1157 | /** | 1398 | /** |
1158 | * @brief Try connecting to a peer to see whether it is online | 1399 | * @brief Try connecting to a peer to see whether it is online |
@@ -1161,22 +1402,18 @@ Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFl | |||
1161 | * | 1402 | * |
1162 | * @param peer the peer whose liveliness is to be checked | 1403 | * @param peer the peer whose liveliness is to be checked |
1163 | * @return #GNUNET_YES if peer had to be inserted | 1404 | * @return #GNUNET_YES if peer had to be inserted |
1164 | * #GNUNET_NO otherwise (if peer was already known or | 1405 | * #GNUNET_NO otherwise |
1165 | * peer was #own_identity) | ||
1166 | */ | 1406 | */ |
1167 | int | 1407 | static int |
1168 | Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | 1408 | issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) |
1169 | { | 1409 | { |
1170 | struct PeerContext *peer_ctx; | 1410 | struct PeerContext *peer_ctx; |
1171 | int ret; | 1411 | int ret; |
1172 | 1412 | ||
1173 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) | 1413 | ret = insert_peer (peer); |
1174 | { | ||
1175 | return GNUNET_NO; | ||
1176 | } | ||
1177 | ret = Peers_insert_peer (peer); | ||
1178 | peer_ctx = get_peer_ctx (peer); | 1414 | peer_ctx = get_peer_ctx (peer); |
1179 | if (GNUNET_NO == Peers_check_peer_flag (peer, Peers_ONLINE)) | 1415 | if ( (GNUNET_NO == check_peer_flag (peer, Peers_ONLINE)) && |
1416 | (NULL == peer_ctx->liveliness_check_pending) ) | ||
1180 | { | 1417 | { |
1181 | check_peer_live (peer_ctx); | 1418 | check_peer_live (peer_ctx); |
1182 | } | 1419 | } |
@@ -1197,8 +1434,8 @@ Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer) | |||
1197 | * #GNUNET_NO if peer is NOT removable | 1434 | * #GNUNET_NO if peer is NOT removable |
1198 | * #GNUNET_SYSERR if peer is not known | 1435 | * #GNUNET_SYSERR if peer is not known |
1199 | */ | 1436 | */ |
1200 | int | 1437 | static int |
1201 | Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | 1438 | check_removable (const struct GNUNET_PeerIdentity *peer) |
1202 | { | 1439 | { |
1203 | struct PeerContext *peer_ctx; | 1440 | struct PeerContext *peer_ctx; |
1204 | 1441 | ||
@@ -1208,7 +1445,7 @@ Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | |||
1208 | } | 1445 | } |
1209 | 1446 | ||
1210 | peer_ctx = get_peer_ctx (peer); | 1447 | peer_ctx = get_peer_ctx (peer); |
1211 | if ( (NULL != peer_ctx->recv_channel) || | 1448 | if ( (NULL != peer_ctx->recv_channel_ctx) || |
1212 | (NULL != peer_ctx->pending_messages_head) || | 1449 | (NULL != peer_ctx->pending_messages_head) || |
1213 | (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) ) | 1450 | (GNUNET_NO == check_peer_flag_set (peer_ctx, Peers_PULL_REPLY_PENDING)) ) |
1214 | { | 1451 | { |
@@ -1217,239 +1454,6 @@ Peers_check_removable (const struct GNUNET_PeerIdentity *peer) | |||
1217 | return GNUNET_YES; | 1454 | return GNUNET_YES; |
1218 | } | 1455 | } |
1219 | 1456 | ||
1220 | uint32_t * | ||
1221 | Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer, | ||
1222 | enum Peers_ChannelRole role); | ||
1223 | |||
1224 | int | ||
1225 | Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags); | ||
1226 | |||
1227 | /** | ||
1228 | * @brief Remove peer | ||
1229 | * | ||
1230 | * @param peer the peer to clean | ||
1231 | * @return #GNUNET_YES if peer was removed | ||
1232 | * #GNUNET_NO otherwise | ||
1233 | */ | ||
1234 | int | ||
1235 | Peers_remove_peer (const struct GNUNET_PeerIdentity *peer) | ||
1236 | { | ||
1237 | struct PeerContext *peer_ctx; | ||
1238 | uint32_t *channel_flag; | ||
1239 | |||
1240 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (peer_map, peer)) | ||
1241 | { | ||
1242 | return GNUNET_NO; | ||
1243 | } | ||
1244 | |||
1245 | peer_ctx = get_peer_ctx (peer); | ||
1246 | set_peer_flag (peer_ctx, Peers_TO_DESTROY); | ||
1247 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1248 | "Going to remove peer %s\n", | ||
1249 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
1250 | Peers_unset_peer_flag (peer, Peers_ONLINE); | ||
1251 | |||
1252 | GNUNET_array_grow (peer_ctx->pending_ops, peer_ctx->num_pending_ops, 0); | ||
1253 | while (NULL != peer_ctx->pending_messages_head) | ||
1254 | { | ||
1255 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1256 | "Removing unsent %s\n", | ||
1257 | peer_ctx->pending_messages_head->type); | ||
1258 | /* Cancle pending message, too */ | ||
1259 | remove_pending_message (peer_ctx->pending_messages_head, GNUNET_YES); | ||
1260 | } | ||
1261 | /* If we are still waiting for notification whether this peer is live | ||
1262 | * cancel the according task */ | ||
1263 | if (NULL != peer_ctx->liveliness_check_pending) | ||
1264 | { | ||
1265 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1266 | "Removing pending liveliness check for peer %s\n", | ||
1267 | GNUNET_i2s (&peer_ctx->peer_id)); | ||
1268 | // TODO wait until cadet sets mq->cancel_impl | ||
1269 | //GNUNET_MQ_send_cancel (peer_ctx->liveliness_check_pending->ev); | ||
1270 | GNUNET_free (peer_ctx->liveliness_check_pending); | ||
1271 | peer_ctx->liveliness_check_pending = NULL; | ||
1272 | } | ||
1273 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); | ||
1274 | if (NULL != peer_ctx->send_channel && | ||
1275 | GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING)) | ||
1276 | { | ||
1277 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1278 | "Destroying send channel\n"); | ||
1279 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | ||
1280 | peer_ctx->send_channel = NULL; | ||
1281 | peer_ctx->mq = NULL; | ||
1282 | } | ||
1283 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING); | ||
1284 | if (NULL != peer_ctx->recv_channel && | ||
1285 | GNUNET_YES != Peers_check_channel_flag (channel_flag, Peers_CHANNEL_DESTROING)) | ||
1286 | { | ||
1287 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1288 | "Destroying recv channel\n"); | ||
1289 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | ||
1290 | peer_ctx->recv_channel = NULL; | ||
1291 | } | ||
1292 | |||
1293 | GNUNET_free (peer_ctx->send_channel_flags); | ||
1294 | GNUNET_free (peer_ctx->recv_channel_flags); | ||
1295 | |||
1296 | if (GNUNET_YES != GNUNET_CONTAINER_multipeermap_remove_all (peer_map, &peer_ctx->peer_id)) | ||
1297 | { | ||
1298 | LOG (GNUNET_ERROR_TYPE_WARNING, "removing peer from peer_map failed\n"); | ||
1299 | } | ||
1300 | GNUNET_free (peer_ctx); | ||
1301 | return GNUNET_YES; | ||
1302 | } | ||
1303 | |||
1304 | |||
1305 | /** | ||
1306 | * @brief set flags on a given peer. | ||
1307 | * | ||
1308 | * @param peer the peer to set flags on | ||
1309 | * @param flags the flags | ||
1310 | */ | ||
1311 | void | ||
1312 | Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1313 | { | ||
1314 | struct PeerContext *peer_ctx; | ||
1315 | |||
1316 | peer_ctx = get_peer_ctx (peer); | ||
1317 | set_peer_flag (peer_ctx, flags); | ||
1318 | } | ||
1319 | |||
1320 | |||
1321 | /** | ||
1322 | * @brief unset flags on a given peer. | ||
1323 | * | ||
1324 | * @param peer the peer to unset flags on | ||
1325 | * @param flags the flags | ||
1326 | */ | ||
1327 | void | ||
1328 | Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1329 | { | ||
1330 | struct PeerContext *peer_ctx; | ||
1331 | |||
1332 | peer_ctx = get_peer_ctx (peer); | ||
1333 | unset_peer_flag (peer_ctx, flags); | ||
1334 | } | ||
1335 | |||
1336 | |||
1337 | /** | ||
1338 | * @brief Check whether flags on a peer are set. | ||
1339 | * | ||
1340 | * @param peer the peer to check the flag of | ||
1341 | * @param flags the flags to check | ||
1342 | * | ||
1343 | * @return #GNUNET_SYSERR if peer is not known | ||
1344 | * #GNUNET_YES if all given flags are set | ||
1345 | * #GNUNET_NO otherwise | ||
1346 | */ | ||
1347 | int | ||
1348 | Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags) | ||
1349 | { | ||
1350 | struct PeerContext *peer_ctx; | ||
1351 | |||
1352 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1353 | { | ||
1354 | return GNUNET_SYSERR; | ||
1355 | } | ||
1356 | peer_ctx = get_peer_ctx (peer); | ||
1357 | return check_peer_flag_set (peer_ctx, flags); | ||
1358 | } | ||
1359 | |||
1360 | |||
1361 | /** | ||
1362 | * @brief set flags on a given channel. | ||
1363 | * | ||
1364 | * @param channel the channel to set flags on | ||
1365 | * @param flags the flags | ||
1366 | */ | ||
1367 | void | ||
1368 | Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1369 | { | ||
1370 | set_channel_flag (channel_flags, flags); | ||
1371 | } | ||
1372 | |||
1373 | |||
1374 | /** | ||
1375 | * @brief unset flags on a given channel. | ||
1376 | * | ||
1377 | * @param channel the channel to unset flags on | ||
1378 | * @param flags the flags | ||
1379 | */ | ||
1380 | void | ||
1381 | Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1382 | { | ||
1383 | unset_channel_flag (channel_flags, flags); | ||
1384 | } | ||
1385 | |||
1386 | |||
1387 | /** | ||
1388 | * @brief Check whether flags on a channel are set. | ||
1389 | * | ||
1390 | * @param channel the channel to check the flag of | ||
1391 | * @param flags the flags to check | ||
1392 | * | ||
1393 | * @return #GNUNET_YES if all given flags are set | ||
1394 | * #GNUNET_NO otherwise | ||
1395 | */ | ||
1396 | int | ||
1397 | Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags) | ||
1398 | { | ||
1399 | return check_channel_flag_set (channel_flags, flags); | ||
1400 | } | ||
1401 | |||
1402 | /** | ||
1403 | * @brief Get the flags for the channel in @a role for @a peer. | ||
1404 | * | ||
1405 | * @param peer Peer to get the channel flags for. | ||
1406 | * @param role Role of channel to get flags for | ||
1407 | * | ||
1408 | * @return The flags. | ||
1409 | */ | ||
1410 | uint32_t * | ||
1411 | Peers_get_channel_flag (const struct GNUNET_PeerIdentity *peer, | ||
1412 | enum Peers_ChannelRole role) | ||
1413 | { | ||
1414 | const struct PeerContext *peer_ctx; | ||
1415 | |||
1416 | peer_ctx = get_peer_ctx (peer); | ||
1417 | if (Peers_CHANNEL_ROLE_SENDING == role) | ||
1418 | { | ||
1419 | return peer_ctx->send_channel_flags; | ||
1420 | } | ||
1421 | else if (Peers_CHANNEL_ROLE_RECEIVING == role) | ||
1422 | { | ||
1423 | return peer_ctx->recv_channel_flags; | ||
1424 | } | ||
1425 | else | ||
1426 | { | ||
1427 | GNUNET_assert (0); | ||
1428 | } | ||
1429 | } | ||
1430 | |||
1431 | /** | ||
1432 | * @brief Check whether we have information about the given peer. | ||
1433 | * | ||
1434 | * FIXME probably deprecated. Make this the new _online. | ||
1435 | * | ||
1436 | * @param peer peer in question | ||
1437 | * | ||
1438 | * @return #GNUNET_YES if peer is known | ||
1439 | * #GNUNET_NO if peer is not knwon | ||
1440 | */ | ||
1441 | int | ||
1442 | Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer) | ||
1443 | { | ||
1444 | if (NULL != peer_map) | ||
1445 | { | ||
1446 | return GNUNET_CONTAINER_multipeermap_contains (peer_map, peer); | ||
1447 | } else | ||
1448 | { | ||
1449 | return GNUNET_NO; | ||
1450 | } | ||
1451 | } | ||
1452 | |||
1453 | 1457 | ||
1454 | /** | 1458 | /** |
1455 | * @brief Check whether @a peer is actually a peer. | 1459 | * @brief Check whether @a peer is actually a peer. |
@@ -1461,8 +1465,8 @@ Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer) | |||
1461 | * @return #GNUNET_YES if peer is valid | 1465 | * @return #GNUNET_YES if peer is valid |
1462 | * #GNUNET_NO if peer is not valid | 1466 | * #GNUNET_NO if peer is not valid |
1463 | */ | 1467 | */ |
1464 | int | 1468 | static int |
1465 | Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer) | 1469 | check_peer_valid (const struct GNUNET_PeerIdentity *peer) |
1466 | { | 1470 | { |
1467 | return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); | 1471 | return GNUNET_CONTAINER_multipeermap_contains (valid_peers, peer); |
1468 | } | 1472 | } |
@@ -1475,10 +1479,10 @@ Peers_check_peer_valid (const struct GNUNET_PeerIdentity *peer) | |||
1475 | * | 1479 | * |
1476 | * @param peer the peer to establish channel to | 1480 | * @param peer the peer to establish channel to |
1477 | */ | 1481 | */ |
1478 | void | 1482 | static void |
1479 | Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) | 1483 | indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) |
1480 | { | 1484 | { |
1481 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | 1485 | GNUNET_assert (GNUNET_YES == check_peer_known (peer)); |
1482 | (void) get_channel (peer); | 1486 | (void) get_channel (peer); |
1483 | } | 1487 | } |
1484 | 1488 | ||
@@ -1492,13 +1496,13 @@ Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer) | |||
1492 | * @return #GNUNET_YES if peer has the intention to send | 1496 | * @return #GNUNET_YES if peer has the intention to send |
1493 | * #GNUNET_NO otherwise | 1497 | * #GNUNET_NO otherwise |
1494 | */ | 1498 | */ |
1495 | int | 1499 | static int |
1496 | Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) | 1500 | check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) |
1497 | { | 1501 | { |
1498 | const struct PeerContext *peer_ctx; | 1502 | const struct PeerContext *peer_ctx; |
1499 | 1503 | ||
1500 | peer_ctx = get_peer_ctx (peer); | 1504 | peer_ctx = get_peer_ctx (peer); |
1501 | if (NULL != peer_ctx->recv_channel) | 1505 | if (NULL != peer_ctx->recv_channel_ctx) |
1502 | { | 1506 | { |
1503 | return GNUNET_YES; | 1507 | return GNUNET_YES; |
1504 | } | 1508 | } |
@@ -1516,13 +1520,14 @@ Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer) | |||
1516 | * @return initial channel context for the channel | 1520 | * @return initial channel context for the channel |
1517 | * (can be NULL -- that's not an error) | 1521 | * (can be NULL -- that's not an error) |
1518 | */ | 1522 | */ |
1519 | void * | 1523 | static void * |
1520 | Peers_handle_inbound_channel (void *cls, | 1524 | handle_inbound_channel (void *cls, |
1521 | struct GNUNET_CADET_Channel *channel, | 1525 | struct GNUNET_CADET_Channel *channel, |
1522 | const struct GNUNET_PeerIdentity *initiator) | 1526 | const struct GNUNET_PeerIdentity *initiator) |
1523 | { | 1527 | { |
1524 | struct PeerContext *peer_ctx; | 1528 | struct PeerContext *peer_ctx; |
1525 | struct GNUNET_PeerIdentity *ctx_peer; | 1529 | struct GNUNET_PeerIdentity *ctx_peer; |
1530 | struct ChannelCtx *channel_ctx; | ||
1526 | 1531 | ||
1527 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1532 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1528 | "New channel was established to us (Peer %s).\n", | 1533 | "New channel was established to us (Peer %s).\n", |
@@ -1533,19 +1538,21 @@ Peers_handle_inbound_channel (void *cls, | |||
1533 | set_peer_live (peer_ctx); | 1538 | set_peer_live (peer_ctx); |
1534 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); | 1539 | ctx_peer = GNUNET_new (struct GNUNET_PeerIdentity); |
1535 | *ctx_peer = *initiator; | 1540 | *ctx_peer = *initiator; |
1541 | channel_ctx = add_channel_ctx (peer_ctx); | ||
1542 | channel_ctx->channel = channel; | ||
1536 | /* We only accept one incoming channel per peer */ | 1543 | /* We only accept one incoming channel per peer */ |
1537 | if (GNUNET_YES == Peers_check_peer_send_intention (initiator)) | 1544 | if (GNUNET_YES == check_peer_send_intention (initiator)) |
1538 | { | 1545 | { |
1539 | set_channel_flag (peer_ctx->recv_channel_flags, | 1546 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1540 | Peers_CHANNEL_ESTABLISHED_TWICE); | 1547 | "Already got one receive channel. Destroying old one.\n"); |
1541 | //GNUNET_CADET_channel_destroy (channel); | 1548 | GNUNET_break_op (0); |
1542 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | 1549 | destroy_channel (peer_ctx->recv_channel_ctx); |
1543 | peer_ctx->recv_channel = channel; | 1550 | peer_ctx->recv_channel_ctx = channel_ctx; |
1544 | /* return the channel context */ | 1551 | /* return the channel context */ |
1545 | return ctx_peer; | 1552 | return channel_ctx; |
1546 | } | 1553 | } |
1547 | peer_ctx->recv_channel = channel; | 1554 | peer_ctx->recv_channel_ctx = channel_ctx; |
1548 | return ctx_peer; | 1555 | return channel_ctx; |
1549 | } | 1556 | } |
1550 | 1557 | ||
1551 | 1558 | ||
@@ -1557,17 +1564,17 @@ Peers_handle_inbound_channel (void *cls, | |||
1557 | * @return #GNUNET_YES if a sending channel towards that peer exists | 1564 | * @return #GNUNET_YES if a sending channel towards that peer exists |
1558 | * #GNUNET_NO otherwise | 1565 | * #GNUNET_NO otherwise |
1559 | */ | 1566 | */ |
1560 | int | 1567 | static int |
1561 | Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) | 1568 | check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) |
1562 | { | 1569 | { |
1563 | struct PeerContext *peer_ctx; | 1570 | struct PeerContext *peer_ctx; |
1564 | 1571 | ||
1565 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 1572 | if (GNUNET_NO == check_peer_known (peer)) |
1566 | { /* If no such peer exists, there is no channel */ | 1573 | { /* If no such peer exists, there is no channel */ |
1567 | return GNUNET_NO; | 1574 | return GNUNET_NO; |
1568 | } | 1575 | } |
1569 | peer_ctx = get_peer_ctx (peer); | 1576 | peer_ctx = get_peer_ctx (peer); |
1570 | if (NULL == peer_ctx->send_channel) | 1577 | if (NULL == peer_ctx->send_channel_ctx) |
1571 | { | 1578 | { |
1572 | return GNUNET_NO; | 1579 | return GNUNET_NO; |
1573 | } | 1580 | } |
@@ -1576,44 +1583,6 @@ Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer) | |||
1576 | 1583 | ||
1577 | 1584 | ||
1578 | /** | 1585 | /** |
1579 | * @brief check whether the given channel is the sending channel of the given | ||
1580 | * peer | ||
1581 | * | ||
1582 | * @param peer the peer in question | ||
1583 | * @param channel the channel to check for | ||
1584 | * @param role either #Peers_CHANNEL_ROLE_SENDING, or | ||
1585 | * #Peers_CHANNEL_ROLE_RECEIVING | ||
1586 | * | ||
1587 | * @return #GNUNET_YES if the given chennel is the sending channel of the peer | ||
1588 | * #GNUNET_NO otherwise | ||
1589 | */ | ||
1590 | int | ||
1591 | Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer, | ||
1592 | const struct GNUNET_CADET_Channel *channel, | ||
1593 | enum Peers_ChannelRole role) | ||
1594 | { | ||
1595 | const struct PeerContext *peer_ctx; | ||
1596 | |||
1597 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1598 | { | ||
1599 | return GNUNET_NO; | ||
1600 | } | ||
1601 | peer_ctx = get_peer_ctx (peer); | ||
1602 | if ( (Peers_CHANNEL_ROLE_SENDING == role) && | ||
1603 | (channel == peer_ctx->send_channel) ) | ||
1604 | { | ||
1605 | return GNUNET_YES; | ||
1606 | } | ||
1607 | if ( (Peers_CHANNEL_ROLE_RECEIVING == role) && | ||
1608 | (channel == peer_ctx->recv_channel) ) | ||
1609 | { | ||
1610 | return GNUNET_YES; | ||
1611 | } | ||
1612 | return GNUNET_NO; | ||
1613 | } | ||
1614 | |||
1615 | |||
1616 | /** | ||
1617 | * @brief Destroy the send channel of a peer e.g. stop indicating a sending | 1586 | * @brief Destroy the send channel of a peer e.g. stop indicating a sending |
1618 | * intention to another peer | 1587 | * intention to another peer |
1619 | * | 1588 | * |
@@ -1625,114 +1594,26 @@ Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer, | |||
1625 | * @return #GNUNET_YES if channel was destroyed | 1594 | * @return #GNUNET_YES if channel was destroyed |
1626 | * #GNUNET_NO otherwise | 1595 | * #GNUNET_NO otherwise |
1627 | */ | 1596 | */ |
1628 | int | 1597 | static int |
1629 | Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer) | 1598 | destroy_sending_channel (const struct GNUNET_PeerIdentity *peer) |
1630 | { | 1599 | { |
1631 | struct PeerContext *peer_ctx; | 1600 | struct PeerContext *peer_ctx; |
1632 | 1601 | ||
1633 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 1602 | if (GNUNET_NO == check_peer_known (peer)) |
1634 | { | 1603 | { |
1635 | return GNUNET_NO; | 1604 | return GNUNET_NO; |
1636 | } | 1605 | } |
1637 | peer_ctx = get_peer_ctx (peer); | 1606 | peer_ctx = get_peer_ctx (peer); |
1638 | if (NULL != peer_ctx->send_channel) | 1607 | if (NULL != peer_ctx->send_channel_ctx) |
1639 | { | 1608 | { |
1640 | set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_CLEAN); | 1609 | destroy_channel (peer_ctx->send_channel_ctx); |
1641 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | 1610 | (void) check_connected (peer); |
1642 | peer_ctx->send_channel = NULL; | ||
1643 | peer_ctx->mq = NULL; | ||
1644 | (void) Peers_check_connected (peer); | ||
1645 | return GNUNET_YES; | 1611 | return GNUNET_YES; |
1646 | } | 1612 | } |
1647 | return GNUNET_NO; | 1613 | return GNUNET_NO; |
1648 | } | 1614 | } |
1649 | 1615 | ||
1650 | /** | 1616 | /** |
1651 | * This is called when a channel is destroyed. | ||
1652 | * | ||
1653 | * @param cls The closure | ||
1654 | * @param channel The channel being closed | ||
1655 | */ | ||
1656 | void | ||
1657 | Peers_cleanup_destroyed_channel (void *cls, | ||
1658 | const struct GNUNET_CADET_Channel *channel) | ||
1659 | { | ||
1660 | struct GNUNET_PeerIdentity *peer = cls; | ||
1661 | struct PeerContext *peer_ctx; | ||
1662 | |||
1663 | if (GNUNET_NO == Peers_check_peer_known (peer)) | ||
1664 | {/* We don't want to implicitly create a context that we're about to kill */ | ||
1665 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1666 | "channel (%s) without associated context was destroyed\n", | ||
1667 | GNUNET_i2s (peer)); | ||
1668 | return; | ||
1669 | } | ||
1670 | peer_ctx = get_peer_ctx (peer); | ||
1671 | |||
1672 | /* If our peer issued the destruction of the channel, the #Peers_TO_DESTROY | ||
1673 | * flag will be set. In this case simply make sure that the channels are | ||
1674 | * cleaned. */ | ||
1675 | /* FIXME This distinction seems to be redundant */ | ||
1676 | if (Peers_check_peer_flag (peer, Peers_TO_DESTROY)) | ||
1677 | {/* We initiatad the destruction of this particular peer */ | ||
1678 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1679 | "Peer is in the process of being destroyed\n"); | ||
1680 | if (channel == peer_ctx->send_channel) | ||
1681 | { | ||
1682 | peer_ctx->send_channel = NULL; | ||
1683 | peer_ctx->mq = NULL; | ||
1684 | } | ||
1685 | else if (channel == peer_ctx->recv_channel) | ||
1686 | { | ||
1687 | peer_ctx->recv_channel = NULL; | ||
1688 | } | ||
1689 | |||
1690 | if (NULL != peer_ctx->send_channel) | ||
1691 | { | ||
1692 | GNUNET_CADET_channel_destroy (peer_ctx->send_channel); | ||
1693 | peer_ctx->send_channel = NULL; | ||
1694 | peer_ctx->mq = NULL; | ||
1695 | } | ||
1696 | if (NULL != peer_ctx->recv_channel) | ||
1697 | { | ||
1698 | GNUNET_CADET_channel_destroy (peer_ctx->recv_channel); | ||
1699 | peer_ctx->recv_channel = NULL; | ||
1700 | } | ||
1701 | /* Set the #Peers_ONLINE flag accordingly */ | ||
1702 | (void) Peers_check_connected (peer); | ||
1703 | return; | ||
1704 | } | ||
1705 | |||
1706 | else | ||
1707 | { /* We did not initiate the destruction of this peer */ | ||
1708 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1709 | "Peer is NOT in the process of being destroyed\n"); | ||
1710 | if (channel == peer_ctx->send_channel) | ||
1711 | { /* Something (but us) killd the channel - clean up peer */ | ||
1712 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1713 | "send channel (%s) was destroyed - cleaning up\n", | ||
1714 | GNUNET_i2s (peer)); | ||
1715 | peer_ctx->send_channel = NULL; | ||
1716 | peer_ctx->mq = NULL; | ||
1717 | } | ||
1718 | else if (channel == peer_ctx->recv_channel) | ||
1719 | { /* Other peer doesn't want to send us messages anymore */ | ||
1720 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
1721 | "Peer %s destroyed recv channel - cleaning up channel\n", | ||
1722 | GNUNET_i2s (peer)); | ||
1723 | peer_ctx->recv_channel = NULL; | ||
1724 | } | ||
1725 | else | ||
1726 | { | ||
1727 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
1728 | "unknown channel (%s) was destroyed\n", | ||
1729 | GNUNET_i2s (peer)); | ||
1730 | } | ||
1731 | } | ||
1732 | (void) Peers_check_connected (peer); | ||
1733 | } | ||
1734 | |||
1735 | /** | ||
1736 | * @brief Send a message to another peer. | 1617 | * @brief Send a message to another peer. |
1737 | * | 1618 | * |
1738 | * Keeps track about pending messages so they can be properly removed when the | 1619 | * Keeps track about pending messages so they can be properly removed when the |
@@ -1742,10 +1623,10 @@ Peers_cleanup_destroyed_channel (void *cls, | |||
1742 | * @param ev envelope of the message | 1623 | * @param ev envelope of the message |
1743 | * @param type type of the message | 1624 | * @param type type of the message |
1744 | */ | 1625 | */ |
1745 | void | 1626 | static void |
1746 | Peers_send_message (const struct GNUNET_PeerIdentity *peer, | 1627 | send_message (const struct GNUNET_PeerIdentity *peer, |
1747 | struct GNUNET_MQ_Envelope *ev, | 1628 | struct GNUNET_MQ_Envelope *ev, |
1748 | const char *type) | 1629 | const char *type) |
1749 | { | 1630 | { |
1750 | struct PendingMessage *pending_msg; | 1631 | struct PendingMessage *pending_msg; |
1751 | struct GNUNET_MQ_Handle *mq; | 1632 | struct GNUNET_MQ_Handle *mq; |
@@ -1772,18 +1653,14 @@ Peers_send_message (const struct GNUNET_PeerIdentity *peer, | |||
1772 | * @return #GNUNET_YES if the operation was scheduled | 1653 | * @return #GNUNET_YES if the operation was scheduled |
1773 | * #GNUNET_NO otherwise | 1654 | * #GNUNET_NO otherwise |
1774 | */ | 1655 | */ |
1775 | int | 1656 | static int |
1776 | Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, | 1657 | schedule_operation (const struct GNUNET_PeerIdentity *peer, |
1777 | const PeerOp peer_op) | 1658 | const PeerOp peer_op) |
1778 | { | 1659 | { |
1779 | struct PeerPendingOp pending_op; | 1660 | struct PeerPendingOp pending_op; |
1780 | struct PeerContext *peer_ctx; | 1661 | struct PeerContext *peer_ctx; |
1781 | 1662 | ||
1782 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (peer, &own_identity)) | 1663 | GNUNET_assert (GNUNET_YES == check_peer_known (peer)); |
1783 | { | ||
1784 | return GNUNET_NO; | ||
1785 | } | ||
1786 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | ||
1787 | 1664 | ||
1788 | //TODO if LIVE/ONLINE execute immediately | 1665 | //TODO if LIVE/ONLINE execute immediately |
1789 | 1666 | ||
@@ -1800,24 +1677,6 @@ Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer, | |||
1800 | return GNUNET_NO; | 1677 | return GNUNET_NO; |
1801 | } | 1678 | } |
1802 | 1679 | ||
1803 | /** | ||
1804 | * @brief Get the recv_channel of @a peer. | ||
1805 | * Needed to correctly handle (call #GNUNET_CADET_receive_done()) incoming | ||
1806 | * messages. | ||
1807 | * | ||
1808 | * @param peer The peer to get the recv_channel from. | ||
1809 | * | ||
1810 | * @return The recv_channel. | ||
1811 | */ | ||
1812 | struct GNUNET_CADET_Channel * | ||
1813 | Peers_get_recv_channel (const struct GNUNET_PeerIdentity *peer) | ||
1814 | { | ||
1815 | struct PeerContext *peer_ctx; | ||
1816 | |||
1817 | GNUNET_assert (GNUNET_YES == Peers_check_peer_known (peer)); | ||
1818 | peer_ctx = get_peer_ctx (peer); | ||
1819 | return peer_ctx->recv_channel; | ||
1820 | } | ||
1821 | /*********************************************************************** | 1680 | /*********************************************************************** |
1822 | * /Old gnunet-service-rps_peers.c | 1681 | * /Old gnunet-service-rps_peers.c |
1823 | ***********************************************************************/ | 1682 | ***********************************************************************/ |
@@ -2273,16 +2132,16 @@ insert_in_view (const struct GNUNET_PeerIdentity *peer) | |||
2273 | { | 2132 | { |
2274 | int online; | 2133 | int online; |
2275 | 2134 | ||
2276 | online = Peers_check_peer_flag (peer, Peers_ONLINE); | 2135 | online = check_peer_flag (peer, Peers_ONLINE); |
2277 | if ( (GNUNET_NO == online) || | 2136 | if ( (GNUNET_NO == online) || |
2278 | (GNUNET_SYSERR == online) ) /* peer is not even known */ | 2137 | (GNUNET_SYSERR == online) ) /* peer is not even known */ |
2279 | { | 2138 | { |
2280 | (void) Peers_issue_peer_liveliness_check (peer); | 2139 | (void) issue_peer_liveliness_check (peer); |
2281 | (void) Peers_schedule_operation (peer, insert_in_view_op); | 2140 | (void) schedule_operation (peer, insert_in_view_op); |
2282 | return GNUNET_NO; | 2141 | return GNUNET_NO; |
2283 | } | 2142 | } |
2284 | /* Open channel towards peer to keep connection open */ | 2143 | /* Open channel towards peer to keep connection open */ |
2285 | Peers_indicate_sending_intention (peer); | 2144 | indicate_sending_intention (peer); |
2286 | return View_put (peer); | 2145 | return View_put (peer); |
2287 | } | 2146 | } |
2288 | 2147 | ||
@@ -2475,8 +2334,11 @@ send_pull_reply (const struct GNUNET_PeerIdentity *peer_id, | |||
2475 | GNUNET_memcpy (&out_msg[1], peer_ids, | 2334 | GNUNET_memcpy (&out_msg[1], peer_ids, |
2476 | send_size * sizeof (struct GNUNET_PeerIdentity)); | 2335 | send_size * sizeof (struct GNUNET_PeerIdentity)); |
2477 | 2336 | ||
2478 | Peers_send_message (peer_id, ev, "PULL REPLY"); | 2337 | send_message (peer_id, ev, "PULL REPLY"); |
2479 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); | 2338 | GNUNET_STATISTICS_update(stats, "# pull reply send issued", 1, GNUNET_NO); |
2339 | // TODO check with send intention: as send_channel is used/opened we indicate | ||
2340 | // a sending intention without intending it. | ||
2341 | // -> clean peer afterwards? | ||
2480 | } | 2342 | } |
2481 | 2343 | ||
2482 | 2344 | ||
@@ -2523,10 +2385,10 @@ insert_in_sampler (void *cls, | |||
2523 | if (0 < RPS_sampler_count_id (prot_sampler, peer)) | 2385 | if (0 < RPS_sampler_count_id (prot_sampler, peer)) |
2524 | { | 2386 | { |
2525 | /* Make sure we 'know' about this peer */ | 2387 | /* Make sure we 'know' about this peer */ |
2526 | (void) Peers_issue_peer_liveliness_check (peer); | 2388 | (void) issue_peer_liveliness_check (peer); |
2527 | /* Establish a channel towards that peer to indicate we are going to send | 2389 | /* Establish a channel towards that peer to indicate we are going to send |
2528 | * messages to it */ | 2390 | * messages to it */ |
2529 | //Peers_indicate_sending_intention (peer); | 2391 | //indicate_sending_intention (peer); |
2530 | } | 2392 | } |
2531 | #ifdef TO_FILE | 2393 | #ifdef TO_FILE |
2532 | num_observed_peers++; | 2394 | num_observed_peers++; |
@@ -2558,10 +2420,10 @@ static void | |||
2558 | got_peer (const struct GNUNET_PeerIdentity *peer) | 2420 | got_peer (const struct GNUNET_PeerIdentity *peer) |
2559 | { | 2421 | { |
2560 | /* If we did not know this peer already, insert it into sampler and view */ | 2422 | /* If we did not know this peer already, insert it into sampler and view */ |
2561 | if (GNUNET_YES == Peers_issue_peer_liveliness_check (peer)) | 2423 | if (GNUNET_YES == issue_peer_liveliness_check (peer)) |
2562 | { | 2424 | { |
2563 | Peers_schedule_operation (peer, insert_in_sampler); | 2425 | schedule_operation (peer, insert_in_sampler); |
2564 | Peers_schedule_operation (peer, insert_in_view_op); | 2426 | schedule_operation (peer, insert_in_view_op); |
2565 | } | 2427 | } |
2566 | } | 2428 | } |
2567 | 2429 | ||
@@ -2576,17 +2438,17 @@ static int | |||
2576 | check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) | 2438 | check_sending_channel_needed (const struct GNUNET_PeerIdentity *peer) |
2577 | { | 2439 | { |
2578 | /* struct GNUNET_CADET_Channel *channel; */ | 2440 | /* struct GNUNET_CADET_Channel *channel; */ |
2579 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 2441 | if (GNUNET_NO == check_peer_known (peer)) |
2580 | { | 2442 | { |
2581 | return GNUNET_NO; | 2443 | return GNUNET_NO; |
2582 | } | 2444 | } |
2583 | if (GNUNET_YES == Peers_check_sending_channel_exists (peer)) | 2445 | if (GNUNET_YES == check_sending_channel_exists (peer)) |
2584 | { | 2446 | { |
2585 | if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) || | 2447 | if ( (0 < RPS_sampler_count_id (prot_sampler, peer)) || |
2586 | (GNUNET_YES == View_contains_peer (peer)) || | 2448 | (GNUNET_YES == View_contains_peer (peer)) || |
2587 | (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) || | 2449 | (GNUNET_YES == CustomPeerMap_contains_peer (push_map, peer)) || |
2588 | (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) || | 2450 | (GNUNET_YES == CustomPeerMap_contains_peer (pull_map, peer)) || |
2589 | (GNUNET_YES == Peers_check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) | 2451 | (GNUNET_YES == check_peer_flag (peer, Peers_PULL_REPLY_PENDING))) |
2590 | { /* If we want to keep the connection to peer open */ | 2452 | { /* If we want to keep the connection to peer open */ |
2591 | return GNUNET_YES; | 2453 | return GNUNET_YES; |
2592 | } | 2454 | } |
@@ -2609,7 +2471,7 @@ remove_peer (const struct GNUNET_PeerIdentity *peer) | |||
2609 | CustomPeerMap_remove_peer (push_map, peer); | 2471 | CustomPeerMap_remove_peer (push_map, peer); |
2610 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); | 2472 | RPS_sampler_reinitialise_by_value (prot_sampler, peer); |
2611 | RPS_sampler_reinitialise_by_value (client_sampler, peer); | 2473 | RPS_sampler_reinitialise_by_value (client_sampler, peer); |
2612 | Peers_remove_peer (peer); | 2474 | destroy_peer (get_peer_ctx (peer)); |
2613 | } | 2475 | } |
2614 | 2476 | ||
2615 | 2477 | ||
@@ -2630,19 +2492,19 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
2630 | GNUNET_i2s (peer)); | 2492 | GNUNET_i2s (peer)); |
2631 | #ifdef ENABLE_MALICIOUS | 2493 | #ifdef ENABLE_MALICIOUS |
2632 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) | 2494 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&attacked_peer, peer)) |
2633 | (void) Peers_destroy_sending_channel (peer); | 2495 | (void) destroy_sending_channel (peer); |
2634 | #else /* ENABLE_MALICIOUS */ | 2496 | #else /* ENABLE_MALICIOUS */ |
2635 | (void) Peers_destroy_sending_channel (peer); | 2497 | (void) destroy_sending_channel (peer); |
2636 | #endif /* ENABLE_MALICIOUS */ | 2498 | #endif /* ENABLE_MALICIOUS */ |
2637 | } | 2499 | } |
2638 | 2500 | ||
2639 | if ( (GNUNET_NO == Peers_check_peer_send_intention (peer)) && | 2501 | if ( (GNUNET_NO == check_peer_send_intention (peer)) && |
2640 | (GNUNET_NO == View_contains_peer (peer)) && | 2502 | (GNUNET_NO == View_contains_peer (peer)) && |
2641 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && | 2503 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && |
2642 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && | 2504 | (GNUNET_NO == CustomPeerMap_contains_peer (push_map, peer)) && |
2643 | (0 == RPS_sampler_count_id (prot_sampler, peer)) && | 2505 | (0 == RPS_sampler_count_id (prot_sampler, peer)) && |
2644 | (0 == RPS_sampler_count_id (client_sampler, peer)) && | 2506 | (0 == RPS_sampler_count_id (client_sampler, peer)) && |
2645 | (GNUNET_NO != Peers_check_removable (peer)) ) | 2507 | (GNUNET_NO != check_removable (peer)) ) |
2646 | { /* We can safely remove this peer */ | 2508 | { /* We can safely remove this peer */ |
2647 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2509 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2648 | "Going to remove peer %s\n", | 2510 | "Going to remove peer %s\n", |
@@ -2652,6 +2514,7 @@ clean_peer (const struct GNUNET_PeerIdentity *peer) | |||
2652 | } | 2514 | } |
2653 | } | 2515 | } |
2654 | 2516 | ||
2517 | |||
2655 | /** | 2518 | /** |
2656 | * @brief This is called when a channel is destroyed. | 2519 | * @brief This is called when a channel is destroyed. |
2657 | * | 2520 | * |
@@ -2668,105 +2531,23 @@ static void | |||
2668 | cleanup_destroyed_channel (void *cls, | 2531 | cleanup_destroyed_channel (void *cls, |
2669 | const struct GNUNET_CADET_Channel *channel) | 2532 | const struct GNUNET_CADET_Channel *channel) |
2670 | { | 2533 | { |
2671 | struct GNUNET_PeerIdentity *peer = cls; | 2534 | struct ChannelCtx *channel_ctx = cls; |
2672 | uint32_t *channel_flag; | 2535 | struct PeerContext *peer_ctx = channel_ctx->peer_ctx; |
2673 | struct PeerContext *peer_ctx; | 2536 | |
2674 | 2537 | // What should be done here: | |
2675 | GNUNET_assert (NULL != peer); | 2538 | // * cleanup everything related to the channel |
2676 | 2539 | // * memory | |
2677 | if (GNUNET_NO == Peers_check_peer_known (peer)) | 2540 | // * remove peer if necessary |
2678 | { /* We don't know a context to that peer */ | 2541 | channel_ctx->channel = NULL; |
2679 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2542 | if (peer_ctx->recv_channel_ctx == channel_ctx) |
2680 | "channel (%s) without associated context was destroyed\n", | ||
2681 | GNUNET_i2s (peer)); | ||
2682 | GNUNET_free (peer); | ||
2683 | return; | ||
2684 | } | ||
2685 | |||
2686 | peer_ctx = get_peer_ctx (peer); | ||
2687 | if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING)) | ||
2688 | { | 2543 | { |
2689 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2544 | remove_channel_ctx (channel_ctx); |
2690 | "Callback on destruction of recv-channel was called (%s)\n", | ||
2691 | GNUNET_i2s (peer)); | ||
2692 | set_channel_flag (peer_ctx->recv_channel_flags, Peers_CHANNEL_DESTROING); | ||
2693 | } else if (GNUNET_YES == Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING)) | ||
2694 | { | ||
2695 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2696 | "Callback on destruction of send-channel was called (%s)\n", | ||
2697 | GNUNET_i2s (peer)); | ||
2698 | set_channel_flag (peer_ctx->send_channel_flags, Peers_CHANNEL_DESTROING); | ||
2699 | } else { | ||
2700 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
2701 | "Channel to be destroyed has is neither sending nor receiving role\n"); | ||
2702 | } | ||
2703 | |||
2704 | if (GNUNET_YES == Peers_check_peer_flag (peer, Peers_TO_DESTROY)) | ||
2705 | { /* We are in the middle of removing that peer from our knowledge. In this | ||
2706 | case simply make sure that the channels are cleaned. */ | ||
2707 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2708 | to_file (file_name_view_log, | ||
2709 | "-%s\t(cleanup channel, ourself)", | ||
2710 | GNUNET_i2s_full (peer)); | ||
2711 | GNUNET_free (peer); | ||
2712 | return; | ||
2713 | } | ||
2714 | |||
2715 | if (GNUNET_YES == | ||
2716 | Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_SENDING)) | ||
2717 | { /* Channel used for sending was destroyed */ | ||
2718 | /* Possible causes of channel destruction: | ||
2719 | * - ourselves -> cleaning send channel -> clean context | ||
2720 | * - other peer -> peer probably went down -> remove | ||
2721 | */ | ||
2722 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_SENDING); | ||
2723 | if (GNUNET_YES == Peers_check_channel_flag (channel_flag, Peers_CHANNEL_CLEAN)) | ||
2724 | { /* We are about to clean the sending channel. Clean the respective | ||
2725 | * context */ | ||
2726 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2727 | GNUNET_free (peer); | ||
2728 | return; | ||
2729 | } | ||
2730 | else | ||
2731 | { /* Other peer destroyed our sending channel that he is supposed to keep | ||
2732 | * open. It probably went down. Remove it from our knowledge. */ | ||
2733 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2734 | remove_peer (peer); | ||
2735 | GNUNET_free (peer); | ||
2736 | return; | ||
2737 | } | ||
2738 | } | 2545 | } |
2739 | else if (GNUNET_YES == | 2546 | else if (peer_ctx->send_channel_ctx == channel_ctx) |
2740 | Peers_check_channel_role (peer, channel, Peers_CHANNEL_ROLE_RECEIVING)) | ||
2741 | { /* Channel used for receiving was destroyed */ | ||
2742 | /* Possible causes of channel destruction: | ||
2743 | * - ourselves -> peer tried to establish channel twice -> clean context | ||
2744 | * - other peer -> peer doesn't want to send us data -> clean | ||
2745 | */ | ||
2746 | channel_flag = Peers_get_channel_flag (peer, Peers_CHANNEL_ROLE_RECEIVING); | ||
2747 | if (GNUNET_YES == | ||
2748 | Peers_check_channel_flag (channel_flag, Peers_CHANNEL_ESTABLISHED_TWICE)) | ||
2749 | { /* Other peer tried to establish a channel to us twice. We do not accept | ||
2750 | * that. Clean the context. */ | ||
2751 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2752 | GNUNET_free (peer); | ||
2753 | return; | ||
2754 | } | ||
2755 | else | ||
2756 | { /* Other peer doesn't want to send us data anymore. We are free to clean | ||
2757 | * it. */ | ||
2758 | Peers_cleanup_destroyed_channel (cls, channel); | ||
2759 | clean_peer (peer); | ||
2760 | GNUNET_free (peer); | ||
2761 | return; | ||
2762 | } | ||
2763 | } | ||
2764 | else | ||
2765 | { | 2547 | { |
2766 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2548 | remove_channel_ctx (channel_ctx); |
2767 | "Destroyed channel is neither sending nor receiving channel\n"); | 2549 | remove_peer (&peer_ctx->peer_id); |
2768 | } | 2550 | } |
2769 | GNUNET_free (peer); | ||
2770 | } | 2551 | } |
2771 | 2552 | ||
2772 | /*********************************************************************** | 2553 | /*********************************************************************** |
@@ -2893,7 +2674,6 @@ client_respond (void *cls, | |||
2893 | GNUNET_memcpy (&out_msg[1], | 2674 | GNUNET_memcpy (&out_msg[1], |
2894 | peer_ids, | 2675 | peer_ids, |
2895 | num_peers * sizeof (struct GNUNET_PeerIdentity)); | 2676 | num_peers * sizeof (struct GNUNET_PeerIdentity)); |
2896 | GNUNET_free (peer_ids); | ||
2897 | 2677 | ||
2898 | cli_ctx = reply_cls->cli_ctx; | 2678 | cli_ctx = reply_cls->cli_ctx; |
2899 | GNUNET_assert (NULL != cli_ctx); | 2679 | GNUNET_assert (NULL != cli_ctx); |
@@ -3026,8 +2806,6 @@ handle_client_seed (void *cls, | |||
3026 | 2806 | ||
3027 | num_peers = ntohl (msg->num_peers); | 2807 | num_peers = ntohl (msg->num_peers); |
3028 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; | 2808 | peers = (struct GNUNET_PeerIdentity *) &msg[1]; |
3029 | //peers = GNUNET_new_array (num_peers, struct GNUNET_PeerIdentity); | ||
3030 | //GNUNET_memcpy (peers, &msg[1], num_peers * sizeof (struct GNUNET_PeerIdentity)); | ||
3031 | 2809 | ||
3032 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2810 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3033 | "Client seeded peers:\n"); | 2811 | "Client seeded peers:\n"); |
@@ -3042,9 +2820,6 @@ handle_client_seed (void *cls, | |||
3042 | 2820 | ||
3043 | got_peer (&peers[i]); | 2821 | got_peer (&peers[i]); |
3044 | } | 2822 | } |
3045 | |||
3046 | ////GNUNET_free (peers); | ||
3047 | |||
3048 | GNUNET_SERVICE_client_continue (cli_ctx->client); | 2823 | GNUNET_SERVICE_client_continue (cli_ctx->client); |
3049 | } | 2824 | } |
3050 | 2825 | ||
@@ -3162,12 +2937,12 @@ static void | |||
3162 | handle_peer_check (void *cls, | 2937 | handle_peer_check (void *cls, |
3163 | const struct GNUNET_MessageHeader *msg) | 2938 | const struct GNUNET_MessageHeader *msg) |
3164 | { | 2939 | { |
3165 | const struct GNUNET_PeerIdentity *peer = cls; | 2940 | const struct ChannelCtx *channel_ctx = cls; |
2941 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3166 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2942 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3167 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); | 2943 | "Received CHECK_LIVE (%s)\n", GNUNET_i2s (peer)); |
3168 | 2944 | ||
3169 | GNUNET_break_op (Peers_check_peer_known (peer)); | 2945 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3170 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | ||
3171 | } | 2946 | } |
3172 | 2947 | ||
3173 | /** | 2948 | /** |
@@ -3183,7 +2958,8 @@ static void | |||
3183 | handle_peer_push (void *cls, | 2958 | handle_peer_push (void *cls, |
3184 | const struct GNUNET_MessageHeader *msg) | 2959 | const struct GNUNET_MessageHeader *msg) |
3185 | { | 2960 | { |
3186 | const struct GNUNET_PeerIdentity *peer = cls; | 2961 | const struct ChannelCtx *channel_ctx = cls; |
2962 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3187 | 2963 | ||
3188 | // (check the proof of work (?)) | 2964 | // (check the proof of work (?)) |
3189 | 2965 | ||
@@ -3211,6 +2987,10 @@ handle_peer_push (void *cls, | |||
3211 | tmp_att_peer); | 2987 | tmp_att_peer); |
3212 | add_peer_array_to_set (peer, 1, att_peer_set); | 2988 | add_peer_array_to_set (peer, 1, att_peer_set); |
3213 | } | 2989 | } |
2990 | else | ||
2991 | { | ||
2992 | GNUNET_free (tmp_att_peer); | ||
2993 | } | ||
3214 | } | 2994 | } |
3215 | 2995 | ||
3216 | 2996 | ||
@@ -3223,8 +3003,8 @@ handle_peer_push (void *cls, | |||
3223 | /* Add the sending peer to the push_map */ | 3003 | /* Add the sending peer to the push_map */ |
3224 | CustomPeerMap_put (push_map, peer); | 3004 | CustomPeerMap_put (push_map, peer); |
3225 | 3005 | ||
3226 | GNUNET_break_op (Peers_check_peer_known (peer)); | 3006 | GNUNET_break_op (check_peer_known (peer)); |
3227 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | 3007 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3228 | } | 3008 | } |
3229 | 3009 | ||
3230 | 3010 | ||
@@ -3240,7 +3020,8 @@ static void | |||
3240 | handle_peer_pull_request (void *cls, | 3020 | handle_peer_pull_request (void *cls, |
3241 | const struct GNUNET_MessageHeader *msg) | 3021 | const struct GNUNET_MessageHeader *msg) |
3242 | { | 3022 | { |
3243 | struct GNUNET_PeerIdentity *peer = cls; | 3023 | const struct ChannelCtx *channel_ctx = cls; |
3024 | const struct GNUNET_PeerIdentity *peer = &channel_ctx->peer_ctx->peer_id; | ||
3244 | const struct GNUNET_PeerIdentity *view_array; | 3025 | const struct GNUNET_PeerIdentity *view_array; |
3245 | 3026 | ||
3246 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); | 3027 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received PULL REQUEST (%s)\n", GNUNET_i2s (peer)); |
@@ -3262,8 +3043,8 @@ handle_peer_pull_request (void *cls, | |||
3262 | } | 3043 | } |
3263 | #endif /* ENABLE_MALICIOUS */ | 3044 | #endif /* ENABLE_MALICIOUS */ |
3264 | 3045 | ||
3265 | GNUNET_break_op (Peers_check_peer_known (peer)); | 3046 | GNUNET_break_op (check_peer_known (peer)); |
3266 | GNUNET_CADET_receive_done (Peers_get_recv_channel (peer)); | 3047 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3267 | view_array = View_get_as_array (); | 3048 | view_array = View_get_as_array (); |
3268 | send_pull_reply (peer, view_array, View_size ()); | 3049 | send_pull_reply (peer, view_array, View_size ()); |
3269 | } | 3050 | } |
@@ -3300,10 +3081,11 @@ check_peer_pull_reply (void *cls, | |||
3300 | return GNUNET_SYSERR; | 3081 | return GNUNET_SYSERR; |
3301 | } | 3082 | } |
3302 | 3083 | ||
3303 | if (GNUNET_YES != Peers_check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) | 3084 | if (GNUNET_YES != check_peer_flag (sender, Peers_PULL_REPLY_PENDING)) |
3304 | { | 3085 | { |
3305 | LOG (GNUNET_ERROR_TYPE_WARNING, | 3086 | LOG (GNUNET_ERROR_TYPE_WARNING, |
3306 | "Received a pull reply from a peer we didn't request one from!\n"); | 3087 | "Received a pull reply from a peer (%s) we didn't request one from!\n", |
3088 | GNUNET_i2s (sender)); | ||
3307 | GNUNET_break_op (0); | 3089 | GNUNET_break_op (0); |
3308 | return GNUNET_SYSERR; | 3090 | return GNUNET_SYSERR; |
3309 | } | 3091 | } |
@@ -3320,8 +3102,9 @@ static void | |||
3320 | handle_peer_pull_reply (void *cls, | 3102 | handle_peer_pull_reply (void *cls, |
3321 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) | 3103 | const struct GNUNET_RPS_P2P_PullReplyMessage *msg) |
3322 | { | 3104 | { |
3105 | const struct ChannelCtx *channel_ctx = cls; | ||
3106 | const struct GNUNET_PeerIdentity *sender = &channel_ctx->peer_ctx->peer_id; | ||
3323 | const struct GNUNET_PeerIdentity *peers; | 3107 | const struct GNUNET_PeerIdentity *peers; |
3324 | struct GNUNET_PeerIdentity *sender = cls; | ||
3325 | uint32_t i; | 3108 | uint32_t i; |
3326 | #ifdef ENABLE_MALICIOUS | 3109 | #ifdef ENABLE_MALICIOUS |
3327 | struct AttackedPeer *tmp_att_peer; | 3110 | struct AttackedPeer *tmp_att_peer; |
@@ -3359,9 +3142,7 @@ handle_peer_pull_reply (void *cls, | |||
3359 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, | 3142 | if (GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (att_peer_set, |
3360 | &peers[i]) | 3143 | &peers[i]) |
3361 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, | 3144 | && GNUNET_NO == GNUNET_CONTAINER_multipeermap_contains (mal_peer_set, |
3362 | &peers[i]) | 3145 | &peers[i])) |
3363 | && 0 != GNUNET_CRYPTO_cmp_peer_identity (&peers[i], | ||
3364 | &own_identity)) | ||
3365 | { | 3146 | { |
3366 | tmp_att_peer = GNUNET_new (struct AttackedPeer); | 3147 | tmp_att_peer = GNUNET_new (struct AttackedPeer); |
3367 | tmp_att_peer->peer_id = peers[i]; | 3148 | tmp_att_peer->peer_id = peers[i]; |
@@ -3373,29 +3154,25 @@ handle_peer_pull_reply (void *cls, | |||
3373 | continue; | 3154 | continue; |
3374 | } | 3155 | } |
3375 | #endif /* ENABLE_MALICIOUS */ | 3156 | #endif /* ENABLE_MALICIOUS */ |
3376 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, | 3157 | /* Make sure we 'know' about this peer */ |
3377 | &peers[i])) | 3158 | (void) insert_peer (&peers[i]); |
3378 | { | ||
3379 | /* Make sure we 'know' about this peer */ | ||
3380 | (void) Peers_insert_peer (&peers[i]); | ||
3381 | 3159 | ||
3382 | if (GNUNET_YES == Peers_check_peer_valid (&peers[i])) | 3160 | if (GNUNET_YES == check_peer_valid (&peers[i])) |
3383 | { | 3161 | { |
3384 | CustomPeerMap_put (pull_map, &peers[i]); | 3162 | CustomPeerMap_put (pull_map, &peers[i]); |
3385 | } | 3163 | } |
3386 | else | 3164 | else |
3387 | { | 3165 | { |
3388 | Peers_schedule_operation (&peers[i], insert_in_pull_map); | 3166 | schedule_operation (&peers[i], insert_in_pull_map); |
3389 | (void) Peers_issue_peer_liveliness_check (&peers[i]); | 3167 | (void) issue_peer_liveliness_check (&peers[i]); |
3390 | } | ||
3391 | } | 3168 | } |
3392 | } | 3169 | } |
3393 | 3170 | ||
3394 | Peers_unset_peer_flag (sender, Peers_PULL_REPLY_PENDING); | 3171 | UNSET_PEER_FLAG (get_peer_ctx (sender), Peers_PULL_REPLY_PENDING); |
3395 | clean_peer (sender); | 3172 | clean_peer (sender); |
3396 | 3173 | ||
3397 | GNUNET_break_op (Peers_check_peer_known (sender)); | 3174 | GNUNET_break_op (check_peer_known (sender)); |
3398 | GNUNET_CADET_receive_done (Peers_get_recv_channel (sender)); | 3175 | GNUNET_CADET_receive_done (channel_ctx->channel); |
3399 | } | 3176 | } |
3400 | 3177 | ||
3401 | 3178 | ||
@@ -3458,16 +3235,16 @@ send_pull_request (const struct GNUNET_PeerIdentity *peer) | |||
3458 | { | 3235 | { |
3459 | struct GNUNET_MQ_Envelope *ev; | 3236 | struct GNUNET_MQ_Envelope *ev; |
3460 | 3237 | ||
3461 | GNUNET_assert (GNUNET_NO == Peers_check_peer_flag (peer, | 3238 | GNUNET_assert (GNUNET_NO == check_peer_flag (peer, |
3462 | Peers_PULL_REPLY_PENDING)); | 3239 | Peers_PULL_REPLY_PENDING)); |
3463 | Peers_set_peer_flag (peer, Peers_PULL_REPLY_PENDING); | 3240 | SET_PEER_FLAG (get_peer_ctx (peer), Peers_PULL_REPLY_PENDING); |
3464 | 3241 | ||
3465 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3242 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3466 | "Going to send PULL REQUEST to peer %s.\n", | 3243 | "Going to send PULL REQUEST to peer %s.\n", |
3467 | GNUNET_i2s (peer)); | 3244 | GNUNET_i2s (peer)); |
3468 | 3245 | ||
3469 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); | 3246 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST); |
3470 | Peers_send_message (peer, ev, "PULL REQUEST"); | 3247 | send_message (peer, ev, "PULL REQUEST"); |
3471 | GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO); | 3248 | GNUNET_STATISTICS_update(stats, "# pull request send issued", 1, GNUNET_NO); |
3472 | } | 3249 | } |
3473 | 3250 | ||
@@ -3487,7 +3264,7 @@ send_push (const struct GNUNET_PeerIdentity *peer_id) | |||
3487 | GNUNET_i2s (peer_id)); | 3264 | GNUNET_i2s (peer_id)); |
3488 | 3265 | ||
3489 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); | 3266 | ev = GNUNET_MQ_msg_header (GNUNET_MESSAGE_TYPE_RPS_PP_PUSH); |
3490 | Peers_send_message (peer_id, ev, "PUSH"); | 3267 | send_message (peer_id, ev, "PUSH"); |
3491 | GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO); | 3268 | GNUNET_STATISTICS_update(stats, "# push send issued", 1, GNUNET_NO); |
3492 | } | 3269 | } |
3493 | 3270 | ||
@@ -3589,6 +3366,7 @@ handle_client_act_malicious (void *cls, | |||
3589 | 3366 | ||
3590 | num_mal_peers_sent = ntohl (msg->num_peers) - 1; | 3367 | num_mal_peers_sent = ntohl (msg->num_peers) - 1; |
3591 | num_mal_peers_old = num_mal_peers; | 3368 | num_mal_peers_old = num_mal_peers; |
3369 | GNUNET_assert (GNUNET_MAX_MALLOC_CHECKED > num_mal_peers_sent); | ||
3592 | GNUNET_array_grow (mal_peers, | 3370 | GNUNET_array_grow (mal_peers, |
3593 | num_mal_peers, | 3371 | num_mal_peers, |
3594 | num_mal_peers + num_mal_peers_sent); | 3372 | num_mal_peers + num_mal_peers_sent); |
@@ -3610,9 +3388,9 @@ handle_client_act_malicious (void *cls, | |||
3610 | &msg->attacked_peer, | 3388 | &msg->attacked_peer, |
3611 | sizeof (struct GNUNET_PeerIdentity)); | 3389 | sizeof (struct GNUNET_PeerIdentity)); |
3612 | /* Set the flag of the attacked peer to valid to avoid problems */ | 3390 | /* Set the flag of the attacked peer to valid to avoid problems */ |
3613 | if (GNUNET_NO == Peers_check_peer_known (&attacked_peer)) | 3391 | if (GNUNET_NO == check_peer_known (&attacked_peer)) |
3614 | { | 3392 | { |
3615 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3393 | (void) issue_peer_liveliness_check (&attacked_peer); |
3616 | } | 3394 | } |
3617 | 3395 | ||
3618 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3396 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -3702,8 +3480,8 @@ do_mal_round (void *cls) | |||
3702 | * Send as many pushes to the attacked peer as possible | 3480 | * Send as many pushes to the attacked peer as possible |
3703 | * That is one push per round as it will ignore more. | 3481 | * That is one push per round as it will ignore more. |
3704 | */ | 3482 | */ |
3705 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3483 | (void) issue_peer_liveliness_check (&attacked_peer); |
3706 | if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE)) | 3484 | if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE)) |
3707 | send_push (&attacked_peer); | 3485 | send_push (&attacked_peer); |
3708 | } | 3486 | } |
3709 | 3487 | ||
@@ -3712,10 +3490,10 @@ do_mal_round (void *cls) | |||
3712 | { /* Combined attack */ | 3490 | { /* Combined attack */ |
3713 | 3491 | ||
3714 | /* Send PUSH to attacked peers */ | 3492 | /* Send PUSH to attacked peers */ |
3715 | if (GNUNET_YES == Peers_check_peer_known (&attacked_peer)) | 3493 | if (GNUNET_YES == check_peer_known (&attacked_peer)) |
3716 | { | 3494 | { |
3717 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3495 | (void) issue_peer_liveliness_check (&attacked_peer); |
3718 | if (GNUNET_YES == Peers_check_peer_flag (&attacked_peer, Peers_ONLINE)) | 3496 | if (GNUNET_YES == check_peer_flag (&attacked_peer, Peers_ONLINE)) |
3719 | { | 3497 | { |
3720 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3498 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
3721 | "Goding to send push to attacked peer (%s)\n", | 3499 | "Goding to send push to attacked peer (%s)\n", |
@@ -3723,7 +3501,7 @@ do_mal_round (void *cls) | |||
3723 | send_push (&attacked_peer); | 3501 | send_push (&attacked_peer); |
3724 | } | 3502 | } |
3725 | } | 3503 | } |
3726 | (void) Peers_issue_peer_liveliness_check (&attacked_peer); | 3504 | (void) issue_peer_liveliness_check (&attacked_peer); |
3727 | 3505 | ||
3728 | /* The maximum of pushes we're going to send this round */ | 3506 | /* The maximum of pushes we're going to send this round */ |
3729 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, | 3507 | num_pushes = GNUNET_MIN (GNUNET_MIN (push_limit - 1, |
@@ -3821,10 +3599,8 @@ do_round (void *cls) | |||
3821 | for (i = 0; i < a_peers; i++) | 3599 | for (i = 0; i < a_peers; i++) |
3822 | { | 3600 | { |
3823 | peer = view_array[permut[i]]; | 3601 | peer = view_array[permut[i]]; |
3824 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer)) // TODO | 3602 | // FIXME if this fails schedule/loop this for later |
3825 | { // FIXME if this fails schedule/loop this for later | 3603 | send_push (&peer); |
3826 | send_push (&peer); | ||
3827 | } | ||
3828 | } | 3604 | } |
3829 | 3605 | ||
3830 | /* Send PULL requests */ | 3606 | /* Send PULL requests */ |
@@ -3842,8 +3618,7 @@ do_round (void *cls) | |||
3842 | for (i = first_border; i < second_border; i++) | 3618 | for (i = first_border; i < second_border; i++) |
3843 | { | 3619 | { |
3844 | peer = view_array[permut[i]]; | 3620 | peer = view_array[permut[i]]; |
3845 | if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, &peer) && | 3621 | if ( GNUNET_NO == check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) |
3846 | GNUNET_NO == Peers_check_peer_flag (&peer, Peers_PULL_REPLY_PENDING)) // TODO | ||
3847 | { // FIXME if this fails schedule/loop this for later | 3622 | { // FIXME if this fails schedule/loop this for later |
3848 | send_pull_request (&peer); | 3623 | send_pull_request (&peer); |
3849 | } | 3624 | } |
@@ -3940,7 +3715,6 @@ do_round (void *cls) | |||
3940 | "-%s", | 3715 | "-%s", |
3941 | GNUNET_i2s_full (&peers_to_clean[i])); | 3716 | GNUNET_i2s_full (&peers_to_clean[i])); |
3942 | clean_peer (&peers_to_clean[i]); | 3717 | clean_peer (&peers_to_clean[i]); |
3943 | //peer_destroy_channel_send (sender); | ||
3944 | } | 3718 | } |
3945 | 3719 | ||
3946 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); | 3720 | GNUNET_array_grow (peers_to_clean, peers_to_clean_size, 0); |
@@ -3996,7 +3770,6 @@ do_round (void *cls) | |||
3996 | GNUNET_i2s (update_peer)); | 3770 | GNUNET_i2s (update_peer)); |
3997 | insert_in_sampler (NULL, update_peer); | 3771 | insert_in_sampler (NULL, update_peer); |
3998 | clean_peer (update_peer); /* This cleans only if it is not in the view */ | 3772 | clean_peer (update_peer); /* This cleans only if it is not in the view */ |
3999 | //peer_destroy_channel_send (sender); | ||
4000 | } | 3773 | } |
4001 | 3774 | ||
4002 | for (i = 0; i < CustomPeerMap_size (pull_map); i++) | 3775 | for (i = 0; i < CustomPeerMap_size (pull_map); i++) |
@@ -4007,7 +3780,6 @@ do_round (void *cls) | |||
4007 | insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i)); | 3780 | insert_in_sampler (NULL, CustomPeerMap_get_peer_by_index (pull_map, i)); |
4008 | /* This cleans only if it is not in the view */ | 3781 | /* This cleans only if it is not in the view */ |
4009 | clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i)); | 3782 | clean_peer (CustomPeerMap_get_peer_by_index (pull_map, i)); |
4010 | //peer_destroy_channel_send (sender); | ||
4011 | } | 3783 | } |
4012 | 3784 | ||
4013 | 3785 | ||
@@ -4110,6 +3882,8 @@ shutdown_task (void *cls) | |||
4110 | struct ClientContext *client_ctx; | 3882 | struct ClientContext *client_ctx; |
4111 | struct ReplyCls *reply_cls; | 3883 | struct ReplyCls *reply_cls; |
4112 | 3884 | ||
3885 | in_shutdown = GNUNET_YES; | ||
3886 | |||
4113 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 3887 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
4114 | "RPS is going down\n"); | 3888 | "RPS is going down\n"); |
4115 | 3889 | ||
@@ -4129,42 +3903,48 @@ shutdown_task (void *cls) | |||
4129 | reply_cls); | 3903 | reply_cls); |
4130 | GNUNET_free (reply_cls); | 3904 | GNUNET_free (reply_cls); |
4131 | } | 3905 | } |
4132 | GNUNET_CONTAINER_DLL_remove (cli_ctx_head, cli_ctx_tail, client_ctx); | 3906 | GNUNET_CONTAINER_DLL_remove (cli_ctx_head, |
3907 | cli_ctx_tail, | ||
3908 | client_ctx); | ||
4133 | GNUNET_free (client_ctx); | 3909 | GNUNET_free (client_ctx); |
4134 | } | 3910 | } |
4135 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle); | 3911 | GNUNET_PEERINFO_notify_cancel (peerinfo_notify_handle); |
4136 | GNUNET_PEERINFO_disconnect (peerinfo_handle); | 3912 | GNUNET_PEERINFO_disconnect (peerinfo_handle); |
4137 | 3913 | peerinfo_handle = NULL; | |
4138 | if (NULL != do_round_task) | 3914 | if (NULL != do_round_task) |
4139 | { | 3915 | { |
4140 | GNUNET_SCHEDULER_cancel (do_round_task); | 3916 | GNUNET_SCHEDULER_cancel (do_round_task); |
4141 | do_round_task = NULL; | 3917 | do_round_task = NULL; |
4142 | } | 3918 | } |
4143 | 3919 | ||
4144 | Peers_terminate (); | 3920 | peers_terminate (); |
4145 | 3921 | ||
4146 | GNUNET_NSE_disconnect (nse); | 3922 | GNUNET_NSE_disconnect (nse); |
4147 | RPS_sampler_destroy (prot_sampler); | 3923 | RPS_sampler_destroy (prot_sampler); |
4148 | RPS_sampler_destroy (client_sampler); | 3924 | RPS_sampler_destroy (client_sampler); |
4149 | GNUNET_CADET_close_port (cadet_port); | 3925 | GNUNET_CADET_close_port (cadet_port); |
4150 | GNUNET_CADET_disconnect (cadet_handle); | 3926 | GNUNET_CADET_disconnect (cadet_handle); |
3927 | cadet_handle = NULL; | ||
4151 | View_destroy (); | 3928 | View_destroy (); |
4152 | CustomPeerMap_destroy (push_map); | 3929 | CustomPeerMap_destroy (push_map); |
4153 | CustomPeerMap_destroy (pull_map); | 3930 | CustomPeerMap_destroy (pull_map); |
4154 | if (NULL != stats) | 3931 | if (NULL != stats) |
4155 | { | 3932 | { |
4156 | GNUNET_STATISTICS_destroy (stats, GNUNET_NO); | 3933 | GNUNET_STATISTICS_destroy (stats, |
3934 | GNUNET_NO); | ||
4157 | stats = NULL; | 3935 | stats = NULL; |
4158 | } | 3936 | } |
4159 | #ifdef ENABLE_MALICIOUS | 3937 | #ifdef ENABLE_MALICIOUS |
4160 | struct AttackedPeer *tmp_att_peer; | 3938 | struct AttackedPeer *tmp_att_peer; |
4161 | /* it is ok to free this const during shutdown: */ | 3939 | /* it is ok to free this const during shutdown: */ |
4162 | GNUNET_free ((char *) file_name_view_log); | 3940 | GNUNET_free ((char *) file_name_view_log); |
4163 | #ifdef TO_FILE | 3941 | #ifdef TO_FILE |
4164 | GNUNET_free ((char *) file_name_observed_log); | 3942 | GNUNET_free ((char *) file_name_observed_log); |
4165 | GNUNET_CONTAINER_multipeermap_destroy (observed_unique_peers); | 3943 | GNUNET_CONTAINER_multipeermap_destroy (observed_unique_peers); |
4166 | #endif /* TO_FILE */ | 3944 | #endif /* TO_FILE */ |
4167 | GNUNET_array_grow (mal_peers, num_mal_peers, 0); | 3945 | GNUNET_array_grow (mal_peers, |
3946 | num_mal_peers, | ||
3947 | 0); | ||
4168 | if (NULL != mal_peer_set) | 3948 | if (NULL != mal_peer_set) |
4169 | GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set); | 3949 | GNUNET_CONTAINER_multipeermap_destroy (mal_peer_set); |
4170 | if (NULL != att_peer_set) | 3950 | if (NULL != att_peer_set) |
@@ -4172,9 +3952,12 @@ shutdown_task (void *cls) | |||
4172 | while (NULL != att_peers_head) | 3952 | while (NULL != att_peers_head) |
4173 | { | 3953 | { |
4174 | tmp_att_peer = att_peers_head; | 3954 | tmp_att_peer = att_peers_head; |
4175 | GNUNET_CONTAINER_DLL_remove (att_peers_head, att_peers_tail, tmp_att_peer); | 3955 | GNUNET_CONTAINER_DLL_remove (att_peers_head, |
3956 | att_peers_tail, | ||
3957 | tmp_att_peer); | ||
3958 | GNUNET_free (tmp_att_peer); | ||
4176 | } | 3959 | } |
4177 | #endif /* ENABLE_MALICIOUS */ | 3960 | #endif /* ENABLE_MALICIOUS */ |
4178 | } | 3961 | } |
4179 | 3962 | ||
4180 | 3963 | ||
@@ -4221,6 +4004,7 @@ client_disconnect_cb (void *cls, | |||
4221 | { | 4004 | { |
4222 | struct ClientContext *cli_ctx = internal_cls; | 4005 | struct ClientContext *cli_ctx = internal_cls; |
4223 | 4006 | ||
4007 | (void) cls; | ||
4224 | GNUNET_assert (client == cli_ctx->client); | 4008 | GNUNET_assert (client == cli_ctx->client); |
4225 | if (NULL == client) | 4009 | if (NULL == client) |
4226 | {/* shutdown task - destroy all clients */ | 4010 | {/* shutdown task - destroy all clients */ |
@@ -4248,29 +4032,31 @@ run (void *cls, | |||
4248 | const struct GNUNET_CONFIGURATION_Handle *c, | 4032 | const struct GNUNET_CONFIGURATION_Handle *c, |
4249 | struct GNUNET_SERVICE_Handle *service) | 4033 | struct GNUNET_SERVICE_Handle *service) |
4250 | { | 4034 | { |
4251 | char* fn_valid_peers; | 4035 | char *fn_valid_peers; |
4252 | struct GNUNET_HashCode port; | ||
4253 | 4036 | ||
4254 | GNUNET_log_setup ("rps", GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), NULL); | 4037 | (void) cls; |
4038 | (void) service; | ||
4039 | GNUNET_log_setup ("rps", | ||
4040 | GNUNET_error_type_to_string (GNUNET_ERROR_TYPE_DEBUG), | ||
4041 | NULL); | ||
4255 | cfg = c; | 4042 | cfg = c; |
4256 | |||
4257 | |||
4258 | /* Get own ID */ | 4043 | /* Get own ID */ |
4259 | GNUNET_CRYPTO_get_peer_identity (cfg, &own_identity); // TODO check return value | 4044 | GNUNET_CRYPTO_get_peer_identity (cfg, |
4045 | &own_identity); // TODO check return value | ||
4260 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 4046 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
4261 | "STARTING SERVICE (rps) for peer [%s]\n", | 4047 | "STARTING SERVICE (rps) for peer [%s]\n", |
4262 | GNUNET_i2s (&own_identity)); | 4048 | GNUNET_i2s (&own_identity)); |
4263 | #ifdef ENABLE_MALICIOUS | 4049 | #ifdef ENABLE_MALICIOUS |
4264 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 4050 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
4265 | "Malicious execution compiled in.\n"); | 4051 | "Malicious execution compiled in.\n"); |
4266 | #endif /* ENABLE_MALICIOUS */ | 4052 | #endif /* ENABLE_MALICIOUS */ |
4267 | |||
4268 | |||
4269 | 4053 | ||
4270 | /* Get time interval from the configuration */ | 4054 | /* Get time interval from the configuration */ |
4271 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_time (cfg, "RPS", | 4055 | if (GNUNET_OK != |
4272 | "ROUNDINTERVAL", | 4056 | GNUNET_CONFIGURATION_get_value_time (cfg, |
4273 | &round_interval)) | 4057 | "RPS", |
4058 | "ROUNDINTERVAL", | ||
4059 | &round_interval)) | ||
4274 | { | 4060 | { |
4275 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, | 4061 | GNUNET_log_config_missing (GNUNET_ERROR_TYPE_ERROR, |
4276 | "RPS", "ROUNDINTERVAL"); | 4062 | "RPS", "ROUNDINTERVAL"); |
@@ -4349,15 +4135,22 @@ run (void *cls, | |||
4349 | &port); | 4135 | &port); |
4350 | cadet_port = GNUNET_CADET_open_port (cadet_handle, | 4136 | cadet_port = GNUNET_CADET_open_port (cadet_handle, |
4351 | &port, | 4137 | &port, |
4352 | &Peers_handle_inbound_channel, /* Connect handler */ | 4138 | &handle_inbound_channel, /* Connect handler */ |
4353 | NULL, /* cls */ | 4139 | NULL, /* cls */ |
4354 | NULL, /* WindowSize handler */ | 4140 | NULL, /* WindowSize handler */ |
4355 | cleanup_destroyed_channel, /* Disconnect handler */ | 4141 | &cleanup_destroyed_channel, /* Disconnect handler */ |
4356 | cadet_handlers); | 4142 | cadet_handlers); |
4143 | if (NULL == cadet_port) | ||
4144 | { | ||
4145 | LOG (GNUNET_ERROR_TYPE_ERROR, | ||
4146 | "Cadet port `%s' is already in use.\n", | ||
4147 | GNUNET_APPLICATION_PORT_RPS); | ||
4148 | GNUNET_assert (0); | ||
4149 | } | ||
4357 | 4150 | ||
4358 | 4151 | ||
4359 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); | 4152 | peerinfo_handle = GNUNET_PEERINFO_connect (cfg); |
4360 | Peers_initialise (fn_valid_peers, cadet_handle, &own_identity); | 4153 | initialise_peers (fn_valid_peers, cadet_handle); |
4361 | GNUNET_free (fn_valid_peers); | 4154 | GNUNET_free (fn_valid_peers); |
4362 | 4155 | ||
4363 | /* Initialise sampler */ | 4156 | /* Initialise sampler */ |
@@ -4380,7 +4173,7 @@ run (void *cls, | |||
4380 | // TODO send push/pull to each of those peers? | 4173 | // TODO send push/pull to each of those peers? |
4381 | // TODO read stored valid peers from last run | 4174 | // TODO read stored valid peers from last run |
4382 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); | 4175 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n"); |
4383 | Peers_get_valid_peers (valid_peers_iterator, NULL); | 4176 | get_valid_peers (valid_peers_iterator, NULL); |
4384 | 4177 | ||
4385 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, | 4178 | peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg, |
4386 | GNUNET_NO, | 4179 | GNUNET_NO, |
diff --git a/src/rps/gnunet-service-rps_custommap.c b/src/rps/gnunet-service-rps_custommap.c index aef081a00..3513ff8da 100644 --- a/src/rps/gnunet-service-rps_custommap.c +++ b/src/rps/gnunet-service-rps_custommap.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -204,6 +202,7 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | |||
204 | p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, *index); | 202 | p = GNUNET_CONTAINER_multihashmap32_get (c_peer_map->hash_map, *index); |
205 | GNUNET_assert (NULL != p); | 203 | GNUNET_assert (NULL != p); |
206 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *index); | 204 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *index); |
205 | // TODO wrong peerid? | ||
207 | GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map, peer); | 206 | GNUNET_CONTAINER_multipeermap_remove_all (c_peer_map->peer_map, peer); |
208 | if (*index != CustomPeerMap_size (c_peer_map)) | 207 | if (*index != CustomPeerMap_size (c_peer_map)) |
209 | { /* fill 'gap' with peer at last index */ | 208 | { /* fill 'gap' with peer at last index */ |
@@ -215,13 +214,14 @@ CustomPeerMap_remove_peer (const struct CustomPeerMap *c_peer_map, | |||
215 | GNUNET_assert (NULL != last_index); | 214 | GNUNET_assert (NULL != last_index); |
216 | GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index); | 215 | GNUNET_assert (CustomPeerMap_size (c_peer_map) == *last_index); |
217 | GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, *index, last_p, | 216 | GNUNET_CONTAINER_multihashmap32_put (c_peer_map->hash_map, *index, last_p, |
218 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); | 217 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
219 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *last_index); | 218 | GNUNET_CONTAINER_multihashmap32_remove_all (c_peer_map->hash_map, *last_index); |
220 | *last_index = *index; | 219 | *last_index = *index; |
221 | } | 220 | } |
222 | GNUNET_free (index); | 221 | GNUNET_free (index); |
223 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == | 222 | GNUNET_assert (GNUNET_CONTAINER_multihashmap32_size (c_peer_map->hash_map) == |
224 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); | 223 | GNUNET_CONTAINER_multipeermap_size (c_peer_map->peer_map)); |
224 | GNUNET_free (p); | ||
225 | return GNUNET_OK; | 225 | return GNUNET_OK; |
226 | } | 226 | } |
227 | 227 | ||
diff --git a/src/rps/gnunet-service-rps_custommap.h b/src/rps/gnunet-service-rps_custommap.h index f339b841d..b42ae9efa 100644 --- a/src/rps/gnunet-service-rps_custommap.h +++ b/src/rps/gnunet-service-rps_custommap.h | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c index cfc5ce77b..4d1ae4650 100644 --- a/src/rps/gnunet-service-rps_sampler.c +++ b/src/rps/gnunet-service-rps_sampler.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -727,6 +725,7 @@ RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle) | |||
727 | } | 725 | } |
728 | GNUNET_free (i); | 726 | GNUNET_free (i); |
729 | } | 727 | } |
728 | GNUNET_free (req_handle->ids); | ||
730 | GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head, | 729 | GNUNET_CONTAINER_DLL_remove (req_handle->sampler->req_handle_head, |
731 | req_handle->sampler->req_handle_tail, | 730 | req_handle->sampler->req_handle_tail, |
732 | req_handle); | 731 | req_handle); |
diff --git a/src/rps/gnunet-service-rps_sampler.h b/src/rps/gnunet-service-rps_sampler.h index f33e7430c..c44844f96 100644 --- a/src/rps/gnunet-service-rps_sampler.h +++ b/src/rps/gnunet-service-rps_sampler.h | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
diff --git a/src/rps/gnunet-service-rps_sampler_elem.c b/src/rps/gnunet-service-rps_sampler_elem.c index 007f818e2..7569801a6 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.c +++ b/src/rps/gnunet-service-rps_sampler_elem.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
diff --git a/src/rps/gnunet-service-rps_sampler_elem.h b/src/rps/gnunet-service-rps_sampler_elem.h index bbf2c147b..1dbdcbadd 100644 --- a/src/rps/gnunet-service-rps_sampler_elem.h +++ b/src/rps/gnunet-service-rps_sampler_elem.h | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
diff --git a/src/rps/gnunet-service-rps_view.c b/src/rps/gnunet-service-rps_view.c index b7a0ba287..26a0b22bc 100644 --- a/src/rps/gnunet-service-rps_view.c +++ b/src/rps/gnunet-service-rps_view.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -231,11 +229,10 @@ View_get_peer_by_index (uint32_t index) | |||
231 | void | 229 | void |
232 | View_clear () | 230 | View_clear () |
233 | { | 231 | { |
234 | uint32_t i; | 232 | for (uint32_t i = 0; 0 < View_size (); i++) |
235 | uint32_t *index; | ||
236 | |||
237 | for (i = 0; 0 < View_size (); i++) | ||
238 | { /* Need to free indices stored at peers */ | 233 | { /* Need to free indices stored at peers */ |
234 | uint32_t *index; | ||
235 | |||
239 | GNUNET_assert (GNUNET_YES == | 236 | GNUNET_assert (GNUNET_YES == |
240 | GNUNET_CONTAINER_multipeermap_contains (mpm, &array[i])); | 237 | GNUNET_CONTAINER_multipeermap_contains (mpm, &array[i])); |
241 | index = GNUNET_CONTAINER_multipeermap_get (mpm, &array[i]); | 238 | index = GNUNET_CONTAINER_multipeermap_get (mpm, &array[i]); |
@@ -246,6 +243,7 @@ View_clear () | |||
246 | GNUNET_assert (0 == View_size ()); | 243 | GNUNET_assert (0 == View_size ()); |
247 | } | 244 | } |
248 | 245 | ||
246 | |||
249 | /** | 247 | /** |
250 | * Destroy peermap. | 248 | * Destroy peermap. |
251 | * | 249 | * |
diff --git a/src/rps/gnunet-service-rps_view.h b/src/rps/gnunet-service-rps_view.h index 6a85a2134..127b49faf 100644 --- a/src/rps/gnunet-service-rps_view.h +++ b/src/rps/gnunet-service-rps_view.h | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
diff --git a/src/rps/rps-test_util.c b/src/rps/rps-test_util.c index 869170a8a..ed682c251 100644 --- a/src/rps/rps-test_util.c +++ b/src/rps/rps-test_util.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -31,13 +29,37 @@ | |||
31 | 29 | ||
32 | #include <inttypes.h> | 30 | #include <inttypes.h> |
33 | 31 | ||
34 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-sampler",__VA_ARGS__) | 32 | #define LOG(kind, ...) GNUNET_log_from(kind,"rps-test_util",__VA_ARGS__) |
33 | |||
34 | #define B2B_PAT "%c%c%c%c%c%c%c%c" | ||
35 | #define B2B(byte) \ | ||
36 | (byte & 0x80 ? '1' : '0'), \ | ||
37 | (byte & 0x40 ? '1' : '0'), \ | ||
38 | (byte & 0x20 ? '1' : '0'), \ | ||
39 | (byte & 0x10 ? '1' : '0'), \ | ||
40 | (byte & 0x08 ? '1' : '0'), \ | ||
41 | (byte & 0x04 ? '1' : '0'), \ | ||
42 | (byte & 0x02 ? '1' : '0'), \ | ||
43 | (byte & 0x01 ? '1' : '0') | ||
35 | 44 | ||
36 | #ifndef TO_FILE | 45 | #ifndef TO_FILE |
37 | #define TO_FILE | 46 | #define TO_FILE |
38 | #endif /* TO_FILE */ | 47 | #endif /* TO_FILE */ |
39 | 48 | ||
40 | #ifdef TO_FILE | 49 | #ifdef TO_FILE |
50 | |||
51 | #define min(x,y) ((x) > (y) ? (y) : (x)) | ||
52 | |||
53 | /** | ||
54 | * @brief buffer for storing the unaligned bits for the next write | ||
55 | */ | ||
56 | static char buf_unaligned; | ||
57 | |||
58 | /** | ||
59 | * @brief number of bits in unaligned buffer | ||
60 | */ | ||
61 | static unsigned num_bits_buf_unaligned; | ||
62 | |||
41 | void | 63 | void |
42 | to_file_ (const char *file_name, char *line) | 64 | to_file_ (const char *file_name, char *line) |
43 | { | 65 | { |
@@ -109,6 +131,215 @@ to_file_ (const char *file_name, char *line) | |||
109 | "Unable to close file\n"); | 131 | "Unable to close file\n"); |
110 | } | 132 | } |
111 | 133 | ||
134 | void | ||
135 | to_file_raw (const char *file_name, const char *buf, size_t size_buf) | ||
136 | { | ||
137 | struct GNUNET_DISK_FileHandle *f; | ||
138 | size_t size_written; | ||
139 | |||
140 | if (NULL == (f = GNUNET_DISK_file_open (file_name, | ||
141 | GNUNET_DISK_OPEN_APPEND | | ||
142 | GNUNET_DISK_OPEN_WRITE | | ||
143 | GNUNET_DISK_OPEN_CREATE, | ||
144 | GNUNET_DISK_PERM_USER_READ | | ||
145 | GNUNET_DISK_PERM_USER_WRITE | | ||
146 | GNUNET_DISK_PERM_GROUP_READ | | ||
147 | GNUNET_DISK_PERM_OTHER_READ))) | ||
148 | { | ||
149 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
150 | "Not able to open file %s\n", | ||
151 | file_name); | ||
152 | return; | ||
153 | } | ||
154 | |||
155 | size_written = GNUNET_DISK_file_write (f, buf, size_buf); | ||
156 | if (size_buf != size_written) | ||
157 | { | ||
158 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
159 | "Unable to write to file! (Size: %u, size_written: %u)\n", | ||
160 | size_buf, | ||
161 | size_written); | ||
162 | |||
163 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
164 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
165 | "Unable to close file\n"); | ||
166 | |||
167 | return; | ||
168 | } | ||
169 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
170 | "Wrote %u bytes raw.\n", | ||
171 | size_written); | ||
172 | if (GNUNET_YES != GNUNET_DISK_file_close (f)) | ||
173 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
174 | "Unable to close file\n"); | ||
175 | } | ||
176 | |||
177 | void | ||
178 | to_file_raw_unaligned (const char *file_name, | ||
179 | const char *buf, | ||
180 | size_t size_buf, | ||
181 | unsigned bits_needed) | ||
182 | { | ||
183 | // TODO endianness! | ||
184 | GNUNET_assert (size_buf >= (bits_needed/8)); | ||
185 | //if (0 == num_bits_buf_unaligned) | ||
186 | //{ | ||
187 | // if (0 == (bits_needed % 8)) | ||
188 | // { | ||
189 | // to_file_raw (file_name, buf, size_buf); | ||
190 | // return; | ||
191 | // } | ||
192 | // to_file_raw (file_name, buf, size_buf - 1); | ||
193 | // buf_unaligned = buf[size_buf - 1]; | ||
194 | // num_bits_buf_unaligned = bits_needed % 8; | ||
195 | // return; | ||
196 | //} | ||
197 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
198 | "Was asked to write %u bits\n", bits_needed); | ||
199 | |||
200 | char buf_write[size_buf + 1]; | ||
201 | const unsigned bytes_iter = (0 != bits_needed % 8? | ||
202 | (bits_needed/8)+1: | ||
203 | bits_needed/8); | ||
204 | // TODO what if no iteration happens? | ||
205 | unsigned size_buf_write = 0; | ||
206 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
207 | "num_bits_buf_unaligned: %u\n", | ||
208 | num_bits_buf_unaligned); | ||
209 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
210 | "ua args: size_buf: %u, bits_needed: %u -> iter: %u\n", | ||
211 | size_buf, | ||
212 | bits_needed, | ||
213 | bytes_iter); | ||
214 | buf_write[0] = buf_unaligned; | ||
215 | /* Iterate over input bytes */ | ||
216 | for (unsigned i = 0; i < bytes_iter; i++) | ||
217 | { | ||
218 | /* Number of bits needed in this iteration - 8 for all except last iter */ | ||
219 | unsigned num_bits_needed_iter; | ||
220 | /* Mask for bits to actually use */ | ||
221 | unsigned mask_bits_needed_iter; | ||
222 | char byte_input; | ||
223 | /* Number of bits needed to align unaligned byte */ | ||
224 | unsigned num_bits_to_align; | ||
225 | /* Number of bits that are to be moved */ | ||
226 | unsigned num_bits_to_move; | ||
227 | /* Mask for bytes to be moved */ | ||
228 | char mask_input_to_move; | ||
229 | /* Masked bits to be moved */ | ||
230 | char bits_to_move; | ||
231 | /* The amount of bits needed to fit the bits to shift to the nearest spot */ | ||
232 | unsigned distance_shift_bits; | ||
233 | /* Shifted bits on the move */ | ||
234 | char bits_moving; | ||
235 | /* (unaligned) byte being filled with bits */ | ||
236 | char byte_to_fill; | ||
237 | /* mask for needed bits of the input byte that have not been moved */ | ||
238 | char mask_input_leftover; | ||
239 | /* needed bits of the input byte that have not been moved */ | ||
240 | char byte_input_leftover; | ||
241 | unsigned num_bits_leftover; | ||
242 | //unsigned num_bits_discard; | ||
243 | char byte_unaligned_new; | ||
244 | |||
245 | if ( (bits_needed - (i * 8)) <= 8) | ||
246 | { | ||
247 | /* last iteration */ | ||
248 | num_bits_needed_iter = bits_needed - (i * 8); | ||
249 | } | ||
250 | else | ||
251 | { | ||
252 | num_bits_needed_iter = 8; | ||
253 | } | ||
254 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
255 | "number of bits needed in this iteration: %u\n", | ||
256 | num_bits_needed_iter); | ||
257 | mask_bits_needed_iter = ((char) 1 << num_bits_needed_iter) - 1; | ||
258 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
259 | "mask needed bits (current iter): "B2B_PAT"\n", | ||
260 | B2B(mask_bits_needed_iter)); | ||
261 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
262 | "Unaligned byte: "B2B_PAT" (%u bits)\n", | ||
263 | B2B(buf_unaligned), | ||
264 | num_bits_buf_unaligned); | ||
265 | byte_input = buf[i]; | ||
266 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
267 | "next whole input byte: "B2B_PAT"\n", | ||
268 | B2B(byte_input)); | ||
269 | byte_input &= mask_bits_needed_iter; | ||
270 | num_bits_to_align = 8 - num_bits_buf_unaligned; | ||
271 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
272 | "input byte, needed bits: "B2B_PAT"\n", | ||
273 | B2B(byte_input)); | ||
274 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
275 | "number of bits needed to align unaligned bit: %u\n", | ||
276 | num_bits_to_align); | ||
277 | num_bits_to_move = min (num_bits_to_align, num_bits_needed_iter); | ||
278 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
279 | "number of bits of new byte to move: %u\n", | ||
280 | num_bits_to_move); | ||
281 | mask_input_to_move = ((char) 1 << num_bits_to_move) - 1; | ||
282 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
283 | "mask of bits of new byte to take for moving: "B2B_PAT"\n", | ||
284 | B2B(mask_input_to_move)); | ||
285 | bits_to_move = byte_input & mask_input_to_move; | ||
286 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
287 | "masked bits of new byte to take for moving: "B2B_PAT"\n", | ||
288 | B2B(bits_to_move)); | ||
289 | distance_shift_bits = num_bits_buf_unaligned; | ||
290 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
291 | "distance needed to shift bits to their correct spot: %u\n", | ||
292 | distance_shift_bits); | ||
293 | bits_moving = bits_to_move << distance_shift_bits; | ||
294 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
295 | "shifted, masked bits of new byte being moved: "B2B_PAT"\n", | ||
296 | B2B(bits_moving)); | ||
297 | byte_to_fill = buf_unaligned | bits_moving; | ||
298 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
299 | "byte being filled: "B2B_PAT"\n", | ||
300 | B2B(byte_to_fill)); | ||
301 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
302 | "pending bytes: %u\n", | ||
303 | num_bits_buf_unaligned + num_bits_needed_iter); | ||
304 | if (num_bits_buf_unaligned + num_bits_needed_iter >= 8) | ||
305 | { | ||
306 | /* buf_unaligned was aligned by filling | ||
307 | * -> can be written to storage */ | ||
308 | buf_write[i] = byte_to_fill; | ||
309 | size_buf_write++; | ||
310 | |||
311 | /* store the leftover, unaligned bits in buffer */ | ||
312 | mask_input_leftover = mask_bits_needed_iter & (~ mask_input_to_move); | ||
313 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
314 | "mask of leftover bits of new byte: "B2B_PAT"\n", | ||
315 | B2B(mask_input_leftover)); | ||
316 | byte_input_leftover = byte_input & mask_input_leftover; | ||
317 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
318 | "masked, leftover bits of new byte: "B2B_PAT"\n", | ||
319 | B2B(byte_input_leftover)); | ||
320 | num_bits_leftover = num_bits_needed_iter - num_bits_to_move; | ||
321 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
322 | "number of unaligned bits left: %u\n", | ||
323 | num_bits_leftover); | ||
324 | //num_bits_discard = 8 - num_bits_needed_iter; | ||
325 | byte_unaligned_new = byte_input_leftover >> num_bits_to_move; | ||
326 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
327 | "new unaligned byte: "B2B_PAT"\n", | ||
328 | B2B(byte_unaligned_new)); | ||
329 | buf_unaligned = byte_unaligned_new; | ||
330 | num_bits_buf_unaligned = num_bits_leftover % 8; | ||
331 | } | ||
332 | else | ||
333 | { | ||
334 | /* unaligned buffer still unaligned but 'fuller' */ | ||
335 | buf_unaligned = byte_to_fill; | ||
336 | num_bits_buf_unaligned = (num_bits_buf_unaligned + bits_needed) % 8; | ||
337 | } | ||
338 | } | ||
339 | to_file_raw (file_name, buf_write, size_buf_write); | ||
340 | LOG (GNUNET_ERROR_TYPE_DEBUG, "\n"); | ||
341 | } | ||
342 | |||
112 | char * | 343 | char * |
113 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) | 344 | auth_key_to_string (struct GNUNET_CRYPTO_AuthKey auth_key) |
114 | { | 345 | { |
@@ -197,10 +428,10 @@ create_file (const char *name) | |||
197 | if (NULL == strstr (name, "sampler_el")) | 428 | if (NULL == strstr (name, "sampler_el")) |
198 | {/* only append random string to sampler */ | 429 | {/* only append random string to sampler */ |
199 | if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) | 430 | if (NULL == (file_name = GNUNET_DISK_mktemp (name_buf))) |
200 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); | 431 | LOG (GNUNET_ERROR_TYPE_WARNING, "Could not create file\n"); |
201 | 432 | ||
202 | GNUNET_free (name_buf); | 433 | GNUNET_free (name_buf); |
203 | return file_name; | 434 | return file_name; |
204 | } | 435 | } |
205 | 436 | ||
206 | return name_buf; | 437 | return name_buf; |
@@ -232,7 +463,7 @@ store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, | |||
232 | const char *prefix) | 463 | const char *prefix) |
233 | { | 464 | { |
234 | unsigned int len_file_name; | 465 | unsigned int len_file_name; |
235 | unsigned int out_size; | 466 | int out_size; |
236 | char *file_name; | 467 | char *file_name; |
237 | const char *pid_long; | 468 | const char *pid_long; |
238 | 469 | ||
diff --git a/src/rps/rps-test_util.h b/src/rps/rps-test_util.h index 59f062331..577a2b0a7 100644 --- a/src/rps/rps-test_util.h +++ b/src/rps/rps-test_util.h | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
@@ -76,5 +74,14 @@ const char * | |||
76 | store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, | 74 | store_prefix_file_name (const struct GNUNET_PeerIdentity *peer, |
77 | const char *prefix); | 75 | const char *prefix); |
78 | 76 | ||
77 | void | ||
78 | to_file_raw (const char *file_name, const char *buf, size_t size_buf); | ||
79 | |||
80 | void | ||
81 | to_file_raw_unaligned (const char *file_name, | ||
82 | const char *buf, | ||
83 | size_t size_buf, | ||
84 | unsigned bits_needed); | ||
85 | |||
79 | #endif /* RPS_TEST_UTIL_H */ | 86 | #endif /* RPS_TEST_UTIL_H */ |
80 | /* end of gnunet-service-rps.c */ | 87 | /* end of gnunet-service-rps.c */ |
diff --git a/src/rps/rps.conf.in b/src/rps/rps.conf.in index b5feb1bd2..7f0a419bd 100644 --- a/src/rps/rps.conf.in +++ b/src/rps/rps.conf.in | |||
@@ -1,5 +1,5 @@ | |||
1 | [rps] | 1 | [rps] |
2 | AUTOSTART = @AUTOSTART@ | 2 | START_ON_DEMAND = @START_ON_DEMAND@ |
3 | BINARY = gnunet-service-rps | 3 | BINARY = gnunet-service-rps |
4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-rps.sock | 4 | UNIXPATH = $GNUNET_RUNTIME_DIR/gnunet-service-rps.sock |
5 | HOME = $SERVICEHOME | 5 | HOME = $SERVICEHOME |
@@ -24,4 +24,4 @@ FILENAME_VALID_PEERS = $GNUNET_DATA_HOME/rps/valid_peers.txt | |||
24 | # until we receive the first estimate from NSE. | 24 | # until we receive the first estimate from NSE. |
25 | # Keep in mind, that (networksize)^(1/3) should be enough. | 25 | # Keep in mind, that (networksize)^(1/3) should be enough. |
26 | # So, 50 is enough for a network of size 50^3 = 125000 | 26 | # So, 50 is enough for a network of size 50^3 = 125000 |
27 | INITSIZE = 10 | 27 | MINSIZE = 10 |
diff --git a/src/rps/rps.h b/src/rps/rps.h index 6a7fa3e14..6bf2273b4 100644 --- a/src/rps/rps.h +++ b/src/rps/rps.h | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2012-2013 GNUnet e.V. | 3 | Copyright (C) 2012-2013 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file rps/rps.h | 19 | * @file rps/rps.h |
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c index 0da3bd4a4..ca80e25e8 100644 --- a/src/rps/rps_api.c +++ b/src/rps/rps_api.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | 18 | ||
21 | /** | 19 | /** |
diff --git a/src/rps/test_rps.c b/src/rps/test_rps.c index 8d31bf50d..92d8c12ea 100644 --- a/src/rps/test_rps.c +++ b/src/rps/test_rps.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2009, 2012 GNUnet e.V. | 3 | Copyright (C) 2009, 2012 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file rps/test_rps.c | 19 | * @file rps/test_rps.c |
@@ -42,6 +40,12 @@ static uint32_t num_peers; | |||
42 | 40 | ||
43 | /** | 41 | /** |
44 | * How long do we run the test? | 42 | * How long do we run the test? |
43 | * In seconds. | ||
44 | */ | ||
45 | static uint32_t timeout_s; | ||
46 | |||
47 | /** | ||
48 | * How long do we run the test? | ||
45 | */ | 49 | */ |
46 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 50 | //#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) |
47 | static struct GNUNET_TIME_Relative timeout; | 51 | static struct GNUNET_TIME_Relative timeout; |
@@ -371,6 +375,11 @@ static int ok; | |||
371 | /** | 375 | /** |
372 | * Identifier for the churn task that runs periodically | 376 | * Identifier for the churn task that runs periodically |
373 | */ | 377 | */ |
378 | static struct GNUNET_SCHEDULER_Task *post_test_task; | ||
379 | |||
380 | /** | ||
381 | * Identifier for the churn task that runs periodically | ||
382 | */ | ||
374 | static struct GNUNET_SCHEDULER_Task *shutdown_task; | 383 | static struct GNUNET_SCHEDULER_Task *shutdown_task; |
375 | 384 | ||
376 | /** | 385 | /** |
@@ -556,6 +565,11 @@ struct SingleTestRun | |||
556 | } cur_test_run; | 565 | } cur_test_run; |
557 | 566 | ||
558 | /** | 567 | /** |
568 | * Did we finish the test? | ||
569 | */ | ||
570 | static int post_test; | ||
571 | |||
572 | /** | ||
559 | * Are we shutting down? | 573 | * Are we shutting down? |
560 | */ | 574 | */ |
561 | static int in_shutdown; | 575 | static int in_shutdown; |
@@ -755,6 +769,41 @@ shutdown_op (void *cls) | |||
755 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 769 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
756 | "Shutdown task scheduled, going down.\n"); | 770 | "Shutdown task scheduled, going down.\n"); |
757 | in_shutdown = GNUNET_YES; | 771 | in_shutdown = GNUNET_YES; |
772 | if (NULL != post_test_task) | ||
773 | { | ||
774 | GNUNET_SCHEDULER_cancel (post_test_task); | ||
775 | } | ||
776 | if (NULL != churn_task) | ||
777 | { | ||
778 | GNUNET_SCHEDULER_cancel (churn_task); | ||
779 | churn_task = NULL; | ||
780 | } | ||
781 | for (i = 0; i < num_peers; i++) | ||
782 | { | ||
783 | if (NULL != rps_peers[i].rps_handle) | ||
784 | { | ||
785 | GNUNET_RPS_disconnect (rps_peers[i].rps_handle); | ||
786 | } | ||
787 | if (NULL != rps_peers[i].op) | ||
788 | { | ||
789 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | ||
790 | } | ||
791 | } | ||
792 | } | ||
793 | |||
794 | |||
795 | /** | ||
796 | * Task run on timeout to collect statistics and potentially shut down. | ||
797 | */ | ||
798 | static void | ||
799 | post_test_op (void *cls) | ||
800 | { | ||
801 | unsigned int i; | ||
802 | |||
803 | post_test_task = NULL; | ||
804 | post_test = GNUNET_YES; | ||
805 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | ||
806 | "Post test task scheduled, going down.\n"); | ||
758 | if (NULL != churn_task) | 807 | if (NULL != churn_task) |
759 | { | 808 | { |
760 | GNUNET_SCHEDULER_cancel (churn_task); | 809 | GNUNET_SCHEDULER_cancel (churn_task); |
@@ -763,7 +812,10 @@ shutdown_op (void *cls) | |||
763 | for (i = 0; i < num_peers; i++) | 812 | for (i = 0; i < num_peers; i++) |
764 | { | 813 | { |
765 | if (NULL != rps_peers[i].op) | 814 | if (NULL != rps_peers[i].op) |
815 | { | ||
766 | GNUNET_TESTBED_operation_done (rps_peers[i].op); | 816 | GNUNET_TESTBED_operation_done (rps_peers[i].op); |
817 | rps_peers[i].op = NULL; | ||
818 | } | ||
767 | if (NULL != cur_test_run.post_test) | 819 | if (NULL != cur_test_run.post_test) |
768 | { | 820 | { |
769 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); | 821 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Executing post_test for peer %u\n", i); |
@@ -789,6 +841,13 @@ seed_peers (void *cls) | |||
789 | unsigned int amount; | 841 | unsigned int amount; |
790 | unsigned int i; | 842 | unsigned int i; |
791 | 843 | ||
844 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
845 | { | ||
846 | return; | ||
847 | } | ||
848 | |||
849 | GNUNET_assert (NULL != peer->rps_handle); | ||
850 | |||
792 | // TODO if malicious don't seed mal peers | 851 | // TODO if malicious don't seed mal peers |
793 | amount = round (.5 * num_peers); | 852 | amount = round (.5 * num_peers); |
794 | 853 | ||
@@ -847,7 +906,7 @@ info_cb (void *cb_cls, | |||
847 | { | 906 | { |
848 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; | 907 | struct OpListEntry *entry = (struct OpListEntry *) cb_cls; |
849 | 908 | ||
850 | if (GNUNET_YES == in_shutdown) | 909 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
851 | { | 910 | { |
852 | return; | 911 | return; |
853 | } | 912 | } |
@@ -901,7 +960,9 @@ rps_connect_complete_cb (void *cls, | |||
901 | struct RPSPeer *rps_peer = cls; | 960 | struct RPSPeer *rps_peer = cls; |
902 | struct GNUNET_RPS_Handle *rps = ca_result; | 961 | struct GNUNET_RPS_Handle *rps = ca_result; |
903 | 962 | ||
904 | if (GNUNET_YES == in_shutdown) | 963 | GNUNET_assert (NULL != ca_result); |
964 | |||
965 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) | ||
905 | { | 966 | { |
906 | return; | 967 | return; |
907 | } | 968 | } |
@@ -944,9 +1005,11 @@ rps_connect_adapter (void *cls, | |||
944 | struct GNUNET_RPS_Handle *h; | 1005 | struct GNUNET_RPS_Handle *h; |
945 | 1006 | ||
946 | h = GNUNET_RPS_connect (cfg); | 1007 | h = GNUNET_RPS_connect (cfg); |
1008 | GNUNET_assert (NULL != h); | ||
947 | 1009 | ||
948 | if (NULL != cur_test_run.pre_test) | 1010 | if (NULL != cur_test_run.pre_test) |
949 | cur_test_run.pre_test (cls, h); | 1011 | cur_test_run.pre_test (cls, h); |
1012 | GNUNET_assert (NULL != h); | ||
950 | 1013 | ||
951 | return h; | 1014 | return h; |
952 | } | 1015 | } |
@@ -1105,10 +1168,10 @@ default_reply_handle (void *cls, | |||
1105 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) | 1168 | if (0 == evaluate () && HAVE_QUICK_QUIT == cur_test_run.have_quick_quit) |
1106 | { | 1169 | { |
1107 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); | 1170 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Test succeeded before timeout\n"); |
1108 | GNUNET_assert (NULL != shutdown_task); | 1171 | GNUNET_assert (NULL != post_test_task); |
1109 | GNUNET_SCHEDULER_cancel (shutdown_task); | 1172 | GNUNET_SCHEDULER_cancel (post_test_task); |
1110 | shutdown_task = GNUNET_SCHEDULER_add_now (&shutdown_op, NULL); | 1173 | post_test_task = GNUNET_SCHEDULER_add_now (&post_test_op, NULL); |
1111 | GNUNET_assert (NULL!= shutdown_task); | 1174 | GNUNET_assert (NULL!= post_test_task); |
1112 | } | 1175 | } |
1113 | } | 1176 | } |
1114 | 1177 | ||
@@ -1122,7 +1185,7 @@ request_peers (void *cls) | |||
1122 | struct RPSPeer *rps_peer; | 1185 | struct RPSPeer *rps_peer; |
1123 | struct PendingReply *pending_rep; | 1186 | struct PendingReply *pending_rep; |
1124 | 1187 | ||
1125 | if (GNUNET_YES == in_shutdown) | 1188 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1126 | return; | 1189 | return; |
1127 | rps_peer = pending_req->rps_peer; | 1190 | rps_peer = pending_req->rps_peer; |
1128 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); | 1191 | GNUNET_assert (1 <= rps_peer->num_pending_reqs); |
@@ -1185,7 +1248,7 @@ cancel_request_cb (void *cls) | |||
1185 | struct RPSPeer *rps_peer = cls; | 1248 | struct RPSPeer *rps_peer = cls; |
1186 | struct PendingReply *pending_rep; | 1249 | struct PendingReply *pending_rep; |
1187 | 1250 | ||
1188 | if (GNUNET_YES == in_shutdown) | 1251 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1189 | return; | 1252 | return; |
1190 | pending_rep = rps_peer->pending_rep_head; | 1253 | pending_rep = rps_peer->pending_rep_head; |
1191 | GNUNET_assert (1 <= rps_peer->num_pending_reps); | 1254 | GNUNET_assert (1 <= rps_peer->num_pending_reps); |
@@ -1290,7 +1353,7 @@ mal_cb (struct RPSPeer *rps_peer) | |||
1290 | { | 1353 | { |
1291 | uint32_t num_mal_peers; | 1354 | uint32_t num_mal_peers; |
1292 | 1355 | ||
1293 | if (GNUNET_YES == in_shutdown) | 1356 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1294 | { | 1357 | { |
1295 | return; | 1358 | return; |
1296 | } | 1359 | } |
@@ -1317,7 +1380,7 @@ mal_cb (struct RPSPeer *rps_peer) | |||
1317 | static void | 1380 | static void |
1318 | single_req_cb (struct RPSPeer *rps_peer) | 1381 | single_req_cb (struct RPSPeer *rps_peer) |
1319 | { | 1382 | { |
1320 | if (GNUNET_YES == in_shutdown) | 1383 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1321 | { | 1384 | { |
1322 | return; | 1385 | return; |
1323 | } | 1386 | } |
@@ -1331,7 +1394,7 @@ single_req_cb (struct RPSPeer *rps_peer) | |||
1331 | static void | 1394 | static void |
1332 | delay_req_cb (struct RPSPeer *rps_peer) | 1395 | delay_req_cb (struct RPSPeer *rps_peer) |
1333 | { | 1396 | { |
1334 | if (GNUNET_YES == in_shutdown) | 1397 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1335 | { | 1398 | { |
1336 | return; | 1399 | return; |
1337 | } | 1400 | } |
@@ -1345,7 +1408,7 @@ delay_req_cb (struct RPSPeer *rps_peer) | |||
1345 | static void | 1408 | static void |
1346 | seed_cb (struct RPSPeer *rps_peer) | 1409 | seed_cb (struct RPSPeer *rps_peer) |
1347 | { | 1410 | { |
1348 | if (GNUNET_YES == in_shutdown) | 1411 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1349 | { | 1412 | { |
1350 | return; | 1413 | return; |
1351 | } | 1414 | } |
@@ -1361,7 +1424,7 @@ seed_cb (struct RPSPeer *rps_peer) | |||
1361 | static void | 1424 | static void |
1362 | seed_big_cb (struct RPSPeer *rps_peer) | 1425 | seed_big_cb (struct RPSPeer *rps_peer) |
1363 | { | 1426 | { |
1364 | if (GNUNET_YES == in_shutdown) | 1427 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1365 | { | 1428 | { |
1366 | return; | 1429 | return; |
1367 | } | 1430 | } |
@@ -1387,7 +1450,7 @@ single_peer_seed_cb (struct RPSPeer *rps_peer) | |||
1387 | static void | 1450 | static void |
1388 | seed_req_cb (struct RPSPeer *rps_peer) | 1451 | seed_req_cb (struct RPSPeer *rps_peer) |
1389 | { | 1452 | { |
1390 | if (GNUNET_YES == in_shutdown) | 1453 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1391 | { | 1454 | { |
1392 | return; | 1455 | return; |
1393 | } | 1456 | } |
@@ -1406,7 +1469,7 @@ seed_req_cb (struct RPSPeer *rps_peer) | |||
1406 | static void | 1469 | static void |
1407 | req_cancel_cb (struct RPSPeer *rps_peer) | 1470 | req_cancel_cb (struct RPSPeer *rps_peer) |
1408 | { | 1471 | { |
1409 | if (GNUNET_YES == in_shutdown) | 1472 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1410 | { | 1473 | { |
1411 | return; | 1474 | return; |
1412 | } | 1475 | } |
@@ -1439,7 +1502,7 @@ churn (void *cls); | |||
1439 | static void | 1502 | static void |
1440 | churn_test_cb (struct RPSPeer *rps_peer) | 1503 | churn_test_cb (struct RPSPeer *rps_peer) |
1441 | { | 1504 | { |
1442 | if (GNUNET_YES == in_shutdown) | 1505 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1443 | { | 1506 | { |
1444 | return; | 1507 | return; |
1445 | } | 1508 | } |
@@ -1480,7 +1543,7 @@ churn_cb (void *cls, | |||
1480 | // FIXME | 1543 | // FIXME |
1481 | struct OpListEntry *entry = cls; | 1544 | struct OpListEntry *entry = cls; |
1482 | 1545 | ||
1483 | if (GNUNET_YES == in_shutdown) | 1546 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1484 | { | 1547 | { |
1485 | return; | 1548 | return; |
1486 | } | 1549 | } |
@@ -1615,7 +1678,7 @@ churn (void *cls) | |||
1615 | double portion_go_online; | 1678 | double portion_go_online; |
1616 | double portion_go_offline; | 1679 | double portion_go_offline; |
1617 | 1680 | ||
1618 | if (GNUNET_YES == in_shutdown) | 1681 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1619 | { | 1682 | { |
1620 | return; | 1683 | return; |
1621 | } | 1684 | } |
@@ -1731,7 +1794,7 @@ profiler_reply_handle (void *cls, | |||
1731 | static void | 1794 | static void |
1732 | profiler_cb (struct RPSPeer *rps_peer) | 1795 | profiler_cb (struct RPSPeer *rps_peer) |
1733 | { | 1796 | { |
1734 | if (GNUNET_YES == in_shutdown) | 1797 | if (GNUNET_YES == in_shutdown || GNUNET_YES == post_test) |
1735 | { | 1798 | { |
1736 | return; | 1799 | return; |
1737 | } | 1800 | } |
@@ -1836,7 +1899,7 @@ static uint32_t binom (uint32_t n, uint32_t k) | |||
1836 | * @param a | 1899 | * @param a |
1837 | * @param b | 1900 | * @param b |
1838 | * | 1901 | * |
1839 | * @return | 1902 | * @return |
1840 | */ | 1903 | */ |
1841 | static int is_in_view (uint32_t a, uint32_t b) | 1904 | static int is_in_view (uint32_t a, uint32_t b) |
1842 | { | 1905 | { |
@@ -2172,30 +2235,33 @@ void view_update_cb (void *cls, | |||
2172 | rps_peer->cur_view_count, | 2235 | rps_peer->cur_view_count, |
2173 | view_size); | 2236 | view_size); |
2174 | //*rps_peer->cur_view = *peers; | 2237 | //*rps_peer->cur_view = *peers; |
2175 | memcpy (rps_peer->cur_view, | 2238 | GNUNET_memcpy (rps_peer->cur_view, |
2176 | peers, | 2239 | peers, |
2177 | view_size * sizeof (struct GNUNET_PeerIdentity)); | 2240 | view_size * sizeof (struct GNUNET_PeerIdentity)); |
2178 | to_file ("/tmp/rps/count_in_views.txt", | 2241 | to_file ("/tmp/rps/count_in_views.txt", |
2179 | "%" PRIu64 " %" PRIu32 "", | 2242 | "%" PRIu64 " %" PRIu32 "", |
2180 | rps_peer->index, | 2243 | rps_peer->index, |
2181 | count_peer_in_views_2 (rps_peer->index)); | 2244 | count_peer_in_views_2 (rps_peer->index)); |
2182 | cumulated_view_sizes(); | 2245 | cumulated_view_sizes(); |
2183 | to_file ("/tmp/rps/repr.txt", | 2246 | if (0 != view_size) |
2184 | "%" PRIu64 /* index */ | 2247 | { |
2185 | " %" PRIu32 /* occurrence in views */ | 2248 | to_file ("/tmp/rps/repr.txt", |
2186 | " %" PRIu32 /* view sizes */ | 2249 | "%" PRIu64 /* index */ |
2187 | " %f" /* fraction of repr in views */ | 2250 | " %" PRIu32 /* occurrence in views */ |
2188 | " %f" /* average view size */ | 2251 | " %" PRIu32 /* view sizes */ |
2189 | " %f" /* prob of occurrence in view slot */ | 2252 | " %f" /* fraction of repr in views */ |
2190 | " %f" "", /* exp frac of repr in views */ | 2253 | " %f" /* average view size */ |
2191 | rps_peer->index, | 2254 | " %f" /* prob of occurrence in view slot */ |
2192 | count_peer_in_views_2 (rps_peer->index), | 2255 | " %f" "", /* exp frac of repr in views */ |
2193 | view_sizes, | 2256 | rps_peer->index, |
2194 | count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ | 2257 | count_peer_in_views_2 (rps_peer->index), |
2195 | view_sizes / (view_size * 1.0), /* average view size */ | 2258 | view_sizes, |
2196 | 1.0 /view_size, /* prob of occurrence in view slot */ | 2259 | count_peer_in_views_2 (rps_peer->index) / (view_size * 1.0), /* fraction of representation in views */ |
2197 | (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ | 2260 | view_sizes / (view_size * 1.0), /* average view size */ |
2198 | ); | 2261 | 1.0 /view_size, /* prob of occurrence in view slot */ |
2262 | (1.0/view_size) * (view_sizes/view_size) /* expected fraction of repr in views */ | ||
2263 | ); | ||
2264 | } | ||
2199 | compute_probabilities (rps_peer->index); | 2265 | compute_probabilities (rps_peer->index); |
2200 | all_views_updated_cb(); | 2266 | all_views_updated_cb(); |
2201 | } | 2267 | } |
@@ -2641,7 +2707,12 @@ run (void *cls, | |||
2641 | 2707 | ||
2642 | if (NULL != churn_task) | 2708 | if (NULL != churn_task) |
2643 | GNUNET_SCHEDULER_cancel (churn_task); | 2709 | GNUNET_SCHEDULER_cancel (churn_task); |
2710 | post_test_task = GNUNET_SCHEDULER_add_delayed (timeout, &post_test_op, NULL); | ||
2711 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, | ||
2712 | (timeout_s * 1.2) + 0.1 * num_peers); | ||
2644 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); | 2713 | shutdown_task = GNUNET_SCHEDULER_add_delayed (timeout, &shutdown_op, NULL); |
2714 | shutdown_task = GNUNET_SCHEDULER_add_shutdown (shutdown_op, NULL); | ||
2715 | |||
2645 | } | 2716 | } |
2646 | 2717 | ||
2647 | 2718 | ||
@@ -2670,7 +2741,7 @@ main (int argc, char *argv[]) | |||
2670 | cur_test_run.stat_collect_flags = 0; | 2741 | cur_test_run.stat_collect_flags = 0; |
2671 | cur_test_run.have_collect_view = NO_COLLECT_VIEW; | 2742 | cur_test_run.have_collect_view = NO_COLLECT_VIEW; |
2672 | churn_task = NULL; | 2743 | churn_task = NULL; |
2673 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); | 2744 | timeout_s = 30; |
2674 | 2745 | ||
2675 | if (strstr (argv[0], "malicious") != NULL) | 2746 | if (strstr (argv[0], "malicious") != NULL) |
2676 | { | 2747 | { |
@@ -2722,7 +2793,7 @@ main (int argc, char *argv[]) | |||
2722 | cur_test_run.main_test = seed_big_cb; | 2793 | cur_test_run.main_test = seed_big_cb; |
2723 | cur_test_run.eval_cb = no_eval; | 2794 | cur_test_run.eval_cb = no_eval; |
2724 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2795 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2725 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2796 | timeout_s = 10; |
2726 | } | 2797 | } |
2727 | 2798 | ||
2728 | else if (strstr (argv[0], "_single_peer_seed") != NULL) | 2799 | else if (strstr (argv[0], "_single_peer_seed") != NULL) |
@@ -2758,7 +2829,7 @@ main (int argc, char *argv[]) | |||
2758 | cur_test_run.main_test = req_cancel_cb; | 2829 | cur_test_run.main_test = req_cancel_cb; |
2759 | cur_test_run.eval_cb = no_eval; | 2830 | cur_test_run.eval_cb = no_eval; |
2760 | cur_test_run.have_churn = HAVE_NO_CHURN; | 2831 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2761 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2832 | timeout_s = 10; |
2762 | } | 2833 | } |
2763 | 2834 | ||
2764 | else if (strstr (argv[0], "_churn") != NULL) | 2835 | else if (strstr (argv[0], "_churn") != NULL) |
@@ -2770,16 +2841,16 @@ main (int argc, char *argv[]) | |||
2770 | cur_test_run.main_test = churn_test_cb; | 2841 | cur_test_run.main_test = churn_test_cb; |
2771 | cur_test_run.reply_handle = default_reply_handle; | 2842 | cur_test_run.reply_handle = default_reply_handle; |
2772 | cur_test_run.eval_cb = default_eval_cb; | 2843 | cur_test_run.eval_cb = default_eval_cb; |
2773 | cur_test_run.have_churn = HAVE_CHURN; | 2844 | cur_test_run.have_churn = HAVE_NO_CHURN; |
2774 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | 2845 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; |
2775 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10); | 2846 | timeout_s = 10; |
2776 | } | 2847 | } |
2777 | 2848 | ||
2778 | else if (strstr (argv[0], "profiler") != NULL) | 2849 | else if (strstr (argv[0], "profiler") != NULL) |
2779 | { | 2850 | { |
2780 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); | 2851 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "This is the profiler\n"); |
2781 | cur_test_run.name = "test-rps-profiler"; | 2852 | cur_test_run.name = "test-rps-profiler"; |
2782 | num_peers = 10; | 2853 | num_peers = 16; |
2783 | mal_type = 3; | 2854 | mal_type = 3; |
2784 | cur_test_run.init_peer = profiler_init_peer; | 2855 | cur_test_run.init_peer = profiler_init_peer; |
2785 | //cur_test_run.pre_test = mal_pre; | 2856 | //cur_test_run.pre_test = mal_pre; |
@@ -2790,7 +2861,8 @@ main (int argc, char *argv[]) | |||
2790 | cur_test_run.post_test = post_profiler; | 2861 | cur_test_run.post_test = post_profiler; |
2791 | cur_test_run.request_interval = 2; | 2862 | cur_test_run.request_interval = 2; |
2792 | cur_test_run.num_requests = 5; | 2863 | cur_test_run.num_requests = 5; |
2793 | cur_test_run.have_churn = HAVE_CHURN; | 2864 | //cur_test_run.have_churn = HAVE_CHURN; |
2865 | cur_test_run.have_churn = HAVE_NO_CHURN; | ||
2794 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; | 2866 | cur_test_run.have_quick_quit = HAVE_NO_QUICK_QUIT; |
2795 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; | 2867 | cur_test_run.have_collect_statistics = COLLECT_STATISTICS; |
2796 | cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS | | 2868 | cur_test_run.stat_collect_flags = STAT_TYPE_ROUNDS | |
@@ -2810,12 +2882,13 @@ main (int argc, char *argv[]) | |||
2810 | STAT_TYPE_RECV_PULL_REQ | | 2882 | STAT_TYPE_RECV_PULL_REQ | |
2811 | STAT_TYPE_RECV_PULL_REP; | 2883 | STAT_TYPE_RECV_PULL_REP; |
2812 | cur_test_run.have_collect_view = COLLECT_VIEW; | 2884 | cur_test_run.have_collect_view = COLLECT_VIEW; |
2813 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300); | 2885 | timeout_s = 150; |
2814 | 2886 | ||
2815 | /* 'Clean' directory */ | 2887 | /* 'Clean' directory */ |
2816 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); | 2888 | (void) GNUNET_DISK_directory_remove ("/tmp/rps/"); |
2817 | GNUNET_DISK_directory_create ("/tmp/rps/"); | 2889 | GNUNET_DISK_directory_create ("/tmp/rps/"); |
2818 | } | 2890 | } |
2891 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, timeout_s); | ||
2819 | 2892 | ||
2820 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); | 2893 | rps_peers = GNUNET_new_array (num_peers, struct RPSPeer); |
2821 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); | 2894 | peer_map = GNUNET_CONTAINER_multipeermap_create (num_peers, GNUNET_NO); |
@@ -2843,6 +2916,7 @@ main (int argc, char *argv[]) | |||
2843 | } | 2916 | } |
2844 | 2917 | ||
2845 | ret_value = cur_test_run.eval_cb(); | 2918 | ret_value = cur_test_run.eval_cb(); |
2919 | |||
2846 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) | 2920 | if (NO_COLLECT_VIEW == cur_test_run.have_collect_view) |
2847 | { | 2921 | { |
2848 | GNUNET_array_grow (rps_peers->cur_view, | 2922 | GNUNET_array_grow (rps_peers->cur_view, |
diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf index 0b49b4e76..84e0e5049 100644 --- a/src/rps/test_rps.conf +++ b/src/rps/test_rps.conf | |||
@@ -1,12 +1,13 @@ | |||
1 | [rps] | 1 | [rps] |
2 | #PREFIX = valgrind --leak-check=full --show-leak-kinds=all --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p | 2 | #PREFIX = valgrind --leak-check=full --show-leak-kinds=all --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p |
3 | #BINARY = gnunet-service-rps | 3 | #PREFIX = valgrind --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p |
4 | UNIXPATH = /tmp/gnunet-service-rps.sock | 4 | #PREFIX = valgrind |
5 | UNIXPATH = $GNUNET_TMP/gnunet-service-rps.sock | ||
5 | HOME = $SERVICEHOME | 6 | HOME = $SERVICEHOME |
6 | # PORT = 2106 | 7 | # PORT = 2106 |
7 | #@UNIXONLY@ PORT = 2087 | 8 | #@UNIXONLY@ PORT = 2087 |
8 | FORCESTART = YES | 9 | IMMEDIATE_START = YES |
9 | AUTOSTART = NO | 10 | START_ON_DEMAND = NO |
10 | NOARMBIND = YES | 11 | NOARMBIND = YES |
11 | #OPTIONS=-l /tmp/rps_profiler_logs/rps-[]-%Y-%m-%d.log | 12 | #OPTIONS=-l /tmp/rps_profiler_logs/rps-[]-%Y-%m-%d.log |
12 | 13 | ||
@@ -21,19 +22,26 @@ FILENAME_VALID_PEERS = $GNUNET_DATA_HOME/rps/valid_peers.txt | |||
21 | # So, 50 is enough for a network of size 50^3 = 125000 | 22 | # So, 50 is enough for a network of size 50^3 = 125000 |
22 | MINSIZE = 4 | 23 | MINSIZE = 4 |
23 | 24 | ||
25 | |||
26 | |||
24 | [testbed] | 27 | [testbed] |
25 | HOSTNAME = localhost | 28 | HOSTNAME = localhost |
26 | 29 | ||
27 | # OPERATION_TIMEOUT = 60 s | ||
28 | |||
29 | # MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 100 | 30 | # MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 100 |
30 | OVERLAY_TOPOLOGY = CLIQUE | ||
31 | #OVERLAY_TOPOLOGY = SMALL_WORLD | ||
32 | #SCALE_FREE_TOPOLOGY_CAP = | ||
33 | 31 | ||
34 | # OVERLAY_RANDOM_LINKS = 25 | 32 | #OVERLAY_TOPOLOGY = CLIQUE |
33 | |||
34 | OVERLAY_TOPOLOGY = SCALE_FREE | ||
35 | SCALE_FREE_TOPOLOGY_CAP = 100 | ||
36 | SCALE_FREE_TOPOLOGY_M = 2 | ||
35 | 37 | ||
36 | # SETUP_TIMEOUT = 2 m | 38 | #OVERLAY_TOPOLOGY = RANDOM |
39 | #OVERLAY_RANDOM_LINKS = 25 | ||
40 | |||
41 | #OVERLAY_TOPOLOGY = SMALL_WORLD | ||
42 | #OVERLAY_RANDOM_LINKS = 25 | ||
43 | |||
44 | SETUP_TIMEOUT = 2 m | ||
37 | 45 | ||
38 | [nse] | 46 | [nse] |
39 | WORKBITS = 0 | 47 | WORKBITS = 0 |
@@ -41,12 +49,13 @@ WORKBITS = 0 | |||
41 | [nat] | 49 | [nat] |
42 | # Use addresses from the local network interfaces (inluding loopback, but also others) | 50 | # Use addresses from the local network interfaces (inluding loopback, but also others) |
43 | USE_LOCALADDR = YES | 51 | USE_LOCALADDR = YES |
52 | ENABLE_UPNP = NO | ||
44 | 53 | ||
45 | # Do we use addresses from localhost address ranges? (::1, 127.0.0.0/8) | 54 | # Do we use addresses from localhost address ranges? (::1, 127.0.0.0/8) |
46 | RETURN_LOCAL_ADDRESSES = YES | 55 | RETURN_LOCAL_ADDRESSES = YES |
47 | 56 | ||
48 | [transport] | 57 | [transport] |
49 | PLUGINS = udp | 58 | PLUGINS = unix |
50 | 59 | ||
51 | [ats] | 60 | [ats] |
52 | # Network specific inbound/outbound quotas | 61 | # Network specific inbound/outbound quotas |
@@ -72,52 +81,51 @@ BLUETOOTH_QUOTA_OUT = unlimited | |||
72 | DISABLE_TRY_CONNECT = YES | 81 | DISABLE_TRY_CONNECT = YES |
73 | 82 | ||
74 | [cadet] | 83 | [cadet] |
75 | DISABLE_TRY_CONNECT = YES | ||
76 | #OPTIONS=-l /tmp/rps_profiler_logs/cadet-[]-%Y-%m-%d.log | 84 | #OPTIONS=-l /tmp/rps_profiler_logs/cadet-[]-%Y-%m-%d.log |
85 | #PREFIX = valgrind | ||
77 | 86 | ||
78 | #[arm] | 87 | #[arm] |
79 | #GLOBAL_POSTFIX=-l /tmp/rps_profiler_logs/other-[]-%Y-%m-%d.log | 88 | #GLOBAL_POSTFIX=-l /tmp/rps_profiler_logs/other-[]-%Y-%m-%d.log |
80 | 89 | ||
81 | #[statistics] | 90 | #[statistics] |
82 | #FORCESTART = NO | 91 | #IMMEDIATE_START = NO |
83 | #AUTOSTART = NO | 92 | #START_ON_DEMAND = NO |
84 | 93 | ||
85 | [peerinfo] | 94 | [peerinfo] |
86 | NO_IO = YES | 95 | NO_IO = YES |
87 | 96 | ||
88 | [hostlist] | 97 | [hostlist] |
89 | FORCESTART = NO | 98 | IMMEDIATE_START = NO |
90 | AUTOSTART = NO | 99 | START_ON_DEMAND = NO |
91 | 100 | ||
92 | [zonemaster] | 101 | [zonemaster] |
93 | FORCESTART = NO | 102 | IMMEDIATE_START = NO |
94 | AUTOSTART = NO | 103 | START_ON_DEMAND = NO |
95 | 104 | ||
96 | [namecache] | 105 | [namecache] |
97 | FORCESTART = NO | 106 | IMMEDIATE_START = NO |
98 | AUTOSTART = NO | 107 | START_ON_DEMAND = NO |
99 | 108 | ||
100 | [namestore] | 109 | [namestore] |
101 | FORCESTART = NO | 110 | IMMEDIATE_START = NO |
102 | AUTOSTART = NO | 111 | START_ON_DEMAND = NO |
103 | 112 | ||
104 | [topology] | 113 | [topology] |
105 | FORCESTART = NO | 114 | IMMEDIATE_START = NO |
106 | AUTOSTART = NO | 115 | START_ON_DEMAND = NO |
107 | 116 | ||
108 | [vpn] | 117 | [vpn] |
109 | FORCESTART = NO | 118 | IMMEDIATE_START = NO |
110 | AUTOSTART = NO | 119 | START_ON_DEMAND = NO |
111 | 120 | ||
112 | [revocation] | 121 | [revocation] |
113 | FORCESTART = NO | 122 | IMMEDIATE_START = NO |
114 | AUTOSTART = NO | 123 | START_ON_DEMAND = NO |
115 | 124 | ||
116 | [gns] | 125 | [gns] |
117 | FORCESTART = NO | 126 | IMMEDIATE_START = NO |
118 | AUTOSTART = NO | 127 | START_ON_DEMAND = NO |
119 | 128 | ||
120 | [fs] | 129 | [fs] |
121 | FORCESTART = NO | 130 | IMMEDIATE_START = NO |
122 | AUTOSTART = NO | 131 | START_ON_DEMAND = NO |
123 | |||
diff --git a/src/rps/test_rps_api.c b/src/rps/test_rps_api.c index 546d8f285..85a0ccdd0 100644 --- a/src/rps/test_rps_api.c +++ b/src/rps/test_rps_api.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file rps/test_rps_api.c | 19 | * @file rps/test_rps_api.c |
diff --git a/src/rps/test_service_rps_custommap.c b/src/rps/test_service_rps_custommap.c index f88842b79..8ce03070e 100644 --- a/src/rps/test_service_rps_custommap.c +++ b/src/rps/test_service_rps_custommap.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file rps/test_service_rps_custommap.c | 19 | * @file rps/test_service_rps_custommap.c |
diff --git a/src/rps/test_service_rps_sampler_elem.c b/src/rps/test_service_rps_sampler_elem.c index 6f515d2c2..43efc8691 100644 --- a/src/rps/test_service_rps_sampler_elem.c +++ b/src/rps/test_service_rps_sampler_elem.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file rps/test_service_rps_sampler_elem.c | 19 | * @file rps/test_service_rps_sampler_elem.c |
diff --git a/src/rps/test_service_rps_view.c b/src/rps/test_service_rps_view.c index 68d1b11d4..16cf4b832 100644 --- a/src/rps/test_service_rps_view.c +++ b/src/rps/test_service_rps_view.c | |||
@@ -2,20 +2,18 @@ | |||
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) | 3 | Copyright (C) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | it under the terms of the GNU General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
7 | by the Free Software Foundation; either version 3, or (at your | 7 | by the Free Software Foundation, either version 3 of the License, |
8 | option) any later version. | 8 | or (at your option) any later version. |
9 | 9 | ||
10 | GNUnet is distributed in the hope that it will be useful, but | 10 | GNUnet is distributed in the hope that it will be useful, but |
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 | 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 General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with GNUnet; see the file COPYING. If not, write to the | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301, USA. | ||
19 | */ | 17 | */ |
20 | /** | 18 | /** |
21 | * @file rps/test_service_rps_view.c | 19 | * @file rps/test_service_rps_view.c |