remibd pushed a commit to branch master in repository gnunet. commit 5581107a9d1fe39e09b62f686fc4fc4466505f2b Author: Rémi Birot-Delrue <asg...@free.fr> Date: Wed Aug 12 19:25:14 2015 +0200
Small typo and improvements (add a few time management functions). * common.scm: - add `bool->int` and `int->bool`; - add `time-rel`, `current-time`, `time-absolute->string`, and `time-relative->absolute`. * uri.scm: minor typo and add LOC URIs to `uri-file-size`. --- gnu/gnunet/common.scm | 57 ++++++++++++++++++++++++++++++++++-------------- gnu/gnunet/fs/uri.scm | 5 ++- 2 files changed, 43 insertions(+), 19 deletions(-) diff --git a/gnu/gnunet/common.scm b/gnu/gnunet/common.scm index 17c88e4..d1d1337 100644 --- a/gnu/gnunet/common.scm +++ b/gnu/gnunet/common.scm @@ -30,6 +30,9 @@ time-relative time-absolute time-rel + current-time + time-absolute->string + time-relative->absolute ecdsa-public-key ecdsa-public-key? @@ -64,17 +67,6 @@ (define time-relative uint64) (define time-absolute uint64) -(define* (time-rel #:key (hours 0) (minutes 0) (seconds 0) (milli 0) (micro 0)) - (let* ((minutes* (+ (* hours 60) minutes)) - (seconds* (+ (* minutes* 60) seconds)) - (milli* (+ (* seconds* 1000) milli)) - (micro* (+ (* milli* 1000) micro))) - (when (negative? micro*) - (scm-error 'out-of-range "time-rel" - "result (~a) is negative" (list micro*) - (list hours minutes seconds milli micro))) - (inexact->exact micro*))) - (define ecdsa-public-key (generate (/ 256 8 4) uint32)) (define eddsa-public-key ecdsa-public-key) (define eddsa-signature (list eddsa-public-key @@ -108,6 +100,13 @@ (define-foreign-definer define-gnunet-fs gnunet-fs-ffi) (define-foreign-definer define-gnunet-id gnunet-identity-ffi) +(define-gnunet %time-absolute-get + "GNUNET_TIME_absolute_get" : '() -> time-absolute) +(define-gnunet %time-absolute->string + "GNUNET_STRINGS_absolute_time_to_string" : (list time-absolute) -> '*) +(define-gnunet %time-relative->absolute + "GNUNET_TIME_relative_to_absolute" : (list time-relative) -> time-absolute) + (define-gnunet %log-setup "GNUNET_log_setup" : '(* * *) -> int) (define-gnunet %xfree "GNUNET_xfree_" : (list '* '* int) -> void) @@ -119,6 +118,13 @@ "GNUNET_STRINGS_string_to_data" : (list '* size_t '* size_t) -> int) +(define (bool->int x) (if x gnunet-yes gnunet-no)) +(define (int->bool x) + (cond ((= gnunet-yes x) #t) + ((= gnunet-no x) #f) + ((= gnunet-system-error x) #:system-error) + (else #:unknown))) + (define log-level-alist (list (cons #:none (string->pointer "NONE")) (cons #:error (string->pointer "ERROR")) @@ -140,12 +146,29 @@ writing, LOG-LEVEL is a keyword from (#:none #:error #:warning #:info #:debug (log-level->pointer log-level) (string->pointer* log-file))) -(define (bool->int x) (if x gnunet-yes gnunet-no)) -(define (int->bool x) - (cond ((= gnunet-yes x) #t) - ((= gnunet-no x) #f) - ((= gnunet-system-error x) #:system-error) - (else #:unknown))) +(define* (time-rel #:key (days 0) (hours 0) (minutes 0) + (seconds 0) (milli 0) (micro 0)) + (let* ((hours* (+ (* days 24) hours)) + (minutes* (+ (* hours* 60) minutes)) + (seconds* (+ (* minutes* 60) seconds)) + (milli* (+ (* seconds* 1000) milli)) + (micro* (+ (* milli* 1000) micro))) + (when (negative? micro*) + (scm-error 'out-of-range "time-rel" + "result (~a) is negative" (list micro*) + (list hours minutes seconds milli micro))) + (inexact->exact micro*))) + +(define (current-time) + "Get the current time as an absolute time." + (%time-absolute-get)) + +(define (time-absolute->string t) + (pointer->string (%time-absolute->string t))) + +(define (time-relative->absolute t) + "Convert a relative time to an absolute time in the future." + (%time-relative->absolute t)) (define %xfilename (string->pointer "guile")) diff --git a/gnu/gnunet/fs/uri.scm b/gnu/gnunet/fs/uri.scm index 485f450..1d76016 100644 --- a/gnu/gnunet/fs/uri.scm +++ b/gnu/gnunet/fs/uri.scm @@ -106,7 +106,7 @@ (cond ((and (eq? %null-pointer %uri) (eq? %null-pointer %error-message)) (throw 'invalid-result "parse-uri" "%uri-parse" - (list str %error-message-pointer))) + (list str %error-message-ptr))) ((eq? %null-pointer %uri) (%free %error-message) ; we don’t use error-message (throw 'invalid-arg "parse-uri" str)) @@ -160,7 +160,8 @@ (define (uri-file-size uri) "Return the size of the file pointed by URI. Raises an invalid-arg error if URI is not a chk uri." - (when (not (eq? #:chk (uri-type uri))) + (when (not (or (eq? #:chk (uri-type uri)) + (eq? #:loc (uri-type uri)))) (throw 'invalid-arg "uri-file-size" uri)) (%uri-chk-get-file-size (unwrap-uri uri)))