diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-09-17 21:51:42 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-09-17 21:51:42 +0000 |
commit | e2ff8e18f5ea9e6be03f13c4482dedb6647d5e2c (patch) | |
tree | d64021bb2c3f1fc6d3d3e8b3542be581d566f4a8 /src/dht | |
parent | 25ecacf03e0da98ee59486c1dc0128e3355ff9b1 (diff) | |
download | gnunet-e2ff8e18f5ea9e6be03f13c4482dedb6647d5e2c.tar.gz gnunet-e2ff8e18f5ea9e6be03f13c4482dedb6647d5e2c.zip |
Removing trail compression message
Diffstat (limited to 'src/dht')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 292 | ||||
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 64 |
2 files changed, 64 insertions, 292 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index c328a6734..912d31fc4 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -52,13 +52,6 @@ | |||
52 | * hashing. | 52 | * hashing. |
53 | */ | 53 | */ |
54 | 54 | ||
55 | |||
56 | /** | ||
57 | * FIXME: URGENT | ||
58 | * We should have a message type like notify successor result. only when | ||
59 | * this message is being recvied by the new successor. we should schedule | ||
60 | * another round of verify successor. | ||
61 | */ | ||
62 | #define DEBUG(...) \ | 55 | #define DEBUG(...) \ |
63 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | 56 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) |
64 | 57 | ||
@@ -630,33 +623,6 @@ struct PeerAddTrailMessage | |||
630 | */ | 623 | */ |
631 | }; | 624 | }; |
632 | 625 | ||
633 | /** | ||
634 | * P2P Trail Compression Message. | ||
635 | */ | ||
636 | struct PeerTrailCompressionMessage | ||
637 | { | ||
638 | /** | ||
639 | * Type: #GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION | ||
640 | */ | ||
641 | struct GNUNET_MessageHeader header; | ||
642 | |||
643 | /** | ||
644 | * Source peer of this trail. | ||
645 | */ | ||
646 | struct GNUNET_PeerIdentity source_peer; | ||
647 | |||
648 | /** | ||
649 | * Trail from source_peer to destination_peer compressed such that | ||
650 | * new_first_friend is the first hop in the trail from source to | ||
651 | * destination. | ||
652 | */ | ||
653 | struct GNUNET_PeerIdentity new_first_friend; | ||
654 | |||
655 | /** | ||
656 | * Unique identifier of trail. | ||
657 | */ | ||
658 | struct GNUNET_HashCode trail_id; | ||
659 | }; | ||
660 | 626 | ||
661 | GNUNET_NETWORK_STRUCT_END | 627 | GNUNET_NETWORK_STRUCT_END |
662 | 628 | ||
@@ -1480,55 +1446,6 @@ GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id, | |||
1480 | process_friend_queue (target_friend); | 1446 | process_friend_queue (target_friend); |
1481 | } | 1447 | } |
1482 | 1448 | ||
1483 | /** | ||
1484 | * Construct a trail compression message and send it to target_friend. | ||
1485 | * @param source_peer Source of the trail. | ||
1486 | * @param trail_id Unique identifier of trail. | ||
1487 | * @param first_friend First hop in compressed trail to reach from source to finger | ||
1488 | * @param target_friend Next friend to get this message. | ||
1489 | */ | ||
1490 | void | ||
1491 | GDS_NEIGHBOURS_send_trail_compression (struct GNUNET_PeerIdentity source_peer, | ||
1492 | struct GNUNET_HashCode trail_id, | ||
1493 | struct GNUNET_PeerIdentity first_friend, | ||
1494 | struct FriendInfo *target_friend) | ||
1495 | { | ||
1496 | struct P2PPendingMessage *pending; | ||
1497 | struct PeerTrailCompressionMessage *tcm; | ||
1498 | size_t msize; | ||
1499 | |||
1500 | msize = sizeof (struct PeerTrailCompressionMessage); | ||
1501 | |||
1502 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | ||
1503 | { | ||
1504 | GNUNET_break (0); | ||
1505 | return; | ||
1506 | } | ||
1507 | |||
1508 | if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND) | ||
1509 | { | ||
1510 | GNUNET_STATISTICS_update (GDS_stats, | ||
1511 | gettext_noop ("# P2P messages dropped due to full queue"), | ||
1512 | 1, GNUNET_NO); | ||
1513 | } | ||
1514 | |||
1515 | pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); | ||
1516 | pending->importance = 0; /* FIXME */ | ||
1517 | pending->timeout = GNUNET_TIME_relative_to_absolute (PENDING_MESSAGE_TIMEOUT); | ||
1518 | tcm = (struct PeerTrailCompressionMessage *) &pending[1]; | ||
1519 | pending->msg = &tcm->header; | ||
1520 | tcm->header.size = htons (msize); | ||
1521 | tcm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION); | ||
1522 | tcm->source_peer = source_peer; | ||
1523 | tcm->new_first_friend = first_friend; | ||
1524 | tcm->trail_id = trail_id; | ||
1525 | |||
1526 | GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, pending); | ||
1527 | target_friend->pending_count++; | ||
1528 | process_friend_queue (target_friend); | ||
1529 | |||
1530 | } | ||
1531 | |||
1532 | 1449 | ||
1533 | /** | 1450 | /** |
1534 | * Construct a verify successor result message and send it to target_friend | 1451 | * Construct a verify successor result message and send it to target_friend |
@@ -3528,187 +3445,6 @@ remove_existing_finger (struct FingerInfo *existing_finger, | |||
3528 | return; | 3445 | return; |
3529 | } | 3446 | } |
3530 | 3447 | ||
3531 | /* | ||
3532 | * Core handle for p2p trail tear compression messages. | ||
3533 | * @param cls closure | ||
3534 | * @param message message | ||
3535 | * @param peer peer identity this notification is about | ||
3536 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | ||
3537 | */ | ||
3538 | static int | ||
3539 | handle_dht_p2p_trail_compression (void *cls, const struct GNUNET_PeerIdentity *peer, | ||
3540 | const struct GNUNET_MessageHeader *message) | ||
3541 | { | ||
3542 | const struct PeerTrailCompressionMessage *trail_compression; | ||
3543 | struct GNUNET_PeerIdentity *next_hop; | ||
3544 | struct FriendInfo *target_friend; | ||
3545 | struct GNUNET_HashCode trail_id; | ||
3546 | size_t msize; | ||
3547 | |||
3548 | msize = ntohs (message->size); | ||
3549 | |||
3550 | if (msize != sizeof (struct PeerTrailCompressionMessage)) | ||
3551 | { | ||
3552 | GNUNET_break_op (0); | ||
3553 | return GNUNET_OK; | ||
3554 | } | ||
3555 | |||
3556 | GNUNET_STATISTICS_update (GDS_stats, | ||
3557 | gettext_noop | ||
3558 | ("# Bytes received from other peers"), msize, | ||
3559 | GNUNET_NO); | ||
3560 | |||
3561 | trail_compression = (const struct PeerTrailCompressionMessage *) message; | ||
3562 | trail_id = trail_compression->trail_id; | ||
3563 | |||
3564 | /* Am I the new first friend to reach to finger of this trail. */ | ||
3565 | if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&trail_compression->new_first_friend, | ||
3566 | &my_identity))) | ||
3567 | { | ||
3568 | if (NULL == | ||
3569 | (GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
3570 | &trail_compression->source_peer))) | ||
3571 | { | ||
3572 | GNUNET_break_op(0); | ||
3573 | return GNUNET_OK; | ||
3574 | } | ||
3575 | |||
3576 | /* Update your prev hop to source of this message. */ | ||
3577 | if(GNUNET_SYSERR == | ||
3578 | (GDS_ROUTING_update_trail_prev_hop (trail_id, | ||
3579 | trail_compression->source_peer))) | ||
3580 | { | ||
3581 | GNUNET_break(0); | ||
3582 | return GNUNET_OK; | ||
3583 | } | ||
3584 | return GNUNET_OK; | ||
3585 | } | ||
3586 | |||
3587 | /* Pass the message to next hop to finally reach to new_first_friend. */ | ||
3588 | next_hop = GDS_ROUTING_get_next_hop (trail_id, GDS_ROUTING_SRC_TO_DEST); | ||
3589 | |||
3590 | if (NULL == next_hop) | ||
3591 | { | ||
3592 | GNUNET_break (0); | ||
3593 | return GNUNET_OK; | ||
3594 | } | ||
3595 | |||
3596 | if( NULL == (target_friend = | ||
3597 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop))) | ||
3598 | { | ||
3599 | GNUNET_break_op(0); | ||
3600 | return GNUNET_OK; | ||
3601 | } | ||
3602 | |||
3603 | GDS_ROUTING_remove_trail (trail_id); | ||
3604 | |||
3605 | GDS_NEIGHBOURS_send_trail_compression (trail_compression->source_peer, | ||
3606 | trail_id, | ||
3607 | trail_compression->new_first_friend, | ||
3608 | target_friend); | ||
3609 | return GNUNET_OK; | ||
3610 | } | ||
3611 | |||
3612 | |||
3613 | /** | ||
3614 | * Scan the trail to check if there is any other friend in the trail other than | ||
3615 | * first hop. If yes then shortcut the trail, send trail compression message to | ||
3616 | * peers which are no longer part of trail and send back the updated trail | ||
3617 | * and trail_length to calling function. | ||
3618 | * @param finger_identity Finger whose trail we will scan. | ||
3619 | * @param finger_trail [in, out] Trail to reach from source to finger, | ||
3620 | * @param finger_trail_length Total number of peers in original finger_trail. | ||
3621 | * @param finger_trail_id Unique identifier of the finger trail. | ||
3622 | * @return updated trail length in case we shortcut the trail, else original | ||
3623 | * trail length. | ||
3624 | */ | ||
3625 | static struct GNUNET_PeerIdentity * | ||
3626 | scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | ||
3627 | const struct GNUNET_PeerIdentity *trail, | ||
3628 | unsigned int trail_length, | ||
3629 | struct GNUNET_HashCode trail_id, | ||
3630 | int *new_trail_length) | ||
3631 | { | ||
3632 | struct FriendInfo *target_friend; | ||
3633 | struct GNUNET_PeerIdentity *new_trail; | ||
3634 | unsigned int i; | ||
3635 | |||
3636 | /* I am my own finger. */ | ||
3637 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &finger_identity)) | ||
3638 | { | ||
3639 | *new_trail_length = 0; | ||
3640 | return NULL; | ||
3641 | } | ||
3642 | |||
3643 | if (0 == trail_length) | ||
3644 | { | ||
3645 | *new_trail_length = 0; | ||
3646 | return NULL; | ||
3647 | } | ||
3648 | |||
3649 | /* If finger identity is a friend. */ | ||
3650 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &finger_identity)) | ||
3651 | { | ||
3652 | *new_trail_length = 0; | ||
3653 | |||
3654 | /* If there is trail to reach this finger/friend */ | ||
3655 | if (trail_length > 0) | ||
3656 | { | ||
3657 | /* Finger is your first friend. */ | ||
3658 | GDS_ROUTING_update_trail_next_hop (trail_id, finger_identity); | ||
3659 | GNUNET_assert (NULL != | ||
3660 | (target_friend = | ||
3661 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
3662 | &trail[0]))); | ||
3663 | |||
3664 | |||
3665 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | ||
3666 | trail_id, finger_identity, | ||
3667 | target_friend); | ||
3668 | } | ||
3669 | return NULL; | ||
3670 | } | ||
3671 | |||
3672 | /* For other cases, when its neither a friend nor my own identity.*/ | ||
3673 | for (i = trail_length - 1; i > 0; i--) | ||
3674 | { | ||
3675 | /* If the element at this index in trail is a friend. */ | ||
3676 | if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, &trail[i])) | ||
3677 | { | ||
3678 | struct FriendInfo *target_friend; | ||
3679 | int j = 0; | ||
3680 | |||
3681 | GNUNET_assert (NULL != | ||
3682 | (target_friend = | ||
3683 | GNUNET_CONTAINER_multipeermap_get (friend_peermap, | ||
3684 | &trail[0]))); | ||
3685 | GDS_ROUTING_update_trail_next_hop (trail_id, trail[i]); | ||
3686 | GDS_NEIGHBOURS_send_trail_compression (my_identity, | ||
3687 | trail_id, trail[i], | ||
3688 | target_friend); | ||
3689 | |||
3690 | |||
3691 | /* Copy the trail from index i to index (trail_length -1) into a new trail | ||
3692 | * and update new trail length */ | ||
3693 | *new_trail_length = trail_length - i; | ||
3694 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * (*new_trail_length)); | ||
3695 | while (i < trail_length) | ||
3696 | { | ||
3697 | memcpy (&new_trail[j], &trail[i], sizeof(struct GNUNET_PeerIdentity)); | ||
3698 | j++; | ||
3699 | i++; | ||
3700 | } | ||
3701 | return new_trail; | ||
3702 | } | ||
3703 | } | ||
3704 | |||
3705 | /* If we did not compress the trail, return the original trail back.*/ | ||
3706 | *new_trail_length = trail_length; | ||
3707 | new_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) * trail_length); | ||
3708 | memcpy (new_trail, trail, trail_length * sizeof (struct GNUNET_PeerIdentity)); | ||
3709 | return new_trail; | ||
3710 | } | ||
3711 | |||
3712 | 3448 | ||
3713 | /** | 3449 | /** |
3714 | * Check if there is already an entry in finger_table at finger_table_index. | 3450 | * Check if there is already an entry in finger_table at finger_table_index. |
@@ -3802,13 +3538,8 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3802 | if (GNUNET_NO == existing_finger->is_present) | 3538 | if (GNUNET_NO == existing_finger->is_present) |
3803 | { | 3539 | { |
3804 | /* Shorten the trail if possible. */ | 3540 | /* Shorten the trail if possible. */ |
3805 | updated_finger_trail_length = finger_trail_length; | 3541 | add_new_finger (finger_identity, finger_trail, |
3806 | updated_trail = scan_and_compress_trail (finger_identity, finger_trail, | 3542 | finger_trail_length, |
3807 | finger_trail_length, | ||
3808 | finger_trail_id, | ||
3809 | &updated_finger_trail_length); | ||
3810 | add_new_finger (finger_identity, updated_trail, | ||
3811 | updated_finger_trail_length, | ||
3812 | finger_trail_id, finger_table_index); | 3543 | finger_trail_id, finger_table_index); |
3813 | update_current_search_finger_index (finger_table_index); | 3544 | update_current_search_finger_index (finger_table_index); |
3814 | return; | 3545 | return; |
@@ -3826,13 +3557,8 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3826 | /* If the new finger is the closest peer. */ | 3557 | /* If the new finger is the closest peer. */ |
3827 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &closest_peer)) | 3558 | if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, &closest_peer)) |
3828 | { | 3559 | { |
3829 | updated_finger_trail_length = finger_trail_length; | ||
3830 | updated_trail = scan_and_compress_trail (finger_identity, finger_trail, | ||
3831 | updated_finger_trail_length, | ||
3832 | finger_trail_id, | ||
3833 | &updated_finger_trail_length); | ||
3834 | remove_existing_finger (existing_finger, finger_table_index); | 3560 | remove_existing_finger (existing_finger, finger_table_index); |
3835 | add_new_finger (finger_identity, updated_trail, updated_finger_trail_length, | 3561 | add_new_finger (finger_identity, finger_trail, finger_trail_length, |
3836 | finger_trail_id, finger_table_index); | 3562 | finger_trail_id, finger_table_index); |
3837 | } | 3563 | } |
3838 | else | 3564 | else |
@@ -3860,15 +3586,11 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity, | |||
3860 | { | 3586 | { |
3861 | return; | 3587 | return; |
3862 | } | 3588 | } |
3863 | updated_finger_trail_length = finger_trail_length; | 3589 | |
3864 | updated_trail = scan_and_compress_trail (finger_identity, finger_trail, | ||
3865 | finger_trail_length, | ||
3866 | finger_trail_id, | ||
3867 | &updated_finger_trail_length); | ||
3868 | /* If there is space to store more trails. */ | 3590 | /* If there is space to store more trails. */ |
3869 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) | 3591 | if (existing_finger->trails_count < MAXIMUM_TRAILS_PER_FINGER) |
3870 | add_new_trail (existing_finger, updated_trail, | 3592 | add_new_trail (existing_finger, finger_trail, |
3871 | updated_finger_trail_length, finger_trail_id); | 3593 | finger_trail_length, finger_trail_id); |
3872 | else | 3594 | else |
3873 | select_and_replace_trail (existing_finger, updated_trail, | 3595 | select_and_replace_trail (existing_finger, updated_trail, |
3874 | updated_finger_trail_length, finger_trail_id); | 3596 | updated_finger_trail_length, finger_trail_id); |
@@ -6336,8 +6058,6 @@ GDS_NEIGHBOURS_init (void) | |||
6336 | {&handle_dht_p2p_trail_setup_rejection, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION, 0}, | 6058 | {&handle_dht_p2p_trail_setup_rejection, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_SETUP_REJECTION, 0}, |
6337 | {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN, | 6059 | {&handle_dht_p2p_trail_teardown, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN, |
6338 | sizeof (struct PeerTrailTearDownMessage)}, | 6060 | sizeof (struct PeerTrailTearDownMessage)}, |
6339 | {&handle_dht_p2p_trail_compression, GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_COMPRESSION, | ||
6340 | sizeof (struct PeerTrailCompressionMessage)}, | ||
6341 | {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0}, | 6061 | {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0}, |
6342 | {&handle_dht_p2p_notify_succ_confirmation, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION, | 6062 | {&handle_dht_p2p_notify_succ_confirmation, GNUNET_MESSAGE_TYPE_XDHT_P2P_NOTIFY_SUCCESSOR_CONFIRMATION, |
6343 | sizeof (struct PeerNotifyConfirmationMessage)}, | 6063 | sizeof (struct PeerNotifyConfirmationMessage)}, |
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 27aa892fa..5fa4a105d 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -38,8 +38,15 @@ | |||
38 | /** | 38 | /** |
39 | * Number of peers which should perform a PUT out of 100 peers | 39 | * Number of peers which should perform a PUT out of 100 peers |
40 | */ | 40 | */ |
41 | #define PUT_PROBABILITY 100 | 41 | #define PUT_PROBABILITY 20 |
42 | 42 | ||
43 | #if ENABLE_MALICIOUS | ||
44 | /** | ||
45 | * Number of peers which should act as malicious peers | ||
46 | */ | ||
47 | #define MALICIOUS_PROBABILITY 50 | ||
48 | |||
49 | #endif | ||
43 | /** | 50 | /** |
44 | * Percentage of peers that should act maliciously. | 51 | * Percentage of peers that should act maliciously. |
45 | * These peers will never start PUT/GET request. | 52 | * These peers will never start PUT/GET request. |
@@ -175,8 +182,27 @@ struct ActiveContext | |||
175 | * The number of peers currently doing GET on our data | 182 | * The number of peers currently doing GET on our data |
176 | */ | 183 | */ |
177 | uint16_t nrefs; | 184 | uint16_t nrefs; |
185 | |||
186 | /** | ||
187 | * If set this peer will act maliciously. | ||
188 | */ | ||
189 | unsigned int malicious; | ||
178 | }; | 190 | }; |
179 | 191 | ||
192 | #if ENABLE_MALICIOUS | ||
193 | struct Malicious_Context | ||
194 | { | ||
195 | /** | ||
196 | * The linked peer context | ||
197 | */ | ||
198 | struct Context *ctx; | ||
199 | |||
200 | /** | ||
201 | * Handler to the DHT service | ||
202 | */ | ||
203 | struct GNUNET_DHT_Handle *dht; | ||
204 | }; | ||
205 | #endif | ||
180 | 206 | ||
181 | /** | 207 | /** |
182 | * An array of contexts. The size of this array should be equal to @a num_peers | 208 | * An array of contexts. The size of this array should be equal to @a num_peers |
@@ -188,6 +214,13 @@ static struct Context *a_ctx; | |||
188 | */ | 214 | */ |
189 | static struct ActiveContext *a_ac; | 215 | static struct ActiveContext *a_ac; |
190 | 216 | ||
217 | #if ENABLE_MALICIOUS | ||
218 | /** | ||
219 | * Array of malicious peers. | ||
220 | */ | ||
221 | static struct MaliciousContext *a_mc; | ||
222 | #endif | ||
223 | |||
191 | /** | 224 | /** |
192 | * The delay between rounds for collecting statistics | 225 | * The delay between rounds for collecting statistics |
193 | */ | 226 | */ |
@@ -1074,6 +1107,7 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1074 | 1107 | ||
1075 | 1108 | ||
1076 | #if ENABLE_MALICIOUS | 1109 | #if ENABLE_MALICIOUS |
1110 | #if 0 | ||
1077 | /** | 1111 | /** |
1078 | * Set the malicious variable in peer malicious context. | 1112 | * Set the malicious variable in peer malicious context. |
1079 | */ | 1113 | */ |
@@ -1096,6 +1130,7 @@ set_malicious() | |||
1096 | } | 1130 | } |
1097 | } | 1131 | } |
1098 | #endif | 1132 | #endif |
1133 | #endif | ||
1099 | 1134 | ||
1100 | 1135 | ||
1101 | /** | 1136 | /** |
@@ -1122,7 +1157,7 @@ service_started (void *cls, | |||
1122 | if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) | 1157 | if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) |
1123 | { | 1158 | { |
1124 | #if ENABLE_MALICIOUS | 1159 | #if ENABLE_MALICIOUS |
1125 | set_malicious(); | 1160 | //set_malicious(); |
1126 | #endif | 1161 | #endif |
1127 | 1162 | ||
1128 | DEBUG("successor_stats_task \n"); | 1163 | DEBUG("successor_stats_task \n"); |
@@ -1156,7 +1191,7 @@ test_run (void *cls, | |||
1156 | { | 1191 | { |
1157 | unsigned int cnt; | 1192 | unsigned int cnt; |
1158 | unsigned int ac_cnt; | 1193 | unsigned int ac_cnt; |
1159 | 1194 | unsigned int malicious_peers; | |
1160 | testbed_handles = peers; | 1195 | testbed_handles = peers; |
1161 | if (NULL == peers) | 1196 | if (NULL == peers) |
1162 | { | 1197 | { |
@@ -1175,6 +1210,9 @@ test_run (void *cls, | |||
1175 | return; | 1210 | return; |
1176 | } | 1211 | } |
1177 | 1212 | ||
1213 | a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); | ||
1214 | ac_cnt = 0; | ||
1215 | |||
1178 | #if ENABLE_MALICIOUS | 1216 | #if ENABLE_MALICIOUS |
1179 | 1217 | ||
1180 | if(PUT_PROBABILITY + MALICIOUS_PEERS > 100) | 1218 | if(PUT_PROBABILITY + MALICIOUS_PEERS > 100) |
@@ -1191,6 +1229,19 @@ test_run (void *cls, | |||
1191 | /* Select n_malicious peers and ensure that those are not active peers. | 1229 | /* Select n_malicious peers and ensure that those are not active peers. |
1192 | keep all malicious peer at one place, and call act malicious for all | 1230 | keep all malicious peer at one place, and call act malicious for all |
1193 | those peers. */ | 1231 | those peers. */ |
1232 | a_mc = GNUNET_malloc (n_malicious * sizeof (struct MaliciousContext)); | ||
1233 | malicious_peers = 0; | ||
1234 | |||
1235 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) | ||
1236 | { | ||
1237 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= | ||
1238 | MALICIOUS_PROBABILITY) | ||
1239 | continue; | ||
1240 | a_ac[ac_cnt].malicious = 1; | ||
1241 | a_mc[ac_cnt].ctx = &a_ctx[cnt]; | ||
1242 | malicious_peers++; | ||
1243 | } | ||
1244 | INFO ("Malicious Peers: %u\n",malicious_peers); | ||
1194 | 1245 | ||
1195 | #endif | 1246 | #endif |
1196 | 1247 | ||
@@ -1198,9 +1249,10 @@ test_run (void *cls, | |||
1198 | ac_cnt = 0; | 1249 | ac_cnt = 0; |
1199 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) | 1250 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) |
1200 | { | 1251 | { |
1201 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= | 1252 | if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= |
1202 | PUT_PROBABILITY) | 1253 | PUT_PROBABILITY) || (a_ac[ac_cnt].malicious == 1)) |
1203 | continue; | 1254 | continue; |
1255 | |||
1204 | a_ctx[cnt].ac = &a_ac[ac_cnt]; | 1256 | a_ctx[cnt].ac = &a_ac[ac_cnt]; |
1205 | a_ac[ac_cnt].ctx = &a_ctx[cnt]; | 1257 | a_ac[ac_cnt].ctx = &a_ctx[cnt]; |
1206 | ac_cnt++; | 1258 | ac_cnt++; |
@@ -1266,7 +1318,7 @@ main (int argc, char *const *argv) | |||
1266 | gettext_noop ("number of peers to start"), | 1318 | gettext_noop ("number of peers to start"), |
1267 | 1, &GNUNET_GETOPT_set_uint, &num_peers}, | 1319 | 1, &GNUNET_GETOPT_set_uint, &num_peers}, |
1268 | {'s', "searches", "COUNT", | 1320 | {'s', "searches", "COUNT", |
1269 | gettext_noop ("maximum number of times we try to search for successor circle formation (default is 1)"), | 1321 | gettext_noop ("maximum number of times we try to search for successor circle formation (0 for R5N)"), |
1270 | 1, &GNUNET_GETOPT_set_uint, &max_searches}, | 1322 | 1, &GNUNET_GETOPT_set_uint, &max_searches}, |
1271 | {'H', "hosts", "FILENAME", | 1323 | {'H', "hosts", "FILENAME", |
1272 | gettext_noop ("name of the file with the login information for the testbed"), | 1324 | gettext_noop ("name of the file with the login information for the testbed"), |