gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] branch master updated (9273184 -> e57fe14)


From: gnunet
Subject: [gnunet-scheme] branch master updated (9273184 -> e57fe14)
Date: Sun, 20 Nov 2022 20:50:38 +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 9273184  fs/struct: Define new message type /:msg:fs:start-search!.
     new e8015e4  fs/struct: Define new message types /:msg:fs:put! and 
/:msg:fs:client:put!.
     new 63f3892  hashcode: Complete translation to bytevector slices.
     new e57fe14  hashcode: Adjust to conventional naming.

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:
 Makefile.am                   |  1 +
 gnu/gnunet/fs/struct.scm      | 50 ++++++++++++++++++++++-
 gnu/gnunet/fs/uri.scm         |  8 ++--
 gnu/gnunet/hashcode-ascii.scm |  8 ++--
 gnu/gnunet/hashcode.scm       | 94 ++++++++++++++++++++++++-------------------
 5 files changed, 109 insertions(+), 52 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index dc4badb..79a5354 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -50,6 +50,7 @@ modules = \
   gnu/gnunet/concurrency/lost-and-found.scm \
   \
   gnu/gnunet/data-string.scm \
+  gnu/gnunet/hashcode.scm \
   \
   gnu/gnunet/mq/envelope.scm \
   gnu/gnunet/mq/error-reporting.scm \
diff --git a/gnu/gnunet/fs/struct.scm b/gnu/gnunet/fs/struct.scm
index 27d19c5..52639f8 100644
--- a/gnu/gnunet/fs/struct.scm
+++ b/gnu/gnunet/fs/struct.scm
@@ -26,7 +26,8 @@
          /:msg:fs:index-start!
          /:msg:fs:index-list:entry
          /:msg:fs:unindex!
-         /:msg:fs:start-search!)
+         /:msg:fs:start-search!
+         /:msg:fs:put!)
   (import (only (rnrs base) define begin * quote)
          (only (gnu gnunet crypto struct)
                /peer-identity)
@@ -190,4 +191,49 @@ exposing ourselves).
 Otherwise, @var{target} must be all zeros."))
        (field (query /hashcode:512)
              (synopsis "Hash of the public key for UBLOCKs: hash of the
-CHK-encoded block for DBLOCKS and IBLOCKS."))))))
+CHK-encoded block for DBLOCKS and IBLOCKS."))))
+
+    ;; TODO: client<->service or peer<->peer?
+    (define-type /:msg:fs:put!
+      (structure/packed
+       (synopsis "Response from file-sharing service with a response for a
+previous FS search.")
+       (documentation "This is followed by the actual encrypted content.")
+       (properties '((message-symbol msg:fs:put!) ; TODO: check
+                    (c-type . PutMessage)))
+       (field (header /:message-header))
+       (field (type u32/big)
+             ;; TODO: reference to block types
+             (synopsis "Type of the block.  Should never be zero"))
+       (field (expiration /time-absolute)
+             (synopsis "When does this result expire?"))))
+
+    (define-type /:msg:fs:client:put!
+      (structure/packed
+       (synopsis "Response from file-sharing service with a response for a
+previous FS search")
+       (documentation
+        "Response from FS service with a result for a previous FS search.
+Note that queries for DBLOCKS and IBLOCKS that have received a
+single response are considered done.  This message is transmitted
+between the service and a client.")
+       (properties '((c-type . ClientPutMessage)
+                    ;; This being the same as for /:msg:fs:client:put!
+                    ;; is correct.
+                    (message-symbol msg:fs:put!)))
+       (field (header /:message-header))
+       (field (type u32/big)
+             ;; TODO: reference to list of block types.
+             (synopsis "Type of the block.  Should never be zero."))
+       (field (expiration /time-absolute)
+             (synopsis "When does this result expire?"))
+       (field (last-transmission /time-absolute)
+             ;; TODO: Define FOREVER
+             (synopsis "When was the last time we have tried to download this
+block?  FOREVER if unknown/not relevant."))
+       (field (number-transmissions u32/big)
+             (synopsis "How often did we transmit this query before getting
+an answer (estimate).")) ; TODO check begin at 0 or 1, when
+       (field (respect-offered u32/big)
+             (synopsis "How much respect did we offer (in total) before
+getting an answer (estimate)."))))))
diff --git a/gnu/gnunet/fs/uri.scm b/gnu/gnunet/fs/uri.scm
index d2255d5..a44b4be 100644
--- a/gnu/gnunet/fs/uri.scm
+++ b/gnu/gnunet/fs/uri.scm
@@ -103,16 +103,16 @@
   ;; Content hash key
   (define-record-type (<content-hash-key> %make-content-hash-key chk?)
     (fields ;; Hash of the original content, used for encryption.
-            ;; Of type <hash-code>.
+            ;; Of type <hashcode:512>.
             (immutable key chk-key)
             ;; Hash of the encrypted content, used for querying.
-            ;; Of type <hash-code>
+            ;; Of type <hashcode:512>
             (immutable query chk-query)))
 
   (define (make-chk key query)
     "Construct a <content-hash-key>"
-    (assert (hashcode? key))
-    (assert (hashcode? query))
+    (assert (hashcode:512? key))
+    (assert (hashcode:512? query))
     (%make-content-hash-key key query))
 
   ;; Information needed to retrieve a file (content-hash-key
diff --git a/gnu/gnunet/hashcode-ascii.scm b/gnu/gnunet/hashcode-ascii.scm
index 95d8d36..bb5e29b 100644
--- a/gnu/gnunet/hashcode-ascii.scm
+++ b/gnu/gnunet/hashcode-ascii.scm
@@ -35,7 +35,7 @@
   #;(define hashcode-ascii-length 103)
 
   (define (hashcode->ascii hashcode)
-    "Convert a <hashcode> to ASCII encoding.  The ASCII encoding is rather
+    "Convert a <hashcode:512> to ASCII encoding.  The ASCII encoding is rather
 GNUnet specific.  It was chosen such that it only uses characters
 in [0-9A-V], can be produced without complex arithmetics and uses a
 small number of characters.  The GNUnet encoding uses 103
@@ -44,11 +44,11 @@ characters.
 @var{block} the hash code"
     (data->string (hashcode->bv hashcode)))
 
-  (define (ascii->hashcode ascii)
+  (define (ascii->hashcode:512 ascii)
     "Convert ASCII encoding back to hash code.
 
 @var{ascii} the encoding
 Return @lisp{#f} in case of an encoding error."
     (let ((bv (guard (c ((bogus-crockford-base32hex? c) #false))
-                    (string->data ascii hashcode-u8-length))))
-      (and bv (bv->hashcode bv)))))
+                    (string->data ascii hashcode:512-u8-length))))
+      (and bv (bv->hashcode:512 bv)))))
diff --git a/gnu/gnunet/hashcode.scm b/gnu/gnunet/hashcode.scm
index 8ef9a06..a5f9994 100644
--- a/gnu/gnunet/hashcode.scm
+++ b/gnu/gnunet/hashcode.scm
@@ -1,6 +1,6 @@
 ;#!r6rs
 ;;   This file is part of scheme-GNUnet, a partial Scheme port of GNUnet.
-;;   Copyright (C) 2006--2020 GNUnet e.V.
+;;   Copyright (C) 2006--2020, 2022 GNUnet e.V.
 ;;
 ;;   GNUnet is free software: you can redistribute it and/or modify it
 ;;   under the terms of the GNU Affero General Public License as published
@@ -20,60 +20,70 @@
 ;; Extracted from src/include/gnunet_common.h
 
 (library (gnu gnunet hashcode)
-  (export hashcode-bit-length hashcode-u8-length
-          short-hashcode-bit-length short-hashcode-u8-length
-          hashcode? short-hashcode?
-          bv->hashcode bv->short-hashcode
-          hashcode->bv short-hashcode->bv)
+  (export hashcode:512-bit-length hashcode:256-u8-length
+          hashcode:512-bit-length hashcode:256-u8-length
+          hashcode:512? hashcode:256?
+          make-hashcode:512/share make-hashcode:512
+         make-hashcode:256/share make-hashcode:256
+          hashcode:512->slice hashcode:256->slice)
   (import (rnrs base)
-         (rnrs control)
-          (rnrs records syntactic)
-         (rnrs bytevectors))
+         (gnu gnunet utils bv-slice)
+          (rnrs records syntactic))
 
-  (define hashcode-bit-length 512)
-  (define short-hashcode-bit-length 256)
-  (define hashcode-u8-length (/ hashcode-bit-length 8))
-  (define short-hashcode-u8-length (/ short-hashcode-bit-length 8))
+  (define hashcode:512-bit-length 512)
+  (define hashcode:256-bit-length 256)
+  (define hashcode:512-u8-length (/ hashcode:512-bit-length 8))
+  (define hashcode:256-u8-length (/ hashcode:256-bit-length 8))
 
   ;; A 512-bit hashcode.  These are the default length for GNUnet,
   ;; using SHA-512.
-  (define-record-type (<hashcode> %make-hashcode hashcode?)
-    (fields (immutable bv %hashcode-bv))
+  (define-record-type (<hashcode:512> make-hashcode:512/share hashcode:512?)
+    (fields (immutable slice hashcode:512-slice))
     (opaque #t)
-    (sealed #t))
+    (sealed #t)
+    (protocol
+     (lambda (%make)
+       (lambda (slice)
+        "Make a hashcode, containing @var{slice} (a readable
+@code{/hashcode:512} bytevector slice).  @var{slice} may not be mutated
+while the constructed hashcode is in use."
+        (assert (= (slice-length slice) hashcode:512-u8-length))
+        (slice/read-only slice)))))
+
+  (define (make-hashcode:512 slice)
+    "Make a hashcode, containing @var{slice} (a readable @code{/hashcode:512}
+bytevector slice).  @var{slice} may not be mutated while the constructed
+hashcode is in use."
+    (make-hashcode:512/share (slice-copy/read-only slice)))
 
   ;; A 256-bit hashcode.  Used under special conditions, like when space
   ;; is critical and security is not impacted by it.
-  (define-record-type (<short-hashcode> %make-short-hashcode short-hashcode?)
-    (fields (immutable bv %short-hashcode-bv))
+  (define-record-type (<hashcode:256> make-hashcode:256/share hashcode:256?)
+    (fields (immutable slice hashcode:256-slice))
     (opaque #t)
-    (sealed #t))
-
-  (define (bv->something %wrap length)
-    (case-lambda
-      "Read something from a bytevector"
-      ((bv) ; whole bytevector
-       (assert (= (bytevector-length bv) length))
-       (%wrap (bytevector-copy bv)))
-      ((bv offset) ; part of a bytevector, starting at some offset
-       (assert (<= (+ offset length) (bytevector-length bv)))
-       (let ((bv-new (make-bytevector length)))
-         (bytevector-copy! bv 0 bv-new 0 length)
-         (%wrap bv-new)))))
+    (sealed #t)
+    (protocol
+     (lambda (%make)
+       (lambda (slice)
+        "Make a short hashcode, containing @var{slice} (a readable
+@code{/hashcode:256} bytevector slice).  @var{slice} may not be mutated
+while the constructed short hashcode is in use."
+        (assert (= (slice-length slice) hashcode:256-u8-length))
+        (slice/read-only slice)))))
 
-  (define bv->hashcode
-    (bv->something %make-hashcode hashcode-u8-length))
-  (define bv->short-hashcode
-    (bv->something %make-short-hashcode short-hashcode-u8-length))
+  (define (bv->hashcode:512 bv)
+    "Read a hashcode from a bytevector (deprecated)."
+    (make-hashcode:512 (bv-slice/read-only bv)))
+  (define (bv->hashcode:256 bv)
+    "Read a short hashcode from a bytevector (deprecated)."
+    (make-hashcode:256 (bv-slice/read-only bv)))
 
-  (define (hashcode->bv hashcode)
+  (define (hashcode:512->bv hashcode)
     "Extract the bytevector corresponding to @var{hashcode}
 (read-only)"
-    (bytevector-copy (%hashcode-bv hashcode)))
+    (slice-copy/bytevector (hashcode:512-slice hashcode)))
 
-  (define (short-hashcode->bv hashcode)
-    "Extract the bytevector corresponding to @var{short-hashcode}
+  (define (hashcode:256->bv hashcode)
+    "Extract the bytevector corresponding to @var{hashcode}
 (read-only)"
-    (bytevector-copy (%short-hashcode-bv hashcode))))
-
-
+    (slice-copy/bytevector (hashcode:256-slice hashcode))))

-- 
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]