viff

changeset 1175:d6ff18bd643c

Replaced addCallback() by schedule_callback() for callbacks using the program counter. To achieve this, schedule_callback() has to return the return value of addCallback() (the Deferred).
author Marcel Keller <mkeller@cs.au.dk>
date Mon, 04 May 2009 14:04:36 +0200
parents ade6aff2dde2
children e86a007bddbd
files apps/aes.py apps/millionaires.py viff/equality.py viff/runtime.py viff/test/test_active_runtime.py
diffstat 5 files changed, 8 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/apps/aes.py	Mon May 04 13:05:21 2009 +0200
     1.2 +++ b/apps/aes.py	Mon May 04 14:04:36 2009 +0200
     1.3 @@ -81,7 +81,7 @@
     1.4          rt.shutdown()
     1.5  
     1.6      g = gather_shares(opened_ciphertext)
     1.7 -    g.addCallback(fin)
     1.8 +    rt.schedule_callback(g, fin)
     1.9  
    1.10  def share_key(rt):
    1.11      key =  []
     2.1 --- a/apps/millionaires.py	Mon May 04 13:05:21 2009 +0200
     2.2 +++ b/apps/millionaires.py	Mon May 04 14:04:36 2009 +0200
     2.3 @@ -97,10 +97,10 @@
     2.4          # the argument (which is None since self.results_ready does
     2.5          # not return anything), so we throw it away using a lambda
     2.6          # expressions which ignores its first argument.
     2.7 -        results.addCallback(lambda _: runtime.synchronize())
     2.8 +        runtime.schedule_callback(results, lambda _: runtime.synchronize())
     2.9          # The next callback shuts the runtime down, killing the
    2.10          # connections between the players.
    2.11 -        results.addCallback(lambda _: runtime.shutdown())
    2.12 +        runtime.schedule_callback(results, lambda _: runtime.shutdown())
    2.13  
    2.14      def results_ready(self, results):
    2.15          # Since this method is called as a callback above, the results
     3.1 --- a/viff/equality.py	Mon May 04 13:05:21 2009 +0200
     3.2 +++ b/viff/equality.py	Mon May 04 14:04:36 2009 +0200
     3.3 @@ -74,7 +74,7 @@
     3.4                  xj = (-1) * (1/Zp(2)) * (bj - 1)
     3.5              return xj
     3.6  
     3.7 -        x = [cj.addCallback(finish, bj) for cj, bj in zip(c, b)]
     3.8 +        x = [self.schedule_callback(cj, finish, bj) for cj, bj in zip(c, b)]
     3.9  
    3.10          # Take the product (this is here the same as the "and") of all
    3.11          # the x'es
     4.1 --- a/viff/runtime.py	Mon May 04 13:05:21 2009 +0200
     4.2 +++ b/viff/runtime.py	Mon May 04 14:04:36 2009 +0200
     4.3 @@ -570,7 +570,7 @@
     4.4          The runtime is shut down when all variables are calculated.
     4.5          """
     4.6          dl = DeferredList(vars)
     4.7 -        dl.addCallback(lambda _: self.shutdown())
     4.8 +        self.schedule_callback(dl, lambda _: self.shutdown())
     4.9  
    4.10      @increment_pc
    4.11      def schedule_callback(self, deferred, func, *args, **kwargs):
    4.12 @@ -603,7 +603,7 @@
    4.13              finally:
    4.14                  self.program_counter[:] = current_pc
    4.15  
    4.16 -        deferred.addCallback(callback_wrapper, *args, **kwargs)
    4.17 +        return deferred.addCallback(callback_wrapper, *args, **kwargs)
    4.18  
    4.19      @increment_pc
    4.20      def synchronize(self):
     5.1 --- a/viff/test/test_active_runtime.py	Mon May 04 13:05:21 2009 +0200
     5.2 +++ b/viff/test/test_active_runtime.py	Mon May 04 14:04:36 2009 +0200
     5.3 @@ -88,7 +88,7 @@
     5.4  
     5.5          double = runtime.double_share_random(T, runtime.threshold,
     5.6                                               2*runtime.threshold, self.Zp)
     5.7 -        double.addCallback(check)
     5.8 +        runtime.schedule_callback(double, check)
     5.9          return double
    5.10  
    5.11      @protocol
    5.12 @@ -116,7 +116,7 @@
    5.13          count, triples = runtime.generate_triples(self.Zp)
    5.14          self.assertEquals(count, runtime.num_players - 2*runtime.threshold)
    5.15  
    5.16 -        triples.addCallback(check)
    5.17 +        runtime.schedule_callback(triples, check)
    5.18          return triples
    5.19  
    5.20