gnunet-svn
[Top][All Lists]
Advanced

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

[gnunet-scheme] 256/324: nse/client: Verify positivity of estimate.


From: gnunet
Subject: [gnunet-scheme] 256/324: nse/client: Verify positivity of estimate.
Date: Tue, 21 Sep 2021 13:24:56 +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 4f0fe630854160aefb39cbc97f8ec756e45839fd
Author: Maxime Devos <maximedevos@telenet.be>
AuthorDate: Fri Sep 10 16:43:14 2021 +0200

    nse/client: Verify positivity of estimate.
    
    * gnu/gnunet/nse/client.scm
      (estimate:logarithmic-number-peers,estimate:standard-deviation)
      (estimate:number-peers): Remove resolved XXX.
      (reconnect)[handlers]<msg:nse:estimate>{well-formed?}: Verify
      'size-estimate' and 'std-deviation' fields.
---
 doc/scheme-gnunet.tm      | 14 ++++++++------
 gnu/gnunet/nse/client.scm | 28 ++++++++++++----------------
 2 files changed, 20 insertions(+), 22 deletions(-)

diff --git a/doc/scheme-gnunet.tm b/doc/scheme-gnunet.tm
index d8b0b81..49b5a74 100644
--- a/doc/scheme-gnunet.tm
+++ b/doc/scheme-gnunet.tm
@@ -573,17 +573,20 @@
   reconnecting, the idempotent procedure <scm|disconnect!> can be called on
   the server object.
 
+  <todo|input, validation, I/O errors?>
+
   The estimate object has a number of accessors:
 
   <\explain>
     <scm|(estimate:logarithmic-number-peers <var|estimate>)>
   </explain|The base-2 logarithm of the number of peers (estimated), as a
-  flonum>
+  positive flonum, possibly zero or infinite>
 
   <\explain>
     <scm|(estimate:number-peers <var|estimate>)>
-  </explain|The number of peers (estimated), as a flonum.<space|1em>This is
-  not necessarily an (inexact) <scm|integer?>, as it is only an estimate.>
+  </explain|The number of peers (estimated), as a flonum, at least <scm|1.0>
+  and possibly infinite.<space|1em>This is not necessarily an (inexact)
+  <scm|integer?>, as it is only an estimate.>
 
   <\explain>
     <scm|(estimate:timestamp estimate)>
@@ -594,15 +597,14 @@
     <scm|(estimate:standard-deviation <var|estimate>)>
   </explain|The estimated standard deviation on the base-2 logarithm of
   peers, calculated over the last 64 rounds, with the <math|<frac|N|N-1>>
-  correction.>
+  correction.<space|1em>This is a positive flonum, possibly zero or
+  infinite.>
 
   Assuming the network size is stable and the errors on the logarithmic
   estimate are normally distributed, the procedure
   <scm|estimate:standard-deviation> can be used to put probablistic error
   bounds on the number of peers on the network. <todo|example>
 
-  <todo|what if the server sends bogus data (e.g. negative)>
-
   <chapter|Implementation details>
 
   TODO<appendix|GNU Free Documentation License>
diff --git a/gnu/gnunet/nse/client.scm b/gnu/gnunet/nse/client.scm
index d7a4369..1339b33 100644
--- a/gnu/gnunet/nse/client.scm
+++ b/gnu/gnunet/nse/client.scm
@@ -35,7 +35,8 @@
          disconnect!
          estimate)
   (import (only (rnrs base)
-               begin define quote lambda case values expt = else apply)
+               begin define quote lambda case values expt = else apply
+               and >=)
          (only (rnrs control)
                when)
          (only (rnrs records syntactic)
@@ -91,27 +92,19 @@ yet, return @code{#false}."
 
     (define (estimate:logarithmic-number-peers estimate)
       "Return the logarithm (base 2) of the number of peers on the network
-in @var{estimate} as a positive (possibly zero) number.  As the estimate
-is an estimate, the return value is inexact.
-
-XXX: if the server is broken, it could return a negative number, or NaN!
-Maybe +inf.0 as well?"
+in @var{estimate} as a positive flonum (possibly zero or infinite)."
       (%estimate:logarithmic-number-peers estimate))
 
     (define (estimate:standard-deviation estimate)
       "Return the standard deviation of the logarithmic estimate
-of the number of peers of the last 64 rounds, as a positive, possibly
-zero flonum.
-
-XXX: if the server is broken, it could be negative!"
+of the number of peers of the last 64 rounds as a positive flonum
+(possibly zero or infinite)."
       (%estimate:standard-deviation estimate))
 
     (define (estimate:number-peers estimate)
       "Return the estimate of the number of peers on the network in
-@var{estimate} as a positive flonum.  It is not necessarily integral.
-
-XXX: if the server is broken, it could return a negative number, or NaN!
-Maybe +inf.0 as well?"
+@var{estimate} as a strictly-positive flonum, at least @code{1.0}
+and possibly infinite."
       (expt 2.0 (estimate:logarithmic-number-peers estimate)))
 
     (define (estimate:timestamp estimate)
@@ -143,8 +136,11 @@ even if not connected.  This is an idempotent operation."
          (type (symbol-value message-type msg:nse:estimate))
          ((interpose code) code)
          ((well-formed? slice)
-          (= (slice-length slice)
-             (sizeof /:msg:nse:estimate '())))
+          (and (= (slice-length slice)
+                  (sizeof /:msg:nse:estimate '()))
+               ;; XXX: these two lines below are not tested
+               (>= (read% /:msg:nse:estimate '(size-estimate) slice) 0)
+               (>= (read% /:msg:nse:estimate '(std-deviation) slice) 0)))
          ((handle! slice) (handle-estimate! slice)))))
       (define (send-start!)
        ;; The service only starts sending estimates once

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