viff

changeset 591:80e49a760164

More whitespace changes.
author Martin Geisler <mg@daimi.au.dk>
date Thu, 20 Mar 2008 00:11:48 +0100
parents 8a79bf7ed805
children ac18c350f8ca
files viff/comparison.py viff/runtime.py viff/shamir.py viff/test/loopback.py viff/test/test_active_runtime.py viff/test/test_async.py viff/test/test_matrix.py
diffstat 7 files changed, 19 insertions(+), 18 deletions(-) [+]
line diff
     1.1 --- a/viff/comparison.py	Thu Mar 20 00:09:46 2008 +0100
     1.2 +++ b/viff/comparison.py	Thu Mar 20 00:11:48 2008 +0100
     1.3 @@ -28,6 +28,7 @@
     1.4  from viff.runtime import Runtime, Share, gather_shares, increment_pc
     1.5  from viff.field import GF256, FieldElement
     1.6  
     1.7 +
     1.8  class ComparisonToft05Mixin:
     1.9      """Comparison by Tomas Toft, 2005."""
    1.10  
    1.11 @@ -137,6 +138,7 @@
    1.12          bot = top_b * (bot_a ^ bot_b) ^ bot_b
    1.13          return (top, bot)
    1.14  
    1.15 +
    1.16  class Toft05Runtime(ComparisonToft05Mixin, Runtime):
    1.17      """Default mix of L{ComparisonToft05Mixin} and L{Runtime}."""
    1.18      pass
    1.19 @@ -337,6 +339,7 @@
    1.20          return self.greater_than_equal_online(share_a, share_b, preproc,
    1.21                                                field)
    1.22  
    1.23 +
    1.24  class Toft07Runtime(ComparisonToft07Mixin, Runtime):
    1.25      """Default mix of L{ComparisonToft07Mixin} and L{Runtime}."""
    1.26      pass
     2.1 --- a/viff/runtime.py	Thu Mar 20 00:09:46 2008 +0100
     2.2 +++ b/viff/runtime.py	Thu Mar 20 00:11:48 2008 +0100
     2.3 @@ -136,6 +136,7 @@
     2.4          Works like L{util.clone_deferred} except that it returns a new
     2.5          Share instead of a Deferred.
     2.6          """
     2.7 +
     2.8          def split_result(result):
     2.9              clone.callback(result)
    2.10              return result
    2.11 @@ -188,6 +189,7 @@
    2.12  
    2.13      Roughly modelled after the Twisted C{gatherResults} function.
    2.14      """
    2.15 +
    2.16      def filter_results(results):
    2.17          return [share for (_, share) in results]
    2.18      share_list = ShareList(shares)
    2.19 @@ -279,7 +281,6 @@
    2.20  
    2.21          self.sendData(program_counter, "share", share.value)
    2.22  
    2.23 -
    2.24      def loseConnection(self):
    2.25          """Disconnect this protocol instance."""
    2.26          self.transport.loseConnection()
    2.27 @@ -479,6 +480,7 @@
    2.28          All connections are closed and the runtime cannot be used
    2.29          again after this has been called.
    2.30          """
    2.31 +
    2.32          def stop(_):
    2.33              println("Initiating shutdown sequence.")
    2.34              for protocol in self.protocols.itervalues():
    2.35 @@ -1008,10 +1010,10 @@
    2.36          who wish to broadcast a message. If this player wishes to
    2.37          broadcast, its id must be in the list of senders and the
    2.38          optional message parameter must be used.
    2.39 -        
    2.40 +
    2.41          If the list of senders consists only of a single sender, the
    2.42          result will be a single element, otherwise it will be a list.
    2.43 -        
    2.44 +
    2.45          A Bracha broadcast is reliable against an active adversary
    2.46          corrupting up to t < n/3 of the players. For more details, see
    2.47          the paper "An asynchronous [(n-1)/3]-resilient consensus
    2.48 @@ -1034,7 +1036,7 @@
    2.49  
    2.50          if len(result) == 1:
    2.51              return result[0]
    2.52 -        
    2.53 +
    2.54          return result
    2.55  
    2.56      @increment_pc
     3.1 --- a/viff/shamir.py	Thu Mar 20 00:09:46 2008 +0100
     3.2 +++ b/viff/shamir.py	Thu Mar 20 00:11:48 2008 +0100
     3.3 @@ -119,14 +119,14 @@
     3.4  
     3.5      >>> from field import GF
     3.6      >>> Zp = GF(47)
     3.7 -    >>> shares = [(Zp(i), Zp(i**2)) for i in range(1, 6)] 
     3.8 -    >>> print shares                                      
     3.9 +    >>> shares = [(Zp(i), Zp(i**2)) for i in range(1, 6)]
    3.10 +    >>> print shares
    3.11      [({1}, {1}), ({2}, {4}), ({3}, {9}), ({4}, {16}), ({5}, {25})]
    3.12      >>> verify_sharing(shares, 2)
    3.13      True
    3.14      >>> verify_sharing(shares, 1)
    3.15      False
    3.16 -    >>> 
    3.17 +    >>>
    3.18  
    3.19      @param shares: The shares to be checked.
    3.20      @param degree: The maximum degree of the interpolating polynomial.
    3.21 @@ -138,7 +138,7 @@
    3.22              return False
    3.23  
    3.24      return True
    3.25 -        
    3.26 +
    3.27  
    3.28  if __name__ == "__main__":
    3.29      import doctest    #pragma NO COVER
     4.1 --- a/viff/test/loopback.py	Thu Mar 20 00:09:46 2008 +0100
     4.2 +++ b/viff/test/loopback.py	Thu Mar 20 00:11:48 2008 +0100
     4.3 @@ -66,6 +66,7 @@
     4.4  
     4.5  from viff.util import rand
     4.6  
     4.7 +
     4.8  class _LoopbackQueue(object):
     4.9      """
    4.10      Trivial wrapper around a list to give it an interface like a queue, which
    4.11 @@ -79,23 +80,19 @@
    4.12      def __init__(self):
    4.13          self._queue = []
    4.14  
    4.15 -
    4.16      def put(self, v):
    4.17          self._queue.append(v)
    4.18          if self._notificationDeferred is not None:
    4.19              d, self._notificationDeferred = self._notificationDeferred, None
    4.20              d.callback(None)
    4.21  
    4.22 -
    4.23      def __nonzero__(self):
    4.24          return bool(self._queue)
    4.25  
    4.26 -
    4.27      def get(self):
    4.28          return self._queue.pop(0)
    4.29  
    4.30  
    4.31 -
    4.32  class _LoopbackAddress(object):
    4.33      implements(IAddress)
    4.34  
    4.35 @@ -107,6 +104,7 @@
    4.36      producer = None
    4.37  
    4.38      # ITransport
    4.39 +
    4.40      def __init__(self, q):
    4.41          self.q = q
    4.42          self._buffer = ''
    4.43 @@ -125,7 +123,7 @@
    4.44          if self.q.disconnect:
    4.45              # We are disconnected, so just return.
    4.46              return
    4.47 -            
    4.48 +
    4.49          if self._pending is None or not self._pending.active():
    4.50              delay = rand.uniform(0, 0.001)
    4.51              self._pending = reactor.callLater(delay, self._send_some_bytes)
    4.52 @@ -179,6 +177,7 @@
    4.53          return _LoopbackAddress()
    4.54  
    4.55      # IConsumer
    4.56 +
    4.57      def registerProducer(self, producer, streaming):
    4.58          assert self.producer is None
    4.59          self.producer = producer
     5.1 --- a/viff/test/test_active_runtime.py	Thu Mar 20 00:09:46 2008 +0100
     5.2 +++ b/viff/test/test_active_runtime.py	Thu Mar 20 00:11:48 2008 +0100
     5.3 @@ -49,8 +49,6 @@
     5.4              y, z = runtime.broadcast([2, 3])
     5.5  
     5.6          x.addCallback(self.assertEquals, "Hello world!")
     5.7 -        
     5.8          y.addCallback(self.assertEquals, "Hello two!")
     5.9          z.addCallback(self.assertEquals, "Hello three!")
    5.10 -        
    5.11          return gatherResults([x, y, z])
     6.1 --- a/viff/test/test_async.py	Thu Mar 20 00:09:46 2008 +0100
     6.2 +++ b/viff/test/test_async.py	Thu Mar 20 00:11:48 2008 +0100
     6.3 @@ -76,7 +76,7 @@
     6.4          closed = DeferredList([closed_a, closed_b])
     6.5          closed.addCallback(check, server_a, client_a, server_b, client_b)
     6.6          return closed
     6.7 -        
     6.8 +
     6.9      def test_interleaving(self):
    6.10          """Ensure that protocol runs are interleaved differently each time."""
    6.11  
     7.1 --- a/viff/test/test_matrix.py	Thu Mar 20 00:09:46 2008 +0100
     7.2 +++ b/viff/test/test_matrix.py	Thu Mar 20 00:11:48 2008 +0100
     7.3 @@ -25,10 +25,10 @@
     7.4  from viff.prss import generate_subsets
     7.5  from twisted.trial.unittest import TestCase
     7.6  
     7.7 +
     7.8  class MatrixTest(TestCase):
     7.9      """Matrix tests."""
    7.10  
    7.11 -    
    7.12      def is_hyper(self, mat):
    7.13          """Checks if a square matrix is hyper-invertible.
    7.14  
    7.15 @@ -54,4 +54,3 @@
    7.16          for i in range(1, 6):
    7.17              m = hyper(i, Zp)
    7.18              self.assertTrue(self.is_hyper(m))
    7.19 -