aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulius Bünger <buenger@mytum.de>2015-04-07 13:58:30 +0000
committerJulius Bünger <buenger@mytum.de>2015-04-07 13:58:30 +0000
commit76880145d9f2f442108a70a09c4949a8026826dc (patch)
tree2c6cd0f00075b7f11bcb850433f51e43332f0bf5
parentdf42828651e3f814a9b4a51dde916db10144cf23 (diff)
downloadgnunet-76880145d9f2f442108a70a09c4949a8026826dc.tar.gz
gnunet-76880145d9f2f442108a70a09c4949a8026826dc.zip
-writing important sampler info to file
-rw-r--r--src/rps/gnunet-service-rps_sampler.c140
1 files changed, 132 insertions, 8 deletions
diff --git a/src/rps/gnunet-service-rps_sampler.c b/src/rps/gnunet-service-rps_sampler.c
index f1fa53e01..9ae85dcb6 100644
--- a/src/rps/gnunet-service-rps_sampler.c
+++ b/src/rps/gnunet-service-rps_sampler.c
@@ -127,6 +127,13 @@ struct RPS_Sampler
127 * Used in the context of RPS 127 * Used in the context of RPS
128 */ 128 */
129 struct GNUNET_TIME_Relative max_round_interval; 129 struct GNUNET_TIME_Relative max_round_interval;
130
131 #ifdef TO_FILE
132 /**
133 * File name to log to
134 */
135 char *file_name;
136 #endif /* TO_FILE */
130}; 137};
131 138
132/** 139/**
@@ -239,6 +246,71 @@ static size_t max_size;
239static uint32_t client_get_index; 246static uint32_t client_get_index;
240 247
241 248
249#ifdef TO_FILE
250/**
251 * This function is used to facilitate writing important information to disk
252 */
253#define to_file(file_name, ...) do {char tmp_buf[512];\
254 int size;\
255 size = GNUNET_snprintf(tmp_buf,sizeof(tmp_buf),__VA_ARGS__);\
256 if (0 > size)\
257 LOG (GNUNET_ERROR_TYPE_WARNING,\
258 "Failed to create tmp_buf\n");\
259 else\
260 to_file_(file_name,tmp_buf);\
261} while (0);
262
263static void
264to_file_ (char *file_name, char *line)
265{
266 struct GNUNET_DISK_FileHandle *f;
267 char output_buffer[512];
268 //size_t size;
269 int size;
270 size_t size2;
271
272
273 if (NULL == (f = GNUNET_DISK_file_open (file_name,
274 GNUNET_DISK_OPEN_APPEND |
275 GNUNET_DISK_OPEN_WRITE |
276 GNUNET_DISK_OPEN_CREATE,
277 GNUNET_DISK_PERM_USER_WRITE)))
278 {
279 LOG (GNUNET_ERROR_TYPE_WARNING,
280 "Not able to open file %s\n",
281 file_name);
282 return;
283 }
284 size = GNUNET_snprintf (output_buffer,
285 sizeof (output_buffer),
286 "%llu %s\n",
287 GNUNET_TIME_absolute_get ().abs_value_us,
288 line);
289 if (0 > size)
290 {
291 LOG (GNUNET_ERROR_TYPE_WARNING,
292 "Failed to write string to buffer (size: %i)\n",
293 size);
294 return;
295 }
296
297 size2 = GNUNET_DISK_file_write (f, output_buffer, size);
298 if (size != size2)
299 {
300 LOG (GNUNET_ERROR_TYPE_WARNING,
301 "Unable to write to file! (Size: %u, size2: %u)\n",
302 size,
303 size2);
304 return;
305 }
306
307 if (GNUNET_YES != GNUNET_DISK_file_close (f))
308 LOG (GNUNET_ERROR_TYPE_WARNING,
309 "Unable to close file\n");
310}
311#endif /* TO_FILE */
312
313
242/** FIXME document */ 314/** FIXME document */
243static struct GetPeerCls *gpc_head; 315static struct GetPeerCls *gpc_head;
244static struct GetPeerCls *gpc_tail; 316static struct GetPeerCls *gpc_tail;
@@ -412,8 +484,19 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size)
412 { /* Shrinking */ 484 { /* Shrinking */
413 /* Temporary store those to properly call the removeCB on those later */ 485 /* Temporary store those to properly call the removeCB on those later */
414 486
415 LOG (GNUNET_ERROR_TYPE_DEBUG, "Shrinking sampler %d -> %d\n", old_size, new_size); 487 LOG (GNUNET_ERROR_TYPE_DEBUG,
416 GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size); 488 "Shrinking sampler %d -> %d\n",
489 old_size,
490 new_size);
491 #ifdef TO_FILE
492 to_file (sampler->file_name,
493 "Shrinking sampler %d -> %d\n",
494 old_size,
495 new_size);
496 #endif /* TO_FILE */
497 GNUNET_array_grow (sampler->sampler_elements,
498 sampler->sampler_size,
499 new_size);
417 LOG (GNUNET_ERROR_TYPE_DEBUG, 500 LOG (GNUNET_ERROR_TYPE_DEBUG,
418 "sampler->sampler_elements now points to %p\n", 501 "sampler->sampler_elements now points to %p\n",
419 sampler->sampler_elements); 502 sampler->sampler_elements);
@@ -421,12 +504,30 @@ sampler_resize (struct RPS_Sampler *sampler, unsigned int new_size)
421 } 504 }
422 else if (old_size < new_size) 505 else if (old_size < new_size)
423 { /* Growing */ 506 { /* Growing */
424 LOG (GNUNET_ERROR_TYPE_DEBUG, "Growing sampler %d -> %d\n", old_size, new_size); 507 LOG (GNUNET_ERROR_TYPE_DEBUG,
425 GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, new_size); 508 "Growing sampler %d -> %d\n",
426 509 old_size,
427 for ( i = old_size ; i < new_size ; i++ ) 510 new_size);
511 #ifdef TO_FILE
512 to_file (sampler->file_name,
513 "Growing sampler %d -> %d\n",
514 old_size,
515 new_size);
516 #endif /* TO_FILE */
517 GNUNET_array_grow (sampler->sampler_elements,
518 sampler->sampler_size,
519 new_size);
520
521 for (i = old_size ; i < new_size ; i++)
428 { /* Add new sampler elements */ 522 { /* Add new sampler elements */
429 sampler->sampler_elements[i] = RPS_sampler_elem_create (); 523 sampler->sampler_elements[i] = RPS_sampler_elem_create ();
524 #ifdef TO_FILE
525 to_file (sampler->file_name,
526 "%" PRIu32 ": Initialised empty sampler element\n",
527 i);
528 //"New sampler with key %s\n",
529 //GNUNET_h2s_full (sampler->sampler_elements[i]->auth_key));
530 #endif /* TO_FILE */
430 } 531 }
431 } 532 }
432 else 533 else
@@ -490,6 +591,13 @@ RPS_sampler_init (size_t init_size,
490 max_size = 1000; // TODO make input to _samplers_init() 591 max_size = 1000; // TODO make input to _samplers_init()
491 592
492 sampler = GNUNET_new (struct RPS_Sampler); 593 sampler = GNUNET_new (struct RPS_Sampler);
594
595 #ifdef TO_FILE
596 if (NULL == (sampler->file_name = GNUNET_DISK_mktemp ("sampler-")))
597 LOG (GNUNET_ERROR_TYPE_WARNING,
598 "Could not create file\n");
599 #endif /* TO_FILE */
600
493 sampler->sampler_size = 0; 601 sampler->sampler_size = 0;
494 sampler->sampler_elements = NULL; 602 sampler->sampler_elements = NULL;
495 sampler->max_round_interval = max_round_interval; 603 sampler->max_round_interval = max_round_interval;
@@ -516,10 +624,18 @@ RPS_sampler_update (struct RPS_Sampler *sampler,
516{ 624{
517 uint32_t i; 625 uint32_t i;
518 626
519 for ( i = 0 ; i < sampler->sampler_size ; i++ ) 627 for (i = 0 ; i < sampler->sampler_size ; i++)
628 {
520 RPS_sampler_elem_next (sampler->sampler_elements[i], 629 RPS_sampler_elem_next (sampler->sampler_elements[i],
521 sampler, 630 sampler,
522 id); 631 id);
632 #ifdef TO_FILE
633 to_file (sampler->file_name,
634 "%" PRIu32 ": Now contains %s\n",
635 i,
636 GNUNET_i2s_full (&sampler->sampler_elements[i]->peer_id));
637 #endif /* TO_FILE */
638 }
523} 639}
524 640
525 641
@@ -727,10 +843,18 @@ RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
727 cb_cls->callback = cb; 843 cb_cls->callback = cb;
728 cb_cls->cls = cls; 844 cb_cls->cls = cls;
729 845
846 #ifdef TO_FILE
847 if (GNUNET_NO == for_client)
848 {
849 to_file (sampler->file_name,
850 "This sampler is probably for Brahms itself\n");
851 }
852 #endif /* TO_FILE */
853
730 LOG (GNUNET_ERROR_TYPE_DEBUG, 854 LOG (GNUNET_ERROR_TYPE_DEBUG,
731 "Scheduling requests for %" PRIX32 " peers\n", num_peers); 855 "Scheduling requests for %" PRIX32 " peers\n", num_peers);
732 856
733 for ( i = 0 ; i < num_peers ; i++ ) 857 for (i = 0 ; i < num_peers ; i++)
734 { 858 {
735 gpc = GNUNET_new (struct GetPeerCls); 859 gpc = GNUNET_new (struct GetPeerCls);
736 gpc->sampler = sampler; 860 gpc->sampler = sampler;