[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnunet-scheme] 06/49: dht/client: Implement message verifiers.
From: |
gnunet |
Subject: |
[gnunet-scheme] 06/49: dht/client: Implement message verifiers. |
Date: |
Sat, 25 Dec 2021 22:59:43 +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 ed1806824099f59570e8e887b213a807937a60b9
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Thu Sep 16 16:54:48 2021 +0200
dht/client: Implement message verifiers.
* gnu/gnunet/dht/client.scm: New module.
---
Makefile.am | 1 +
gnu/gnunet/dht/client.scm | 110 ++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 111 insertions(+)
diff --git a/Makefile.am b/Makefile.am
index afa6103..5c7aa2e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -63,6 +63,7 @@ modules = \
gnu/gnunet/config/db.scm \
gnu/gnunet/config/fs.scm \
\
+ gnu/gnunet/dht/client.scm \
gnu/gnunet/dht/struct.scm \
\
gnu/gnunet/util/cmsg.scm \
diff --git a/gnu/gnunet/dht/client.scm b/gnu/gnunet/dht/client.scm
new file mode 100644
index 0000000..1f65a23
--- /dev/null
+++ b/gnu/gnunet/dht/client.scm
@@ -0,0 +1,110 @@
+;; This file is part of GNUnet
+;; Copyright (C) 2004-2013, 2016 GNUnet e.V.
+;; Copyright (C) 2021 Maxime Devos
+;;
+;; GNUnet is free software: you can redistribute it and/or modify it
+;; under the terms of the GNU Affero General Public License as published
+;; by the Free Software Foundation, either version 3 of the License,
+;; or (at your option) any later version.
+;;
+;; GNUnet is distributed in the hope that it will be useful, but
+;; WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+;; Affero General Public License for more details.
+;;
+;; You should have received a copy of the GNU Affero General Public License
+;; along with this program. If not, see <http://www.gnu.org/licenses/>.
+;;
+;; SPDX-License-Identifier: AGPL-3.0-or-later
+
+;; Author: Christian Grothoff
+;; Author: Nathan Evans
+;; ^^ TODO: not visible yet, but once more parts are ported ...
+;; Author: Maxime Devos (Scheme port)
+(define-library (gnu gnunet dht client)
+ (export connect
+ disconnect!
+ put!
+ cancel-put!
+ start-get!
+ filter-get:known-results!
+ stop-get!
+ ;; Extended API: monitor
+ start-monitor!
+ stop-monitor!)
+ (import (gnu gnunet mq handler)
+ (only (guile)
+ define-syntax-rule)
+ (only (gnu extractor enum)
+ symbol-value)
+ (gnu gnunet dht struct)
+ (only (gnu gnunet crypto struct)
+ /peer-identity)
+ (only (gnu gnunet message protocols)
+ message-type)
+ (only (gnu gnunet netstruct syntactic)
+ read% sizeof)
+ (only (gnu gnunet utils bv-slice)
+ slice-length slice/read-only)
+ (only (rnrs base)
+ and >= = quote * + - define begin ... let*))
+ (begin
+ (define-syntax-rule (well-formed?/path-length slice type (field ...)
compare)
+ "Verify the TYPE message in @var{slice}, which has @var{field ...} ...
+(e.g. one or more of get-path-length or put-path-length) and corresponding
+/peer-identities at the end of the message is well-formed -- i.e., check if
the length
+of @var{slice} corresponds to the size of @var{type} and the get-path-length
and
+put-path-length.
+
+@var{compare} must be @code{=} if no additional payload follows, or @code{>=}
+if an addiional payload may follow. The message type and the size in the
+message header is assumed to be correct."
+ ;; Warning: slice is evaluated multiple times!
+ (and (>= (slice-length slice) (sizeof type '()))
+ (let* ((header (slice/read-only slice 0 (sizeof type '())))
+ (extra-size (- (slice-length slice) (sizeof type '())))
+ (field (read% type '(field) slice))
+ ...)
+ (compare extra-size (* (+ field ...) (sizeof /peer-identity
'()))))))
+
+ ;; TODO: WIP!
+ (define (reconnect . todo)
+ (define handlers
+ (message-handlers
+ (message-handler
+ (type (symbol-value message-type msg:dht:monitor:get))
+ ((interpose exp) exp)
+ ((well-formed? slice)
+ ;; The C implementation verifies that 'get-path-length' at most
+ ;; (- (expt 2 16) 1), but this seems only to prevent integer
overflow,
+ ;; which cannot happen in Scheme due to the use of bignums.
+ ;;
+ ;; This message does _not_ have a payload, so use = instead of >=.
+ (well-formed?/path-length slice /:msg:dht:monitor:get-response
+ (get-path-length) =))
+ ((handle! slice) ???))
+ (message-handler
+ (type (symbol-value message-type msg:dht:monitor:get-response))
+ ((interpose exp) exp)
+ ((well-formed? slice)
+ ;; Payload follows, hence >= instead of =.
+ (well-formed?/path-length slice /:msg:dht:monitor:get-response
+ (get-path-length put-path-length) >=))
+ ((handle! slice) ???))
+ (message-handler
+ (type (symbol-value message-type msg:dht:monitor:put))
+ ((interpose exp) exp)
+ ((well-formed? slice)
+ ;; Payload follows, hence >= instead of =.
+ (well-formed?/path-length slice /:msg:dht:monitor:put
+ (put-path-length) >=))
+ ((handle! slice) ???))
+ (message-handler
+ (type (symbol-value message-type msg:dht:client:result))
+ ((interpose exp) exp)
+ ((well-formed? slice)
+ ;; Actual data follows, hence >= instead of =.
+ (well-formed?/path-length slice /:msg:dht:client:result
+ (get-path-length put-path-length) >=))
+ ((handle! slice) ???))))
+ todo)))
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
- [gnunet-scheme] branch master updated (6c136b9 -> 5c7bf08), gnunet, 2021/12/25
- [gnunet-scheme] 04/49: dht/struct: New module., gnunet, 2021/12/25
- [gnunet-scheme] 01/49: Rename messge type 156., gnunet, 2021/12/25
- [gnunet-scheme] 06/49: dht/client: Implement message verifiers.,
gnunet <=
- [gnunet-scheme] 02/49: bv-slice: Support signed integers., gnunet, 2021/12/25
- [gnunet-scheme] 05/49: Define block types., gnunet, 2021/12/25
- [gnunet-scheme] 03/49: netstruct/procedural: Support signed integers., gnunet, 2021/12/25
- [gnunet-scheme] 08/49: examples: Consider extending the web interface with other services., gnunet, 2021/12/25
- [gnunet-scheme] 07/49: dht/client: Implement reconnecting., gnunet, 2021/12/25
- [gnunet-scheme] 09/49: examples/web: Connect to the DHT service., gnunet, 2021/12/25
- [gnunet-scheme] 10/49: dht/client: Register new get operations for processing., gnunet, 2021/12/25
- [gnunet-scheme] 12/49: dht/client: Send messages for new get operations., gnunet, 2021/12/25
- [gnunet-scheme] 13/49: dht/client: Send PUT messages., gnunet, 2021/12/25
- [gnunet-scheme] 24/49: examples/web: Put different information on separate pages., gnunet, 2021/12/25