Beispiel #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
Beispiel #2
  def __init__(self, mirrorinfolist, blocklist, manifestdict, privacythreshold, pollinginterval = .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
    print "-----mirrorinfolist---------------/n prasit"
    print mirrorinfolist
    print "-----blocklist---------------/nprasit"
    print blocklist
    print "-----manifestdict---------------/nprasit"
    print manifestdict
    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'] = []
    #print manifestdict['blockcount'] #prasit
    bitstringlength = uppirlib.compute_bitstring_length(manifestdict['blockcount'])
    # let's generate the bitstrings
    for thisrequestinfo in self.activemirrorinfolist[:-1]:

      for block in blocklist:
        # I'll generate random bitstrings for N-1 of the mirrors...

    # 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.activemirrorinfolist[:-1]:
        thisbitstring = simplexordatastore.do_xor(thisbitstring, requestinfo['blockbitstringlist'][blocknum])
      # ...and flip the appropriate bit for the block we want
      #print thisbitstring #prasit
      thisbitstring = uppirlib.flip_bitstring_bit(thisbitstring, blocklist[blocknum])
      #print thisbitstring #prasit
    # 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.returnedxorblocksdict = {}
    for blocknum in blocklist:
      # make these all empty lists to start with
      self.returnedxorblocksdict[blocknum] = []
    # and here is where they are put when reconstructed
    self.finishedblockdict = {}