aboutsummaryrefslogtreecommitdiff
path: root/src/fragmentation/test_fragmentation.c
diff options
context:
space:
mode:
authorng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
committerng0 <ng0@n0.is>2019-09-08 12:33:09 +0000
commitd41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb (patch)
tree9efd18ea7d425652085ed0bd5e8e45604bc5f6b9 /src/fragmentation/test_fragmentation.c
parenta0fce305c565c0937d917a92712f15e9c5736260 (diff)
downloadgnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.tar.gz
gnunet-d41ed82a4ea0cc8e1674b6d5d2c49fd6462610bb.zip
uncrustify as demanded.
Diffstat (limited to 'src/fragmentation/test_fragmentation.c')
-rw-r--r--src/fragmentation/test_fragmentation.c246
1 files changed, 123 insertions, 123 deletions
diff --git a/src/fragmentation/test_fragmentation.c b/src/fragmentation/test_fragmentation.c
index a49f6d71a..51ae2bb60 100644
--- a/src/fragmentation/test_fragmentation.c
+++ b/src/fragmentation/test_fragmentation.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20/** 20/**
21 * @file fragmentation/test_fragmentation.c 21 * @file fragmentation/test_fragmentation.c
22 * @brief test for fragmentation.c 22 * @brief test for fragmentation.c
@@ -68,52 +68,52 @@ static struct GNUNET_TIME_Relative ack_delay;
68 68
69 69
70static void 70static void
71do_shutdown (void *cls) 71do_shutdown(void *cls)
72{ 72{
73 ret = 0; 73 ret = 0;
74 shutdown_task = NULL; 74 shutdown_task = NULL;
75 GNUNET_DEFRAGMENT_context_destroy (defrag); 75 GNUNET_DEFRAGMENT_context_destroy(defrag);
76 defrag = NULL; 76 defrag = NULL;
77 if (NULL != frag) 77 if (NULL != frag)
78 { 78 {
79 GNUNET_FRAGMENT_context_destroy (frag, &msg_delay, &ack_delay); 79 GNUNET_FRAGMENT_context_destroy(frag, &msg_delay, &ack_delay);
80 frag = NULL; 80 frag = NULL;
81 } 81 }
82 fprintf (stderr, 82 fprintf(stderr,
83 "\nFinal message-delay: %s\n", 83 "\nFinal message-delay: %s\n",
84 GNUNET_STRINGS_relative_time_to_string (msg_delay, 84 GNUNET_STRINGS_relative_time_to_string(msg_delay,
85 GNUNET_YES)); 85 GNUNET_YES));
86 fprintf (stderr, 86 fprintf(stderr,
87 "Final ack-delay: %s\n", 87 "Final ack-delay: %s\n",
88 GNUNET_STRINGS_relative_time_to_string (ack_delay, 88 GNUNET_STRINGS_relative_time_to_string(ack_delay,
89 GNUNET_YES)); 89 GNUNET_YES));
90} 90}
91 91
92 92
93static void 93static void
94proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr) 94proc_msgs(void *cls, const struct GNUNET_MessageHeader *hdr)
95{ 95{
96 static unsigned int total; 96 static unsigned int total;
97 unsigned int i; 97 unsigned int i;
98 const char *buf; 98 const char *buf;
99 99
100#if DETAILS 100#if DETAILS
101 fprintf (stderr, "%s", "M! "); /* message complete, good! */ 101 fprintf(stderr, "%s", "M! "); /* message complete, good! */
102#endif 102#endif
103 buf = (const char *) hdr; 103 buf = (const char *)hdr;
104 for (i = sizeof (struct GNUNET_MessageHeader); i < ntohs (hdr->size); i++) 104 for (i = sizeof(struct GNUNET_MessageHeader); i < ntohs(hdr->size); i++)
105 GNUNET_assert (buf[i] == (char) i); 105 GNUNET_assert(buf[i] == (char)i);
106 total++; 106 total++;
107#if ! DETAILS 107#if !DETAILS
108 if (0 == (total % (NUM_MSGS / 100))) 108 if (0 == (total % (NUM_MSGS / 100)))
109 fprintf (stderr, "%s", "."); 109 fprintf(stderr, "%s", ".");
110#endif 110#endif
111 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */ 111 /* tolerate 10% loss, i.e. due to duplicate fragment IDs */
112 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0)) 112 if ((total >= NUM_MSGS - (NUM_MSGS / 10)) && (ret != 0))
113 { 113 {
114 if (NULL == shutdown_task) 114 if (NULL == shutdown_task)
115 shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL); 115 shutdown_task = GNUNET_SCHEDULER_add_now(&do_shutdown, NULL);
116 } 116 }
117} 117}
118 118
119 119
@@ -121,45 +121,45 @@ proc_msgs (void *cls, const struct GNUNET_MessageHeader *hdr)
121 * Process fragment (by passing to defrag). 121 * Process fragment (by passing to defrag).
122 */ 122 */
123static void 123static void
124proc_frac (void *cls, const struct GNUNET_MessageHeader *hdr) 124proc_frac(void *cls, const struct GNUNET_MessageHeader *hdr)
125{ 125{
126 struct GNUNET_FRAGMENT_Context **fc = cls; 126 struct GNUNET_FRAGMENT_Context **fc = cls;
127 int ret; 127 int ret;
128 128
129 GNUNET_FRAGMENT_context_transmission_done (*fc); 129 GNUNET_FRAGMENT_context_transmission_done(*fc);
130 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) 130 if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
131 { 131 {
132 frag_drops++; 132 frag_drops++;
133#if DETAILS 133#if DETAILS
134 fprintf (stderr, "%s", "DF "); /* dropped Frag */ 134 fprintf(stderr, "%s", "DF "); /* dropped Frag */
135#endif 135#endif
136 return; /* random drop */ 136 return; /* random drop */
137 } 137 }
138 if (NULL == defrag) 138 if (NULL == defrag)
139 { 139 {
140 fprintf (stderr, "%s", "?E "); /* Error: frag after shutdown!? */ 140 fprintf(stderr, "%s", "?E "); /* Error: frag after shutdown!? */
141 return; 141 return;
142 } 142 }
143 ret = GNUNET_DEFRAGMENT_process_fragment (defrag, hdr); 143 ret = GNUNET_DEFRAGMENT_process_fragment(defrag, hdr);
144 if (ret == GNUNET_NO) 144 if (ret == GNUNET_NO)
145 { 145 {
146#if DETAILS 146#if DETAILS
147 fprintf (stderr, "%s", "FF "); /* duplicate fragment */ 147 fprintf(stderr, "%s", "FF "); /* duplicate fragment */
148#endif 148#endif
149 dups++; 149 dups++;
150 } 150 }
151 else if (ret == GNUNET_OK) 151 else if (ret == GNUNET_OK)
152 { 152 {
153#if DETAILS 153#if DETAILS
154 fprintf (stderr, "%s", "F! "); /* good fragment */ 154 fprintf(stderr, "%s", "F! "); /* good fragment */
155#endif 155#endif
156 fragc++; 156 fragc++;
157 } 157 }
158} 158}
159 159
160 160
161static void 161static void
162next_transmission () 162next_transmission()
163{ 163{
164 static unsigned int i; 164 static unsigned int i;
165 struct GNUNET_MessageHeader *msg; 165 struct GNUNET_MessageHeader *msg;
@@ -167,32 +167,32 @@ next_transmission ()
167 unsigned int j; 167 unsigned int j;
168 168
169 if (0 == i) 169 if (0 == i)
170 { 170 {
171 for (j = 0; j < sizeof (buf); j++) 171 for (j = 0; j < sizeof(buf); j++)
172 buf[j] = (char) j; 172 buf[j] = (char)j;
173 } 173 }
174 else 174 else
175 { 175 {
176 GNUNET_FRAGMENT_context_destroy (frag, 176 GNUNET_FRAGMENT_context_destroy(frag,
177 &msg_delay, 177 &msg_delay,
178 &ack_delay); 178 &ack_delay);
179 frag = NULL; 179 frag = NULL;
180 } 180 }
181 if (i == NUM_MSGS) 181 if (i == NUM_MSGS)
182 return; 182 return;
183#if DETAILS 183#if DETAILS
184 fprintf (stderr, "%s", "T! "); /* sending message */ 184 fprintf(stderr, "%s", "T! "); /* sending message */
185#endif 185#endif
186 msg = (struct GNUNET_MessageHeader *) buf; 186 msg = (struct GNUNET_MessageHeader *)buf;
187 msg->type = htons ((uint16_t) i); 187 msg->type = htons((uint16_t)i);
188 msg->size = 188 msg->size =
189 htons (sizeof (struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024)); 189 htons(sizeof(struct GNUNET_MessageHeader) + (17 * i) % (32 * 1024));
190 frag = GNUNET_FRAGMENT_context_create (NULL /* no stats */ , 190 frag = GNUNET_FRAGMENT_context_create(NULL /* no stats */,
191 MTU, &trackers[i], 191 MTU, &trackers[i],
192 msg_delay, 192 msg_delay,
193 ack_delay, 193 ack_delay,
194 msg, 194 msg,
195 &proc_frac, &frag); 195 &proc_frac, &frag);
196 i++; 196 i++;
197} 197}
198 198
@@ -201,46 +201,46 @@ next_transmission ()
201 * Process ACK (by passing to fragmenter) 201 * Process ACK (by passing to fragmenter)
202 */ 202 */
203static void 203static void
204proc_acks (void *cls, 204proc_acks(void *cls,
205 uint32_t msg_id, 205 uint32_t msg_id,
206 const struct GNUNET_MessageHeader *hdr) 206 const struct GNUNET_MessageHeader *hdr)
207{ 207{
208 unsigned int i; 208 unsigned int i;
209 int ret; 209 int ret;
210 210
211 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE)) 211 if (0 == GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, DROPRATE))
212 { 212 {
213 ack_drops++; 213 ack_drops++;
214#if DETAILS 214#if DETAILS
215 fprintf (stderr, "%s", "DA "); /* dropped ACK */ 215 fprintf(stderr, "%s", "DA "); /* dropped ACK */
216#endif 216#endif
217 return; /* random drop */ 217 return; /* random drop */
218 } 218 }
219 for (i = 0; i < NUM_MSGS; i++) 219 for (i = 0; i < NUM_MSGS; i++)
220 {
221 if (NULL == frag)
222 continue;
223 ret = GNUNET_FRAGMENT_process_ack (frag, hdr);
224 if (ret == GNUNET_OK)
225 { 220 {
221 if (NULL == frag)
222 continue;
223 ret = GNUNET_FRAGMENT_process_ack(frag, hdr);
224 if (ret == GNUNET_OK)
225 {
226#if DETAILS 226#if DETAILS
227 fprintf (stderr, "%s", "GA "); /* good ACK */ 227 fprintf(stderr, "%s", "GA "); /* good ACK */
228#endif 228#endif
229 next_transmission (); 229 next_transmission();
230 acks++; 230 acks++;
231 return; 231 return;
232 } 232 }
233 if (ret == GNUNET_NO) 233 if (ret == GNUNET_NO)
234 { 234 {
235#if DETAILS 235#if DETAILS
236 fprintf (stderr, "%s", "AA "); /* duplciate ACK */ 236 fprintf(stderr, "%s", "AA "); /* duplciate ACK */
237#endif 237#endif
238 acks++; 238 acks++;
239 return; 239 return;
240 }
240 } 241 }
241 }
242#if DETAILS 242#if DETAILS
243 fprintf (stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */ 243 fprintf(stderr, "%s", "?A "); /* BAD: ack that nobody feels responsible for... */
244#endif 244#endif
245} 245}
246 246
@@ -249,22 +249,22 @@ proc_acks (void *cls,
249 * Main function run with scheduler. 249 * Main function run with scheduler.
250 */ 250 */
251static void 251static void
252run (void *cls, 252run(void *cls,
253 char *const *args, 253 char *const *args,
254 const char *cfgfile, 254 const char *cfgfile,
255 const struct GNUNET_CONFIGURATION_Handle *cfg) 255 const struct GNUNET_CONFIGURATION_Handle *cfg)
256{ 256{
257 defrag = GNUNET_DEFRAGMENT_context_create (NULL, MTU, 257 defrag = GNUNET_DEFRAGMENT_context_create(NULL, MTU,
258 3, 258 3,
259 NULL, 259 NULL,
260 &proc_msgs, 260 &proc_msgs,
261 &proc_acks); 261 &proc_acks);
262 next_transmission (); 262 next_transmission();
263} 263}
264 264
265 265
266int 266int
267main (int argc, char *argv[]) 267main(int argc, char *argv[])
268{ 268{
269 struct GNUNET_GETOPT_CommandLineOption options[] = { 269 struct GNUNET_GETOPT_CommandLineOption options[] = {
270 GNUNET_GETOPT_OPTION_END 270 GNUNET_GETOPT_OPTION_END
@@ -281,23 +281,23 @@ main (int argc, char *argv[])
281 281
282 msg_delay = GNUNET_TIME_UNIT_MILLISECONDS; 282 msg_delay = GNUNET_TIME_UNIT_MILLISECONDS;
283 ack_delay = GNUNET_TIME_UNIT_SECONDS; 283 ack_delay = GNUNET_TIME_UNIT_SECONDS;
284 GNUNET_log_setup ("test-fragmentation", 284 GNUNET_log_setup("test-fragmentation",
285 "WARNING", 285 "WARNING",
286 NULL); 286 NULL);
287 for (i = 0; i < NUM_MSGS; i++) 287 for (i = 0; i < NUM_MSGS; i++)
288 GNUNET_BANDWIDTH_tracker_init (&trackers[i], NULL, NULL, 288 GNUNET_BANDWIDTH_tracker_init(&trackers[i], NULL, NULL,
289 GNUNET_BANDWIDTH_value_init ((i + 1) * 1024), 289 GNUNET_BANDWIDTH_value_init((i + 1) * 1024),
290 100); 290 100);
291 GNUNET_PROGRAM_run (5, 291 GNUNET_PROGRAM_run(5,
292 argv_prog, 292 argv_prog,
293 "test-fragmentation", "nohelp", 293 "test-fragmentation", "nohelp",
294 options, 294 options,
295 &run, NULL); 295 &run, NULL);
296 fprintf (stderr, 296 fprintf(stderr,
297 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n", 297 "\nHad %u good fragments, %u duplicate fragments, %u acks and %u simulated drops of acks\n",
298 fragc, 298 fragc,
299 dups, 299 dups,
300 acks, 300 acks,
301 ack_drops); 301 ack_drops);
302 return ret; 302 return ret;
303} 303}