Пример #1
def _reconstruct_block(blockinfolist):
    # private helper to reconstruct a block
    # xor the blocks together
    currentresult = blockinfolist[0]["xorblock"]
    for xorblockdict in blockinfolist[1:]:
        currentresult = simplexordatastore.do_xor(currentresult, xorblockdict["xorblock"])

    # and return the answer
    return currentresult
Пример #2
    def __init__(self, mirrorinfolist, blocklist, manifestdict, privacythreshold, pollinginterval=0.1):
      Get ready to handle requests for XOR block strings, etc.

      mirrorinfolist: a list of dictionaries with information about mirrors

      blocklist: the blocks that need to be retrieved

      manifestdict: the manifest with information about the release

      privacythreshold: the number of mirrors that would need to collude to
                       break privacy

      pollinginterval: the amount of time to sleep between checking for
                       the ability to serve a mirror.   

      TypeError may be raised if invalid parameters are given.

      InsufficientMirrors if there are not enough mirrors

        self.blocklist = blocklist
        self.manifestdict = manifestdict
        self.privacythreshold = privacythreshold
        self.pollinginterval = pollinginterval

        if len(mirrorinfolist) < self.privacythreshold:
            raise InsufficientMirrors(
                "Requested the use of "
                + str(self.privacythreshold)
                + " mirrors, but only "
                + str(len(mirrorinfolist))
                + " were available."

        # now we do the 'random' part.   I copy the mirrorinfolist to avoid changing
        # the list in place.
        self.fullmirrorinfolist = mirrorinfolist[:]

        # let's make a list of mirror information (what has been retrieved, etc.)
        self.activemirrorinfolist = []
        for mirrorinfo in self.fullmirrorinfolist[: self.privacythreshold]:
            thisrequestinfo = {}
            thisrequestinfo["mirrorinfo"] = mirrorinfo
            thisrequestinfo["servingrequest"] = False
            thisrequestinfo["blocksneeded"] = blocklist[:]
            thisrequestinfo["blockbitstringlist"] = []


        # these mirror will receive the strings really used to xor
        half = (len(self.activemirrorinfolist) / 2) + 1
        self.actural_mirror_list = self.activemirrorinfolist[:half]
        print 'The mirror we really "used"', [m["mirrorinfo"] for m in self.actural_mirror_list]
        bitstringlength = uppirlib.compute_bitstring_length(manifestdict["blockcount"])
        # let's generate the bitstrings
        for thisrequestinfo in self.activemirrorinfolist:

            for block in blocklist:
                # I'll generate random bitstrings for N-1 of the mirrors...
        self.actural_mirror_list[-1]["blockbitstringlist"] = []
        # now, let's do the 'derived' ones...
        for blocknum in range(len(blocklist)):
            thisbitstring = "\0" * bitstringlength

            # xor the random strings together
            for requestinfo in self.actural_mirror_list[:-1]:
                thisbitstring = simplexordatastore.do_xor(thisbitstring, requestinfo["blockbitstringlist"][blocknum])

            # ...and flip the appropriate bit for the block we want
            thisbitstring = uppirlib.flip_bitstring_bit(thisbitstring, blocklist[blocknum])

        # we're done setting up the bitstrings!

        # want to have a structure for locking
        self.tablelock = threading.Lock()

        # and we'll keep track of the ones that are waiting in the wings...
        self.backupmirrorinfolist = self.fullmirrorinfolist[self.privacythreshold :]

        # the returned blocks are put here...

        self.neededreturnedxorblocksdict = {}
        self.returnedxorblocksdict = {}
        for blocknum in blocklist:
            # make these all empty lists to start with
            self.returnedxorblocksdict[blocknum] = []
            self.neededreturnedxorblocksdict[blocknum] = []
        # and here is where they are put when reconstructed
        self.finishedblockdict = {}