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
def main(): global _global_myxordatastore global _global_manifestdict # If we were asked to retrieve the mainfest file, do so... if _commandlineoptions.retrievemanifestfrom: # We need to download this file... rawmanifestdata = uppirlib.retrieve_rawmanifest(_commandlineoptions.retrievemanifestfrom) # ...make sure it is valid... manifestdict = uppirlib.parse_manifest(rawmanifestdata) # ...and write it out if it's okay open(_commandlineoptions.manifestfilename, "w").write(rawmanifestdata) else: # Simply read it in from disk rawmanifestdata = open(_commandlineoptions.manifestfilename).read() manifestdict = uppirlib.parse_manifest(rawmanifestdata) # We should detach here. I don't do it earlier so that error # messages are written to the terminal... I don't do it later so that any # threads don't exist already. If I do put it much later, the code hangs... if _commandlineoptions.daemonize: daemon.daemonize() myxordatastore = fastsimplexordatastore.XORDatastore(manifestdict['blocksize'], manifestdict['blockcount']) # now let's put the content in the datastore in preparation to serve it uppirlib.populate_xordatastore(manifestdict, myxordatastore, rootdir = _commandlineoptions.mirrorroot) # we're now ready to handle clients! _log('ready to start servers!') # an ugly hack, but Python's request handlers don't have an easy way to # pass arguments _global_myxordatastore = myxordatastore _global_manifestdict = manifestdict # first, let's fire up the upPIR server service_uppir_clients(myxordatastore, _commandlineoptions.ip, _commandlineoptions.port) # If I should serve legacy clients via HTTP, let's start that up... if _commandlineoptions.http: service_http_clients(myxordatastore, manifestdict, _commandlineoptions.ip, _commandlineoptions.httpport) _log('servers started!') # let's send the mirror information periodically... # we should log any errors... while True: try: _send_mirrorinfo() except Exception, e: _log(str(e)+"\n"+str(traceback.format_tb(sys.exc_info()[2]))) time.sleep(_commandlineoptions.mirrorlistadvertisedelay)