aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-11-16 14:12:41 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-11-16 14:12:41 +0000
commitb65e40508cbfd1eef561529e110efcace93037e2 (patch)
tree9d67252d47ce32de4e0c41fc90ba2a4da565bc8a /src
parentb0685d4301b6ddf5d95e5467add39a23b51aa5a1 (diff)
downloadgnunet-b65e40508cbfd1eef561529e110efcace93037e2.tar.gz
gnunet-b65e40508cbfd1eef561529e110efcace93037e2.zip
rewritten test...not yet finished
Diffstat (limited to 'src')
-rw-r--r--src/core/test_core_quota_compliance.c418
1 files changed, 166 insertions, 252 deletions
diff --git a/src/core/test_core_quota_compliance.c b/src/core/test_core_quota_compliance.c
index 2fbe8dcc5..d144dd4b3 100644
--- a/src/core/test_core_quota_compliance.c
+++ b/src/core/test_core_quota_compliance.c
@@ -34,29 +34,22 @@
34#include "gnunet_program_lib.h" 34#include "gnunet_program_lib.h"
35#include "gnunet_scheduler_lib.h" 35#include "gnunet_scheduler_lib.h"
36#include "gnunet_transport_service.h" 36#include "gnunet_transport_service.h"
37#include "gnunet_statistics_service.h"
38 37
39#define VERBOSE GNUNET_YES 38#define VERBOSE GNUNET_NO
40 39
41#define START_ARM GNUNET_YES 40#define START_ARM GNUNET_YES
42#define DEBUG_CONNECTIONS GNUNET_YES
43 41
44/** 42/**
45 * Note that this value must not significantly exceed 43 * Note that this value must not significantly exceed
46 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise 44 * 'MAX_PENDING' in 'gnunet-service-transport.c', otherwise
47 * messages may be dropped even for a reliable transport. 45 * messages may be dropped even for a reliable transport.
48 */ 46 */
49#define TOTAL_MSGS (600 * 10) 47#define TOTAL_MSGS (60 * 10)
50
51#define MEASUREMENT_MSG_SIZE 10240
52#define MEASUREMENT_MAX_QUOTA 1024 * 1024 * 1024
53#define MEASUREMENT_MIN_QUOTA 1024
54#define MEASUREMENT_INTERVALL GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
55 48
56/** 49/**
57 * How long until we give up on transmitting the message? 50 * How long until we give up on transmitting the message?
58 */ 51 */
59#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 6000) 52#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
60 53
61/** 54/**
62 * What delay do we request from the core service for transmission? 55 * What delay do we request from the core service for transmission?
@@ -66,35 +59,25 @@
66#define FAST_TIMEOUT GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2) 59#define FAST_TIMEOUT GNUNET_TIME_relative_divide (GNUNET_CONSTANTS_MAX_CORK_DELAY, 2)
67 60
68#define MTYPE 12345 61#define MTYPE 12345
69 62#define MSIZE 1024
70static int is_asymmetric_send_constant; 63#define MEASUREMENT_LENGTH GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
71static int is_asymmetric_recv_constant;
72static unsigned long long current_quota_p1_in;
73static unsigned long long current_quota_p1_out;
74static unsigned long long current_quota_p2_in;
75static unsigned long long current_quota_p2_out;
76 64
77static unsigned long long total_bytes; 65static unsigned long long total_bytes;
78static unsigned long long total_bytes_sent;
79static unsigned long long total_bytes_recv;
80 66
81static struct GNUNET_TIME_Absolute start_time; 67static struct GNUNET_TIME_Absolute start_time;
82 68
83static GNUNET_SCHEDULER_TaskIdentifier err_task; 69static GNUNET_SCHEDULER_TaskIdentifier err_task;
84 70
85static GNUNET_SCHEDULER_TaskIdentifier send_task;
86
87static GNUNET_SCHEDULER_TaskIdentifier measure_task; 71static GNUNET_SCHEDULER_TaskIdentifier measure_task;
88 72
73
89struct PeerContext 74struct PeerContext
90{ 75{
91 struct GNUNET_CONFIGURATION_Handle *cfg; 76 struct GNUNET_CONFIGURATION_Handle *cfg;
92 struct GNUNET_STATISTICS_Handle *stats;
93 struct GNUNET_CORE_Handle *ch; 77 struct GNUNET_CORE_Handle *ch;
94 struct GNUNET_PeerIdentity id; 78 struct GNUNET_PeerIdentity id;
95 struct GNUNET_TRANSPORT_Handle *th; 79 struct GNUNET_TRANSPORT_Handle *th;
96 struct GNUNET_MessageHeader *hello; 80 struct GNUNET_MessageHeader *hello;
97
98 int connect_status; 81 int connect_status;
99#if START_ARM 82#if START_ARM
100 struct GNUNET_OS_Process *arm_proc; 83 struct GNUNET_OS_Process *arm_proc;
@@ -106,9 +89,11 @@ static struct PeerContext p1;
106static struct PeerContext p2; 89static struct PeerContext p2;
107 90
108static int ok; 91static int ok;
109static int measurement_running;
110 92
111struct GNUNET_CORE_TransmitHandle * ch; 93static int32_t tr_n;
94
95static int running;
96
112 97
113#if VERBOSE 98#if VERBOSE
114#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) 99#define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0)
@@ -136,6 +121,9 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
136 GNUNET_TRANSPORT_disconnect (p2.th); 121 GNUNET_TRANSPORT_disconnect (p2.th);
137 p2.th = NULL; 122 p2.th = NULL;
138 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value; 123 delta = GNUNET_TIME_absolute_get_duration (start_time).rel_value;
124 fprintf (stderr,
125 "\nThroughput was %llu kb/s\n",
126 total_bytes * 1000 / 1024 / delta);
139 ok = 0; 127 ok = 0;
140} 128}
141 129
@@ -143,9 +131,12 @@ terminate_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
143static void 131static void
144terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 132terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
145{ 133{
134 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Testcase timout, exit!\n");
146 GNUNET_break (0); 135 GNUNET_break (0);
147 if (send_task != GNUNET_SCHEDULER_NO_TASK) 136
148 GNUNET_SCHEDULER_cancel (send_task); 137 if (measure_task != GNUNET_SCHEDULER_NO_TASK)
138 GNUNET_SCHEDULER_cancel(measure_task);
139
149 GNUNET_CORE_disconnect (p1.ch); 140 GNUNET_CORE_disconnect (p1.ch);
150 p1.ch = NULL; 141 p1.ch = NULL;
151 GNUNET_CORE_disconnect (p2.ch); 142 GNUNET_CORE_disconnect (p2.ch);
@@ -158,129 +149,112 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
158} 149}
159 150
160static void 151static void
161next_fin (void *cls, int success) 152measurement_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
162{ 153{
154 measure_task = GNUNET_SCHEDULER_NO_TASK;
155 fprintf(stdout,"\n");
156 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "FINIIISH!\n");
157 running = GNUNET_NO;
163 158
164} 159 GNUNET_SCHEDULER_cancel (err_task);
165 160 GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
166 161
167static int
168check_2 (void *cls,
169 const char *subsystem,
170 const char *name, uint64_t value, int is_persistent)
171{
172 fprintf(stderr, "%s %s %llu\n", subsystem, name, (long long unsigned int) value);
173 return GNUNET_OK;
174} 162}
175 163
176static size_t 164static size_t
177transmit_ready (void *cls, size_t size, void *buf); 165transmit_ready (void *cls, size_t size, void *buf)
178
179static void
180send_tsk (void *cls,
181 const struct GNUNET_SCHEDULER_TaskContext *tc)
182{
183 send_task = GNUNET_SCHEDULER_NO_TASK;
184
185 ch = GNUNET_CORE_notify_transmit_ready (p1.ch,
186 0,
187 FAST_TIMEOUT,
188 &p2.id,
189 sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE,
190 &transmit_ready, &p1);
191}
192
193static void
194measurement_end (void *cls,
195 const struct GNUNET_SCHEDULER_TaskContext *tc)
196{ 166{
197 struct GNUNET_TIME_Relative duration; 167 char *cbuf = buf;
198 168 struct TestMessage hdr;
199 measure_task = GNUNET_SCHEDULER_NO_TASK; 169 unsigned int s;
200 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) 170 unsigned int ret;
201 return;
202
203 if (err_task != GNUNET_SCHEDULER_NO_TASK)
204 GNUNET_SCHEDULER_cancel (err_task);
205 if (send_task != GNUNET_SCHEDULER_NO_TASK)
206 GNUNET_SCHEDULER_cancel (send_task);
207
208 GNUNET_STATISTICS_get(p1.stats,"core","# discarded CORE_SEND requests",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p1);
209 GNUNET_STATISTICS_get(p1.stats,"core","# discarded CORE_SEND requests",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p2);
210 GNUNET_STATISTICS_get(p1.stats,"core","# discarded lower priority CORE_SEND requests",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p1);
211 GNUNET_STATISTICS_get(p1.stats,"core","# discarded lower priority CORE_SEND requests",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p2);
212
213 GNUNET_STATISTICS_get(p1.stats,"core","# discarded CORE_SEND request bytes",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p1);
214 GNUNET_STATISTICS_get(p1.stats,"core","# discarded CORE_SEND request bytes",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p2);
215 GNUNET_STATISTICS_get(p1.stats,"core","# discarded lower priority CORE_SEND request bytes",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p1);
216 GNUNET_STATISTICS_get(p1.stats,"core","# discarded lower priority CORE_SEND request bytes",GNUNET_TIME_UNIT_SECONDS, &next_fin, &check_2, &p2);
217 measurement_running = GNUNET_NO;
218 duration = GNUNET_TIME_absolute_get_difference(start_time, GNUNET_TIME_absolute_get());
219 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
220 "\nQuota compliance: \n" \
221 "Receive rate: %10llu kB/s\n"
222 "Send rate : %10llu kB/s\n" \
223 "Quota : %10llu kB/s\n",
224 (total_bytes_recv/(duration.rel_value / 1000)/1024),
225 (total_bytes_sent/(duration.rel_value / 1000)/1024),
226 current_quota_p1_in/1024);
227 GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
228}
229
230 171
231static void 172 GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
232measure (unsigned long long quota_p1, unsigned long long quota_p2) 173 if (buf == NULL)
233{ 174 {
175 if (p1.ch != NULL)
176 GNUNET_break (NULL !=
177 GNUNET_CORE_notify_transmit_ready (p1.ch,
178 0,
179 FAST_TIMEOUT,
180 &p2.id,
181 MSIZE,
182 &transmit_ready, &p1));
183 return 0;
184 }
185 GNUNET_assert (tr_n < TOTAL_MSGS);
186 ret = 0;
187 s = MSIZE;
188 GNUNET_assert (size >= s);
189 GNUNET_assert (buf != NULL);
190 cbuf = buf;
191 do
192 {
234#if VERBOSE 193#if VERBOSE
235 if ((is_asymmetric_send_constant == GNUNET_YES) || (is_asymmetric_recv_constant == GNUNET_YES)) 194 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
236 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 195 "Sending message %u of size %u at offset %u\n",
237 "Starting core level measurement for %u seconds receiving peer quota %llu kB/s, sending peer quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p1_in / 1024, current_quota_p2_out / 1024); 196 tr_n,
238 else 197 s,
239 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 198 ret);
240 "Starting core level measurement for %u seconds, symmetric quota %llu kB/s\n", MEASUREMENT_INTERVALL.rel_value / 1000 , current_quota_p2_out / 1024);
241
242#endif
243#if DEBUG_CONNECTIONS
244 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
245 "Asking core (1) for transmission to peer `%4s'\n",
246 GNUNET_i2s (&p2.id));
247#endif 199#endif
200 hdr.header.size = htons (s);
201 hdr.header.type = htons (MTYPE);
202 hdr.num = htonl (tr_n);
203 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
204 ret += sizeof (struct TestMessage);
205 memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage));
206 ret += s - sizeof (struct TestMessage);
207 tr_n++;
208 s = MSIZE;
209 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
210 break; /* sometimes pack buffer full, sometimes not */
211 }
212 while (size - ret >= s);
213 GNUNET_SCHEDULER_cancel (err_task);
248 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, 214 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
249 &terminate_task_error, 215 &terminate_task_error,
250 NULL); 216 NULL);
251 measure_task = GNUNET_SCHEDULER_add_delayed (MEASUREMENT_INTERVALL, 217
252 &measurement_end, 218 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
253 NULL); 219 "Returning total message block of size %u\n",
254 start_time = GNUNET_TIME_absolute_get (); 220 ret);
255 measurement_running = GNUNET_YES; 221 total_bytes += ret;
256 total_bytes = 0; 222 return ret;
257 total_bytes_sent = 0;
258 ch = GNUNET_CORE_notify_transmit_ready (p1.ch,
259 0,
260 TIMEOUT,
261 &p2.id,
262 sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE,
263 &transmit_ready, &p1);
264} 223}
265 224
266static void connect_notify (void *cls, 225
226
227static void
228connect_notify (void *cls,
267 const struct GNUNET_PeerIdentity *peer, 229 const struct GNUNET_PeerIdentity *peer,
268 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 230 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
269{ 231{
270 struct PeerContext *pc = cls; 232 struct PeerContext *pc = cls;
271 233
272 GNUNET_assert (pc->connect_status == 0); 234 GNUNET_assert (pc->connect_status == 0);
273 pc->connect_status = 1; 235 pc->connect_status = 1;
274 if (pc == &p1) 236 if (pc == &p1)
275 { 237 {
276 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 238 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
277 "Encrypted connection established to peer `%4s'\n", 239 "Encrypted connection established to peer `%4s'\n",
278 GNUNET_i2s (peer)); 240 GNUNET_i2s (peer));
279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
280 "Asking core (1) for transmission to peer `%4s'\n", 242 "Asking core (1) for transmission to peer `%4s'\n",
281 GNUNET_i2s (&p2.id)); 243 GNUNET_i2s (&p2.id));
282 measure (MEASUREMENT_MIN_QUOTA, MEASUREMENT_MIN_QUOTA); 244 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
283 } 245 &terminate_task_error,
246 NULL);
247 start_time = GNUNET_TIME_absolute_get ();
248 running = GNUNET_YES;
249 measure_task = GNUNET_SCHEDULER_add_delayed(MEASUREMENT_LENGTH, &measurement_stop, NULL);
250
251 GNUNET_break (NULL != GNUNET_CORE_notify_transmit_ready (p1.ch,
252 0,
253 TIMEOUT,
254 &p2.id,
255 MSIZE,
256 &transmit_ready, &p1));
257 }
284} 258}
285 259
286 260
@@ -290,10 +264,8 @@ disconnect_notify (void *cls,
290{ 264{
291 struct PeerContext *pc = cls; 265 struct PeerContext *pc = cls;
292 pc->connect_status = 0; 266 pc->connect_status = 0;
293#if DEBUG_CONNECTIONS
294 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
295 "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer)); 268 "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer));
296#endif
297} 269}
298 270
299 271
@@ -303,11 +275,10 @@ inbound_notify (void *cls,
303 const struct GNUNET_MessageHeader *message, 275 const struct GNUNET_MessageHeader *message,
304 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 276 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
305{ 277{
306 total_bytes_recv += ntohs (message->size); 278#if VERBOSE
307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 279 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
308 "Core provides inbound data from `%4s' size %u.\n", GNUNET_i2s (other), ntohs (message->size)); 280 "Core provides inbound data from `%4s'.\n", GNUNET_i2s (other));
309#if DEBUG_CONNECTIONS 281#endif
310 #endif
311 return GNUNET_OK; 282 return GNUNET_OK;
312} 283}
313 284
@@ -318,7 +289,7 @@ outbound_notify (void *cls,
318 const struct GNUNET_MessageHeader *message, 289 const struct GNUNET_MessageHeader *message,
319 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 290 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
320{ 291{
321#if DEBUG_CONNECTIONS 292#if VERBOSE
322 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 293 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
323 "Core notifies about outbound data for `%4s'.\n", 294 "Core notifies about outbound data for `%4s'.\n",
324 GNUNET_i2s (other)); 295 GNUNET_i2s (other));
@@ -327,8 +298,8 @@ outbound_notify (void *cls,
327} 298}
328 299
329 300
330static int tr_n; 301static size_t
331 302transmit_ready (void *cls, size_t size, void *buf);
332 303
333static int 304static int
334process_mtype (void *cls, 305process_mtype (void *cls,
@@ -341,11 +312,32 @@ process_mtype (void *cls,
341 const struct TestMessage *hdr; 312 const struct TestMessage *hdr;
342 313
343 hdr = (const struct TestMessage*) message; 314 hdr = (const struct TestMessage*) message;
344 s = sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE; 315 s = MSIZE;
345 if (MTYPE != ntohs (message->type)) 316 if (MTYPE != ntohs (message->type))
346 return GNUNET_SYSERR; 317 return GNUNET_SYSERR;
347 318 if (ntohs (message->size) != s)
348#if DEBUG_CONNECTIONS 319 {
320 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
321 "Expected message %u of size %u, got %u bytes of message %u\n",
322 n, s,
323 ntohs (message->size),
324 ntohl (hdr->num));
325 GNUNET_SCHEDULER_cancel (err_task);
326 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
327 return GNUNET_SYSERR;
328 }
329 if (ntohl (hdr->num) != n)
330 {
331 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
332 "Expected message %u of size %u, got %u bytes of message %u\n",
333 n, s,
334 ntohs (message->size),
335 ntohl (hdr->num));
336 GNUNET_SCHEDULER_cancel (err_task);
337 err_task = GNUNET_SCHEDULER_add_now (&terminate_task_error, NULL);
338 return GNUNET_SYSERR;
339 }
340#if VERBOSE
349 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
350 "Got message %u of size %u\n", 342 "Got message %u of size %u\n",
351 ntohl (hdr->num), 343 ntohl (hdr->num),
@@ -354,7 +346,22 @@ process_mtype (void *cls,
354 n++; 346 n++;
355 if (0 == (n % (TOTAL_MSGS/100))) 347 if (0 == (n % (TOTAL_MSGS/100)))
356 fprintf (stderr, "."); 348 fprintf (stderr, ".");
357 349 if (n == TOTAL_MSGS)
350 {
351 GNUNET_SCHEDULER_cancel (err_task);
352 GNUNET_SCHEDULER_add_now (&terminate_task, NULL);
353 }
354 else
355 {
356 if (running == GNUNET_YES)
357 GNUNET_break (NULL !=
358 GNUNET_CORE_notify_transmit_ready (p1.ch,
359 0,
360 FAST_TIMEOUT,
361 &p2.id,
362 MSIZE,
363 &transmit_ready, &p1));
364 }
358 return GNUNET_OK; 365 return GNUNET_OK;
359} 366}
360 367
@@ -365,75 +372,6 @@ static struct GNUNET_CORE_MessageHandler handlers[] = {
365}; 372};
366 373
367 374
368static size_t
369transmit_ready (void *cls, size_t size, void *buf)
370{
371 char *cbuf = buf;
372 struct TestMessage hdr;
373 unsigned int s;
374 unsigned int ret;
375
376 if (measurement_running != GNUNET_YES)
377 return 0;
378
379 GNUNET_assert (size <= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE);
380 if (buf == NULL)
381 {
382 if (p1.ch != NULL)
383 {
384 ch = GNUNET_CORE_notify_transmit_ready (p1.ch,
385 0,
386 FAST_TIMEOUT,
387 &p2.id,
388 sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE,
389 &transmit_ready, &p1);
390 GNUNET_break (NULL != ch);
391 }
392 return 0;
393 }
394 ret = 0;
395 ch = NULL;
396 s = sizeof (struct TestMessage) + MEASUREMENT_MSG_SIZE;
397
398 GNUNET_assert (size >= s);
399 GNUNET_assert (buf != NULL);
400 cbuf = buf;
401 do
402 {
403#if DEBUG_CONNECTIONS
404 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
405 "Sending message %u of size %u at offset %u\n",
406 tr_n,
407 s,
408 ret);
409#endif
410 hdr.header.size = htons (s);
411 hdr.header.type = htons (MTYPE);
412 hdr.num = htonl (tr_n);
413 memcpy (&cbuf[ret], &hdr, sizeof (struct TestMessage));
414 ret += sizeof (struct TestMessage);
415 memset (&cbuf[ret], tr_n, s - sizeof (struct TestMessage));
416 ret += s - sizeof (struct TestMessage);
417 tr_n++;
418 if (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 16))
419 break; /* sometimes pack buffer full, sometimes not */
420 }
421 while (size - ret >= s);
422 GNUNET_SCHEDULER_cancel (err_task);
423 err_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT,
424 &terminate_task_error,
425 NULL);
426
427 total_bytes += ret;
428 total_bytes_sent += ret;
429 if (send_task != GNUNET_SCHEDULER_NO_TASK)
430 GNUNET_SCHEDULER_cancel(send_task);
431 send_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS, 20), &send_tsk, NULL);
432
433 return ret;
434}
435
436
437 375
438static void 376static void
439init_notify (void *cls, 377init_notify (void *cls,
@@ -442,11 +380,10 @@ init_notify (void *cls,
442 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) 380 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
443{ 381{
444 struct PeerContext *p = cls; 382 struct PeerContext *p = cls;
445#if DEBUG_CONNECTIONS 383
446 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 384 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
447 "Connection to CORE service of `%4s' established\n", 385 "Connection to CORE service of `%4s' established\n",
448 GNUNET_i2s (my_identity)); 386 GNUNET_i2s (my_identity));
449#endif
450 GNUNET_assert (server != NULL); 387 GNUNET_assert (server != NULL);
451 p->id = *my_identity; 388 p->id = *my_identity;
452 p->ch = server; 389 p->ch = server;
@@ -460,7 +397,7 @@ init_notify (void *cls,
460 &init_notify, 397 &init_notify,
461 &connect_notify, 398 &connect_notify,
462 &disconnect_notify, 399 &disconnect_notify,
463 NULL, 400 NULL,
464 &inbound_notify, 401 &inbound_notify,
465 GNUNET_YES, 402 GNUNET_YES,
466 &outbound_notify, GNUNET_YES, handlers); 403 &outbound_notify, GNUNET_YES, handlers);
@@ -474,7 +411,7 @@ init_notify (void *cls,
474 "Asking core (1) to connect to peer `%4s'\n", 411 "Asking core (1) to connect to peer `%4s'\n",
475 GNUNET_i2s (&p2.id)); 412 GNUNET_i2s (&p2.id));
476 GNUNET_CORE_peer_request_connect (p1.ch, 413 GNUNET_CORE_peer_request_connect (p1.ch,
477 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5), 414 GNUNET_TIME_UNIT_SECONDS,
478 &p2.id, 415 &p2.id,
479 NULL, NULL); 416 NULL, NULL);
480 } 417 }
@@ -488,11 +425,9 @@ process_hello (void *cls,
488 struct PeerContext *p = cls; 425 struct PeerContext *p = cls;
489 426
490 GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p); 427 GNUNET_TRANSPORT_get_hello_cancel (p->th, &process_hello, p);
491#if DEBUG_CONNECTIONS
492 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 428 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
493 "Received (my) `%s' from transport service\n", 429 "Received (my) `%s' from transport service\n",
494 "HELLO"); 430 "HELLO");
495#endif
496 GNUNET_assert (message != NULL); 431 GNUNET_assert (message != NULL);
497 p->hello = GNUNET_malloc (ntohs (message->size)); 432 p->hello = GNUNET_malloc (ntohs (message->size));
498 memcpy (p->hello, message, ntohs (message->size)); 433 memcpy (p->hello, message, ntohs (message->size));
@@ -522,8 +457,6 @@ setup_peer (struct PeerContext *p, const char *cfgname)
522 "-c", cfgname, NULL); 457 "-c", cfgname, NULL);
523#endif 458#endif
524 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname)); 459 GNUNET_assert (GNUNET_OK == GNUNET_CONFIGURATION_load (p->cfg, cfgname));
525 p->stats = GNUNET_STATISTICS_create ("core", p->cfg);
526 GNUNET_assert (p->stats != NULL);
527 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL); 460 p->th = GNUNET_TRANSPORT_connect (p->cfg, NULL, p, NULL, NULL, NULL);
528 GNUNET_assert (p->th != NULL); 461 GNUNET_assert (p->th != NULL);
529 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p); 462 GNUNET_TRANSPORT_get_hello (p->th, &process_hello, p);
@@ -548,23 +481,6 @@ run (void *cls,
548 NULL, 481 NULL,
549 &inbound_notify, 482 &inbound_notify,
550 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers); 483 GNUNET_YES, &outbound_notify, GNUNET_YES, handlers);
551
552 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg,
553 "CORE",
554 "TOTAL_QUOTA_IN",
555 &current_quota_p1_in));
556 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg,
557 "CORE",
558 "TOTAL_QUOTA_IN",
559 &current_quota_p2_in));
560 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p1.cfg,
561 "CORE",
562 "TOTAL_QUOTA_OUT",
563 &current_quota_p1_out));
564 GNUNET_assert (GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_number (p2.cfg,
565 "CORE",
566 "TOTAL_QUOTA_OUT",
567 &current_quota_p2_out));
568} 484}
569 485
570 486
@@ -573,15 +489,14 @@ stop_arm (struct PeerContext *p)
573{ 489{
574#if START_ARM 490#if START_ARM
575 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM)) 491 if (0 != GNUNET_OS_process_kill (p->arm_proc, SIGTERM))
576 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); 492 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill");
577 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK) 493 if (GNUNET_OS_process_wait(p->arm_proc) != GNUNET_OK)
578 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid"); 494 GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "waitpid");
579 495 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
580 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"ARM process stopped\n"); 496 "ARM process %u stopped\n", GNUNET_OS_process_get_pid (p->arm_proc));
581 GNUNET_OS_process_close (p->arm_proc); 497 GNUNET_OS_process_close (p->arm_proc);
582 p->arm_proc = NULL; 498 p->arm_proc = NULL;
583#endif 499#endif
584 GNUNET_STATISTICS_destroy (p->stats, 0);
585 GNUNET_CONFIGURATION_destroy (p->cfg); 500 GNUNET_CONFIGURATION_destroy (p->cfg);
586} 501}
587 502
@@ -601,7 +516,7 @@ check ()
601 }; 516 };
602 ok = 1; 517 ok = 1;
603 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1, 518 GNUNET_PROGRAM_run ((sizeof (argv) / sizeof (char *)) - 1,
604 argv, "test_core_quota_compliance", "nohelp", options, &run, &ok); 519 argv, "test-core-quota-compliance", "nohelp", options, &run, &ok);
605 stop_arm (&p1); 520 stop_arm (&p1);
606 stop_arm (&p2); 521 stop_arm (&p2);
607 return ok; 522 return ok;
@@ -620,10 +535,9 @@ main (int argc, char *argv[])
620#endif 535#endif
621 NULL); 536 NULL);
622 ret = check (); 537 ret = check ();
623 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-peer-2"); 538 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-1");
624 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-quota-peer-2"); 539 GNUNET_DISK_directory_remove ("/tmp/test-gnunet-core-peer-2");
625 540
626 return ret; 541 return ret;
627} 542}
628 543/* end of test_core_api_reliability.c */
629/* end of test_core_quota_compliance.c */