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 wrap: on
line diff
--- a/apps/aes.py	Mon May 04 13:05:21 2009 +0200
+++ b/apps/aes.py	Mon May 04 14:04:36 2009 +0200
@@ -81,7 +81,7 @@
         rt.shutdown()
 
     g = gather_shares(opened_ciphertext)
-    g.addCallback(fin)
+    rt.schedule_callback(g, fin)
 
 def share_key(rt):
     key =  []
--- a/apps/millionaires.py	Mon May 04 13:05:21 2009 +0200
+++ b/apps/millionaires.py	Mon May 04 14:04:36 2009 +0200
@@ -97,10 +97,10 @@
         # the argument (which is None since self.results_ready does
         # not return anything), so we throw it away using a lambda
         # expressions which ignores its first argument.
-        results.addCallback(lambda _: runtime.synchronize())
+        runtime.schedule_callback(results, lambda _: runtime.synchronize())
         # The next callback shuts the runtime down, killing the
         # connections between the players.
-        results.addCallback(lambda _: runtime.shutdown())
+        runtime.schedule_callback(results, lambda _: runtime.shutdown())
 
     def results_ready(self, results):
         # Since this method is called as a callback above, the results
--- a/viff/equality.py	Mon May 04 13:05:21 2009 +0200
+++ b/viff/equality.py	Mon May 04 14:04:36 2009 +0200
@@ -74,7 +74,7 @@
                 xj = (-1) * (1/Zp(2)) * (bj - 1)
             return xj
 
-        x = [cj.addCallback(finish, bj) for cj, bj in zip(c, b)]
+        x = [self.schedule_callback(cj, finish, bj) for cj, bj in zip(c, b)]
 
         # Take the product (this is here the same as the "and") of all
         # the x'es
--- a/viff/runtime.py	Mon May 04 13:05:21 2009 +0200
+++ b/viff/runtime.py	Mon May 04 14:04:36 2009 +0200
@@ -570,7 +570,7 @@
         The runtime is shut down when all variables are calculated.
         """
         dl = DeferredList(vars)
-        dl.addCallback(lambda _: self.shutdown())
+        self.schedule_callback(dl, lambda _: self.shutdown())
 
     @increment_pc
     def schedule_callback(self, deferred, func, *args, **kwargs):
@@ -603,7 +603,7 @@
             finally:
                 self.program_counter[:] = current_pc
 
-        deferred.addCallback(callback_wrapper, *args, **kwargs)
+        return deferred.addCallback(callback_wrapper, *args, **kwargs)
 
     @increment_pc
     def synchronize(self):
--- a/viff/test/test_active_runtime.py	Mon May 04 13:05:21 2009 +0200
+++ b/viff/test/test_active_runtime.py	Mon May 04 14:04:36 2009 +0200
@@ -88,7 +88,7 @@
 
         double = runtime.double_share_random(T, runtime.threshold,
                                              2*runtime.threshold, self.Zp)
-        double.addCallback(check)
+        runtime.schedule_callback(double, check)
         return double
 
     @protocol
@@ -116,7 +116,7 @@
         count, triples = runtime.generate_triples(self.Zp)
         self.assertEquals(count, runtime.num_players - 2*runtime.threshold)
 
-        triples.addCallback(check)
+        runtime.schedule_callback(triples, check)
         return triples