diff options
author | Maxime Devos <maximedevos@telenet.be> | 2023-03-01 10:11:06 +0100 |
---|---|---|
committer | Maxime Devos <maximedevos@telenet.be> | 2023-03-04 01:30:55 +0100 |
commit | 785d73834f3d2076f55f0d85187308953447f09b (patch) | |
tree | 5e979b21e422f873d569f23c726dc219a93db3bb | |
parent | 2a263aabfdd3e0216fd91aaa62368d68dd71b175 (diff) | |
download | gnunet-scheme-785d73834f3d2076f55f0d85187308953447f09b.tar.gz gnunet-scheme-785d73834f3d2076f55f0d85187308953447f09b.zip |
dht/client: Rewrite <insertion> in terms of cisw.
* doc/distributed-hash-table.scm: Adjust API.
* examples/web.scm: Adjust to new procedure names.
* gnu/gnunet/dht/client.scm (datum->insertion): Rename to ...
(make-insertion/share): ... this.
(make-insertion): New procedure.
(<insertion>): Rewrite as a cisw.
(insertion=?): Add standard cisw procedure.
(analyse-client-put): Adjust to renaming.
* tests/distributed-hash-table.scm
("copy-insertion: equal and independent")
("synchronuous ping-pong with multiple balls (no interruptions, no
cancellation)")
("search callback re-entrancy"):
("searches restarted after disconnect")
("cancelling a search within a search callback does not hang")
(i): Adjust to new names.
(insertion=?,insertion->sexp): Remove now unused procedures.
-rw-r--r-- | doc/distributed-hash-table.tm | 14 | ||||
-rw-r--r-- | examples/web.scm | 4 | ||||
-rw-r--r-- | gnu/gnunet/dht/client.scm | 52 | ||||
-rw-r--r-- | tests/distributed-hash-table.scm | 19 |
4 files changed, 44 insertions, 45 deletions
diff --git a/doc/distributed-hash-table.tm b/doc/distributed-hash-table.tm index da57120..837c45e 100644 --- a/doc/distributed-hash-table.tm +++ b/doc/distributed-hash-table.tm | |||
@@ -59,18 +59,18 @@ | |||
59 | </explain> | 59 | </explain> |
60 | 60 | ||
61 | <\explain> | 61 | <\explain> |
62 | <scm|(datum-\<gtr\>insertion <var|datum> | 62 | <scm|(make-insertion <var|datum> #:desired-replication-level)><index|make-insertion> |
63 | #:desired-replication-level)><index|datum-\<gtr\>insertion> | ||
64 | <|explain> | 63 | <|explain> |
65 | Make an insertion object for inserting the datum <var|datum>, desiring a | 64 | Make an insertion object for inserting the datum <var|datum>, desiring a |
66 | replication level <var|desired-replication-level> (see | 65 | replication level <var|desired-replication-level> (see |
67 | <reference|replication levels???>)<todo|various options>. | 66 | <reference|replication levels???>)<todo|various options>. |
68 | 67 | ||
69 | The datum and desired replication level can be recovered with the | 68 | Insertions are <acronym|cisw> (<reference|cisw>) ojects and as such the |
70 | accessors <scm|insertion-\<gtr\>datum><index|insertion-\<gtr\>datum> and | 69 | procedures <scm|insertion-\<gtr\>datum><index|insertion-\<gtr\>datum>, |
71 | <var|insertion-desired-replication-level><index|insertion-desired-replication-level>. | 70 | <scm|insertion-desired-replication-level><index|insertion-desired-replication-level>, |
72 | It can be tested if an object is an insertion object with the predicate | 71 | <scm|insertion?><index|insertion?>, <scm|make-insertion>, |
73 | <scm|insertion?><index|insertion?>. | 72 | <scm|make-insertion/share><index|make-insertion/share> and |
73 | <scm|insertion=?><index|insertion=?> have the usual semantics. | ||
74 | </explain> | 74 | </explain> |
75 | 75 | ||
76 | <\explain> | 76 | <\explain> |
diff --git a/examples/web.scm b/examples/web.scm index 9f233aa..4c2d2ff 100644 --- a/examples/web.scm +++ b/examples/web.scm | |||
@@ -1,5 +1,5 @@ | |||
1 | ;; This file is part of scheme-GNUnet. | 1 | ;; This file is part of scheme-GNUnet. |
2 | ;; Copyright © 2021, 2022 GNUnet e.V. | 2 | ;; Copyright © 2021--2023 GNUnet e.V. |
3 | ;; | 3 | ;; |
4 | ;; scheme-GNUnet is free software: you can redistribute it and/or modify it | 4 | ;; scheme-GNUnet is free software: you can redistribute it and/or modify it |
5 | ;; under the terms of the GNU Affero General Public License as published | 5 | ;; under the terms of the GNU Affero General Public License as published |
@@ -154,7 +154,7 @@ for success is used." | |||
154 | (define (process-put-dht dht-server parameters) | 154 | (define (process-put-dht dht-server parameters) |
155 | ;; TODO replication level, expiration ... | 155 | ;; TODO replication level, expiration ... |
156 | (dht:put! dht-server | 156 | (dht:put! dht-server |
157 | (dht:datum->insertion | 157 | (dht:make-insertion/share |
158 | (dht:make-datum/share | 158 | (dht:make-datum/share |
159 | (string->number (assoc-ref parameters "type")) | 159 | (string->number (assoc-ref parameters "type")) |
160 | (decode/key (assoc-ref parameters "key-encoding") | 160 | (decode/key (assoc-ref parameters "key-encoding") |
diff --git a/gnu/gnunet/dht/client.scm b/gnu/gnunet/dht/client.scm index 27530df..1b86d6d 100644 --- a/gnu/gnunet/dht/client.scm +++ b/gnu/gnunet/dht/client.scm | |||
@@ -42,7 +42,8 @@ | |||
42 | 42 | ||
43 | make-datum make-datum/share datum? datum-type datum-key datum-value | 43 | make-datum make-datum/share datum? datum-type datum-key datum-value |
44 | datum-expiration datum=? | 44 | datum-expiration datum=? |
45 | datum->insertion insertion? insertion->datum | 45 | make-insertion make-insertion/share insertion? insertion->datum |
46 | insertion=? | ||
46 | insertion-desired-replication-level | 47 | insertion-desired-replication-level |
47 | make-query query? query-type query-key query-desired-replication-level | 48 | make-query query? query-type query-key query-desired-replication-level |
48 | datum->search-result search-result? search-result->datum | 49 | datum->search-result search-result? search-result->datum |
@@ -266,29 +267,34 @@ the constructor." | |||
266 | (%make-datum/share type key value expiration)) | 267 | (%make-datum/share type key value expiration)) |
267 | 268 | ||
268 | ;; A request to insert something in the DHT. | 269 | ;; A request to insert something in the DHT. |
269 | (define-record-type (<insertion> datum->insertion insertion?) | 270 | (define-record-type* (<insertion> insertion?) |
270 | (fields (immutable datum insertion->datum) | 271 | #:copy (copy-insertion |
271 | (immutable desired-replication-level | 272 | "Make a copy of the insertion, such that modifications to the |
272 | insertion-desired-replication-level)) | 273 | slices in the old insertion do not impact the new insertion.") |
273 | (protocol | 274 | #:constructor/copy %make-insertion |
274 | (lambda (%make) | 275 | #:constructor %make-insertion/share |
275 | (lambda* (datum #:key (desired-replication-level 3)) ; TODO defaults | 276 | #:equality insertion=? |
276 | "Make an insertion object for inserting the datum @var{datum}, | 277 | #:field (datum #:copy copy-datum |
278 | #:equality datum=? | ||
279 | #:getter insertion->datum | ||
280 | #:preprocess validate-datum) | ||
281 | #:field (desired-replication-leval | ||
282 | #:copy identity | ||
283 | #:equality = | ||
284 | #:getter insertion-desired-replication-level | ||
285 | #:preprocess bound-replication-level)) | ||
286 | |||
287 | (define* (make-insertion datum #:key (desired-replication-level 3)) ; TODO defaults | ||
288 | "Make an insertion object for inserting the datum @var{datum}, | ||
277 | desiring a replication level @var{desired-replication-level} (see ??). | 289 | desiring a replication level @var{desired-replication-level} (see ??). |
278 | 290 | ||
279 | The datum and desired replication level can be recovered with the accessors | 291 | Insertions are cisw (?) ojects and as such the procedures |
280 | @var{insertion->datum} and @var{insertion-desired-replication-level}. It can | 292 | @code{insertion->datum}, @code{insertion-desired-replication-level}, |
281 | be tested if an object is an insertion object with the predicate | 293 | @code{insertion?}, @code{make-insertion}, @code{make-insertion/share} |
282 | @code{insertion?}." | 294 | and @code{insertion=?} have the usual semantics." |
283 | (%make (validate-datum datum) | 295 | (%make-insertion datum desired-replication-level)) |
284 | (bound-replication-level desired-replication-level)))))) | 296 | (define* (make-insertion/share datum #:key (desired-replication-level 3)) |
285 | 297 | (%make-insertion/share datum desired-replication-level)) | |
286 | (define (copy-insertion old) | ||
287 | "Make a copy of the insertion @var{old}, such that modifications to the | ||
288 | slices in @var{old} do not impact the new insertion." | ||
289 | (datum->insertion (copy-datum (insertion->datum old)) | ||
290 | #:desired-replication-level | ||
291 | (insertion-desired-replication-level old))) | ||
292 | 298 | ||
293 | (define-record-type (<query> make-query query?) | 299 | (define-record-type (<query> make-query query?) |
294 | (fields (immutable type query-type) | 300 | (fields (immutable type query-type) |
@@ -508,7 +514,7 @@ currently unsupported." | |||
508 | (define value (slice-slice message (sizeof /:msg:dht:client:put '()))) | 514 | (define value (slice-slice message (sizeof /:msg:dht:client:put '()))) |
509 | (analyse /:msg:dht:client:put header | 515 | (analyse /:msg:dht:client:put header |
510 | (values | 516 | (values |
511 | (datum->insertion | 517 | (make-insertion/share |
512 | (make-datum/share | 518 | (make-datum/share |
513 | (r% type) | 519 | (r% type) |
514 | (make-hashcode:512/share (s% key)) | 520 | (make-hashcode:512/share (s% key)) |
diff --git a/tests/distributed-hash-table.scm b/tests/distributed-hash-table.scm index 367d530..10e57ab 100644 --- a/tests/distributed-hash-table.scm +++ b/tests/distributed-hash-table.scm | |||
@@ -254,10 +254,6 @@ | |||
254 | (slice->bytevector (datum-value z)) | 254 | (slice->bytevector (datum-value z)) |
255 | (datum-expiration z))) | 255 | (datum-expiration z))) |
256 | 256 | ||
257 | (define (insertion->sexp z) | ||
258 | (list (datum->sexp (insertion->datum z)) | ||
259 | (insertion-desired-replication-level z))) | ||
260 | |||
261 | (define (search-result->sexp z) | 257 | (define (search-result->sexp z) |
262 | (list (slice->bytevector (search-result-get-path z)) | 258 | (list (slice->bytevector (search-result-get-path z)) |
263 | (slice->bytevector (search-result-put-path z)) | 259 | (slice->bytevector (search-result-put-path z)) |
@@ -269,9 +265,6 @@ | |||
269 | (define (search-result=? x y) | 265 | (define (search-result=? x y) |
270 | (equal? (search-result->sexp x) (search-result->sexp y))) | 266 | (equal? (search-result->sexp x) (search-result->sexp y))) |
271 | 267 | ||
272 | (define (insertion=? x y) | ||
273 | (equal? (insertion->sexp x) (insertion->sexp y))) | ||
274 | |||
275 | (define (hashcode-independent? x y) | 268 | (define (hashcode-independent? x y) |
276 | (slice-independent? (hashcode:512->slice x) (hashcode:512->slice y))) | 269 | (slice-independent? (hashcode:512->slice x) (hashcode:512->slice y))) |
277 | 270 | ||
@@ -333,7 +326,7 @@ | |||
333 | (let* ((old-value (make-slice/read-write* 71)) | 326 | (let* ((old-value (make-slice/read-write* 71)) |
334 | (old-datum (make-a-datum #:value old-value)) | 327 | (old-datum (make-a-datum #:value old-value)) |
335 | (old | 328 | (old |
336 | (datum->insertion old-datum #:desired-replication-level (random 8))) | 329 | (make-insertion/share old-datum #:desired-replication-level (random 8))) |
337 | (new (copy-insertion old))) | 330 | (new (copy-insertion old))) |
338 | (and (insertion=? old new) | 331 | (and (insertion=? old new) |
339 | (insertion-independent? old new)))) | 332 | (insertion-independent? old new)))) |
@@ -434,7 +427,7 @@ | |||
434 | ;;; Cancelling, closing the connection, parallelism and multiple | 427 | ;;; Cancelling, closing the connection, parallelism and multiple |
435 | ;;; in-progress requests are currently untested (TBD and implemented!). | 428 | ;;; in-progress requests are currently untested (TBD and implemented!). |
436 | 429 | ||
437 | (define i (datum->insertion (make-a-datum) #:desired-replication-level 7)) | 430 | (define i (make-insertion/share (make-a-datum) #:desired-replication-level 7)) |
438 | 431 | ||
439 | (define (no-error-handler . e) | 432 | (define (no-error-handler . e) |
440 | (pk 'e e) | 433 | (pk 'e e) |
@@ -617,7 +610,7 @@ supported. When @var{explode} is signalled, the connection is closed." | |||
617 | (define key (round->key round)) | 610 | (define key (round->key round)) |
618 | (define value (make-slice/read-write 8)) | 611 | (define value (make-slice/read-write 8)) |
619 | (slice-u64-set! value 0 j (endianness little)) | 612 | (slice-u64-set! value 0 j (endianness little)) |
620 | (datum->insertion (make-datum/share type key value))) | 613 | (make-insertion/share (make-datum/share type key value))) |
621 | (define (make-a-query type round) | 614 | (define (make-a-query type round) |
622 | (define key (round->key round)) | 615 | (define key (round->key round)) |
623 | (make-query type key)) | 616 | (make-query type key)) |
@@ -768,7 +761,7 @@ supported. When @var{explode} is signalled, the connection is closed." | |||
768 | (define value-s (make-slice/read-write (sizeof u64/big '()))) | 761 | (define value-s (make-slice/read-write (sizeof u64/big '()))) |
769 | (slice-u64-set! key-s 0 round (endianness big)) | 762 | (slice-u64-set! key-s 0 round (endianness big)) |
770 | (slice-u64-set! value-s 0 (value round) (endianness big)) | 763 | (slice-u64-set! value-s 0 (value round) (endianness big)) |
771 | (put! server (datum->insertion | 764 | (put! server (make-insertion/share |
772 | (make-datum/share type (make-hashcode:512/share key-s) value-s))) | 765 | (make-datum/share type (make-hashcode:512/share key-s) value-s))) |
773 | (when (< round (- ROUNDS 1)) | 766 | (when (< round (- ROUNDS 1)) |
774 | (loop (+ round 1)))) | 767 | (loop (+ round 1)))) |
@@ -792,7 +785,7 @@ supported. When @var{explode} is signalled, the connection is closed." | |||
792 | ;; The 'found' callback is responsible for cancellation. | 785 | ;; The 'found' callback is responsible for cancellation. |
793 | #:linger? #true)) | 786 | #:linger? #true)) |
794 | (signal-condition! search-defined) | 787 | (signal-condition! search-defined) |
795 | (put! server (datum->insertion datum)) | 788 | (put! server (make-insertion/share datum)) |
796 | (wait done) | 789 | (wait done) |
797 | #true))) | 790 | #true))) |
798 | 791 | ||
@@ -854,7 +847,7 @@ supported. When @var{explode} is signalled, the connection is closed." | |||
854 | (wait disconnected/condition) | 847 | (wait disconnected/condition) |
855 | ;; Insert the datum, such that @var{search} can complete (assuming | 848 | ;; Insert the datum, such that @var{search} can complete (assuming |
856 | ;; that @var{server} remembered to start the search again!). | 849 | ;; that @var{server} remembered to start the search again!). |
857 | (put! server (datum->insertion datum)) | 850 | (put! server (make-insertion/share datum)) |
858 | (wait found/condition) | 851 | (wait found/condition) |
859 | ;; Explicitely cancel 'search' such that it is not cancelled too | 852 | ;; Explicitely cancel 'search' such that it is not cancelled too |
860 | ;; early due to GC. | 853 | ;; early due to GC. |