diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rps/gnunet-service-rps.c | 64 |
1 files changed, 47 insertions, 17 deletions
diff --git a/src/rps/gnunet-service-rps.c b/src/rps/gnunet-service-rps.c index 88fe5521a..14f8e26bf 100644 --- a/src/rps/gnunet-service-rps.c +++ b/src/rps/gnunet-service-rps.c | |||
@@ -403,40 +403,67 @@ in_arr (const struct GNUNET_PeerIdentity *array, | |||
403 | 403 | ||
404 | unsigned int i; | 404 | unsigned int i; |
405 | 405 | ||
406 | i = 0; | 406 | for (i = 0; i < arr_size ; i++) |
407 | while (0 != GNUNET_CRYPTO_cmp_peer_identity (&array[i], peer) && | 407 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&array[i], peer)) |
408 | i < arr_size) | 408 | return GNUNET_YES; |
409 | i++; | 409 | return GNUNET_NO; |
410 | } | ||
410 | 411 | ||
411 | if (i == arr_size) | 412 | |
412 | return GNUNET_NO; | 413 | /** |
413 | else | 414 | * Print peerlist to log. |
414 | return GNUNET_YES; | 415 | */ |
416 | void | ||
417 | print_peer_list (struct GNUNET_PeerIdentity *list, unsigned int len) | ||
418 | { | ||
419 | unsigned int i; | ||
420 | |||
421 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
422 | "Printing peer list of length %u at %p:\n", | ||
423 | len, | ||
424 | list); | ||
425 | for (i = 0 ; i < len ; i++) | ||
426 | { | ||
427 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
428 | "%u. peer: %s\n", | ||
429 | i, GNUNET_i2s (&list[i])); | ||
430 | } | ||
415 | } | 431 | } |
416 | 432 | ||
433 | |||
417 | /** | 434 | /** |
418 | * Remove peer from list. | 435 | * Remove peer from list. |
419 | */ | 436 | */ |
420 | void | 437 | void |
421 | rem_from_list (struct GNUNET_PeerIdentity *peer_list, | 438 | rem_from_list (struct GNUNET_PeerIdentity **peer_list, |
422 | unsigned int *list_size, | 439 | unsigned int *list_size, |
423 | const struct GNUNET_PeerIdentity *peer) | 440 | const struct GNUNET_PeerIdentity *peer) |
424 | { | 441 | { |
425 | unsigned int i; | 442 | unsigned int i; |
443 | struct GNUNET_PeerIdentity *tmp; | ||
444 | |||
445 | tmp = *peer_list; | ||
446 | |||
447 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
448 | "Removing peer %s from list at %p\n", | ||
449 | GNUNET_i2s (peer), | ||
450 | tmp); | ||
451 | print_peer_list (tmp, *list_size); | ||
426 | 452 | ||
427 | for ( i = 0 ; i < *list_size ; i++ ) | 453 | for ( i = 0 ; i < *list_size ; i++ ) |
428 | { | 454 | { |
429 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&peer_list[i], peer)) | 455 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&tmp[i], peer)) |
430 | { | 456 | { |
431 | if (i < *list_size -1) | 457 | if (i < *list_size -1) |
432 | { /* Not at the last entry -- shift peers left */ | 458 | { /* Not at the last entry -- shift peers left */ |
433 | memcpy (&peer_list[i], &peer_list[i +1], | 459 | memcpy (&tmp[i], &tmp[i +1], |
434 | (*list_size - i -1) * sizeof (struct GNUNET_PeerIdentity)); | 460 | ((*list_size) - i -1) * sizeof (struct GNUNET_PeerIdentity)); |
435 | } | 461 | } |
436 | /* Remove last entry (should be now useless PeerID) */ | 462 | /* Remove last entry (should be now useless PeerID) */ |
437 | GNUNET_array_grow (peer_list, *list_size, *list_size -1); | 463 | GNUNET_array_grow (tmp, *list_size, (*list_size) -1); |
438 | } | 464 | } |
439 | } | 465 | } |
466 | *peer_list = tmp; | ||
440 | } | 467 | } |
441 | 468 | ||
442 | /** | 469 | /** |
@@ -475,7 +502,9 @@ get_rand_peer_ignore_list (const struct GNUNET_PeerIdentity *peer_list, | |||
475 | 502 | ||
476 | while (in_arr (ignore_list, ignore_size, peer)) | 503 | while (in_arr (ignore_list, ignore_size, peer)) |
477 | { | 504 | { |
478 | rem_from_list (tmp_peer_list, &tmp_size, peer); | 505 | rem_from_list (&tmp_peer_list, &tmp_size, peer); |
506 | |||
507 | print_peer_list (tmp_peer_list, tmp_size); | ||
479 | 508 | ||
480 | if (0 == tmp_size) | 509 | if (0 == tmp_size) |
481 | { | 510 | { |
@@ -1081,9 +1110,10 @@ handle_peer_pull_request (void *cls, | |||
1081 | if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) | 1110 | if (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE < send_size) |
1082 | /* Compute number of peers to send | 1111 | /* Compute number of peers to send |
1083 | * If too long, simply truncate */ | 1112 | * If too long, simply truncate */ |
1084 | send_size = (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - | 1113 | send_size = |
1085 | sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / | 1114 | (GNUNET_CONSTANTS_MAX_CADET_MESSAGE_SIZE - |
1086 | sizeof (struct GNUNET_PeerIdentity); | 1115 | sizeof (struct GNUNET_RPS_P2P_PullReplyMessage)) / |
1116 | sizeof (struct GNUNET_PeerIdentity); | ||
1087 | else | 1117 | else |
1088 | send_size = gossip_list_size; | 1118 | send_size = gossip_list_size; |
1089 | 1119 | ||