aboutsummaryrefslogtreecommitdiff
path: root/src/rps
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-02-22 18:47:59 +0000
committerJulius Bünger <buenger@mytum.de>2015-02-22 18:47:59 +0000
commitdb554c393137201c6a5c846eee77b0f11882b18c (patch)
treeb00b33d73202222b08062d60022f6738d01624ec /src/rps
parenta76817c408f2d8cf3b0b8619ff38f163ee882be6 (diff)
downloadgnunet-db554c393137201c6a5c846eee77b0f11882b18c.tar.gz
gnunet-db554c393137201c6a5c846eee77b0f11882b18c.zip
baseline for test with malicious peers
Diffstat (limited to 'src/rps')
-rw-r--r--src/rps/gnunet-service-rps.c67
-rw-r--r--src/rps/rps.h33
-rw-r--r--src/rps/rps_api.c28
-rw-r--r--src/rps/test_rps_malicious_1.c334
4 files changed, 453 insertions, 9 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 3d61de21b..5b564da1b 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -1205,6 +1205,7 @@ handle_peer_pull_request (void *cls,
1205 return GNUNET_OK; 1205 return GNUNET_OK;
1206} 1206}
1207 1207
1208
1208/** 1209/**
1209 * Handle PULL REPLY message from another peer. 1210 * Handle PULL REPLY message from another peer.
1210 * 1211 *
@@ -1218,9 +1219,9 @@ handle_peer_pull_request (void *cls,
1218 */ 1219 */
1219 static int 1220 static int
1220handle_peer_pull_reply (void *cls, 1221handle_peer_pull_reply (void *cls,
1221 struct GNUNET_CADET_Channel *channel, 1222 struct GNUNET_CADET_Channel *channel,
1222 void **channel_ctx, 1223 void **channel_ctx,
1223 const struct GNUNET_MessageHeader *msg) 1224 const struct GNUNET_MessageHeader *msg)
1224{ 1225{
1225 LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REPLY received\n"); 1226 LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REPLY received\n");
1226 1227
@@ -1293,6 +1294,59 @@ handle_peer_pull_reply (void *cls,
1293} 1294}
1294 1295
1295 1296
1297#if ENABLE_MALICIOUS
1298/**
1299 * Turn RPS service to act malicious.
1300 *
1301 * @param cls Closure
1302 * @param channel The channel the PUSH was received over
1303 * @param channel_ctx The context associated with this channel
1304 * @param msg The message header
1305 */
1306 static int
1307handle_peer_act_malicious (void *cls,
1308 struct GNUNET_CADET_Channel *channel,
1309 void **channel_ctx,
1310 const struct GNUNET_MessageHeader *msg)
1311{
1312 LOG (GNUNET_ERROR_TYPE_DEBUG, "PULL REPLY received\n");
1313
1314 /* Check for protocol violation */
1315 //if (sizeof (struct GNUNET_RPS_P2P_PullReplyMessage) > ntohs (msg->size))
1316 //{
1317 // GNUNET_break_op (0);
1318 // return GNUNET_SYSERR;
1319 //}
1320 //in_msg = (struct GNUNET_RPS_P2P_PullReplyMessage *) msg;
1321 //if ((ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
1322 // sizeof (struct GNUNET_PeerIdentity) != ntohl (in_msg->num_peers))
1323 //{
1324 // LOG (GNUNET_ERROR_TYPE_ERROR,
1325 // "message says it sends %" PRIu64 " peers, have space for %i peers\n",
1326 // ntohl (in_msg->num_peers),
1327 // (ntohs (msg->size) - sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) /
1328 // sizeof (struct GNUNET_PeerIdentity));
1329 // GNUNET_break_op (0);
1330 // return GNUNET_SYSERR;
1331 //}
1332
1333 //sender = (struct GNUNET_PeerIdentity *) GNUNET_CADET_channel_get_info (
1334 // (struct GNUNET_CADET_Channel *) channel, GNUNET_CADET_OPTION_PEER);
1335 // // Guess simply casting isn't the nicest way...
1336 // // FIXME wait for cadet to change this function
1337 //sender_ctx = get_peer_ctx (peer_map, sender);
1338
1339 //if (GNUNET_YES == get_peer_flag (sender_ctx, PULL_REPLY_PENDING))
1340 //{
1341 // GNUNET_break_op (0);
1342 // return GNUNET_OK;
1343 //}
1344
1345 /* Do actual logic */
1346}
1347#endif
1348
1349
1296/** 1350/**
1297 * Send out PUSHes and PULLs. 1351 * Send out PUSHes and PULLs.
1298 * 1352 *
@@ -1648,11 +1702,11 @@ peer_remove_cb (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
1648 */ 1702 */
1649static void 1703static void
1650shutdown_task (void *cls, 1704shutdown_task (void *cls,
1651 const struct GNUNET_SCHEDULER_TaskContext *tc) 1705 const struct GNUNET_SCHEDULER_TaskContext *tc)
1652{ 1706{
1653 LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n"); 1707 LOG (GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n");
1654 1708
1655 if ( NULL != do_round_task ) 1709 if (NULL != do_round_task)
1656 { 1710 {
1657 GNUNET_SCHEDULER_cancel (do_round_task); 1711 GNUNET_SCHEDULER_cancel (do_round_task);
1658 do_round_task = NULL; 1712 do_round_task = NULL;
@@ -1884,6 +1938,9 @@ run (void *cls,
1884 {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST, 1938 {&handle_peer_pull_request, GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REQUEST,
1885 sizeof (struct GNUNET_MessageHeader)}, 1939 sizeof (struct GNUNET_MessageHeader)},
1886 {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0}, 1940 {&handle_peer_pull_reply , GNUNET_MESSAGE_TYPE_RPS_PP_PULL_REPLY , 0},
1941 #if ENABLE_MALICIOUS
1942 {&handle_peer_act_malicious, GNUNET_MESSAGE_TYPE_RPS_ACT_MALICIOUS , 0},
1943 #endif
1887 {NULL, 0, 0} 1944 {NULL, 0, 0}
1888 }; 1945 };
1889 1946
diff --git a/src/rps/rps.h b/src/rps/rps.h
index 3f76326a3..9aaa19a0c 100644
--- a/src/rps/rps.h
+++ b/src/rps/rps.h
@@ -96,7 +96,7 @@ struct GNUNET_RPS_CS_ReplyMessage
96 /** 96 /**
97 * Identifyer of the message. 97 * Identifyer of the message.
98 */ 98 */
99 uint64_t n; 99 uint64_t n GNUNET_PACKED;
100 100
101 /** 101 /**
102 * Number of random peer replied 102 * Number of random peer replied
@@ -107,7 +107,7 @@ struct GNUNET_RPS_CS_ReplyMessage
107}; 107};
108 108
109/** 109/**
110 * Message from client to service with seed of peers 110 * Message from client to service with seed of peers.
111 */ 111 */
112struct GNUNET_RPS_CS_SeedMessage 112struct GNUNET_RPS_CS_SeedMessage
113{ 113{
@@ -119,7 +119,34 @@ struct GNUNET_RPS_CS_SeedMessage
119 /** 119 /**
120 * Number of peers 120 * Number of peers
121 */ 121 */
122 uint64_t num_peers; 122 uint64_t num_peers GNUNET_PACKED;
123
124 /* Followed by num_peers * GNUNET_PeerIdentity */
125};
126
127/**
128 * Message from client to service to turn service malicious.
129 */
130struct GNUNET_RPS_CS_ActMaliciousMessage
131{
132 /**
133 * Header including size and type in NBO
134 */
135 struct GNUNET_MessageHeader header;
136
137 /**
138 * Type of malicious behaviour.
139 *
140 * 0 No malicious bahaviour at all
141 * 1 Try to maximise representation
142 * 2 Try to partition the network
143 */
144 uint32_t type GNUNET_PACKED;
145
146 /**
147 * Number of peers
148 */
149 uint64_t num_peers GNUNET_PACKED;
123 150
124 /* Followed by num_peers * GNUNET_PeerIdentity */ 151 /* Followed by num_peers * GNUNET_PeerIdentity */
125}; 152};
diff --git a/src/rps/rps_api.c b/src/rps/rps_api.c
index 4879fd6e9..42102eef7 100644
--- a/src/rps/rps_api.c
+++ b/src/rps/rps_api.c
@@ -235,7 +235,8 @@ GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
235 * @param ids the ids of the peers seeded 235 * @param ids the ids of the peers seeded
236 */ 236 */
237 void 237 void
238GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n, 238GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h,
239 uint32_t n,
239 const struct GNUNET_PeerIdentity *ids) 240 const struct GNUNET_PeerIdentity *ids)
240{ 241{
241 uint32_t size_needed; 242 uint32_t size_needed;
@@ -289,6 +290,31 @@ GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
289} 290}
290 291
291 292
293#if ENABLE_MALICIOUS
294/**
295 * Turn RPS service to act malicious.
296 *
297 * @param h handle to the rps service
298 * @param type which type of malicious peer to turn to.
299 * 0 Don't act malicious at all
300 * 1 Try to maximise representation
301 * 2 Try to partition the network
302 * (isolate one peer from the rest)
303 * @param n number of @a ids
304 * @param ids the ids of the malicious peers
305 * if @type is 2 the last id is the id of the
306 * peer to be isolated from the rest
307 */
308 void
309GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
310 uint32_t type,
311 uint32_t num_peers,
312 const struct GNUNET_PeerIdentity *ids)
313{
314}
315#endif
316
317
292/** 318/**
293 * Cancle an issued request. 319 * Cancle an issued request.
294 * 320 *
diff --git a/src/rps/test_rps_malicious_1.c b/src/rps/test_rps_malicious_1.c
new file mode 100644
index 000000000..9e05e707a
--- /dev/null
+++ b/src/rps/test_rps_malicious_1.c
@@ -0,0 +1,334 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2009, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20/**
21 * @file rps/test_rps_multipeer.c
22 * @brief Testcase for the random peer sampling service. Starts
23 * a peergroup with a given number of peers, then waits to
24 * receive size pushes/pulls from each peer. Expects to wait
25 * for one message from each peer.
26 */
27#include "platform.h"
28#include "gnunet_testbed_service.h"
29#include "gnunet_rps_service.h"
30#include <time.h>
31
32
33/**
34 * How many peers do we start?
35 */
36#define NUM_PEERS 5
37
38/**
39 * How long do we run the test?
40 */
41#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
42
43
44/**
45 * Portion of malicious peers
46 */
47static double portion = .1;
48
49
50/**
51 * Information we track for each peer.
52 */
53struct RPSPeer
54{
55 /**
56 * Handle for RPS connect operation.
57 */
58 struct GNUNET_TESTBED_Operation *op;
59
60 /**
61 * Handle to RPS service.
62 */
63 struct GNUNET_RPS_Handle *rps_handle;
64};
65
66
67/**
68 * Information for all the peers.
69 */
70static struct RPSPeer rps_peers[NUM_PEERS];
71
72/**
73 * IDs of the peers.
74 */
75static struct GNUNET_PeerIdentity rps_peer_ids[NUM_PEERS];
76
77/**
78 * Return value from 'main'.
79 */
80static int ok;
81
82
83/**
84 * Task run on timeout to shut everything down.
85 */
86static void
87shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
88{
89 unsigned int i;
90
91 for (i=0;i<NUM_PEERS;i++)
92 GNUNET_TESTBED_operation_done (rps_peers[i].op);
93 GNUNET_SCHEDULER_shutdown ();
94}
95
96
97/**
98 * Callback to call when network size estimate is updated.
99 *
100 * @param cls closure
101 * @param timestamp server timestamp
102 * @param estimate the value of the current network size estimate
103 * @param std_dev standard deviation (rounded down to nearest integer)
104 * of the size estimation values seen
105 *
106 */
107static void
108handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *peers)
109{
110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got peer %s\n", GNUNET_i2s (peers));
111
112 ok = 0;
113}
114
115
116/**
117 * (Randomly) request random peers.
118 */
119 void
120request_peers (void *cls,
121 const struct GNUNET_SCHEDULER_TaskContext *tc)
122{
123 struct RPSPeer *peer = (struct RPSPeer *) cls;
124 struct GNUNET_RPS_Request_Handle *req_handle;
125
126 req_handle = GNUNET_RPS_request_peers (peer->rps_handle, 1, handle_reply, NULL);
127 GNUNET_free (req_handle);
128}
129
130
131/**
132 * Seed peers.
133 */
134 void
135seed_peers (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
136{
137 unsigned int amount;
138 struct RPSPeer *peer = (struct RPSPeer *) cls;
139 unsigned int i;
140
141 GNUNET_assert (1 >= portion
142 && 0 < portion);
143
144 amount = round (portion * NUM_PEERS);
145
146 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding peers:\n");
147 for (i = 0 ; i < amount ; i++)
148 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Seeding %u. peer: %s\n",
149 i,
150 GNUNET_i2s (&rps_peer_ids[i]));
151
152 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
153}
154
155
156/**
157 * Get the id of peer i.
158 */
159 void
160info_cb (void *cb_cls,
161 struct GNUNET_TESTBED_Operation *op,
162 const struct GNUNET_TESTBED_PeerInformation *pinfo,
163 const char *emsg)
164{
165 unsigned int *i = (unsigned int *) cb_cls;
166
167 if (NULL == pinfo || NULL != emsg)
168 {
169 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
170 return;
171 }
172
173 rps_peer_ids[*i] = *(pinfo->result.id);
174
175 GNUNET_free (cb_cls);
176}
177
178
179/**
180 * Callback to be called when RPS service connect operation is completed
181 *
182 * @param cls the callback closure from functions generating an operation
183 * @param op the operation that has been finished
184 * @param ca_result the RPS service handle returned from rps_connect_adapter
185 * @param emsg error message in case the operation has failed; will be NULL if
186 * operation has executed successfully.
187 */
188static void
189rps_connect_complete_cb (void *cls,
190 struct GNUNET_TESTBED_Operation *op,
191 void *ca_result,
192 const char *emsg)
193{
194 struct RPSPeer *peer = cls;
195 struct GNUNET_RPS_Handle *rps = ca_result;
196 struct GNUNET_RPS_Request_Handle *req_handle;
197
198 peer->rps_handle = rps;
199
200 GNUNET_assert (op == peer->op);
201 if (NULL != emsg)
202 {
203 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
204 "Failed to connect to RPS service: %s\n",
205 emsg);
206 ok = 1;
207 GNUNET_SCHEDULER_shutdown ();
208 return;
209 }
210 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
211
212 req_handle = GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL);
213 GNUNET_free (req_handle);
214
215 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
216 request_peers, peer);
217 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
218 seed_peers, peer);
219 // TODO test seeding > GNUNET_SERVER_MAX_MESSAGE_SIZE peers
220}
221
222
223/**
224 * Adapter function called to establish a connection to
225 * the RPS service.
226 *
227 * @param cls closure
228 * @param cfg configuration of the peer to connect to; will be available until
229 * GNUNET_TESTBED_operation_done() is called on the operation returned
230 * from GNUNET_TESTBED_service_connect()
231 * @return service handle to return in 'op_result', NULL on error
232 */
233static void *
234rps_connect_adapter (void *cls,
235 const struct GNUNET_CONFIGURATION_Handle *cfg)
236{
237 struct GNUNET_RPS_Handle *h;
238 uint64_t num_mal_peers;
239
240 num_mal_peers = round (portion * NUM_PEERS);
241
242 h = GNUNET_RPS_connect (cfg);
243 #if ENABLE_MALICIOUS
244 GNUNET_RPS_act_malicious (h, htonl (1), htonl (num_mal_peers), rps_peer_ids);
245 #endif
246 return h;
247}
248
249
250/**
251 * Adapter function called to destroy connection to
252 * RPS service.
253 *
254 * @param cls closure
255 * @param op_result service handle returned from the connect adapter
256 */
257static void
258rps_disconnect_adapter (void *cls,
259 void *op_result)
260{
261 struct GNUNET_RPS_Handle *h = op_result;
262 GNUNET_RPS_disconnect (h);
263}
264
265
266/**
267 * Actual "main" function for the testcase.
268 *
269 * @param cls closure
270 * @param h the run handle
271 * @param num_peers number of peers in 'peers'
272 * @param peers handle to peers run in the testbed
273 * @param links_succeeded the number of overlay link connection attempts that
274 * succeeded
275 * @param links_failed the number of overlay link connection attempts that
276 * failed
277 */
278static void
279run (void *cls,
280 struct GNUNET_TESTBED_RunHandle *h,
281 unsigned int num_peers,
282 struct GNUNET_TESTBED_Peer **peers,
283 unsigned int links_succeeded,
284 unsigned int links_failed)
285{
286 unsigned int i;
287 unsigned int *tmp_i;
288
289 for (i = 0 ; i < NUM_PEERS ; i++)
290 {
291 tmp_i = GNUNET_new (unsigned int);
292 *tmp_i = i;
293
294 (void) GNUNET_TESTBED_peer_get_information (peers[i],
295 GNUNET_TESTBED_PIT_IDENTITY,
296 &info_cb, tmp_i);
297 }
298
299 GNUNET_assert (NUM_PEERS == num_peers);
300 for (i = 0 ; i < num_peers ; i++)
301 //rps_peers[i].peer_index = i;
302 rps_peers[i].op =
303 GNUNET_TESTBED_service_connect (&rps_peers[i],
304 peers[i],
305 "rps",
306 &rps_connect_complete_cb,
307 &rps_peers[i],
308 &rps_connect_adapter,
309 &rps_disconnect_adapter,
310 &rps_peers[i]);
311 GNUNET_SCHEDULER_add_delayed (TIMEOUT, &shutdown_task, NULL);
312}
313
314
315/**
316 * Entry point for the testcase, sets up the testbed.
317 *
318 * @param argc unused
319 * @param argv unused
320 * @return 0 on success
321 */
322int
323main (int argc, char *argv[])
324{
325 ok = 1;
326 (void) GNUNET_TESTBED_test_run ("test-rps-multipeer",
327 "test_rps.conf",
328 NUM_PEERS,
329 0, NULL, NULL,
330 &run, NULL);
331 return ok;
332}
333
334/* end of test_rps_multipeer.c */