gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 225/324: mq: Inject errors when message verification has


From: gnunet
Subject: [gnunet-scheme] 225/324: mq: Inject errors when message verification has negative result.
Date: Tue, 21 Sep 2021 13:24:25 +0200

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 289c4adba9ab875223a269aaee1b9b28b3981537
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Thu Sep 2 18:55:54 2021 +0200

    mq: Inject errors when message verification has negative result.
    
    * README.org (List of errors): Document logic:ill-formed.
    * doc/scheme-gnunet.tm (logic:ill-formed): New explanation.
    * gnu/gnunet/mq.scm (inject-message!): Document logic:ill-formed
      error. Inject that error when the verificator returns falsehood.
    * tests/mq.scm ("ill-formed message error"): New test.
---
 README.org           |  4 +++-
 doc/scheme-gnunet.tm | 12 ++++++++++--
 gnu/gnunet/mq.scm    |  7 +++----
 tests/mq.scm         | 26 +++++++++++++++++++++++++-
 4 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/README.org b/README.org
index d1a9710..13e68a1 100644
--- a/README.org
+++ b/README.org
@@ -132,7 +132,9 @@
    Input errors (decoding)
    + logic:no-handler type . rest
      No handler for received message type (rest is currently unspecified)
-   + TODO verification failed, unknown message type
+   + logic:ill-formed type . rest
+     Message is invalid according to message handler (rest is currently
+     unspecified)
 ** Configuration                                                  :test:good:
    + gnu/gnunet/config/parser.scm: Parse configuration files.
    + gnu/gnunet/config/expand.scm: Perform variable expansion.
diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index 3005ed9..51f65c7 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -424,8 +424,16 @@
 
   <\explain>
     <scm|logic:no-handler> <var|type> . <var|rest>
-  </explain|The received message of type <var|type> (as an integer) does not
-  have a corresponding message handler.<space|1em><var|rest> is currently
+  <|explain>
+    The received message of type <var|type> (as an integer) does not have a
+    corresponding message handler.<space|1em><var|rest> is currently
+    unspecified.
+  </explain>
+
+  <\explain>
+    <scm|logic:ill-formed> <var|type> . <var|rest>
+  </explain|The received message of type (as an integer) is ill-formed
+  according to the message handler.<space|1em><var|rest> is currently
   unspecified.>
 
   <todo|errors for no message handler and malformed messages>
diff --git a/gnu/gnunet/mq.scm b/gnu/gnunet/mq.scm
index 540e463..24546ca 100644
--- a/gnu/gnunet/mq.scm
+++ b/gnu/gnunet/mq.scm
@@ -184,8 +184,8 @@ messages must be sent in-order (TODO really received 
in-order?)."
       "Call the message handler that was registered
 for the type of the message @var{mq} in the message queue var{mq}
 with the message @var{message}. In case the message is malformed
-(according to the message handler), inject a @code{&malformed-message}
-error instead (TODO).  In case no appropriate message handler exists,
+(according to the message handler), inject a @code{logic:ill-formed}
+error instead.  In case no appropriate message handler exists,
 inject a @code{logic:no-handler} error instead.
 
 It is an error for @var{message} to be so small it doesn't have
@@ -220,8 +220,7 @@ of message queues."
             (? (not handler)
                (inject-error! mq 'logic:no-handler type))
             (? (not (verify-message? handler message))
-               ;; TODO: error handling
-               (inject-error! handler ???))) ; malformed message
+               (inject-error! mq 'logic:ill-formed type)))
            ;; TODO: maybe a good place to catch out-of-memory
            ;; and stack overflow errors ...
            (handle-message! handler message)))
diff --git a/tests/mq.scm b/tests/mq.scm
index 3485022..c4763c9 100644
--- a/tests/mq.scm
+++ b/tests/mq.scm
@@ -631,7 +631,31 @@ with @code{x}."
         (! mq (make-message-queue no-handlers error-handler #f)))
        (inject-message! mq slice)
        errored?))
-;; TODO: what if the message is (otherwise) malformed?
+
+(test-assert "ill-formed message error"
+  (let^ ((! errored? #f)
+        (! slice (bv-slice/read-write #vu8(0 4 0 0)))
+        (! handlers
+           (message-handlers
+            (message-handler
+             (type 0)
+             ((interpose code) code)
+             ((well-formed? s)
+              (assert (eq? s slice))
+              #f)
+             ((handle! slice)
+              (error "unreachable")))))
+        (! (error-handler . e)
+           (match e
+             ;; Note: it theoretically may have some unspecified rest
+             ;; rest arguments.  In ‘real code’, use
+             ;; (logic:ill-formed 0 . rest) instead.
+             ('(logic:ill-formed 0)
+              (assert (not errored?))
+              (set! errored? #t))))
+        (! mq (make-message-queue handlers error-handler #f)))
+       (inject-message! mq slice)
+       errored?))
 
 
 

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