diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-12-21 18:03:30 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-12-21 18:03:30 +0000 |
commit | 49c4c6aea3a3c00fa8a7649e2abbc82a579d10a9 (patch) | |
tree | cfbcc4a57a772714e8292c09c4e4fafbb2499a30 /src/nse/gnunet-service-nse.c | |
parent | 5eddc3e06cc947cd605aec8c65ce16770d79b64e (diff) | |
download | gnunet-49c4c6aea3a3c00fa8a7649e2abbc82a579d10a9.tar.gz gnunet-49c4c6aea3a3c00fa8a7649e2abbc82a579d10a9.zip |
Added statistic reading to NSE, fixed some minor bugs
Diffstat (limited to 'src/nse/gnunet-service-nse.c')
-rw-r--r-- | src/nse/gnunet-service-nse.c | 107 |
1 files changed, 70 insertions, 37 deletions
diff --git a/src/nse/gnunet-service-nse.c b/src/nse/gnunet-service-nse.c index d37ecd941..30493851e 100644 --- a/src/nse/gnunet-service-nse.c +++ b/src/nse/gnunet-service-nse.c | |||
@@ -125,6 +125,26 @@ struct NSEPeerEntry | |||
125 | * been taken care of. | 125 | * been taken care of. |
126 | */ | 126 | */ |
127 | int previous_round; | 127 | int previous_round; |
128 | |||
129 | #if ENABLE_HISTOGRAM | ||
130 | |||
131 | /** | ||
132 | * Amount of messages received from this peer on this round. | ||
133 | */ | ||
134 | unsigned int received_messages; | ||
135 | |||
136 | /** | ||
137 | * Amount of messages transmitted to this peer on this round. | ||
138 | */ | ||
139 | unsigned int transmitted_messages; | ||
140 | |||
141 | /** | ||
142 | * Which size did we tell the peer the network is? | ||
143 | */ | ||
144 | unsigned int last_transmitted_size; | ||
145 | |||
146 | #endif | ||
147 | |||
128 | }; | 148 | }; |
129 | 149 | ||
130 | 150 | ||
@@ -593,6 +613,11 @@ transmit_ready (void *cls, size_t size, void *buf) | |||
593 | GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO); | 613 | GNUNET_STATISTICS_update (stats, "# flood messages started", 1, GNUNET_NO); |
594 | GNUNET_STATISTICS_update (stats, "# flood messages transmitted", 1, | 614 | GNUNET_STATISTICS_update (stats, "# flood messages transmitted", 1, |
595 | GNUNET_NO); | 615 | GNUNET_NO); |
616 | #if ENABLE_HISTOGRAM | ||
617 | peer_entry->transmitted_messages++; | ||
618 | peer_entry->last_transmitted_size = | ||
619 | ntohl(size_estimate_messages[idx].matching_bits); | ||
620 | #endif | ||
596 | memcpy (buf, &size_estimate_messages[idx], | 621 | memcpy (buf, &size_estimate_messages[idx], |
597 | sizeof (struct GNUNET_NSE_FloodMessage)); | 622 | sizeof (struct GNUNET_NSE_FloodMessage)); |
598 | return sizeof (struct GNUNET_NSE_FloodMessage); | 623 | return sizeof (struct GNUNET_NSE_FloodMessage); |
@@ -699,6 +724,14 @@ schedule_current_round (void *cls, const GNUNET_HashCode * key, void *value) | |||
699 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 724 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
700 | peer_entry->previous_round = GNUNET_NO; | 725 | peer_entry->previous_round = GNUNET_NO; |
701 | } | 726 | } |
727 | #if ENABLE_HISTOGRAM | ||
728 | if (peer_entry->received_messages > 1) | ||
729 | GNUNET_STATISTICS_update(stats, "# extra messages", | ||
730 | peer_entry->received_messages - 1, GNUNET_NO); | ||
731 | peer_entry->transmitted_messages = 0; | ||
732 | peer_entry->last_transmitted_size = 0; | ||
733 | peer_entry->received_messages = 0; | ||
734 | #endif | ||
702 | delay = | 735 | delay = |
703 | get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0); | 736 | get_transmit_delay ((peer_entry->previous_round == GNUNET_NO) ? -1 : 0); |
704 | peer_entry->transmit_task = | 737 | peer_entry->transmit_task = |
@@ -1012,6 +1045,12 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1012 | GNUNET_break (0); | 1045 | GNUNET_break (0); |
1013 | return GNUNET_OK; | 1046 | return GNUNET_OK; |
1014 | } | 1047 | } |
1048 | #if ENABLE_HISTOGRAM | ||
1049 | peer_entry->received_messages++; | ||
1050 | if (peer_entry->transmitted_messages > 0 && | ||
1051 | peer_entry->last_transmitted_size >= matching_bits) | ||
1052 | GNUNET_STATISTICS_update(stats, "# cross messages", 1, GNUNET_NO); | ||
1053 | #endif | ||
1015 | 1054 | ||
1016 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); | 1055 | ts = GNUNET_TIME_absolute_ntoh (incoming_flood->timestamp); |
1017 | 1056 | ||
@@ -1048,48 +1087,21 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1048 | update_network_size_estimate (); | 1087 | update_network_size_estimate (); |
1049 | return GNUNET_OK; | 1088 | return GNUNET_OK; |
1050 | } | 1089 | } |
1051 | if (matching_bits >= ntohl (size_estimate_messages[idx].matching_bits)) | ||
1052 | { | ||
1053 | /* cancel transmission from us to this peer for this round */ | ||
1054 | if (idx == estimate_index) | ||
1055 | { | ||
1056 | if (peer_entry->previous_round == GNUNET_YES) | ||
1057 | { | ||
1058 | /* cancel any activity for current round */ | ||
1059 | if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) | ||
1060 | { | ||
1061 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | ||
1062 | peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; | ||
1063 | } | ||
1064 | if (peer_entry->th != NULL) | ||
1065 | { | ||
1066 | GNUNET_CORE_notify_transmit_ready_cancel (peer_entry->th); | ||
1067 | peer_entry->th = NULL; | ||
1068 | } | ||
1069 | } | ||
1070 | } | ||
1071 | else | ||
1072 | { | ||
1073 | /* cancel previous round only */ | ||
1074 | peer_entry->previous_round = GNUNET_YES; | ||
1075 | } | ||
1076 | } | ||
1077 | if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits)) | 1090 | if (matching_bits == ntohl (size_estimate_messages[idx].matching_bits)) |
1078 | { | 1091 | { |
1079 | /* cancel transmission in the other direction, as this peer clearly has | 1092 | /* Cancel transmission in the other direction, as this peer clearly has |
1080 | up-to-date information already */ | 1093 | up-to-date information already. Even if we didn't talk to this peer in |
1094 | the previous round, we should no longer send it stale information as it | ||
1095 | told us about the current round! */ | ||
1096 | peer_entry->previous_round = GNUNET_YES; | ||
1081 | if (idx != estimate_index) | 1097 | if (idx != estimate_index) |
1082 | { | 1098 | { |
1083 | /* do not transmit information for the previous round to this peer | 1099 | /* do not transmit information for the previous round to this peer |
1084 | anymore (but allow current round) */ | 1100 | anymore (but allow current round) */ |
1085 | peer_entry->previous_round = GNUNET_YES; | ||
1086 | return GNUNET_OK; | 1101 | return GNUNET_OK; |
1087 | } | 1102 | } |
1088 | /* even if we didn't talk to this peer in the previous round, we should | 1103 | /* got up-to-date information for current round, cancel transmission to |
1089 | no longer send it stale information as it told us about the current | 1104 | * this peer altogether */ |
1090 | round! */ | ||
1091 | peer_entry->previous_round = GNUNET_YES; | ||
1092 | /* got up-to-date information for current round, cancel transmission altogether */ | ||
1093 | if (GNUNET_SCHEDULER_NO_TASK != peer_entry->transmit_task) | 1105 | if (GNUNET_SCHEDULER_NO_TASK != peer_entry->transmit_task) |
1094 | { | 1106 | { |
1095 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | 1107 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); |
@@ -1102,7 +1114,7 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1102 | } | 1114 | } |
1103 | return GNUNET_OK; | 1115 | return GNUNET_OK; |
1104 | } | 1116 | } |
1105 | if (matching_bits <= ntohl (size_estimate_messages[idx].matching_bits)) | 1117 | if (matching_bits < ntohl (size_estimate_messages[idx].matching_bits)) |
1106 | { | 1118 | { |
1107 | if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES)) | 1119 | if ((idx < estimate_index) && (peer_entry->previous_round == GNUNET_YES)) |
1108 | peer_entry->previous_round = GNUNET_NO; | 1120 | peer_entry->previous_round = GNUNET_NO; |
@@ -1125,6 +1137,28 @@ handle_p2p_size_estimate (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1125 | GNUNET_break_op (0); | 1137 | GNUNET_break_op (0); |
1126 | return GNUNET_OK; | 1138 | return GNUNET_OK; |
1127 | } | 1139 | } |
1140 | GNUNET_assert (matching_bits > | ||
1141 | ntohl (size_estimate_messages[idx].matching_bits)); | ||
1142 | /* cancel transmission from us to this peer for this round */ | ||
1143 | if (idx == estimate_index) | ||
1144 | { | ||
1145 | /* cancel any activity for current round */ | ||
1146 | if (peer_entry->transmit_task != GNUNET_SCHEDULER_NO_TASK) | ||
1147 | { | ||
1148 | GNUNET_SCHEDULER_cancel (peer_entry->transmit_task); | ||
1149 | peer_entry->transmit_task = GNUNET_SCHEDULER_NO_TASK; | ||
1150 | } | ||
1151 | if (peer_entry->th != NULL) | ||
1152 | { | ||
1153 | GNUNET_CORE_notify_transmit_ready_cancel (peer_entry->th); | ||
1154 | peer_entry->th = NULL; | ||
1155 | } | ||
1156 | } | ||
1157 | else | ||
1158 | { | ||
1159 | /* cancel previous round only */ | ||
1160 | peer_entry->previous_round = GNUNET_YES; | ||
1161 | } | ||
1128 | size_estimate_messages[idx] = *incoming_flood; | 1162 | size_estimate_messages[idx] = *incoming_flood; |
1129 | size_estimate_messages[idx].hop_count = | 1163 | size_estimate_messages[idx].hop_count = |
1130 | htonl (ntohl (incoming_flood->hop_count) + 1); | 1164 | htonl (ntohl (incoming_flood->hop_count) + 1); |
@@ -1304,8 +1338,7 @@ core_init (void *cls, struct GNUNET_CORE_Handle *server, | |||
1304 | if (GNUNET_YES == check_proof_of_work (&my_public_key, my_proof)) | 1338 | if (GNUNET_YES == check_proof_of_work (&my_public_key, my_proof)) |
1305 | { | 1339 | { |
1306 | prev_time.abs_value = | 1340 | prev_time.abs_value = |
1307 | current_timestamp.abs_value - (estimate_index - | 1341 | current_timestamp.abs_value - gnunet_nse_interval.rel_value; |
1308 | 1) * gnunet_nse_interval.rel_value; | ||
1309 | setup_flood_message (estimate_index, prev_time); | 1342 | setup_flood_message (estimate_index, prev_time); |
1310 | estimate_count++; | 1343 | estimate_count++; |
1311 | } | 1344 | } |