gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet-scheme] branch master updated (7ccff30 -> d89a12f)


From: gnunet
Subject: [gnunet-scheme] branch master updated (7ccff30 -> d89a12f)
Date: Tue, 11 Jan 2022 12:03:45 +0100

This is an automated email from the git hooks/post-receive script.

maxime-devos pushed a change to branch master
in repository gnunet-scheme.

    from 7ccff30  doc: Document 'start-get!', 'put!' and friends.
     new 07d07a4  examples/web: Remove addressed TODO.
     new 0f9ef00  bv-slice: Don't print bytes in unreadable slices.
     new d89a12f  NEWS: Update.

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 NEWS                          |  5 ++++-
 examples/web.scm              | 12 ------------
 gnu/gnunet/utils/bv-slice.scm | 29 +++++++++++++++++++----------
 tests/bv-slice.scm            | 16 ++++++++++++++++
 4 files changed, 39 insertions(+), 23 deletions(-)

diff --git a/NEWS b/NEWS
index 63f9961..a940072 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-# Copyright (C) 2021 GNUnet e.V.
+# Copyright (C) 2021,2022 GNUnet e.V.
 # SPDX-License-Identifier: FSFAP
 # Copying and distribution of this file, with or without modification,
 # are permitted in any medium without royalty provided the copyright
@@ -11,3 +11,6 @@
    - The NSE client now accepts NaN as standard deviation instead of printing 
an error message.
      Sometimes the NSE service sends NaN as standard deviation, see
      <https://bugs.gnunet.org/view.php?id=7021#c18399>.
+   - The bytes in a slice are only printed when the slice is readable,
+     so unreadability of slices cannot be circumvented with object->string
+     anymore.
\ No newline at end of file
diff --git a/examples/web.scm b/examples/web.scm
index 01021c4..8f105b6 100644
--- a/examples/web.scm
+++ b/examples/web.scm
@@ -237,18 +237,6 @@ If incorrect, return @code{#false}. TODO more validation."
   (define server (open-server impl `(#:port 8089)))
   (define (url-handler* request body)
     (url-handler dht-server nse-server request body))
-  ;; TODO: Form to start GET and PUT requests?
-  ;; For now, hard code the data to insert.
-  (dht:put! dht-server
-           (dht:datum->insertion
-            (dht:make-datum
-             (symbol-value block-type block:test)
-             (bv-slice/read-write (make-bytevector 64))
-             (bv-slice/read-write #vu8(#xde #xad #xbe #xef)))))
-  (dht:start-get! dht-server
-                 (dht:make-query
-                  (symbol-value block-type block:test)
-                  (bv-slice/read-write (make-bytevector 64))) pk)
   (let loop ()
     (let-values (((client request body)
                  (read-client impl server)))
diff --git a/gnu/gnunet/utils/bv-slice.scm b/gnu/gnunet/utils/bv-slice.scm
index 6637852..add0f1b 100644
--- a/gnu/gnunet/utils/bv-slice.scm
+++ b/gnu/gnunet/utils/bv-slice.scm
@@ -95,18 +95,27 @@
                       "CAP_READ")
                      ((slice-writable? slice)
                       "CAP_WRITE")
+                     ;; Currently not constructible.
                      (#t
                       "0")))
-    (put-string port "):")
-    (let ((bv (slice-bv slice))
-         (end (+ (slice-offset slice)
-                 (slice-length slice))))
-      (let loop ((i (slice-offset slice)))
-       (if (< i end)
-           (let ((val (bytevector-u8-ref bv i)))
-             (put-char port #\ )
-             (put-string port (number->string val))
-             (loop (+ i 1))))))
+    ;; When the slice is readable, print the bytes in the slice.
+    (cond ((slice-readable? slice)
+          (put-string port "):")
+          (let ((bv (slice-bv slice))
+                (end (+ (slice-offset slice)
+                        (slice-length slice))))
+            (let loop ((i (slice-offset slice)))
+              (if (< i end)
+                  (let ((val (bytevector-u8-ref bv i)))
+                    (put-char port #\ )
+                    (put-string port (number->string val))
+                    (loop (+ i 1)))))))
+         (#true
+          ;; While the bytes in the slice cannot be printer because
+          ;; the slice is not readable, the length of the slice can
+          ;; still be printed.
+          (put-string port ") length: ")
+          (put-string port (number->string (slice-length slice)))))
     (put-char port #\>))
   (set-record-type-printer! <slice> print-slice)
 
diff --git a/tests/bv-slice.scm b/tests/bv-slice.scm
index e8f5bb7..e110592 100644
--- a/tests/bv-slice.scm
+++ b/tests/bv-slice.scm
@@ -139,6 +139,22 @@
   -128
   (slice-s8-ref (bv-slice/read-write #vu8(#b10000000)) 0))
 
+(test-equal "slice to string, read-write"
+  "#<slice (CAP_READ | CAP_WRITE): 1 2 3>"
+  (object->string (bv-slice/read-write #vu8(1 2 3))))
+
+(test-equal "slice to string, read-only"
+  "#<slice (CAP_READ): 1 2 3>"
+  (object->string
+   (slice/read-only (bv-slice/read-write #vu8(1 2 3)))))
+
+;; Make sure the lack of a read capability cannot be circumvented by
+;; object->string.
+(test-equal "slice to string, write-only"
+  "#<slice (CAP_WRITE) length: 3>"
+  (object->string
+   (slice/write-only (bv-slice/read-write #vu8(1 2 3)))))
+
 (test-end "bv-slice")
 
 ;; ^ TODO: test other procedures

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]