aboutsummaryrefslogtreecommitdiff
path: root/src/cadet
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2015-10-06 12:03:16 +0000
committerBart Polot <bart@net.in.tum.de>2015-10-06 12:03:16 +0000
commitbbbeab39580171d6dffc2832f83829b94c4f331b (patch)
tree16f02883a734b9e4caa480f610d8118ae3fb0a8f /src/cadet
parent79f53fe65e00a29889b290fca9c9390101ea537e (diff)
downloadgnunet-bbbeab39580171d6dffc2832f83829b94c4f331b.tar.gz
gnunet-bbbeab39580171d6dffc2832f83829b94c4f331b.zip
- refactor test dropping, reduce test load
Diffstat (limited to 'src/cadet')
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c25
-rw-r--r--src/cadet/test_cadet.c2
2 files changed, 24 insertions, 3 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index f3161383a..540add681 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -1139,6 +1139,28 @@ fill_buf (struct CadetPeerQueue *queue, void *buf, size_t size, uint32_t *pid)
1139 1139
1140 1140
1141/** 1141/**
1142 * Debug function should NEVER return true in production code, useful to
1143 * simulate losses for testcases.
1144 *
1145 * @param q Queue handle with info about the message.
1146 *
1147 * @return #GNUNET_YES or #GNUNET_NO with the decision to drop.
1148 */
1149static int
1150should_I_drop (struct CadetPeerQueue *q)
1151{
1152 static int i = 0;
1153
1154 if (0 == drop_percent)
1155 return GNUNET_NO;
1156
1157 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 101) < drop_percent)
1158 return GNUNET_YES;
1159
1160 return GNUNET_NO;
1161}
1162
1163/**
1142 * Core callback to write a queued packet to core buffer 1164 * Core callback to write a queued packet to core buffer
1143 * 1165 *
1144 * @param cls Closure (peer info). 1166 * @param cls Closure (peer info).
@@ -1237,8 +1259,7 @@ queue_send (void *cls, size_t size, void *buf)
1237 1259
1238 msg_size = fill_buf (queue, (void *) dst, size, &pid); 1260 msg_size = fill_buf (queue, (void *) dst, size, &pid);
1239 1261
1240 if (0 < drop_percent && 1262 if (should_I_drop (queue))
1241 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 101) < drop_percent)
1242 { 1263 {
1243 LOG (GNUNET_ERROR_TYPE_WARNING, "DD %s (%s %u) on conn %s %s\n", 1264 LOG (GNUNET_ERROR_TYPE_WARNING, "DD %s (%s %u) on conn %s %s\n",
1244 GC_m2s (queue->type), GC_m2s (queue->payload_type), 1265 GC_m2s (queue->type), GC_m2s (queue->payload_type),
diff --git a/src/cadet/test_cadet.c b/src/cadet/test_cadet.c
index 8e90f2897..2b69579a5 100644
--- a/src/cadet/test_cadet.c
+++ b/src/cadet/test_cadet.c
@@ -33,7 +33,7 @@
33/** 33/**
34 * How many messages to send 34 * How many messages to send
35 */ 35 */
36#define TOTAL_PACKETS 5000 /* Cannot exceed 64k! */ 36#define TOTAL_PACKETS 200 /* Cannot exceed 64k! */
37 37
38/** 38/**
39 * How long until we give up on connecting the peers? 39 * How long until we give up on connecting the peers?