aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rps/test_rps_multipeer.c99
1 files changed, 91 insertions, 8 deletions
diff --git a/src/rps/test_rps_multipeer.c b/src/rps/test_rps_multipeer.c
index a349d4cc2..f45558a1b 100644
--- a/src/rps/test_rps_multipeer.c
+++ b/src/rps/test_rps_multipeer.c
@@ -24,7 +24,7 @@
24 * receive size pushes/pulls from each peer. Expects to wait 24 * receive size pushes/pulls from each peer. Expects to wait
25 * for one message from each peer. 25 * for one message from each peer.
26 */ 26 */
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#include <time.h>
@@ -33,12 +33,18 @@
33/** 33/**
34 * How many peers do we start? 34 * How many peers do we start?
35 */ 35 */
36#define NUM_PEERS 3 36#define NUM_PEERS 5
37 37
38/** 38/**
39 * How long do we run the test? 39 * How long do we run the test?
40 */ 40 */
41#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 120) 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;
42 48
43 49
44/** 50/**
@@ -64,6 +70,11 @@ struct RPSPeer
64static struct RPSPeer rps_peers[NUM_PEERS]; 70static struct RPSPeer rps_peers[NUM_PEERS];
65 71
66/** 72/**
73 * IDs of the peers.
74 */
75static struct GNUNET_PeerIdentity rps_peer_ids[NUM_PEERS];
76
77/**
67 * Return value from 'main'. 78 * Return value from 'main'.
68 */ 79 */
69static int ok; 80static int ok;
@@ -96,14 +107,70 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
96static void 107static void
97handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *peers) 108handle_reply (void *cls, uint64_t n, const struct GNUNET_PeerIdentity *peers)
98{ 109{
99 110 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got peer %s\n", GNUNET_i2s (peers));
100 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Got peer %s\n", GNUNET_i2s(peers));
101 111
102 ok = 0; 112 ok = 0;
103} 113}
104 114
105 115
106/** 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
125 GNUNET_RPS_request_peers (peer->rps_handle, 1, handle_reply, NULL);
126}
127
128
129/**
130 * Seed peers.
131 */
132 void
133seed_peers (void *cls,
134 const struct GNUNET_SCHEDULER_TaskContext *tc)
135{
136 unsigned int amount;
137 struct RPSPeer *peer = (struct RPSPeer *) cls;
138
139 GNUNET_assert (1 >= portion &&
140 0 < portion);
141
142 amount = portion * NUM_PEERS;
143
144 // TODO log
145
146 GNUNET_RPS_seed_ids (peer->rps_handle, amount, rps_peer_ids);
147}
148
149
150/**
151 * Get the id of peer i.
152 */
153 void
154info_cb (void *cb_cls,
155 struct GNUNET_TESTBED_Operation *op,
156 const struct GNUNET_TESTBED_PeerInformation *pinfo,
157 const char *emsg)
158{
159 unsigned int *i = (unsigned int *) cb_cls;
160
161 if (NULL == pinfo || NULL != emsg)
162 {
163 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got Error: %s\n", emsg);
164 return;
165 }
166
167 rps_peer_ids[*i] = *(pinfo->result.id);
168
169 GNUNET_free (cb_cls);
170}
171
172
173/**
107 * Callback to be called when RPS service connect operation is completed 174 * Callback to be called when RPS service connect operation is completed
108 * 175 *
109 * @param cls the callback closure from functions generating an operation 176 * @param cls the callback closure from functions generating an operation
@@ -120,6 +187,7 @@ rps_connect_complete_cb (void *cls,
120{ 187{
121 struct RPSPeer *peer = cls; 188 struct RPSPeer *peer = cls;
122 struct GNUNET_RPS_Handle *rps = ca_result; 189 struct GNUNET_RPS_Handle *rps = ca_result;
190 peer->rps_handle = rps;
123 191
124 GNUNET_assert (op == peer->op); 192 GNUNET_assert (op == peer->op);
125 if (NULL != emsg) 193 if (NULL != emsg)
@@ -133,9 +201,12 @@ rps_connect_complete_cb (void *cls,
133 } 201 }
134 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n"); 202 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started client successfully\n");
135 203
136 peer->rps_handle = rps; 204 GNUNET_RPS_request_peers (rps, 1, handle_reply, NULL);
137 GNUNET_RPS_request_peers(rps, 1, handle_reply, NULL); 205
138 GNUNET_RPS_request_peers(rps, 1, handle_reply, NULL); 206 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
207 request_peers, peer);
208 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10),
209 seed_peers, peer);
139} 210}
140 211
141 212
@@ -194,9 +265,21 @@ run (void *cls,
194 unsigned int links_failed) 265 unsigned int links_failed)
195{ 266{
196 unsigned int i; 267 unsigned int i;
268 unsigned int *tmp_i;
269
270 for ( i = 0 ; i < NUM_PEERS ; i++ )
271 {
272 tmp_i = GNUNET_new (unsigned int);
273 *tmp_i = i;
274
275 (void) GNUNET_TESTBED_peer_get_information (peers[i],
276 GNUNET_TESTBED_PIT_IDENTITY,
277 &info_cb, tmp_i);
278 }
197 279
198 GNUNET_assert (NUM_PEERS == num_peers); 280 GNUNET_assert (NUM_PEERS == num_peers);
199 for (i=0;i<num_peers;i++) 281 for (i=0;i<num_peers;i++)
282 //rps_peers[i].peer_index = i;
200 rps_peers[i].op = GNUNET_TESTBED_service_connect (&rps_peers[i], 283 rps_peers[i].op = GNUNET_TESTBED_service_connect (&rps_peers[i],
201 peers[i], 284 peers[i],
202 "rps", 285 "rps",