[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 15/17: Small typo and improvements (add a few time management f
From: |
Rémi Birot-Delrue |
Subject: |
[gnunet] 15/17: 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`. |
Date: |
Wed, 12 Aug 2015 18:24:42 +0000 |
remibd pushed a commit to branch master
in repository gnunet.
commit 5581107a9d1fe39e09b62f686fc4fc4466505f2b
Author: RĂ©mi Birot-Delrue <address@hidden>
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)))
- [gnunet] 05/17: Add draft support for indexing/publication. * fs.scm: - add a `<file-information>` type and associated functions (`wrap-file-information`, `unwrap-file-information`, and `make-file-information`); - add incomplete bindings to `GNUNET_FS_directory_scan_*` functions (`start-directory-scan`, `stop-directory-scan`, `directory-scanner-result`) - add `share-tree->file-information` - add `start-publish` and `stop-publish` * examples/publish.scm: a very simple and ugly `gnunet-publish` clone., (continued)
- [gnunet] 05/17: Add draft support for indexing/publication. * fs.scm: - add a `<file-information>` type and associated functions (`wrap-file-information`, `unwrap-file-information`, and `make-file-information`); - add incomplete bindings to `GNUNET_FS_directory_scan_*` functions (`start-directory-scan`, `stop-directory-scan`, `directory-scanner-result`) - add `share-tree->file-information` - add `start-publish` and `stop-publish` * examples/publish.scm: a very simple and ugly `gnunet-publish` clone., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 12/17: Complete the container/metadata bindings., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 13/17: Remove `set-next-task!`, as the corresponding functions have been removed from GNUnet., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 07/17: Small bug fixes and add publishing in namespaces for examples/publish.scm * common.scm: add `gnunet-id-ffi` (FFI for libgnunetidentity). * identity.scm: replace `define-gnunet-fs` with `define-gnunet-id`. * fs.scm: corrects a bug in `start-publish` (gave `GNUNET_FS_publish_start` a pointer to the ego in place of a pointer to its private key). * examples/publish.scm: add handling of namespaces and replace simple global variables with parameters., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 08/17: Add `examples/identity.scm`, `examples/identity-bis.scm`, `examples/search-ns.scm`, and a few minor modifications. * examples/search-ns.scm: a basic tool to search namespaces. * examples/identity.scm: a basic tool to list egos. * examples/identity-bis.scm: idem, but using `start-identity-lookup`. * fs/uri.scm: `wrap-uri` throws an `invalid-arg` exception when given a null pointer. * tests/uri.scm: c.f. ↑ * configuration.scm: add `configuration-value-set?`. * identity.scm: add `ecdsa-public-key->string`., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 09/17: Rewrite of examples/publish.scm, small bug fixes and typos. * examples/publish.scm: rewritten to correctly handle namespaces. * gnu/gnunet/binding-utils.scm: add `or%`. * gnu/gnunet/fs.scm: bug fix: `start-*` function throw an error instead of returning %null-pointer. * gnu/gnunet/identity.scm: typo., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 14/17: Code cleaning: various improvements and bug fixes. * identity.scm: `open-identity-service` now throws an exception on failure. * binding-utils.scm: just add `destructuring-bind`. * common.scm: `time-rel` now throws an exception instead of returning a meaningless negative result; add `setup-log`. * container/metadata.scm: `metadata-set!` now throws an exception on error. * tests/container-metadata.scm: add tests for `metadata-copy`, `metadata-clear`, `metadata-equal?` and `add-publication-date!`, Rémi Birot-Delrue, 2015/08/12
- [gnunet] 11/17: Add `close-filesharing-service` and dynamic allocation in `open-filesharing-handle`., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 10/17: Add `time-rel` to replace all ad-hoc time calculations., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 17/17: Minor modifications to get all examples working. * binding-utils.scm: add `and=>%` (`and=>` for foreign pointers). * fs/progress-info.scm: bug fix: on '(#:publish #:complete) do not assert any more there’s a SKS URI (we don’t always publish in a namespace). * examples/search.scm: add a one-line help message. * examples/search-ns.scm, examples/publish.scm: typos., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 15/17: 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`.,
Rémi Birot-Delrue <=
- [gnunet] 16/17: Add a record type for GNUNET_FS_ProgressInfo and a few tests. * progress-info.scm: add a record type for `GNUNET_FS_ProgressInfo` and alter `parse-c-progress-info` to handle it. * fs.scm: - correct `make-file-information`; - deprecate directory-scan (too many bugs to fix, `make-file-information will` do for now); - replace `*block-options*` with `make-block-options`; - update `procedure->*` functions to use `parse-c-progress-info`. * examples/*.scm: follow modifications on fs.scm. * tests/progress-info.scm: add a fake progress-info to test `parse-c-progress-info`. * tests/fs.scm: add a small test for `make-file-information`., Rémi Birot-Delrue, 2015/08/12