aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-03-25 17:17:13 +0000
committerJulius Bünger <buenger@mytum.de>2015-03-25 17:17:13 +0000
commit4ef920e458c83feb09f599c6fa8b1b3d8505cee8 (patch)
treec1ac4e565abe3a6ee02568dddd684dd2c33e7a48 /src
parenta5680e9d17a0a94cc10623f222f8c4a83b8b36f6 (diff)
downloadgnunet-4ef920e458c83feb09f599c6fa8b1b3d8505cee8.tar.gz
gnunet-4ef920e458c83feb09f599c6fa8b1b3d8505cee8.zip
-only turn portion of peers malicious
Diffstat (limited to 'src')
-rw-r--r--src/rps/test_rps_malicious_1.c99
1 files changed, 71 insertions, 28 deletions
diff --git a/src/rps/test_rps_malicious_1.c b/src/rps/test_rps_malicious_1.c
index a30607d87..50ae2ac86 100644
--- a/src/rps/test_rps_malicious_1.c
+++ b/src/rps/test_rps_malicious_1.c
@@ -27,13 +27,14 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_testbed_service.h" 28#include "gnunet_testbed_service.h"
29#include "gnunet_rps_service.h" 29#include "gnunet_rps_service.h"
30#include <time.h> 30
31#include <inttypes.h>
31 32
32 33
33/** 34/**
34 * How many peers do we start? 35 * How many peers do we start?
35 */ 36 */
36#define NUM_PEERS 5 37#define NUM_PEERS 10
37 38
38/** 39/**
39 * How long do we run the test? 40 * How long do we run the test?
@@ -53,6 +54,11 @@ static double portion = .1;
53struct RPSPeer 54struct RPSPeer
54{ 55{
55 /** 56 /**
57 * Index of the peer.
58 */
59 unsigned int index;
60
61 /**
56 * Handle for RPS connect operation. 62 * Handle for RPS connect operation.
57 */ 63 */
58 struct GNUNET_TESTBED_Operation *op; 64 struct GNUNET_TESTBED_Operation *op;
@@ -61,6 +67,11 @@ struct RPSPeer
61 * Handle to RPS service. 67 * Handle to RPS service.
62 */ 68 */
63 struct GNUNET_RPS_Handle *rps_handle; 69 struct GNUNET_RPS_Handle *rps_handle;
70
71 /**
72 * ID of the peer.
73 */
74 struct GNUNET_PeerIdentity *peer_id;
64}; 75};
65 76
66 77
@@ -162,7 +173,7 @@ info_cb (void *cb_cls,
162 const struct GNUNET_TESTBED_PeerInformation *pinfo, 173 const struct GNUNET_TESTBED_PeerInformation *pinfo,
163 const char *emsg) 174 const char *emsg)
164{ 175{
165 unsigned int *i = (unsigned int *) cb_cls; 176 unsigned int i = *((unsigned int *) cb_cls);
166 177
167 if (NULL == pinfo || NULL != emsg) 178 if (NULL == pinfo || NULL != emsg)
168 { 179 {
@@ -170,9 +181,11 @@ info_cb (void *cb_cls,
170 return; 181 return;
171 } 182 }
172 183
173 rps_peer_ids[*i] = *(pinfo->result.id);
174
175 GNUNET_free (cb_cls); 184 GNUNET_free (cb_cls);
185
186 rps_peer_ids[i] = *(pinfo->result.id);
187 rps_peers[i].peer_id = &rps_peer_ids[i];
188
176} 189}
177 190
178 191
@@ -191,31 +204,45 @@ rps_connect_complete_cb (void *cls,
191 void *ca_result, 204 void *ca_result,
192 const char *emsg) 205 const char *emsg)
193{ 206{
194 struct RPSPeer *peer = cls; 207 struct RPSPeer *rps_peer = cls;
195 struct GNUNET_RPS_Handle *rps = ca_result; 208 struct GNUNET_RPS_Handle *rps = ca_result;
196 struct GNUNET_RPS_Request_Handle *req_handle; 209 struct GNUNET_RPS_Request_Handle *req_handle;
210 uint32_t num_mal_peers;
197 211
198 peer->rps_handle = rps; 212 rps_peer->rps_handle = rps;
199 213
200 GNUNET_assert (op == peer->op); 214 GNUNET_assert (op == rps_peer->op);
201 if (NULL != emsg) 215 if (NULL != emsg)
202 { 216 {
203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 217 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
204 "Failed to connect to RPS service: %s\n", 218 "Failed to connect to RPS service: %s\n",
205 emsg); 219 emsg);
206 ok = 1; 220 ok = 1;
207 GNUNET_SCHEDULER_shutdown (); 221 GNUNET_SCHEDULER_shutdown ();
208 return; 222 return;
209 } 223 }
224
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); 225 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
211 226
227 #ifdef ENABLE_MALICIOUS
228 GNUNET_assert (1 >= portion
229 && 0 < portion);
230 num_mal_peers = round (portion * NUM_PEERS);
231
232 if (rps_peer->index >= num_mal_peers)
233 {
234 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL);
235 GNUNET_free (req_handle);
236 }
237 #else /* ENABLE_MALICIOUS */
212 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL); 238 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL);
213 GNUNET_free (req_handle); 239 GNUNET_free (req_handle);
240 #endif /* ENABLE_MALICIOUS */
214 241
215 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 242 //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
216 request_peers, peer); 243 // request_peers, peer);
217 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10), 244 //GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
218 seed_peers, peer); 245 // seed_peers, peer);
219 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers 246 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
220} 247}
221 248
@@ -235,19 +262,29 @@ rps_connect_adapter (void *cls,
235 const struct GNUNET_CONFIGURATION_Handle *cfg) 262 const struct GNUNET_CONFIGURATION_Handle *cfg)
236{ 263{
237 struct GNUNET_RPS_Handle *h; 264 struct GNUNET_RPS_Handle *h;
238 #if ENABLE_MALICIOUS 265 #ifdef ENABLE_MALICIOUS
239 uint64_t num_mal_peers; 266 uint32_t num_mal_peers;
267 struct RPSPeer *rps_peer = (struct RPSPeer *) cls;
240 #endif /* ENABLE_MALICIOUS */ 268 #endif /* ENABLE_MALICIOUS */
241 269
242 h = GNUNET_RPS_connect (cfg); 270 h = GNUNET_RPS_connect (cfg);
243 271
244 #if ENABLE_MALICIOUS 272 #ifdef ENABLE_MALICIOUS
245 GNUNET_assert (1 >= portion 273 GNUNET_assert (1 >= portion
246 && 0 < portion); 274 && 0 < portion);
247
248 num_mal_peers = round (portion * NUM_PEERS); 275 num_mal_peers = round (portion * NUM_PEERS);
249 GNUNET_RPS_act_malicious (h, htonl (1), num_mal_peers, rps_peer_ids); 276
250 #endif /* ENABLE_MALICIOUS */ 277 if (rps_peer->index < num_mal_peers)
278 {
279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
280 "%u. peer [%s] of %" PRIu32 " malicious peers turning malicious\n",
281 rps_peer->index,
282 GNUNET_i2s (rps_peer->peer_id),
283 num_mal_peers);
284
285 GNUNET_RPS_act_malicious (h, 1, num_mal_peers, rps_peer_ids);
286 #endif /* ENABLE_MALICIOUS */
287 }
251 288
252 return h; 289 return h;
253} 290}
@@ -292,6 +329,8 @@ run (void *cls,
292 unsigned int i; 329 unsigned int i;
293 unsigned int *tmp_i; 330 unsigned int *tmp_i;
294 331
332 tmp_i = GNUNET_new (unsigned int);
333
295 for (i = 0 ; i < NUM_PEERS ; i++) 334 for (i = 0 ; i < NUM_PEERS ; i++)
296 { 335 {
297 tmp_i = GNUNET_new (unsigned int); 336 tmp_i = GNUNET_new (unsigned int);
@@ -299,12 +338,15 @@ run (void *cls,
299 338
300 (void) GNUNET_TESTBED_peer_get_information (peers[i], 339 (void) GNUNET_TESTBED_peer_get_information (peers[i],
301 GNUNET_TESTBED_PIT_IDENTITY, 340 GNUNET_TESTBED_PIT_IDENTITY,
302 &info_cb, tmp_i); 341 &info_cb,
342 tmp_i);
303 } 343 }
304 344
345
305 GNUNET_assert (NUM_PEERS == num_peers); 346 GNUNET_assert (NUM_PEERS == num_peers);
306 for (i = 0 ; i < num_peers ; i++) 347 for (i = 0 ; i < num_peers ; i++)
307 //rps_peers[i].peer_index = i; 348 {
349 rps_peers[i].index = i;
308 rps_peers[i].op = 350 rps_peers[i].op =
309 GNUNET_TESTBED_service_connect (&rps_peers[i], 351 GNUNET_TESTBED_service_connect (&rps_peers[i],
310 peers[i], 352 peers[i],
@@ -314,6 +356,7 @@ run (void *cls,
314 &rps_connect_adapter, 356 &rps_connect_adapter,
315 &rps_disconnect_adapter, 357 &rps_disconnect_adapter,
316 &rps_peers[i]); 358 &rps_peers[i]);
359 }
317 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL); 360 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
318} 361}
319 362