예제 #1
0
def _testmirror(rh, testinfodict):
  manifestdict = uppirlib.parse_manifest(_global_rawmanifestdata)
  myxordatastore = fastsimplexordatastore.XORDatastore(manifestdict['blocksize'], manifestdict['blockcount'])
  uppirlib.populate_xordatastore(manifestdict, myxordatastore, rootdir = _commandlineoptions.rootdir)
  bitstring = base64.b64decode(testinfodict['chunklist'])
  expectedData = base64.b64decode(testinfodict['data'])
  expectedbitstringlength = uppirlib.compute_bitstring_length(myxordatastore.numberofblocks)

  if len(bitstring) != expectedbitstringlength:
    # Invalid request length...
    _log("UPPIR "+remoteip+" "+str(remoteport)+" Invalid request with length: "+str(len(bitstring)))

    session.sendmessage(rh.request, 'Invalid request length')
    return

  mirrorip = testinfodict['ip']
  mirrorport = testinfodict['port']
  #print "bitstring"+testinfodict['chunklist']+"\n"
  xoranswer = myxordatastore.produce_xor_from_bitstring(bitstring)
  if xoranswer != expectedData: # or True
    session.sendmessage(rh.request, 'TEST: Invalid mirror: '+str(mirrorip)+":"+str(mirrorport))
    #print "xor"+base64.b64encode(xoranswer)+"\n"
    #print "mir"+base64.b64encode(expectedData)+"\n"
    _remove_mirror(mirrorip, mirrorport)
  else:
    session.sendmessage(rh.request, 'TEST: Correct mirror: '+str(mirrorip)+":"+str(mirrorport))
  return
예제 #2
0
  def handle(self):

    # read the request from the socket...
    requeststring = session.recvmessage(self.request)

    # for logging purposes, get the remote info
    remoteip, remoteport = self.request.getpeername()

    # if it's a request for a XORBLOCK
    if requeststring.startswith('XORBLOCK'):

      bitstring = requeststring[len('XORBLOCK'):]
  
      expectedbitstringlength = uppirlib.compute_bitstring_length(_global_myxordatastore.numberofblocks)

      if len(bitstring) != expectedbitstringlength:
        # Invalid request length...
        _log("UPPIR "+remoteip+" "+str(remoteport)+" Invalid request with length: "+str(len(bitstring)))

        session.sendmessage(self.request, 'Invalid request length')
        return
  
      # Now let's process this...
      xoranswer = _global_myxordatastore.produce_xor_from_bitstring(bitstring)

      # and send the reply.
      session.sendmessage(self.request, xoranswer)
      _log("UPPIR "+remoteip+" "+str(remoteport)+" GOOD")

      # done!
      return

    elif requeststring == 'HELLO':
      # send a reply.
      session.sendmessage(self.request, "HI!")
      _log("UPPIR "+remoteip+" "+str(remoteport)+" HI!")

      # done!
      return

    else:
      # we don't know what this is!   Log and tell the requestor
      _log("UPPIR "+remoteip+" "+str(remoteport)+" Invalid request type starts:'"+requeststring[:5]+"'")

      session.sendmessage(self.request, 'Invalid request type')
      return
예제 #3
0
  def handle(self):

    # read the request from the socket...
    requeststring = session.recvmessage(self.request)

    # for logging purposes, get the remote info
    remoteip, remoteport = self.request.getpeername()

    # if it's a request for a XORBLOCK
    if requeststring.startswith('XORBLOCK'):

      bitstring = requeststring[len('XORBLOCK'):]
  
      expectedbitstringlength = uppirlib.compute_bitstring_length(_global_myxordatastore.numberofblocks)

      if len(bitstring) != expectedbitstringlength:
        # Invalid request length...
        _log("UPPIR "+remoteip+" "+str(remoteport)+" Invalid request with length: "+str(len(bitstring)))

        session.sendmessage(self.request, 'Invalid request length')
        return
  
      # Now let's process this...
      xoranswer = _global_myxordatastore.produce_xor_from_bitstring(bitstring)

      # and send the reply.
      session.sendmessage(self.request, xoranswer)
      _log("UPPIR "+remoteip+" "+str(remoteport)+" GOOD")

      # done!
      return

    elif requeststring == 'HELLO':
      # send a reply.
      session.sendmessage(self.request, "HI!")
      _log("UPPIR "+remoteip+" "+str(remoteport)+" HI!")

      # done!
      return

    else:
      # we don't know what this is!   Log and tell the requestor
      _log("UPPIR "+remoteip+" "+str(remoteport)+" Invalid request type starts:'"+requeststring[:5]+"'")

      session.sendmessage(self.request, 'Invalid request type')
      return
예제 #4
0
  def __init__(self, mirrorinfolist, blocklist, manifestdict, privacythreshold, pollinginterval = .1):
    """
    <Purpose>
      Get ready to handle requests for XOR block strings, etc.

    <Arguments>
      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.   

    <Exceptions>
      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[:]
    random.shuffle(self.fullmirrorinfolist)


    # 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'] = []
  
      self.activemirrorinfolist.append(thisrequestinfo)
      
    #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...
        thisrequestinfo['blockbitstringlist'].append(_randomnumberfunction(bitstringlength))

    # 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
      self.activemirrorinfolist[-1]['blockbitstringlist'].append(thisbitstring)
    
    # 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 = {}
예제 #5
0
  def __init__(self, mirrorinfolist, blocklist, manifestdict, privacythreshold, pollinginterval = .1):
    """
    <Purpose>
      Get ready to handle requests for XOR block strings, etc.

    <Arguments>
      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.   

    <Exceptions>
      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[:]
    random.shuffle(self.fullmirrorinfolist)


    # 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'] = []
  
      self.activemirrorinfolist.append(thisrequestinfo)
      

    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...
        thisrequestinfo['blockbitstringlist'].append(_randomnumberfunction(bitstringlength))

    # 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
      thisbitstring = uppirlib.flip_bitstring_bit(thisbitstring, blocklist[blocknum])
      self.activemirrorinfolist[-1]['blockbitstringlist'].append(thisbitstring)
    
    # 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 = {}