viff

changeset 626:689eda33b658

Changed broadcast state variables to be local to each broadcast. Instead of having global tables for broadcast in general, we now use local tables for each broadcast method call such that the tables can be garbage collected when they are no longer needed. It is now also unnecessary to store a table for each program counter, making the local tables smaller than the previous global tables.
author Mikkel Krøigård <mk@daimi.au.dk>
date Tue, 01 Apr 2008 16:28:33 +0200
parents a444dd00be4c
children e9875a429017
files viff/runtime.py
diffstat 1 files changed, 13 insertions(+), 21 deletions(-) [+]
line diff
     1.1 --- a/viff/runtime.py	Sat Mar 29 21:05:21 2008 +0100
     1.2 +++ b/viff/runtime.py	Tue Apr 01 16:28:33 2008 +0200
     1.3 @@ -630,15 +630,6 @@
     1.4          """Initialize runtime."""
     1.5          BasicRuntime.__init__(self, player, threshold, options)
     1.6  
     1.7 -        #: Echo counters for Bracha broadcast.
     1.8 -        self._bracha_echo = {}
     1.9 -        #: Ready counters for Bracha broadcast.
    1.10 -        self._bracha_ready = {}
    1.11 -        #: Have we sent a ready message?
    1.12 -        self._bracha_sent_ready = {}
    1.13 -        #: Have we delivered the message?
    1.14 -        self._bracha_delivered = {}
    1.15 -
    1.16      @increment_pc
    1.17      def open(self, share, receivers=None, threshold=None):
    1.18          """Open a secret sharing.
    1.19 @@ -948,11 +939,12 @@
    1.20          # dictionary for each of the following variables. The reason
    1.21          # is that we need to count for each distinct message how many
    1.22          # echo and ready messages we have received.
    1.23 -        self._bracha_echo[pc] = {}
    1.24 -        self._bracha_ready[pc] = {}
    1.25 -        self._bracha_sent_ready[pc] = {}
    1.26 -        self._bracha_delivered[pc] = {}
    1.27  
    1.28 +        bracha_echo = {}
    1.29 +        bracha_ready = {}
    1.30 +        bracha_sent_ready = {}
    1.31 +        bracha_delivered = {}
    1.32 +        
    1.33          def unsafe_broadcast(data_type, message):
    1.34              # Performs a regular broadcast without any guarantees. In
    1.35              # other words, it sends the message to each player except
    1.36 @@ -964,13 +956,13 @@
    1.37              # This is called when we receive an echo message. It
    1.38              # updates the echo count for the message and enters the
    1.39              # ready state if the count is high enough.
    1.40 -            ids = self._bracha_echo[pc].setdefault(message, [])
    1.41 -            ready = self._bracha_sent_ready[pc].setdefault(message, False)
    1.42 +            ids = bracha_echo.setdefault(message, [])
    1.43 +            ready = bracha_sent_ready.setdefault(message, False)
    1.44  
    1.45              if peer_id not in ids:
    1.46                  ids.append(peer_id)
    1.47                  if len(ids) >= ceil((n+t+1)/2) and not ready:
    1.48 -                    self._bracha_sent_ready[pc][message] = True
    1.49 +                    bracha_sent_ready[message] = True
    1.50                      unsafe_broadcast("ready", message)
    1.51                      ready_received(message, self.id)
    1.52  
    1.53 @@ -979,18 +971,18 @@
    1.54              # updates the ready count for the message. Depending on
    1.55              # the count, we may either stay in the same state or enter
    1.56              # the ready or delivered state.
    1.57 -            ids = self._bracha_ready[pc].setdefault(message, [])
    1.58 -            ready = self._bracha_sent_ready[pc].setdefault(message, False)
    1.59 -            delivered = self._bracha_delivered[pc].setdefault(message, False)
    1.60 +            ids = bracha_ready.setdefault(message, [])
    1.61 +            ready = bracha_sent_ready.setdefault(message, False)
    1.62 +            delivered = bracha_delivered.setdefault(message, False)
    1.63              if peer_id not in ids:
    1.64                  ids.append(peer_id)
    1.65                  if len(ids) == t+1 and not ready:
    1.66 -                    self._bracha_sent_ready[pc][message] = True
    1.67 +                    bracha_sent_ready[message] = True
    1.68                      unsafe_broadcast("ready", message)
    1.69                      ready_received(message, self.id)
    1.70  
    1.71                  elif len(ids) == 2*t+1 and not delivered:
    1.72 -                    self._bracha_delivered[pc][message] = True
    1.73 +                    bracha_delivered[message] = True
    1.74                      result.callback(message)
    1.75  
    1.76          def send_received(message):