[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet] 14/17: Code cleaning: various improvements and bug fixes. * ide
From: |
Rémi Birot-Delrue |
Subject: |
[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!` |
Date: |
Wed, 12 Aug 2015 18:24:42 +0000 |
remibd pushed a commit to branch master
in repository gnunet.
commit 9cef3b7d4339016e5f4d5a05dc7e4505923e2a16
Author: Rémi Birot-Delrue <address@hidden>
Date: Mon Aug 10 19:18:22 2015 +0200
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!`
---
gnu/gnunet/binding-utils.scm | 7 +++++++
gnu/gnunet/common.scm | 31 ++++++++++++++++++++++++++++++-
gnu/gnunet/container/metadata.scm | 6 ++++--
gnu/gnunet/identity.scm | 9 ++++++---
tests/container-metadata.scm | 15 +++++++++++++++
5 files changed, 62 insertions(+), 6 deletions(-)
diff --git a/gnu/gnunet/binding-utils.scm b/gnu/gnunet/binding-utils.scm
index 0ab899f..1dd9d87 100644
--- a/gnu/gnunet/binding-utils.scm
+++ b/gnu/gnunet/binding-utils.scm
@@ -30,6 +30,8 @@
rassoc
rassoc-ref
+ destructuring-bind
+
string->pointer*
pointer->string*
make-c-struct*
@@ -93,3 +95,8 @@ if STRING is empty (\"\")."
(if (eq? %null-pointer x*)
(or% y ...)
x*)))))
+
+;;; Utilities
+
+(define-syntax-rule (destructuring-bind pattern value body body* ...)
+ (match value (pattern body body* ...)))
diff --git a/gnu/gnunet/common.scm b/gnu/gnunet/common.scm
index 0d1a6b4..17c88e4 100644
--- a/gnu/gnunet/common.scm
+++ b/gnu/gnunet/common.scm
@@ -45,6 +45,8 @@
define-gnunet-fs
define-gnunet-id
+ setup-log
+
%make-blob-pointer
%malloc
%free
@@ -67,7 +69,11 @@
(seconds* (+ (* minutes* 60) seconds))
(milli* (+ (* seconds* 1000) milli))
(micro* (+ (* milli* 1000) micro)))
- 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)
@@ -102,6 +108,8 @@
(define-foreign-definer define-gnunet-fs gnunet-fs-ffi)
(define-foreign-definer define-gnunet-id gnunet-identity-ffi)
+(define-gnunet %log-setup "GNUNET_log_setup" : '(* * *) -> int)
+
(define-gnunet %xfree "GNUNET_xfree_" : (list '* '* int) -> void)
(define-gnunet %xmalloc "GNUNET_xmalloc_" : (list size_t '* int) -> '*)
@@ -111,6 +119,27 @@
"GNUNET_STRINGS_string_to_data" : (list '* size_t '* size_t) -> int)
+(define log-level-alist
+ (list (cons #:none (string->pointer "NONE"))
+ (cons #:error (string->pointer "ERROR"))
+ (cons #:warning (string->pointer "WARNING"))
+ (cons #:info (string->pointer "INFO"))
+ (cons #:debug (string->pointer "DEBUG"))
+ (cons #:invalid (string->pointer "INVALID"))
+ (cons #:bulk (string->pointer "BULK"))
+ (cons #:unspecified (string->pointer "UNSPECIFIED"))))
+
+(define* (setup-log client-name log-level #:optional (log-file ""))
+ "Setup GNUnet’s logging. CLIENT-NAME is the name of the program you’re
+writing, LOG-LEVEL is a keyword from (#:none #:error #:warning #:info #:debug
+#:invalid #:bulk), LOG-FILE is either a filename or #f for `stderr'."
+ (define (log-level->pointer key)
+ (or (assq-ref log-level-alist key)
+ (assq-ref log-level-alist #:unspecified)))
+ (%log-setup (string->pointer client-name)
+ (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)
diff --git a/gnu/gnunet/container/metadata.scm
b/gnu/gnunet/container/metadata.scm
index e9a31e5..9437ead 100644
--- a/gnu/gnunet/container/metadata.scm
+++ b/gnu/gnunet/container/metadata.scm
@@ -148,8 +148,10 @@
(bytevector-length (metadata-item-data item))))
(define (metadata-set! metadata item)
- (apply %metadata-insert (unwrap-metadata metadata)
- (metadata-item->list item)))
+ (let ((res (apply %metadata-insert (unwrap-metadata metadata)
+ (metadata-item->list item))))
+ (when (= res gnunet-system-error)
+ (throw 'entry-already-exist "metadata-set!" metadata item))))
(define (metadata-ref metadata type)
(pointer->string
diff --git a/gnu/gnunet/identity.scm b/gnu/gnunet/identity.scm
index 06cfe8c..68850c1 100644
--- a/gnu/gnunet/identity.scm
+++ b/gnu/gnunet/identity.scm
@@ -98,9 +98,12 @@ assigned by the user for this ego (or #f if the user just
deleted this ego).
Return a handle to the identity service that’s needed by every identity related
function."
- (%identity-connect (unwrap-configuration config)
- (identity-callback->pointer identity-callback)
- %null-pointer))
+ (or%
+ (%identity-connect (unwrap-configuration config)
+ (identity-callback->pointer identity-callback)
+ %null-pointer)
+ (throw 'invalid-result "open-identity-service" "%identity-connect"
+ %null-pointer)))
(define (close-identity-service identity-handle)
"Disconnect from the identity service."
diff --git a/tests/container-metadata.scm b/tests/container-metadata.scm
index 76ef233..900b4e5 100644
--- a/tests/container-metadata.scm
+++ b/tests/container-metadata.scm
@@ -45,4 +45,19 @@
(test-equal '("foo" "bar")
(metadata-map (lambda (name . _) name) test-meta))
+;; copy
+(define test-meta-copy (metadata-copy test-meta))
+(test-equal "foo.scm" (metadata-ref test-meta-copy #:original-filename))
+
+;; equal?
+(test-assert (metadata-equal? test-meta test-meta-copy))
+
+;; clear!
+(metadata-clear! test-meta-copy)
+(test-equal #f (metadata-ref test-meta-copy #:original-filename))
+
+;; add-publication-date!
+(metadata-add-publication-date! test-meta-copy)
+(test-assert (metadata-ref test-meta-copy #:publication-date))
+
(test-end)
- [gnunet] 04/17: Add a few utility functions. * binding-utils.scm: add `pointer->string*`. * common.scm: add `bool->int` and `int->bool`, two functions to easily convert `gnunet-ok`, `gnunet-no`, `gnunet-syserror` values to booleans. * fs/uri.scm: export `keyword-list->string`. * tests/uri.scm: test `keyword-list->string`. * scheduler.scm: add `cancel-task!`., (continued)
- [gnunet] 04/17: Add a few utility functions. * binding-utils.scm: add `pointer->string*`. * common.scm: add `bool->int` and `int->bool`, two functions to easily convert `gnunet-ok`, `gnunet-no`, `gnunet-syserror` values to booleans. * fs/uri.scm: export `keyword-list->string`. * tests/uri.scm: test `keyword-list->string`. * scheduler.scm: add `cancel-task!`., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 02/17: API cleanup: separates search and URI, adds sks URIs. * examples/search.scm: echo changes in the API; * gnu/gnunet/common.scm: add ecdsa-public-key? and string->data-pointer; * gnu/gnunet/fs.scm: replace search-service-open with open-filesharing-service, replace start-ksk-search with start-search; * gnu/gnunet/fs/uri.scm: add make-sks-uri-pointer and make-sks-uri; * tests/uri.scm: add tests for make-sks-uri-pointer and make-sks-uri., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 03/17: Bind basic download functionalities * examples/download.scm: a loose `gnunet-download' clone. * system/foreign/unions.scm: add the possibility to specify #f as a union variant to get a padding of the size of the union. * gnu/gnunet/fs/progress-info.scm: just adapted to the modification to unions.scm. * gnu/gnunet/fs/uri.scm: add a few utility functions: `parse-uri' and `uri-file-size'. * gnu/gnunet/fs/fs.scm: add `start-download` and `stop-download`., Rémi Birot-Delrue, 2015/08/12
- [gnunet] 06/17: Bind GNUNET_FS_IDENTITY_* functions and add support for publishing in namespaces. * identity.scm: complete bindings of GNUNET_FS_IDENTITY * fs.scm: add support for egos/namespaces to `start-publish` * binding-utils: remove the useless import of `assert`, Rémi Birot-Delrue, 2015/08/12
- [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 <=
- [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, 2015/08/12
- [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