aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2014-12-14 21:48:00 +0000
committerJulius Bünger <buenger@mytum.de>2014-12-14 21:48:00 +0000
commit6a74800a488adf754645249267e93e6c82d22219 (patch)
tree6e9313db06c581a88f5a440239a662d5dcfbbb6b /src
parenta8e5b09df9ce6f090ab4ecfde02fc7ab3b667c13 (diff)
downloadgnunet-6a74800a488adf754645249267e93e6c82d22219.tar.gz
gnunet-6a74800a488adf754645249267e93e6c82d22219.zip
before deleting PeerList
Signed-off-by: Julius Bünger <buenger@mytum.de>
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_rps_service.h11
-rw-r--r--src/rps/gnunet-service-rps.c440
-rw-r--r--src/rps/test_rps.conf6
3 files changed, 335 insertions, 122 deletions
diff --git a/src/include/gnunet_rps_service.h b/src/include/gnunet_rps_service.h
index dc822b8f1..3a3b2cbad 100644
--- a/src/include/gnunet_rps_service.h
+++ b/src/include/gnunet_rps_service.h
@@ -41,6 +41,12 @@ extern "C"
41 41
42typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls, uint64_t num_peers, struct GNUNET_PeerIdentity *peers); 42typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls, uint64_t num_peers, struct GNUNET_PeerIdentity *peers);
43 43
44/**
45 * Request n random peers.
46 *
47 * This is a wrapper function that makes it useless to have to
48 * (dis)connect from/to the service.
49 */
44 struct GNUNET_RPS_Request_Handle * 50 struct GNUNET_RPS_Request_Handle *
45GNUNET_RPS_request_peers_single_call (const struct GNUNET_CONFIGURATION_Handle *cfg, 51GNUNET_RPS_request_peers_single_call (const struct GNUNET_CONFIGURATION_Handle *cfg,
46 uint64_t n, 52 uint64_t n,
@@ -55,6 +61,11 @@ GNUNET_RPS_connect( const struct GNUNET_CONFIGURATION_Handle *cfg );
55 61
56/** 62/**
57 * Request n random peers. 63 * Request n random peers.
64 *
65 * This does exacly the same as GNUNET_RPS_request_peers_single_call
66 * but needs a GNUNET_RPS_Handle.
67 * This exists only for other parts of GNUnet that expect having to
68 * (dis)connect from/to a service.
58 */ 69 */
59 struct GNUNET_RPS_Request_Handle * 70 struct GNUNET_RPS_Request_Handle *
60GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint64_t n, 71GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint64_t n,
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c
index 6d96f5486..386e97190 100644
--- a/src/rps/gnunet-service-rps.c
+++ b/src/rps/gnunet-service-rps.c
@@ -44,10 +44,6 @@
44 44
45// TODO multipeerlist indep of gossiped list 45// TODO multipeerlist indep of gossiped list
46 46
47// TODO maybe wait during initialisation some time to get some peers
48// - initialise peers before proceeding
49// - Use the magic 0000 peer GNUNET_CADET_get_peers() returns
50
51// (TODO api -- possibility of getting weak random peer immideately) 47// (TODO api -- possibility of getting weak random peer immideately)
52 48
53// TODO malicious peer 49// TODO malicious peer
@@ -84,8 +80,7 @@ peer_id_cmp (const void *p1, const void *p2)
84 * functions providing (pseudo)randomness! 80 * functions providing (pseudo)randomness!
85***********************************************************************/ 81***********************************************************************/
86 82
87// TODO init list 83// TODO care about invalid input of the caller (size 0 or less...)
88// TODO grow/shrink list
89 84
90/** 85/**
91 * A sampler sampling PeerIDs. 86 * A sampler sampling PeerIDs.
@@ -109,18 +104,59 @@ struct Sampler
109 */ 104 */
110 struct GNUNET_HashCode peer_id_hash; 105 struct GNUNET_HashCode peer_id_hash;
111 106
107 /**
108 * Samplers are kept in a linked list.
109 */
110 struct Sampler *next;
111
112 /**
113 * Samplers are kept in a linked list.
114 */
115 struct Sampler *prev;
116
112}; 117};
113 118
114typedef void (* SAMPLER_deleteCB) (void *cls, struct GNUNET_PeerIdentity *id, struct GNUNET_HashCode hash); 119/**
120 * A n-tuple of samplers.
121 */
122struct Samplers
123{
124 /**
125 * Number of samplers we hold.
126 */
127 size_t size;
128
129 /**
130 * All PeerIDs in one array.
131 */
132 struct GNUNET_PeerIdentity peer_ids[];
133
134 /**
135 * The head of the DLL.
136 */
137 struct Sampler *head;
138
139 /**
140 * The tail of the DLL.
141 */
142 struct Sampler *tail;
143
144};
145
146
147typedef void (* SAMPLER_deleteCB) (void *cls, const struct GNUNET_PeerIdentity *id, struct GNUNET_HashCode hash);
115 148
116/** 149/**
117 * (Re)Initialise given Sampler with random min-wise independent function. 150 * (Re)Initialise given Sampler with random min-wise independent function.
118 * 151 *
119 * In this implementation this means choosing an auth_key for later use in 152 * In this implementation this means choosing an auth_key for later use in
120 * a hmac at random. 153 * a hmac at random.
154 *
155 * @param id pointer to the place where this sampler will store the PeerID.
156 * This will be overwritten.
121 */ 157 */
122 struct Sampler * 158 struct Sampler *
123SAMPLER_init() 159SAMPLER_init(struct GNUNET_PeerIdentity *id)
124{ 160{
125 struct Sampler *s; 161 struct Sampler *s;
126 162
@@ -131,14 +167,22 @@ SAMPLER_init()
131 &(s->auth_key.key), 167 &(s->auth_key.key),
132 GNUNET_CRYPTO_HASH_LENGTH); 168 GNUNET_CRYPTO_HASH_LENGTH);
133 169
134 s->peer_id = own_identity; // Maybe set to own PeerID. So we always have 170 //s->peer_id = GNUNET_new( struct GNUNET_PeerIdentity );
171 GNUENT_assert(NULL != id);
172 s->peer_id = id;
173 memcpy(s->peer_id, own_identity, sizeof(struct GNUNET_PeerIdentity));
174 //s->peer_id = own_identity; // Maybe set to own PeerID. So we always have
135 // a valid PeerID in the sampler. 175 // a valid PeerID in the sampler.
136 // Maybe take a PeerID as second argument. 176 // Maybe take a PeerID as second argument.
177 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: initialised with PeerID %s (at %p) \n", GNUNET_i2s(s->peer_id), s->peer_id);
137 178
138 GNUNET_CRYPTO_hmac(&s->auth_key, s->peer_id, 179 GNUNET_CRYPTO_hmac(&s->auth_key, s->peer_id,
139 sizeof(struct GNUNET_PeerIdentity), 180 sizeof(struct GNUNET_PeerIdentity),
140 &s->peer_id_hash); 181 &s->peer_id_hash);
141 182
183 s->prev = NULL;
184 s->next = NULL;
185
142 return s; 186 return s;
143} 187}
144 188
@@ -151,7 +195,7 @@ SAMPLER_init()
151 int 195 int
152hash_cmp(struct GNUNET_HashCode hash1, struct GNUNET_HashCode hash2) 196hash_cmp(struct GNUNET_HashCode hash1, struct GNUNET_HashCode hash2)
153{ 197{
154 return memcmp( (const void *) &hash1, (const void *) & hash2, sizeof(struct GNUNET_HashCode)) < 0; 198 return memcmp( (const void *) &hash1, (const void *) & hash2, sizeof(struct GNUNET_HashCode));
155} 199}
156 200
157/** 201/**
@@ -159,61 +203,106 @@ hash_cmp(struct GNUNET_HashCode hash1, struct GNUNET_HashCode hash2)
159 */ 203 */
160 static void 204 static void
161SAMPLER_next(struct Sampler *s, const struct GNUNET_PeerIdentity *id, SAMPLER_deleteCB del_cb, void *cb_cls) 205SAMPLER_next(struct Sampler *s, const struct GNUNET_PeerIdentity *id, SAMPLER_deleteCB del_cb, void *cb_cls)
206 // TODO set id in peer_ids
162{ 207{
163 struct GNUNET_HashCode other_hash; 208 struct GNUNET_HashCode other_hash;
164 209
165 GNUNET_CRYPTO_hmac(&s->auth_key, 210 if ( id == s->peer_id )
166 id, 211 {
167 sizeof(struct GNUNET_PeerIdentity), 212 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s\n",
168 &other_hash); 213 GNUNET_i2s(id));
169 214 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Have already PeerID %s\n",
170 if ( NULL == s->peer_id ) { // Or whatever is a valid way to say 215 GNUNET_i2s(s->peer_id));
171 // "we have no PeerID at the moment" 216 }
172 *s->peer_id = *id; 217 else
173 s->peer_id_hash = other_hash; 218 {
174 219 GNUNET_CRYPTO_hmac(&s->auth_key,
175 } else { 220 id,
176 221 sizeof(struct GNUNET_PeerIdentity),
177 if ( hash_cmp(other_hash, s->peer_id_hash) ) { 222 &other_hash);
178 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s; Discarding old PeerID %s\n", 223
179 GNUNET_i2s(id), GNUNET_i2s(s->peer_id)); 224 if ( NULL == s->peer_id )
180 225 { // Or whatever is a valid way to say
181 if ( NULL != del_cb ) { 226 // "we have no PeerID at the moment"
227 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s; Simply accepting (got NULL previously).\n",
228 GNUNET_i2s(id));
229 memcpy(s->peer_id, id, sizeof(struct GNUNET_PeerIdentity));
230 //s->peer_id = id;
231 s->peer_id_hash = other_hash;
232 }
233 else if ( 0 > hash_cmp(other_hash, s->peer_id_hash) )
234 {
235 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s\n",
236 GNUNET_i2s(id));
237 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Discarding old PeerID %s\n",
238 GNUNET_i2s(s->peer_id));
239
240 if ( NULL != del_cb )
241 {
242 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Removing old PeerID %s with the delete callback.\n",
243 GNUNET_i2s(s->peer_id));
182 del_cb(cb_cls, s->peer_id, s->peer_id_hash); 244 del_cb(cb_cls, s->peer_id, s->peer_id_hash);
183 } 245 }
184 *s->peer_id = *id;
185 s->peer_id_hash = other_hash;
186 246
187 } else { 247 memcpy(s->peer_id, id, sizeof(struct GNUNET_PeerIdentity));
188 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s; Keeping old PeerID %s\n", 248 //s->peer_id = id;
189 GNUNET_i2s(id), GNUNET_i2s(s->peer_id)); 249 s->peer_id_hash = other_hash;
250 }
251 else
252 {
253 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Got PeerID %s\n",
254 GNUNET_i2s(id), id);
255 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER: Keeping old PeerID %s\n",
256 GNUNET_i2s(s->peer_id), s->peer_id);
190 } 257 }
191
192 } 258 }
193} 259}
194 260
195 261
262/**
263 * Initialise a tuple of samplers.
264 */
265struct Samplers *
266SAMPLER_samplers_init(size_t init_size)
267{
268 struct Samplers *samplers;
269 struct Sampler *s;
270 uint64_t i;
271
272 samplers = GNUNET_new(struct Samplers);
273 samplers->size = init_size;
274 samplers->head = samplers->tail = NULL;
275 samplers->peer_ids = GNUNET_new_array(init_size, struct GNUNET_PeerIdentity);
276
277 for ( i = 0 ; i < init_size ; i++ )
278 {
279 GNUNET_array_append(samplers->peer_ids,
280 sizeof(struct GNUNET_PeerIdentity),
281 own_identity);
282 s = SAMPLER_init(&samplers->peer_ids[i]);
283 GNUNET_CONTAINER_DLL_insert_tail(samplers->head,
284 samplers->tail,
285 );
286 }
287 return sammplers;
288}
289
196 290
197/** 291/**
198 * A fuction to update every sampler in the given list 292 * A fuction to update every sampler in the given list
199 */ 293 */
200 static void 294 static void
201SAMPLER_update_list(struct GNUNET_CONTAINER_SList *lst, const struct GNUNET_PeerIdentity *id, 295SAMPLER_update_list(struct Samplers *samplers, const struct GNUNET_PeerIdentity *id,
202 SAMPLER_deleteCB del_cb, void *cb_cls) 296 SAMPLER_deleteCB del_cb, void *cb_cls)
203{ 297{
204 struct GNUNET_CONTAINER_SList_Iterator *iter;
205 struct Sampler *sampler; 298 struct Sampler *sampler;
206 size_t s;
207 299
208 iter = GNUNET_malloc(sizeof(struct GNUNET_CONTAINER_SList_Iterator)); 300 sampler = samplers->head;
209 *iter = GNUNET_CONTAINER_slist_begin(lst); 301 while ( NULL != sampler->next )
210 s = sizeof(struct Sampler); 302 {
211 do {
212 sampler = (struct Sampler *) GNUNET_CONTAINER_slist_get(iter, &s);
213 SAMPLER_next(sampler, id, del_cb, cb_cls); 303 SAMPLER_next(sampler, id, del_cb, cb_cls);
214 } while ( GNUNET_NO != GNUNET_CONTAINER_slist_next(iter) ); 304 }
215 305
216 GNUNET_CONTAINER_slist_iter_destroy(iter);
217} 306}
218 307
219/** 308/**
@@ -222,24 +311,23 @@ SAMPLER_update_list(struct GNUNET_CONTAINER_SList *lst, const struct GNUNET_Peer
222 * We might want to reinitialise this sampler after giving the 311 * We might want to reinitialise this sampler after giving the
223 * corrsponding peer to the client. 312 * corrsponding peer to the client.
224 */ 313 */
225 struct GNUNET_PeerIdentity* 314 const struct GNUNET_PeerIdentity*
226SAMPLER_get_rand_peer (struct GNUNET_CONTAINER_SList *lst) 315SAMPLER_get_rand_peer (struct Samplers *samplers)
227{ 316{
228 uint64_t list_size;
229
230 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER_get_rand_peer:\n"); 317 LOG(GNUNET_ERROR_TYPE_DEBUG, "SAMPLER_get_rand_peer:\n");
231 318
232 list_size = (uint64_t) GNUNET_CONTAINER_slist_count(lst); 319 if ( 0 == samplers->size )
233 320 {
234 if ( 0 == list_size ) {
235 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: List empty - Returning own PeerID %s\n", GNUNET_i2s(own_identity)); 321 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: List empty - Returning own PeerID %s\n", GNUNET_i2s(own_identity));
236 return own_identity; 322 return own_identity;
237 } else { 323 }
324 else
325 {
238 uint64_t index; 326 uint64_t index;
239 struct GNUNET_CONTAINER_SList_Iterator *iter; 327 struct Sampler *iter;
240 uint64_t i; 328 uint64_t i;
241 size_t s; 329 size_t s;
242 struct GNUNET_PeerIdentity *peer; 330 const struct GNUNET_PeerIdentity *peer;
243 331
244 /** 332 /**
245 * Choose the index of the peer we want to give back 333 * Choose the index of the peer we want to give back
@@ -251,20 +339,20 @@ SAMPLER_get_rand_peer (struct GNUNET_CONTAINER_SList *lst)
251 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: Length of Slist: %" PRIu64 ", index: %" PRIu64 "\n", list_size, index); 339 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: Length of Slist: %" PRIu64 ", index: %" PRIu64 "\n", list_size, index);
252 340
253 s = sizeof( struct Sampler ); 341 s = sizeof( struct Sampler );
254 iter = GNUNET_malloc(sizeof(struct GNUNET_CONTAINER_SList_Iterator)); 342 iter = samplers->head;
255 *iter = GNUNET_CONTAINER_slist_begin(lst); 343 for ( i = 0 ; i < index ; i++ )
256 for ( i = 0 ; i < index ; i++ ) { 344 {
257 if (GNUNET_NO == GNUNET_CONTAINER_slist_next(iter) ) { // Maybe unneeded 345 if ( NULL == iter->next )
258 *iter = GNUNET_CONTAINER_slist_begin(lst); 346 { // Maybe unneeded
347 iter = samplers->head;
259 } 348 }
260 } 349 }
261 350
262 // TODO something missing? 351 // TODO something missing?
263 352
264 // FIXME this looks wrong: 353 peer = iter->peer_id;
265 peer = ((struct Sampler *) GNUNET_CONTAINER_slist_get(iter, &s))->peer_id; 354 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: Returning PeerID %s\n", GNUNET_i2s(peer));
266 GNUNET_CONTAINER_slist_iter_destroy(iter); 355 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: (own ID: %s)\n", GNUNET_i2s(own_identity));
267 LOG(GNUNET_ERROR_TYPE_DEBUG, "Sgrp: Returning PeerID %s (own ID: %s)\n", GNUNET_i2s(peer), GNUNET_i2s(own_identity));
268 356
269 return peer; 357 return peer;
270 } 358 }
@@ -277,18 +365,18 @@ SAMPLER_get_rand_peer (struct GNUNET_CONTAINER_SList *lst)
277 * corrsponding peer to the client. 365 * corrsponding peer to the client.
278 * Random with or without consumption? 366 * Random with or without consumption?
279 */ 367 */
280 struct GNUNET_PeerIdentity** // TODO give back simple array 368 const struct GNUNET_PeerIdentity* // TODO give back simple array
281SAMPLER_get_n_rand_peers (struct GNUNET_CONTAINER_SList *lst, uint64_t n) 369SAMPLER_get_n_rand_peers (struct Samplers *samplers, uint64_t n)
282{ 370{
283 // TODO check if we have too much (distinct) sampled peers 371 // TODO check if we have too much (distinct) sampled peers
284 // If we are not ready yet maybe schedule for later 372 // If we are not ready yet maybe schedule for later
285 struct GNUNET_PeerIdentity **peers; 373 const struct GNUNET_PeerIdentity *peers;
286 uint64_t i; 374 uint64_t i;
287 375
288 peers = GNUNET_malloc(n * sizeof(struct GNUNET_PeerIdentity *)); 376 peers = GNUNET_malloc(n * sizeof(struct GNUNET_PeerIdentity));
289 377
290 for ( i = 0 ; i < n ; i++ ) { 378 for ( i = 0 ; i < n ; i++ ) {
291 peers[i] = SAMPLER_get_rand_peer(lst); 379 peers[i] = SAMPLER_get_rand_peer(samplers);
292 } 380 }
293 381
294 // TODO something else missing? 382 // TODO something else missing?
@@ -299,24 +387,52 @@ SAMPLER_get_n_rand_peers (struct GNUNET_CONTAINER_SList *lst, uint64_t n)
299 * Counts how many Samplers currently hold a given PeerID. 387 * Counts how many Samplers currently hold a given PeerID.
300 */ 388 */
301 uint64_t 389 uint64_t
302SAMPLER_count_id ( struct GNUNET_CONTAINER_SList *lst, struct GNUNET_PeerIdentity *id ) { 390SAMPLER_count_id ( struct Samplers *samplers, struct GNUNET_PeerIdentity *id )
303 size_t s; 391{
304 struct GNUNET_CONTAINER_SList_Iterator *iter; 392 struct Sampler *iter;
305 uint64_t count; 393 uint64_t count;
306 394
307 s = sizeof( struct Sampler ); 395 iter = samplers->head;
308 iter = GNUNET_new(struct GNUNET_CONTAINER_SList_Iterator);
309 *iter = GNUNET_CONTAINER_slist_begin(lst);
310 count = 0; 396 count = 0;
311 while ( GNUNET_YES == GNUNET_CONTAINER_slist_next(iter) ) { 397 while ( NULL != iter )
312 if ( peer_id_cmp( ((struct Sampler *) GNUNET_CONTAINER_slist_get(iter, &s))->peer_id, id) ) { 398 {
399 if ( peer_id_cmp( iter->peer_id, id) )
313 count++; 400 count++;
314 } 401 iter = iter->next;
315 } 402 }
316 GNUNET_CONTAINER_slist_iter_destroy(iter);
317 return count; 403 return count;
318} 404}
319 405
406/**
407 * Gow the size of the tuple of samplers.
408 */
409 void
410SAMPLER_samplers_grow (struct Samplers * samplers, size_t new_size)
411{
412 uint64_t i;
413 struct Sampler;
414
415 if ( new_size > samplers->size )
416 {
417 GNUNET_array_grow(samplers->peer_ids, samplers->size, new_size);
418 for ( i = 0 ; i < new_size - samplers-size ; i++ )
419 {
420 sampler = SAMPLER_init(&samplers->peer_ids[samplers->size + i]);
421 GNUNET_CONTAINER_DLL_insert_tail(samplers->head, samplers->tail, sampler);
422 }
423 }
424 else if ( new_size < samplers->size )
425 {
426 for ( i = 0 ; i < samplers->size - new_size ; i++)
427 {
428 // TODO call delCB on elem?
429 GNUNET_CONTAINER_DLL_remove(samplers->head, samplers->tail, samplers->tail);
430 }
431 GNUNET_array_grow(samplers->peer_ids, samplers->size, new_size);
432 }
433
434 samplers->size = new_size;
435}
320 436
321/*********************************************************************** 437/***********************************************************************
322 * /Sampler 438 * /Sampler
@@ -325,9 +441,70 @@ SAMPLER_count_id ( struct GNUNET_CONTAINER_SList *lst, struct GNUNET_PeerIdentit
325 441
326 442
327/*********************************************************************** 443/***********************************************************************
328 * Gossip list 444 * Peer list
329***********************************************************************/ 445***********************************************************************/
330 446
447/**
448 * A struct that just holds the PeerID.
449 */
450struct PeerEntry
451{
452 /**
453 * The PeerID.
454 */
455 struct GNUNET_PeerIdentity *id;
456};
457
458/**
459 * A DLL holding PeerIDs.
460 */
461struct PeerList
462{
463 /**
464 * The size of the list.
465 */
466 size_t size;
467
468 /**
469 * Array of PeerIDs.
470 */
471 struct GNUNET_PeerIdentity *peer_ids;
472
473 /**
474 * Head of the DLL.
475 */
476 struct PeerEntry *head;
477
478 /**
479 * Tail of the DLL.
480 */
481 struct PeerEntry *tail;
482};
483
484/**
485 * Give back an empty PeerList.
486 */
487 struct PeerList*
488PeerList_init()
489{
490 struct PeerList *peer_list;
491
492 peer_list = GNUNET_new(struct PeerList);
493 peer_list->size = 0;
494 peer_list->peer_ids = NULL;
495 peer_list->head = peer_list->tail = NULL;
496
497 return peer_list;
498}
499
500/**
501 * Put one PeerID into the given PeerList.
502 */
503 void
504PeerList_put(struct PeerList *peer_list, struct GNUNET_PeerIdentity *id)
505{
506}
507
331///** 508///**
332// * Get one random peer out of the gossiped peer list. 509// * Get one random peer out of the gossiped peer list.
333// */ 510// */
@@ -357,7 +534,7 @@ SAMPLER_count_id ( struct GNUNET_CONTAINER_SList *lst, struct GNUNET_PeerIdentit
357 534
358 535
359/*********************************************************************** 536/***********************************************************************
360 * /Gossip list 537 * /Peer list
361***********************************************************************/ 538***********************************************************************/
362 539
363 540
@@ -439,12 +616,17 @@ static struct GNUNET_CONTAINER_MultiPeerMap *peer_map;
439// TODO other events to grow/shrink size? 616// TODO other events to grow/shrink size?
440 617
441/** 618/**
442 * List of samplers 619 * List of samplers // TODO get rid of that
443 */ 620 */
444struct GNUNET_CONTAINER_SList *sampler_list; 621struct GNUNET_CONTAINER_SList *sampler_list;
445 622
446/** 623/**
447 * Sampler list size 624 * List of samplers.
625 */
626struct Samplers *samplers; // TODO rename to sampler_list
627
628/**
629 * Sampler list size // TODO get rid of that
448 * 630 *
449 * Adapts to the nse. Size should be in BigTheta(network_size)^(1/3). 631 * Adapts to the nse. Size should be in BigTheta(network_size)^(1/3).
450 */ 632 */
@@ -838,6 +1020,7 @@ delete_cb (void *cls, struct GNUNET_PeerIdentity *id, struct GNUNET_HashCode has
838{ 1020{
839 size_t s; 1021 size_t s;
840 1022
1023 //s = SAMPLER_count_id(samplers, id); // TODO
841 s = SAMPLER_count_id(sampler_list, id); 1024 s = SAMPLER_count_id(sampler_list, id);
842 if ( 1 >= s ) { 1025 if ( 1 >= s ) {
843 // TODO cleanup peer 1026 // TODO cleanup peer
@@ -874,27 +1057,28 @@ do_round(void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
874 /* If the NSE has changed adapt the lists accordingly */ 1057 /* If the NSE has changed adapt the lists accordingly */
875 // TODO check nse == 0! 1058 // TODO check nse == 0!
876 LOG(GNUNET_ERROR_TYPE_DEBUG, "Checking size estimate.\n"); 1059 LOG(GNUNET_ERROR_TYPE_DEBUG, "Checking size estimate.\n");
877 if ( sampler_list_size < est_size ) { 1060 SAMPLER_samplers_grow(samplers, est_size);
878 LOG(GNUNET_ERROR_TYPE_DEBUG, "Growing size.\n"); 1061 //if ( sampler_list_size < est_size ) {
879 /* Grow the lists. */ 1062 // LOG(GNUNET_ERROR_TYPE_DEBUG, "Growing size.\n");
880 for ( i = 0 ; i < est_size - sampler_list_size ; i++ ) { 1063 // /* Grow the lists. */
881 s = SAMPLER_init(); 1064 // for ( i = 0 ; i < est_size - sampler_list_size ; i++ ) {
882 GNUNET_CONTAINER_slist_add_end(sampler_list, 1065 // s = SAMPLER_init();
883 GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, // DEPRECATED 1066 // GNUNET_CONTAINER_slist_add_end(sampler_list,
884 s, 1067 // GNUNET_CONTAINER_SLIST_DISPOSITION_TRANSIENT, // DEPRECATED
885 sizeof(struct Sampler)); 1068 // s,
886 1069 // sizeof(struct Sampler));
887 // TODO add peers to gossiped ones? 1070
888 } 1071 // // TODO add peers to gossiped ones?
889 } else if ( sampler_list_size > est_size ) { 1072 // }
890 LOG(GNUNET_ERROR_TYPE_DEBUG, "Shrinking size.\n"); 1073 //} else if ( sampler_list_size > est_size ) {
891 /* Shrink the lists. */ 1074 // LOG(GNUNET_ERROR_TYPE_DEBUG, "Shrinking size.\n");
892 for ( i = 0 ; i < sampler_list_size - est_size ; i++ ) { 1075 // /* Shrink the lists. */
893 *iter = GNUNET_CONTAINER_slist_begin(sampler_list); 1076 // for ( i = 0 ; i < sampler_list_size - est_size ; i++ ) {
894 GNUNET_CONTAINER_slist_erase(iter); 1077 // *iter = GNUNET_CONTAINER_slist_begin(sampler_list);
895 GNUNET_CONTAINER_slist_iter_destroy(iter); // Maybe unneeded but I don't know whether _erase() also deletes the iter 1078 // GNUNET_CONTAINER_slist_erase(iter);
896 } 1079 // GNUNET_CONTAINER_slist_iter_destroy(iter); // Maybe unneeded but I don't know whether _erase() also deletes the iter
897 } 1080 // }
1081 //}
898 1082
899 GNUNET_array_grow(gossip_list, gossip_list_size, est_size); // FIXME Do conversion correct or change type 1083 GNUNET_array_grow(gossip_list, gossip_list_size, est_size); // FIXME Do conversion correct or change type
900 1084
@@ -1061,7 +1245,7 @@ init_peer_cb (void *cls,
1061{ 1245{
1062 // FIXME use the magic 0000 PeerID 1246 // FIXME use the magic 0000 PeerID
1063 if ( NULL != peer ) { 1247 if ( NULL != peer ) {
1064 LOG(GNUNET_ERROR_TYPE_DEBUG, "Got peer %s from CADET\n", GNUNET_i2s(peer)); 1248 LOG(GNUNET_ERROR_TYPE_DEBUG, "Got peer %s (at %p) from CADET\n", GNUNET_i2s(peer), peer);
1065 SAMPLER_update_list(sampler_list, peer, NULL, NULL); 1249 SAMPLER_update_list(sampler_list, peer, NULL, NULL);
1066 if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains( peer_map, peer ) ) { 1250 if ( GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains( peer_map, peer ) ) {
1067 } else { 1251 } else {
@@ -1099,8 +1283,23 @@ shutdown_task (void *cls,
1099{ 1283{
1100 LOG(GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n"); 1284 LOG(GNUNET_ERROR_TYPE_DEBUG, "RPS is going down\n");
1101 1285
1286 if ( GNUNET_SCHEDULER_NO_TASK != do_round_task )
1287 {
1288 GNUNET_SCHEDULER_cancel (do_round_task);
1289 do_round_task = GNUNET_SCHEDULER_NO_TASK;
1290 }
1291
1102 GNUNET_NSE_disconnect(nse); 1292 GNUNET_NSE_disconnect(nse);
1103 GNUNET_CADET_disconnect(cadet_handle); 1293 GNUNET_CADET_disconnect(cadet_handle);
1294 GNUNET_free(own_identity);
1295 //GNUNET_free(round_interval);
1296 //GNUNET_free(est_size);
1297 //GNUNET_free(gossip_list_size);
1298 //GNUNET_free(sampler_list_size);
1299 GNUNET_free(gossip_list);
1300 // TODO for i in sampler_list free sampler
1301 // TODO destroy sampler_list
1302 // TODO destroy push/pull_list
1104 // TODO delete global data 1303 // TODO delete global data
1105} 1304}
1106 1305
@@ -1225,7 +1424,9 @@ run (void *cls,
1225 1424
1226 own_identity = GNUNET_new(struct GNUNET_PeerIdentity); 1425 own_identity = GNUNET_new(struct GNUNET_PeerIdentity);
1227 1426
1228 GNUNET_CRYPTO_get_peer_identity(cfg, own_identity); 1427 GNUNET_CRYPTO_get_peer_identity(cfg, own_identity); // TODO check return value
1428
1429 LOG(GNUNET_ERROR_TYPE_DEBUG, "Own identity is %s (at %p).\n", GNUNET_i2s(own_identity), own_identity);
1229 1430
1230 1431
1231 1432
@@ -1242,7 +1443,7 @@ run (void *cls,
1242 /* Get initial size of sampler/gossip list from the configuration */ 1443 /* Get initial size of sampler/gossip list from the configuration */
1243 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "RPS", 1444 if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (cfg, "RPS",
1244 "INITSIZE", 1445 "INITSIZE",
1245 (long long unsigned int *) &est_size)) // FIXME convert 1446 (long long unsigned int *) &est_size))
1246 { 1447 {
1247 LOG(GNUNET_ERROR_TYPE_DEBUG, "Failed to read INITSIZE from config\n"); 1448 LOG(GNUNET_ERROR_TYPE_DEBUG, "Failed to read INITSIZE from config\n");
1248 GNUNET_SCHEDULER_shutdown(); 1449 GNUNET_SCHEDULER_shutdown();
@@ -1299,20 +1500,21 @@ run (void *cls,
1299 /* Initialise sampler and gossip list */ 1500 /* Initialise sampler and gossip list */
1300 struct Sampler *s; 1501 struct Sampler *s;
1301 1502
1302 sampler_list = GNUNET_CONTAINER_slist_create(); 1503 //sampler_list = GNUNET_CONTAINER_slist_create();
1504 samplers = SAMPLER_samplers_init(est_size);
1303 1505
1304 //if ( gossip_list_size == sampler_list_size ) { 1506 //if ( gossip_list_size == sampler_list_size ) {
1305 for ( i = 0 ; i < sampler_list_size ; i++ ) { 1507 // for ( i = 0 ; i < sampler_list_size ; i++ ) {
1306 /* Init sampler list */ 1508 // /* Init sampler list */
1307 s = SAMPLER_init(); 1509 // s = SAMPLER_init();
1308 GNUNET_CONTAINER_slist_add(sampler_list, 1510 // GNUNET_CONTAINER_slist_add(sampler_list,
1309 GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, // TODO DEPRECATED 1511 // GNUNET_CONTAINER_SLIST_DISPOSITION_DYNAMIC, // TODO DEPRECATED
1310 s, 1512 // s,
1311 sizeof(struct Sampler)); 1513 // sizeof(struct Sampler));
1312 /* Init gossip list */ 1514 // /* Init gossip list */
1313 // TODO init gossip list 1515 // // TODO init gossip list
1314 // What do we need to do here? 1516 // // What do we need to do here?
1315 } 1517 // }
1316 //} else { 1518 //} else {
1317 // for ( i = 0 ; i < gossip_list_size ; i++ ) { 1519 // for ( i = 0 ; i < gossip_list_size ; i++ ) {
1318 // // TODO init gossip list 1520 // // TODO init gossip list
@@ -1323,8 +1525,8 @@ run (void *cls,
1323 // // TODO init Sampled list 1525 // // TODO init Sampled list
1324 // } 1526 // }
1325 //} 1527 //}
1326 uint64_t tmp_s = (uint64_t) GNUNET_CONTAINER_slist_count(sampler_list); 1528 //uint64_t tmp_s = (uint64_t) GNUNET_CONTAINER_slist_count(sampler_list);
1327 LOG(GNUNET_ERROR_TYPE_DEBUG, "Initialised sampler list %" PRIu64 "\n", tmp_s); 1529 //LOG(GNUNET_ERROR_TYPE_DEBUG, "Initialised sampler list %" PRIu64 "\n", tmp_s);
1328 1530
1329 1531
1330 1532
diff --git a/src/rps/test_rps.conf b/src/rps/test_rps.conf
index 0a5655d53..ea683e96f 100644
--- a/src/rps/test_rps.conf
+++ b/src/rps/test_rps.conf
@@ -1,6 +1,6 @@
1[rps] 1[rps]
2AUTOSTART = YES 2AUTOSTART = YES
3PREFIX = valgrind --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p 3#PREFIX = valgrind --log-file=/tmp/rps/valgrind!gnunet-service-rps!%p
4BINARY = gnunet-service-rps 4BINARY = gnunet-service-rps
5UNIXPATH = /tmp/gnunet-service-rps.sock 5UNIXPATH = /tmp/gnunet-service-rps.sock
6HOME = $SERVICEHOME 6HOME = $SERVICEHOME
@@ -24,7 +24,7 @@ OPERATION_TIMEOUT = 60 s
24 24
25MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 1 25MAX_PARALLEL_TOPOLOGY_CONFIG_OPERATIONS = 1
26OVERLAY_TOPOLOGY = CLIQUE 26OVERLAY_TOPOLOGY = CLIQUE
27#SCALE_FREE_TOPOLOGY_CAP = 27SCALE_FREE_TOPOLOGY_CAP =
28 28
29OVERLAY_RANDOM_LINKS = 5 29OVERLAY_RANDOM_LINKS = 5
30 30
@@ -32,4 +32,4 @@ SETUP_TIMEOUT = 2 m
32 32
33 33
34[nse] 34[nse]
35WORKBITS = 0 \ No newline at end of file 35WORKBITS = 0