diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-09-22 15:12:15 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-09-22 15:12:15 +0000 |
commit | 3a85995c4a7a48f7afae1c554e9df3547ca7db3f (patch) | |
tree | bf4d46b158a973e4900e4792e80e860b324c2a0a /src/dht/gnunet_dht_profiler.c | |
parent | b97fc3b79ac05184f0928af8071e76dcbd8f99ea (diff) | |
download | gnunet-3a85995c4a7a48f7afae1c554e9df3547ca7db3f.tar.gz gnunet-3a85995c4a7a48f7afae1c554e9df3547ca7db3f.zip |
- Act malicious API complete
- Using multiple trails in PUT/GET
Diffstat (limited to 'src/dht/gnunet_dht_profiler.c')
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 327 |
1 files changed, 214 insertions, 113 deletions
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 5fa4a105d..592e31bfe 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -38,21 +38,20 @@ | |||
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 20 | 41 | #define PUT_PROBABILITY 50 |
42 | 42 | ||
43 | #if ENABLE_MALICIOUS | 43 | #if ENABLE_MALICIOUS |
44 | /** | 44 | /** |
45 | * Number of peers which should act as malicious peers | 45 | * Number of peers which should act as malicious peers |
46 | */ | 46 | */ |
47 | #define MALICIOUS_PROBABILITY 50 | 47 | #define MALICIOUS_PROBABILITY 20 |
48 | 48 | ||
49 | #endif | ||
50 | /** | 49 | /** |
51 | * Percentage of peers that should act maliciously. | 50 | * Context for a peer which should act maliciously. |
52 | * These peers will never start PUT/GET request. | ||
53 | * n_active and n_malicious should not intersect. | ||
54 | */ | 51 | */ |
55 | #define MALICIOUS_PEERS 0 | 52 | struct MaliciousContext; |
53 | #endif | ||
54 | |||
56 | 55 | ||
57 | /** | 56 | /** |
58 | * Configuration | 57 | * Configuration |
@@ -70,16 +69,10 @@ static char *hosts_file; | |||
70 | struct ActiveContext; | 69 | struct ActiveContext; |
71 | 70 | ||
72 | /** | 71 | /** |
73 | * Context for a peer which should act maliciously. | ||
74 | */ | ||
75 | struct MaliciousContext; | ||
76 | |||
77 | /** | ||
78 | * Context to hold data of peer | 72 | * Context to hold data of peer |
79 | */ | 73 | */ |
80 | struct Context | 74 | struct Context |
81 | { | 75 | { |
82 | |||
83 | /** | 76 | /** |
84 | * The testbed peer this context belongs to | 77 | * The testbed peer this context belongs to |
85 | */ | 78 | */ |
@@ -119,6 +112,11 @@ struct MaliciousContext | |||
119 | * Handler to the DHT service | 112 | * Handler to the DHT service |
120 | */ | 113 | */ |
121 | struct GNUNET_DHT_Handle *dht; | 114 | struct GNUNET_DHT_Handle *dht; |
115 | |||
116 | /** | ||
117 | * Handler to malicious api | ||
118 | */ | ||
119 | struct GNUNET_DHT_ActMaliciousHandle *dht_malicious; | ||
122 | }; | 120 | }; |
123 | 121 | ||
124 | /** | 122 | /** |
@@ -126,6 +124,32 @@ struct MaliciousContext | |||
126 | */ | 124 | */ |
127 | struct Context **malicious_peer_contexts = NULL; | 125 | struct Context **malicious_peer_contexts = NULL; |
128 | 126 | ||
127 | /** | ||
128 | * Context for a peer which should act maliciously. | ||
129 | */ | ||
130 | struct Malicious_Context | ||
131 | { | ||
132 | /** | ||
133 | * The linked peer context | ||
134 | */ | ||
135 | struct Context *ctx; | ||
136 | |||
137 | /** | ||
138 | * Handler to the DHT service | ||
139 | */ | ||
140 | struct GNUNET_DHT_Handle *dht; | ||
141 | }; | ||
142 | |||
143 | /** | ||
144 | * Array of malicious peers. | ||
145 | */ | ||
146 | static struct MaliciousContext *a_mc; | ||
147 | |||
148 | /** | ||
149 | * Number or malicious peers. | ||
150 | */ | ||
151 | static unsigned int n_malicious; | ||
152 | |||
129 | #endif | 153 | #endif |
130 | 154 | ||
131 | /** | 155 | /** |
@@ -182,27 +206,8 @@ struct ActiveContext | |||
182 | * The number of peers currently doing GET on our data | 206 | * The number of peers currently doing GET on our data |
183 | */ | 207 | */ |
184 | uint16_t nrefs; | 208 | uint16_t nrefs; |
185 | |||
186 | /** | ||
187 | * If set this peer will act maliciously. | ||
188 | */ | ||
189 | unsigned int malicious; | ||
190 | }; | 209 | }; |
191 | 210 | ||
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 | ||
206 | 211 | ||
207 | /** | 212 | /** |
208 | * An array of contexts. The size of this array should be equal to @a num_peers | 213 | * An array of contexts. The size of this array should be equal to @a num_peers |
@@ -214,13 +219,6 @@ static struct Context *a_ctx; | |||
214 | */ | 219 | */ |
215 | static struct ActiveContext *a_ac; | 220 | static struct ActiveContext *a_ac; |
216 | 221 | ||
217 | #if ENABLE_MALICIOUS | ||
218 | /** | ||
219 | * Array of malicious peers. | ||
220 | */ | ||
221 | static struct MaliciousContext *a_mc; | ||
222 | #endif | ||
223 | |||
224 | /** | 222 | /** |
225 | * The delay between rounds for collecting statistics | 223 | * The delay between rounds for collecting statistics |
226 | */ | 224 | */ |
@@ -246,13 +244,6 @@ static struct GNUNET_TIME_Relative timeout; | |||
246 | */ | 244 | */ |
247 | static unsigned int num_peers; | 245 | static unsigned int num_peers; |
248 | 246 | ||
249 | #if ENABLE_MALICIOUS | ||
250 | /** | ||
251 | * Number or malicious peers. | ||
252 | */ | ||
253 | static unsigned int n_malicious; | ||
254 | #endif | ||
255 | |||
256 | /** | 247 | /** |
257 | * Number of active peers | 248 | * Number of active peers |
258 | */ | 249 | */ |
@@ -411,6 +402,11 @@ static enum | |||
411 | static int in_shutdown = 0; | 402 | static int in_shutdown = 0; |
412 | 403 | ||
413 | /** | 404 | /** |
405 | * Total number of times to check if circle is formed or not. | ||
406 | */ | ||
407 | static unsigned int tries; | ||
408 | |||
409 | /** | ||
414 | * Task that collects successor statistics from all the peers. | 410 | * Task that collects successor statistics from all the peers. |
415 | * @param cls | 411 | * @param cls |
416 | * @param tc | 412 | * @param tc |
@@ -419,6 +415,12 @@ static void | |||
419 | collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 415 | collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
420 | 416 | ||
421 | /** | 417 | /** |
418 | * Connect to DHT services of active peers | ||
419 | */ | ||
420 | static void | ||
421 | start_profiling(); | ||
422 | |||
423 | /** | ||
422 | * Shutdown task. Cleanup all resources and operations. | 424 | * Shutdown task. Cleanup all resources and operations. |
423 | * | 425 | * |
424 | * @param cls NULL | 426 | * @param cls NULL |
@@ -823,18 +825,12 @@ static void * | |||
823 | dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) | 825 | dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) |
824 | { | 826 | { |
825 | n_dht++; | 827 | n_dht++; |
828 | DEBUG("\n Inside dht_connect , n_dht = %u",n_dht); | ||
826 | return GNUNET_DHT_connect (cfg, 10); | 829 | return GNUNET_DHT_connect (cfg, 10); |
827 | } | 830 | } |
828 | 831 | ||
829 | 832 | ||
830 | /** | 833 | /** |
831 | * Connect to DHT services of active peers | ||
832 | */ | ||
833 | static void | ||
834 | start_profiling(); | ||
835 | |||
836 | |||
837 | /** | ||
838 | * Adapter function called to destroy a connection to | 834 | * Adapter function called to destroy a connection to |
839 | * a service. | 835 | * a service. |
840 | * | 836 | * |
@@ -872,7 +868,6 @@ dht_disconnect (void *cls, void *op_result) | |||
872 | } | 868 | } |
873 | } | 869 | } |
874 | 870 | ||
875 | |||
876 | /** | 871 | /** |
877 | * Connect to DHT services of active peers | 872 | * Connect to DHT services of active peers |
878 | */ | 873 | */ |
@@ -881,7 +876,7 @@ start_profiling() | |||
881 | { | 876 | { |
882 | struct Context *ctx; | 877 | struct Context *ctx; |
883 | unsigned int i; | 878 | unsigned int i; |
884 | 879 | ||
885 | DEBUG("GNUNET_TESTBED_service_connect \n"); | 880 | DEBUG("GNUNET_TESTBED_service_connect \n"); |
886 | GNUNET_break (GNUNET_YES != in_shutdown); | 881 | GNUNET_break (GNUNET_YES != in_shutdown); |
887 | for(i = 0; i < n_active; i++) | 882 | for(i = 0; i < n_active; i++) |
@@ -900,18 +895,157 @@ start_profiling() | |||
900 | } | 895 | } |
901 | } | 896 | } |
902 | 897 | ||
898 | #if ENABLE_MALICIOUS | ||
899 | /** | ||
900 | * Count of total number of malicious peers. | ||
901 | */ | ||
902 | static unsigned int count_malicious; | ||
903 | |||
904 | /** | ||
905 | * Continuation of GNUNET_DHT_act_malicious | ||
906 | * @param cls Malicious context | ||
907 | * @param success #GNUNET_OK if the ACT_MALICIOUS was transmitted, | ||
908 | * #GNUNET_NO on timeout, | ||
909 | * #GNUNET_SYSERR on disconnect from service | ||
910 | * after the ACT_MALICIOUS message was transmitted | ||
911 | * (so we don't know if it was received or not) | ||
912 | */ | ||
913 | static void | ||
914 | act_malicious_cont (void *cls, int success) | ||
915 | { | ||
916 | struct MaliciousContext *mc = cls; | ||
917 | struct Context *ctx = mc->ctx; | ||
918 | |||
919 | GNUNET_TESTBED_operation_done (ctx->op); | ||
920 | ctx->op = NULL; | ||
921 | return; | ||
922 | } | ||
923 | |||
924 | |||
925 | /** | ||
926 | * Call malicious API for all the malicious peers. | ||
927 | * @param cls the malicious context. | ||
928 | * @param op the operation that has been finished | ||
929 | * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter() | ||
930 | * @param emsg error message in case the operation has failed; will be NULL if | ||
931 | * operation has executed successfully. | ||
932 | */ | ||
933 | void | ||
934 | dht_set_malicious(void *cls, | ||
935 | struct GNUNET_TESTBED_Operation *op, | ||
936 | void *ca_result, | ||
937 | const char *emsg) | ||
938 | { | ||
939 | struct MaliciousContext *mc = cls; | ||
940 | struct Context *ctx = mc->ctx; | ||
941 | |||
942 | GNUNET_assert (NULL != ctx); | ||
943 | GNUNET_assert (NULL != ctx->op); | ||
944 | GNUNET_assert (ctx->op == op); | ||
945 | mc->dht = (struct GNUNET_DHT_Handle *) ca_result; | ||
946 | if (NULL != emsg) | ||
947 | { | ||
948 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: %s\n", emsg); | ||
949 | GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect_malicious() */ | ||
950 | ctx->op = NULL; | ||
951 | return; | ||
952 | } | ||
953 | mc->dht_malicious = GNUNET_DHT_act_malicious(mc->dht, 1, act_malicious_cont, mc); | ||
954 | } | ||
955 | |||
956 | |||
957 | /** | ||
958 | * Adapter function called to destroy a connection to | ||
959 | * a service. | ||
960 | * | ||
961 | * @param cls the active context | ||
962 | * @param op_result service handle returned from the connect adapter | ||
963 | */ | ||
964 | static void | ||
965 | dht_disconnect_malicious (void *cls, void *op_result) | ||
966 | { | ||
967 | struct MaliciousContext *mc = cls; | ||
968 | count_malicious++; | ||
969 | GNUNET_assert (NULL != mc->dht); | ||
970 | GNUNET_assert (mc->dht == op_result); | ||
971 | GNUNET_DHT_disconnect (mc->dht); | ||
972 | mc->dht = NULL; | ||
973 | mc->ctx->op = NULL; | ||
974 | n_dht--; | ||
975 | |||
976 | if (0 != n_dht) | ||
977 | return; | ||
978 | |||
979 | if(n_malicious == count_malicious) | ||
980 | { | ||
981 | DEBUG("\n Call start_profiling()"); | ||
982 | start_profiling(); | ||
983 | } | ||
984 | } | ||
985 | |||
986 | |||
987 | /** | ||
988 | * Set the malicious variable in peer malicious context. | ||
989 | */ | ||
990 | static void | ||
991 | set_malicious() | ||
992 | { | ||
993 | unsigned int i; | ||
994 | DEBUG ("Setting %u peers malicious",n_malicious); | ||
995 | |||
996 | for(i = 0; i < n_malicious; i++) | ||
997 | { | ||
998 | DEBUG("\n Inside loop , i = %u",i); | ||
999 | struct MaliciousContext *mc = &a_mc[i]; | ||
1000 | mc->ctx->op = | ||
1001 | GNUNET_TESTBED_service_connect (mc->ctx, | ||
1002 | mc->ctx->peer, | ||
1003 | "dht", | ||
1004 | &dht_set_malicious, mc, | ||
1005 | &dht_connect, | ||
1006 | &dht_disconnect_malicious, | ||
1007 | mc); | ||
1008 | } | ||
1009 | } | ||
1010 | |||
1011 | #endif | ||
1012 | |||
1013 | |||
1014 | /** | ||
1015 | * Start collecting relevant statistics. If ENABLE_MALICIOUS set, first | ||
1016 | * set the malicious peers. If not, then start with PUT operation on active | ||
1017 | * peers. | ||
1018 | */ | ||
1019 | static void | ||
1020 | start_func() | ||
1021 | { | ||
1022 | #if ENABLE_MALICIOUS | ||
1023 | set_malicious(); | ||
1024 | return; | ||
1025 | #endif | ||
1026 | start_profiling(); | ||
1027 | } | ||
1028 | |||
1029 | |||
1030 | /** | ||
1031 | * Remove entry from successor peer hashmap. | ||
1032 | * @param cls closure | ||
1033 | * @param key current public key | ||
1034 | * @param value value in the hash map | ||
1035 | * @return #GNUNET_YES if we should continue to iterate, | ||
1036 | * #GNUNET_NO if not. | ||
1037 | */ | ||
903 | static int | 1038 | static int |
904 | hashmap_iterate_remove(void *cls, | 1039 | hashmap_iterate_remove(void *cls, |
905 | const struct GNUNET_HashCode *key, | 1040 | const struct GNUNET_HashCode *key, |
906 | void *value) | 1041 | void *value) |
907 | { | 1042 | { |
908 | GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, key, value)); | 1043 | GNUNET_assert (GNUNET_YES == |
1044 | GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, key, value)); | ||
909 | return GNUNET_YES; | 1045 | return GNUNET_YES; |
910 | } | 1046 | } |
911 | 1047 | ||
912 | 1048 | ||
913 | static unsigned int tries; | ||
914 | |||
915 | /** | 1049 | /** |
916 | * Stats callback. Iterate over the hashmap and check if all th peers form | 1050 | * Stats callback. Iterate over the hashmap and check if all th peers form |
917 | * a virtual ring topology. | 1051 | * a virtual ring topology. |
@@ -931,20 +1065,21 @@ successor_stats_cont (void *cls, | |||
931 | struct GNUNET_HashCode *key; | 1065 | struct GNUNET_HashCode *key; |
932 | int count; | 1066 | int count; |
933 | 1067 | ||
934 | |||
935 | /* Don't schedule the task till we are looking for circle here. */ | 1068 | /* Don't schedule the task till we are looking for circle here. */ |
936 | successor_stats_task = GNUNET_SCHEDULER_NO_TASK; | 1069 | successor_stats_task = GNUNET_SCHEDULER_NO_TASK; |
937 | GNUNET_TESTBED_operation_done (successor_stats_op); | 1070 | GNUNET_TESTBED_operation_done (successor_stats_op); |
938 | successor_stats_op = NULL; | 1071 | successor_stats_op = NULL; |
939 | if (0 == max_searches) | 1072 | if (0 == max_searches) |
940 | { | 1073 | { |
941 | start_profiling(); | 1074 | start_func(); |
942 | return; | 1075 | return; |
943 | } | 1076 | } |
1077 | |||
1078 | GNUNET_assert (NULL != start_key); | ||
944 | start_val = | 1079 | start_val = |
945 | (struct GNUNET_HashCode *) GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap, | 1080 | (struct GNUNET_HashCode *) GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap, |
946 | start_key); | 1081 | start_key); |
947 | 1082 | ||
948 | val = start_val; | 1083 | val = start_val; |
949 | for (count = 0; count < num_peers; count++) | 1084 | for (count = 0; count < num_peers; count++) |
950 | { | 1085 | { |
@@ -977,16 +1112,13 @@ successor_stats_cont (void *cls, | |||
977 | 1112 | ||
978 | successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, | 1113 | successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, |
979 | GNUNET_NO); | 1114 | GNUNET_NO); |
980 | //TODO:Check if comparison is correct. | ||
981 | if ((start_val == val) && (count == num_peers)) | 1115 | if ((start_val == val) && (count == num_peers)) |
982 | { | 1116 | { |
983 | DEBUG("CIRCLE COMPLETED after %u tries", tries); | 1117 | DEBUG("CIRCLE COMPLETED after %u tries", tries); |
984 | //FIXME: FREE HASHMAP. | ||
985 | //FIXME: If circle is done, then check that finger table of all the peers | ||
986 | //are fill atleast O(log N) and then start with the experiments. | ||
987 | if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) | 1118 | if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) |
988 | start_profiling(); | 1119 | { |
989 | 1120 | start_func(); | |
1121 | } | ||
990 | return; | 1122 | return; |
991 | } | 1123 | } |
992 | else | 1124 | else |
@@ -995,7 +1127,7 @@ successor_stats_cont (void *cls, | |||
995 | { | 1127 | { |
996 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1128 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
997 | "Maximum tries %u exceeded while checking successor TOTAL TRIES %u" | 1129 | "Maximum tries %u exceeded while checking successor TOTAL TRIES %u" |
998 | " cirle formation. Exiting\n", | 1130 | " circle formation. Exiting\n", |
999 | max_searches,tries); | 1131 | max_searches,tries); |
1000 | if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task) | 1132 | if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task) |
1001 | { | 1133 | { |
@@ -1003,7 +1135,7 @@ successor_stats_cont (void *cls, | |||
1003 | } | 1135 | } |
1004 | if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) | 1136 | if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) |
1005 | { | 1137 | { |
1006 | start_profiling(); | 1138 | start_func(); |
1007 | } | 1139 | } |
1008 | 1140 | ||
1009 | return; | 1141 | return; |
@@ -1039,7 +1171,7 @@ successor_stats_iterator (void *cls, | |||
1039 | static const char *key_string = "XDHT"; | 1171 | static const char *key_string = "XDHT"; |
1040 | if (0 == max_searches) | 1172 | if (0 == max_searches) |
1041 | return GNUNET_OK; | 1173 | return GNUNET_OK; |
1042 | 1174 | ||
1043 | if (0 == strncmp (key_string, name, strlen (key_string))) | 1175 | if (0 == strncmp (key_string, name, strlen (key_string))) |
1044 | { | 1176 | { |
1045 | char *my_id_str; | 1177 | char *my_id_str; |
@@ -1062,18 +1194,19 @@ successor_stats_iterator (void *cls, | |||
1062 | 1194 | ||
1063 | succ_key = GNUNET_new(struct GNUNET_HashCode); | 1195 | succ_key = GNUNET_new(struct GNUNET_HashCode); |
1064 | GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key); | 1196 | GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key); |
1065 | 1197 | ||
1066 | if (0 == flag) | 1198 | if (0 == flag) |
1067 | { | 1199 | { |
1200 | GNUNET_assert(NULL != my_id_key); | ||
1068 | start_key = my_id_key; | 1201 | start_key = my_id_key; |
1202 | GNUNET_assert(NULL != start_key); | ||
1069 | flag = 1; | 1203 | flag = 1; |
1070 | } | 1204 | } |
1071 | /* FIXME: GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE do not free the value | ||
1072 | which is replaced, need to free it. */ | ||
1073 | GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap, | 1205 | GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap, |
1074 | my_id_key, (void *)succ_key, | 1206 | my_id_key, (void *)succ_key, |
1075 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | 1207 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); |
1076 | } | 1208 | } |
1209 | |||
1077 | return GNUNET_OK; | 1210 | return GNUNET_OK; |
1078 | } | 1211 | } |
1079 | 1212 | ||
@@ -1106,33 +1239,6 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1106 | } | 1239 | } |
1107 | 1240 | ||
1108 | 1241 | ||
1109 | #if ENABLE_MALICIOUS | ||
1110 | #if 0 | ||
1111 | /** | ||
1112 | * Set the malicious variable in peer malicious context. | ||
1113 | */ | ||
1114 | static void | ||
1115 | set_malicious() | ||
1116 | { | ||
1117 | unsigned int i; | ||
1118 | DEBUG ("Setting %u peers malicious"); | ||
1119 | for(i = 0; i < n_malicious; i++) | ||
1120 | { | ||
1121 | struct MaliciousContext *mc = &a_mc[i]; | ||
1122 | mc->ctx->op = | ||
1123 | GNUNET_TESTBED_service_connect (ac->ctx, | ||
1124 | ac->ctx->peer, | ||
1125 | "dht", | ||
1126 | &dht_set_malicious, mc, | ||
1127 | &dht_connect, | ||
1128 | &dht_finish, | ||
1129 | mc); | ||
1130 | } | ||
1131 | } | ||
1132 | #endif | ||
1133 | #endif | ||
1134 | |||
1135 | |||
1136 | /** | 1242 | /** |
1137 | * Callback called when DHT service on the peer is started | 1243 | * Callback called when DHT service on the peer is started |
1138 | * | 1244 | * |
@@ -1156,14 +1262,11 @@ service_started (void *cls, | |||
1156 | DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers); | 1262 | DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers); |
1157 | if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) | 1263 | if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) |
1158 | { | 1264 | { |
1159 | #if ENABLE_MALICIOUS | ||
1160 | //set_malicious(); | ||
1161 | #endif | ||
1162 | |||
1163 | DEBUG("successor_stats_task \n"); | 1265 | DEBUG("successor_stats_task \n"); |
1164 | struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context); | 1266 | struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context); |
1165 | collect_stat_cls->service_connect_ctx = cls; | 1267 | collect_stat_cls->service_connect_ctx = cls; |
1166 | collect_stat_cls->op = op; | 1268 | collect_stat_cls->op = op; |
1269 | |||
1167 | successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats, | 1270 | successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats, |
1168 | &collect_stats, | 1271 | &collect_stats, |
1169 | collect_stat_cls); | 1272 | collect_stat_cls); |
@@ -1215,7 +1318,7 @@ test_run (void *cls, | |||
1215 | 1318 | ||
1216 | #if ENABLE_MALICIOUS | 1319 | #if ENABLE_MALICIOUS |
1217 | 1320 | ||
1218 | if(PUT_PROBABILITY + MALICIOUS_PEERS > 100) | 1321 | if(PUT_PROBABILITY + MALICIOUS_PROBABILITY > 100) |
1219 | { | 1322 | { |
1220 | DEBUG ("Reduce either number of malicious peer or active peers. "); | 1323 | DEBUG ("Reduce either number of malicious peer or active peers. "); |
1221 | GNUNET_SCHEDULER_shutdown (); | 1324 | GNUNET_SCHEDULER_shutdown (); |
@@ -1224,23 +1327,21 @@ test_run (void *cls, | |||
1224 | } | 1327 | } |
1225 | 1328 | ||
1226 | /* Select the peers which should act maliciously. */ | 1329 | /* Select the peers which should act maliciously. */ |
1227 | n_malicious = num_peers * MALICIOUS_PEERS / 100; | 1330 | n_malicious = num_peers * MALICIOUS_PROBABILITY / 100; |
1228 | 1331 | ||
1229 | /* Select n_malicious peers and ensure that those are not active peers. | ||
1230 | keep all malicious peer at one place, and call act malicious for all | ||
1231 | those peers. */ | ||
1232 | a_mc = GNUNET_malloc (n_malicious * sizeof (struct MaliciousContext)); | 1332 | a_mc = GNUNET_malloc (n_malicious * sizeof (struct MaliciousContext)); |
1233 | malicious_peers = 0; | 1333 | malicious_peers = 0; |
1234 | 1334 | ||
1235 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) | 1335 | for (cnt = 0; cnt < num_peers && malicious_peers < n_malicious; cnt++) |
1236 | { | 1336 | { |
1237 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= | 1337 | if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= |
1238 | MALICIOUS_PROBABILITY) | 1338 | MALICIOUS_PROBABILITY) |
1239 | continue; | 1339 | continue; |
1240 | a_ac[ac_cnt].malicious = 1; | 1340 | a_ctx[cnt].mc = &a_mc[malicious_peers]; |
1241 | a_mc[ac_cnt].ctx = &a_ctx[cnt]; | 1341 | a_mc[malicious_peers].ctx = &a_ctx[cnt]; |
1242 | malicious_peers++; | 1342 | malicious_peers++; |
1243 | } | 1343 | } |
1344 | n_malicious = malicious_peers; | ||
1244 | INFO ("Malicious Peers: %u\n",malicious_peers); | 1345 | INFO ("Malicious Peers: %u\n",malicious_peers); |
1245 | 1346 | ||
1246 | #endif | 1347 | #endif |
@@ -1250,7 +1351,7 @@ test_run (void *cls, | |||
1250 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) | 1351 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) |
1251 | { | 1352 | { |
1252 | if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= | 1353 | if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= |
1253 | PUT_PROBABILITY) || (a_ac[ac_cnt].malicious == 1)) | 1354 | PUT_PROBABILITY) || (a_ctx[ac_cnt].mc != NULL)) |
1254 | continue; | 1355 | continue; |
1255 | 1356 | ||
1256 | a_ctx[cnt].ac = &a_ac[ac_cnt]; | 1357 | a_ctx[cnt].ac = &a_ac[ac_cnt]; |