aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet_dht_profiler.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2016-06-24 12:29:10 +0000
committerChristian Grothoff <christian@grothoff.org>2016-06-24 12:29:10 +0000
commitad471e4ff9c4bd212cb40aa7fd72ca0b0396ac77 (patch)
treed11167474553038591caf7d02825028762990369 /src/dht/gnunet_dht_profiler.c
parent67edb6d2abc0b4a3b0d79bbd854a90218a81e2cc (diff)
downloadgnunet-ad471e4ff9c4bd212cb40aa7fd72ca0b0396ac77.tar.gz
gnunet-ad471e4ff9c4bd212cb40aa7fd72ca0b0396ac77.zip
-fix ftbfs
Diffstat (limited to 'src/dht/gnunet_dht_profiler.c')
-rw-r--r--src/dht/gnunet_dht_profiler.c232
1 files changed, 0 insertions, 232 deletions
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c
index 3dd93287d..460eaa572 100644
--- a/src/dht/gnunet_dht_profiler.c
+++ b/src/dht/gnunet_dht_profiler.c
@@ -40,19 +40,6 @@
40 */ 40 */
41#define PUT_PROBABILITY 50 41#define PUT_PROBABILITY 50
42 42
43#if ENABLE_MALICIOUS
44/**
45 * Number of peers which should act as malicious peers
46 */
47#define MALICIOUS_PROBABILITY 20
48
49/**
50 * Context for a peer which should act maliciously.
51 */
52struct MaliciousContext;
53#endif
54
55
56/** 43/**
57 * Configuration 44 * Configuration
58 */ 45 */
@@ -88,69 +75,8 @@ struct Context
88 */ 75 */
89 struct ActiveContext *ac; 76 struct ActiveContext *ac;
90 77
91#if ENABLE_MALICIOUS
92 /**
93 * Malicious context; NULL if this peer is NOT malicious.
94 */
95 struct MaliciousContext *mc;
96#endif
97};
98
99
100#if ENABLE_MALICIOUS
101/**
102 * Context for a peer which should act maliciously.
103 */
104struct MaliciousContext
105{
106 /**
107 * The linked peer context
108 */
109 struct Context *ctx;
110
111 /**
112 * Handler to the DHT service
113 */
114 struct GNUNET_DHT_Handle *dht;
115
116 /**
117 * Handler to malicious api
118 */
119 struct GNUNET_DHT_ActMaliciousHandle *dht_malicious;
120};
121
122/**
123 * List of all the malicious peers contexts.
124 */
125struct Context **malicious_peer_contexts = NULL;
126
127/**
128 * Context for a peer which should act maliciously.
129 */
130struct 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}; 78};
142 79
143/**
144 * Array of malicious peers.
145 */
146static struct MaliciousContext *a_mc;
147
148/**
149 * Number or malicious peers.
150 */
151static unsigned int n_malicious;
152
153#endif
154 80
155/** 81/**
156 * Context for a peer which actively does DHT PUT/GET 82 * Context for a peer which actively does DHT PUT/GET
@@ -906,122 +832,6 @@ start_profiling()
906 } 832 }
907} 833}
908 834
909#if ENABLE_MALICIOUS
910/**
911 * Count of total number of malicious peers.
912 */
913static unsigned int count_malicious;
914
915/**
916 * Continuation of GNUNET_DHT_act_malicious
917 * @param cls Malicious context
918 * @param success #GNUNET_OK if the ACT_MALICIOUS was transmitted,
919 * #GNUNET_NO on timeout,
920 * #GNUNET_SYSERR on disconnect from service
921 * after the ACT_MALICIOUS message was transmitted
922 * (so we don't know if it was received or not)
923 */
924static void
925act_malicious_cont (void *cls, int success)
926{
927 struct MaliciousContext *mc = cls;
928 struct Context *ctx = mc->ctx;
929
930 GNUNET_TESTBED_operation_done (ctx->op);
931 ctx->op = NULL;
932 return;
933}
934
935
936/**
937 * Call malicious API for all the malicious peers.
938 * @param cls the malicious context.
939 * @param op the operation that has been finished
940 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
941 * @param emsg error message in case the operation has failed; will be NULL if
942 * operation has executed successfully.
943 */
944static void
945dht_set_malicious(void *cls,
946 struct GNUNET_TESTBED_Operation *op,
947 void *ca_result,
948 const char *emsg)
949{
950 struct MaliciousContext *mc = cls;
951 struct Context *ctx = mc->ctx;
952
953 GNUNET_assert (NULL != ctx);
954 GNUNET_assert (NULL != ctx->op);
955 GNUNET_assert (ctx->op == op);
956 mc->dht = (struct GNUNET_DHT_Handle *) ca_result;
957 if (NULL != emsg)
958 {
959 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: %s\n", emsg);
960 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect_malicious() */
961 ctx->op = NULL;
962 return;
963 }
964 mc->dht_malicious = GNUNET_DHT_act_malicious(mc->dht, 1, act_malicious_cont, mc);
965}
966
967
968/**
969 * Adapter function called to destroy a connection to
970 * a service.
971 *
972 * @param cls the active context
973 * @param op_result service handle returned from the connect adapter
974 */
975static void
976dht_disconnect_malicious (void *cls, void *op_result)
977{
978 struct MaliciousContext *mc = cls;
979 count_malicious++;
980 GNUNET_assert (NULL != mc->dht);
981 GNUNET_assert (mc->dht == op_result);
982 GNUNET_DHT_disconnect (mc->dht);
983 mc->dht = NULL;
984 mc->ctx->op = NULL;
985 n_dht--;
986
987 if (0 != n_dht)
988 return;
989
990 if(n_malicious == count_malicious)
991 {
992 DEBUG("\n Call start_profiling()");
993 start_profiling();
994 }
995}
996
997
998/**
999 * Set the malicious variable in peer malicious context.
1000 */
1001static void
1002set_malicious()
1003{
1004 unsigned int i;
1005
1006 DEBUG ("Setting %u peers malicious",
1007 n_malicious);
1008 for(i = 0; i < n_malicious; i++)
1009 {
1010 struct MaliciousContext *mc = &a_mc[i];
1011 mc->ctx->op =
1012 GNUNET_TESTBED_service_connect (mc->ctx,
1013 mc->ctx->peer,
1014 "dht",
1015 &dht_set_malicious, mc,
1016 &dht_connect,
1017 &dht_disconnect_malicious,
1018 mc);
1019 }
1020}
1021
1022#endif
1023
1024
1025/** 835/**
1026 * Start collecting relevant statistics. If ENABLE_MALICIOUS set, first 836 * Start collecting relevant statistics. If ENABLE_MALICIOUS set, first
1027 * set the malicious peers. If not, then start with PUT operation on active 837 * set the malicious peers. If not, then start with PUT operation on active
@@ -1030,11 +840,7 @@ set_malicious()
1030static void 840static void
1031start_func() 841start_func()
1032{ 842{
1033#if ENABLE_MALICIOUS
1034 set_malicious();
1035#else
1036 start_profiling(); 843 start_profiling();
1037#endif
1038} 844}
1039 845
1040 846
@@ -1308,50 +1114,12 @@ test_run (void *cls,
1308 1114
1309 a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); 1115 a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext));
1310 ac_cnt = 0; 1116 ac_cnt = 0;
1311
1312#if ENABLE_MALICIOUS
1313 unsigned int malicious_peers;
1314 if(PUT_PROBABILITY + MALICIOUS_PROBABILITY > 100)
1315 {
1316 DEBUG ("Reduce either number of malicious peer or active peers. ");
1317 GNUNET_SCHEDULER_shutdown ();
1318 GNUNET_free (a_ctx);
1319 return;
1320 }
1321
1322 /* Select the peers which should act maliciously. */
1323 n_malicious = num_peers * MALICIOUS_PROBABILITY / 100;
1324
1325 a_mc = GNUNET_malloc (n_malicious * sizeof (struct MaliciousContext));
1326 malicious_peers = 0;
1327
1328 for (cnt = 0; cnt < num_peers && malicious_peers < n_malicious; cnt++)
1329 {
1330 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
1331 MALICIOUS_PROBABILITY)
1332 continue;
1333 a_ctx[cnt].mc = &a_mc[malicious_peers];
1334 a_mc[malicious_peers].ctx = &a_ctx[cnt];
1335 malicious_peers++;
1336 }
1337 n_malicious = malicious_peers;
1338 INFO ("Malicious Peers: %u\n",malicious_peers);
1339
1340#endif
1341
1342 a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext));
1343 ac_cnt = 0;
1344 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) 1117 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
1345 { 1118 {
1346 if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= 1119 if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
1347 PUT_PROBABILITY)) 1120 PUT_PROBABILITY))
1348 continue; 1121 continue;
1349 1122
1350#if ENABLE_MALICIOUS
1351 if(a_ctx[ac_cnt].mc != NULL)
1352 continue;
1353#endif
1354
1355 a_ctx[cnt].ac = &a_ac[ac_cnt]; 1123 a_ctx[cnt].ac = &a_ac[ac_cnt];
1356 a_ac[ac_cnt].ctx = &a_ctx[cnt]; 1124 a_ac[ac_cnt].ctx = &a_ctx[cnt];
1357 ac_cnt++; 1125 ac_cnt++;