[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 02/03: dht: Implement documented data structures.
From: |
gnunet |
Subject: |
[gnunet-scheme] 02/03: dht: Implement documented data structures. |
Date: |
Sun, 26 Dec 2021 18:37:20 +0100 |
This is an automated email from the git hooks/post-receive script.
maxime-devos pushed a commit to branch master
in repository gnunet-scheme.
commit e0c9caff602ab1cf6041718f3290f3d836844ad7
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Sun Dec 26 11:27:29 2021 +0000
dht: Implement documented data structures.
TODO: actually use and test them.
* gnu/gnunet/dht/client.scm
(validate-key, validate-datum): New procedures.
(<datum>, <insertion>, <query>, <search-result>): New data structures.
---
gnu/gnunet/dht/client.scm | 102 +++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 101 insertions(+), 1 deletion(-)
diff --git a/gnu/gnunet/dht/client.scm b/gnu/gnunet/dht/client.scm
index 7055458..c2e3813 100644
--- a/gnu/gnunet/dht/client.scm
+++ b/gnu/gnunet/dht/client.scm
@@ -26,6 +26,15 @@
%minimum-replication-level
%maximum-replication-level
bound-replication-level
+
+ ;; Non-interactive data structures
+ make-datum datum? datum-key datum-value datum-expiration
+ datum->insertion insertion? insertion->datum
+ insertion-desired-replication-level
+ make-query query? query-type query-key query-desired-replication-level
+ datum->search-result search-result? search-result->datum
+ search-result-get-path search-result-put-path
+
connect
disconnect!
put!
@@ -45,7 +54,7 @@
(gnu gnunet mq-impl stream)
(gnu gnunet mq envelope)
(only (guile)
- pk define-syntax-rule define* error
+ pk define-syntax-rule define* lambda* error
make-hash-table hashq-set! hashq-remove! hashv-set! hashv-ref
hash-map->list)
(only (ice-9 atomic)
@@ -107,6 +116,97 @@ valid replication to the level, to the range the DHT
service likes."
(max %effective-minimum-replication-level
(min %effective-maximum-replication-level replication-level)))
+ (define (validate-key key)
+ "If @var{key} is, in-fact, a readable /hashcode:512, return it as a
+readable bytevector slice. If not, raise an appropriate exception. "
+ (if (= (slice-length key) (sizeof /hashcode:512 '()))
+ (slice/read-only key)
+ (error "length of key incorrect")))
+
+ (define (validate-datum key)
+ "If @var{key} is, in-fact, a datum, return it. Otherwise, raise an
appropriate exception."
+ (if (= (slice-length key) (sizeof /hashcode:512 '()))
+ (slice/read-only key)
+ (error "length of key incorrect")))
+
+ ;; TODO: use the data structures below and test them
+
+ ;; An key-value entry in the DHT.
+ (define-record-type (<datum> make-datum datum?)
+ (fields (immutable key datum-key)
+ (immutable value datum-value)
+ (immutable expiration datum-expiration))
+ (protocol
+ (lambda (%make)
+ (lambda* (type key value #:key (expiration 0)) ; TODO default
expiration
+ "Make ad datum object of block type @var{type} (or its corresponding
+numeric value), with key @var{key} (a readable @code{/hashcode:512} bytevector
+slice), value @var{value} (a readable bytevector slice) and expiring at
@var{expiration}.
+The keyword argument @var{expiration} is optional, see ???.
+
+The numeric value of the block type can be retrieved with the accessor
+@code{datum-type}. The accessors @code{datum-key}, @code{datum-value} and
+@code{datum-expiration} return the keyn value and expiration time respectively.
+It can be tested if an object is a datum object with the predicate
@code{datum?}."
+ (%make (canonical-block-type type)
+ (validate-key key)
+ (slice/read-only value) ; TODO: max size
+ expiration))))) ; TODO validate expiration
+
+ ;; A request to insert something in the DHT.
+ (define-record-type (<insertion> datum->insertion insertion?)
+ (fields (immutable datum insertion->datum)
+ (immutable desired-replication-level
+ insertion-desired-replication-level))
+ (protocol
+ (lambda (%make)
+ (lambda* (datum #:key (desired-replication-level 3)) ; TODO defaults
+ "Make an insertion object for inserting the datum @var{datum},
+desiring a replication level @var{desired-replication-level} (see ??).
+
+The datum and desired replication level can be recovered with the accessors
+@var{insertion->datum} and @var{insertion-desired-replication-level}. It can
+be tested if an object is an insertion object with the predicate
+@code{insertion?}."
+ (%make (validate-datum datum)
+ (bound-replication-level desired-replication-level))))))
+
+ (define-record-type (<query> make-query query?)
+ (fields (immutable type query-type)
+ (immutable key query-key)
+ (immutable desired-replication-level
query-desired-replication-level))
+ (protocol
+ (lambda (%make)
+ (lambda* (type key #:key (desired-replication-level 3))
+ "Make a query object for searching for a value of block type
@var{type}
+(or its corresponding numeric value), with key @var{key} (a readable
+@code{/hashcode:512} bytevector slice), at desired replication level
+@var{desired-replication-level}.
+
+The numeric value of the block type, the key and the desired replication level
+can be recovered with the accessors @code{query-type}, @code{query-key} and
+@code{query-desired-replication-level}. It can be tested if an object is a
+query object with the predicate @code{query?}."
+ (%make (canonical-block-type type)
+ (validate-key key)
+ (bound-replication-level desired-replication-level))))))
+
+ (define-record-type (<search-result> datum->search-result search-result?)
+ (fields (immutable datum search-result->datum)
+ (immutable get-path search-result-get-path)
+ (immutable put-path search-result-put-path))
+ (protocol
+ (lambda (%make)
+ (lambda* (datum #:key (get-path #f) (put-path #f))
+ "Make a search result object for the datum @var{datum}. The datum can
+be recovered with the accessor @code{search-result->datum}. It can be tested if
+an object is a search result with the predicate @code{search-result?}. The
+optional keyword arguments @code{get-path} and @code{put-path} are currently
+undocumented and untested."
+ ;; TODO: get-path and put-path
+ (%make (validate-datum datum) get-path put-path)))))
+
+
;; New get or put operations are initially in new-get-operations or
;; new-put-operation, and not in id->operation-map. They are moved
;; in the background by 'process-new-get-operations' and
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.