viff

changeset 587:bc6db28e18d0

Moved _exchange_shares and _expect_share to BasicRuntime.
author Martin Geisler <mg@daimi.au.dk>
date Wed, 19 Mar 2008 23:29:38 +0100
parents 4c10edd5c7a4
children 7c14124ca29e
files viff/runtime.py
diffstat 1 files changed, 22 insertions(+), 22 deletions(-) [+]
line diff
     1.1 --- a/viff/runtime.py	Wed Mar 19 23:26:40 2008 +0100
     1.2 +++ b/viff/runtime.py	Wed Mar 19 23:29:38 2008 +0100
     1.3 @@ -560,6 +560,28 @@
     1.4              # We have already received the data from the other side.
     1.5              deferred.callback(data)
     1.6  
     1.7 +    def _exchange_shares(self, id, field_element):
     1.8 +        """Exchange shares with another player.
     1.9 +
    1.10 +        We send the player our share and record a Deferred which will
    1.11 +        trigger when the share from the other side arrives.
    1.12 +        """
    1.13 +        assert isinstance(field_element, FieldElement)
    1.14 +
    1.15 +        if id == self.id:
    1.16 +            return Share(self, field_element.field, field_element)
    1.17 +        else:
    1.18 +            share = self._expect_share(id, field_element.field)
    1.19 +            pc = tuple(self.program_counter)
    1.20 +            self.protocols[id].sendShare(pc, field_element)
    1.21 +            return share
    1.22 +
    1.23 +    def _expect_share(self, peer_id, field):
    1.24 +        share = Share(self, field)
    1.25 +        share.addCallback(lambda value: field(value))
    1.26 +        self._expect_data(peer_id, "share", share)
    1.27 +        return share
    1.28 +
    1.29  
    1.30  class Runtime(BasicRuntime):
    1.31      """The VIFF runtime.
    1.32 @@ -1015,28 +1037,6 @@
    1.33          
    1.34          return result
    1.35  
    1.36 -    def _exchange_shares(self, id, field_element):
    1.37 -        """Exchange shares with another player.
    1.38 -
    1.39 -        We send the player our share and record a Deferred which will
    1.40 -        trigger when the share from the other side arrives.
    1.41 -        """
    1.42 -        assert isinstance(field_element, FieldElement)
    1.43 -
    1.44 -        if id == self.id:
    1.45 -            return Share(self, field_element.field, field_element)
    1.46 -        else:
    1.47 -            share = self._expect_share(id, field_element.field)
    1.48 -            pc = tuple(self.program_counter)
    1.49 -            self.protocols[id].sendShare(pc, field_element)
    1.50 -            return share
    1.51 -
    1.52 -    def _expect_share(self, peer_id, field):
    1.53 -        share = Share(self, field)
    1.54 -        share.addCallback(lambda value: field(value))
    1.55 -        self._expect_data(peer_id, "share", share)
    1.56 -        return share
    1.57 -
    1.58      @increment_pc
    1.59      def _recombine(self, shares, threshold):
    1.60          """Shamir recombine a list of deferred (id,share) pairs."""