aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2019-04-15 11:32:51 +0200
committerChristian Grothoff <christian@grothoff.org>2019-04-15 11:34:42 +0200
commit6e7793d8d8018baeb85fb661e1ee58251b61bf9a (patch)
treeb5cce84fbee99f8df6dc8116209b77bff6dfddce /src/util
parent45a04d9f5558f666c01f7fd0844be964bf610c9a (diff)
downloadgnunet-6e7793d8d8018baeb85fb661e1ee58251b61bf9a.tar.gz
gnunet-6e7793d8d8018baeb85fb661e1ee58251b61bf9a.zip
misc work on TNG
Diffstat (limited to 'src/util')
-rw-r--r--src/util/scheduler.c2
-rw-r--r--src/util/time.c100
2 files changed, 60 insertions, 42 deletions
diff --git a/src/util/scheduler.c b/src/util/scheduler.c
index 3bd7ccec7..2ddbb8c60 100644
--- a/src/util/scheduler.c
+++ b/src/util/scheduler.c
@@ -915,6 +915,7 @@ driver_add_multiple (struct GNUNET_SCHEDULER_Task *t)
915static void 915static void
916install_parent_control_handler (void *cls) 916install_parent_control_handler (void *cls)
917{ 917{
918 (void) cls;
918 install_parent_control_task = NULL; 919 install_parent_control_task = NULL;
919 GNUNET_OS_install_parent_control_handler (NULL); 920 GNUNET_OS_install_parent_control_handler (NULL);
920} 921}
@@ -926,6 +927,7 @@ shutdown_pipe_cb (void *cls)
926 char c; 927 char c;
927 const struct GNUNET_DISK_FileHandle *pr; 928 const struct GNUNET_DISK_FileHandle *pr;
928 929
930 (void) cls;
929 shutdown_pipe_task = NULL; 931 shutdown_pipe_task = NULL;
930 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle, 932 pr = GNUNET_DISK_pipe_handle (shutdown_pipe_handle,
931 GNUNET_DISK_PIPE_END_READ); 933 GNUNET_DISK_PIPE_END_READ);
diff --git a/src/util/time.c b/src/util/time.c
index 799c6cc63..758921718 100644
--- a/src/util/time.c
+++ b/src/util/time.c
@@ -770,6 +770,22 @@ GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIM
770 770
771 771
772/** 772/**
773 * Return a random time value between 0.5*r and 1.5*r.
774 *
775 * @param r input time for scaling
776 * @return randomized time
777 */
778struct GNUNET_TIME_Relative
779GNUNET_TIME_randomize (struct GNUNET_TIME_Relative r)
780{
781 double d = ((rand() % 1001) - 500) / 1000.0;
782
783 return relative_multiply_double (r,
784 d);
785}
786
787
788/**
773 * Obtain the current time and make sure it is monotonically 789 * Obtain the current time and make sure it is monotonically
774 * increasing. Guards against systems without an RTC or 790 * increasing. Guards against systems without an RTC or
775 * clocks running backwards and other nasty surprises. Does 791 * clocks running backwards and other nasty surprises. Does
@@ -819,53 +835,53 @@ GNUNET_TIME_absolute_get_monotonic (const struct GNUNET_CONFIGURATION_Handle *cf
819 struct GNUNET_DISK_FileHandle *fh; 835 struct GNUNET_DISK_FileHandle *fh;
820 836
821 fh = GNUNET_DISK_file_open (filename, 837 fh = GNUNET_DISK_file_open (filename,
822 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE, 838 GNUNET_DISK_OPEN_READWRITE | GNUNET_DISK_OPEN_CREATE,
823 GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_WRITE | 839 GNUNET_DISK_PERM_USER_WRITE | GNUNET_DISK_PERM_GROUP_WRITE |
824 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ); 840 GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_GROUP_READ);
825 if (NULL == fh) 841 if (NULL == fh)
826 { 842 {
827 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 843 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
828 _("Failed to map `%s', cannot assure monotonic time!\n"), 844 _("Failed to map `%s', cannot assure monotonic time!\n"),
829 filename); 845 filename);
830 } 846 }
831 else 847 else
832 { 848 {
833 off_t size; 849 off_t size;
834 850
835 size = 0; 851 size = 0;
836 GNUNET_break (GNUNET_OK == 852 GNUNET_break (GNUNET_OK ==
837 GNUNET_DISK_file_handle_size (fh, 853 GNUNET_DISK_file_handle_size (fh,
838 &size)); 854 &size));
839 if (size < sizeof (*map)) 855 if (size < (off_t) sizeof (*map))
840 { 856 {
841 struct GNUNET_TIME_AbsoluteNBO o; 857 struct GNUNET_TIME_AbsoluteNBO o;
842 858
843 o = GNUNET_TIME_absolute_hton (now); 859 o = GNUNET_TIME_absolute_hton (now);
844 if (sizeof (o) != 860 if (sizeof (o) !=
845 GNUNET_DISK_file_write (fh, 861 GNUNET_DISK_file_write (fh,
846 &o, 862 &o,
847 sizeof (o))) 863 sizeof (o)))
848 size = 0; 864 size = 0;
849 else 865 else
850 size = sizeof (o); 866 size = sizeof (o);
851 } 867 }
852 if (size == sizeof (*map)) 868 if (size == sizeof (*map))
853 { 869 {
854 map = GNUNET_DISK_file_map (fh, 870 map = GNUNET_DISK_file_map (fh,
855 &map_handle, 871 &map_handle,
856 GNUNET_DISK_MAP_TYPE_READWRITE, 872 GNUNET_DISK_MAP_TYPE_READWRITE,
857 sizeof (*map)); 873 sizeof (*map));
858 if (NULL == map) 874 if (NULL == map)
859 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 875 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
860 _("Failed to map `%s', cannot assure monotonic time!\n"), 876 _("Failed to map `%s', cannot assure monotonic time!\n"),
861 filename); 877 filename);
862 } 878 }
863 else 879 else
864 { 880 {
865 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 881 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
866 _("Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"), 882 _("Failed to setup monotonic time file `%s', cannot assure monotonic time!\n"),
867 filename); 883 filename);
868 } 884 }
869 } 885 }
870 GNUNET_DISK_file_close (fh); 886 GNUNET_DISK_file_close (fh);
871 GNUNET_free (filename); 887 GNUNET_free (filename);