def main(): global _global_rawmanifestdata global _global_rawmirrorlist # read in the manifest file rawmanifestdata = open(_commandlineoptions.manifestfilename).read() # an ugly hack, but Python's request handlers don't have an easy way to # pass arguments _global_rawmanifestdata = rawmanifestdata _global_rawmirrorlist = json.dumps([]) # I do this just for the sanity / corruption check manifestdict = uppirlib.parse_manifest(rawmanifestdata) vendorip = manifestdict['vendorhostname'] vendorport = manifestdict['vendorport'] # 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() # we're now ready to handle clients! _log('ready to start servers!') # first, let's fire up the upPIR server start_vendor_service(manifestdict, vendorip, vendorport) _log('servers started!')
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(): # If we were asked to retrieve the mainfest file, do so... if _commandlineoptions.retrievemanifestfrom: # We need to download this file... # If the manifest cannot be verified with the digital signature of the vebdor, # we get the empty manifest. We keep trying to get this file until we get # the correct manifest from the vendor. rawmanifestdata = '' while not rawmanifestdata: 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 will check that the files are in the release # find the list of files manifestfilelist = uppirlib.get_filenames_in_release(manifestdict) print manifestfilelist # ensure the requested files are in there... for filename in _commandlineoptions.filestoretrieve: if filename not in manifestfilelist: print "File:",filename,"is not listed in the manifest." sys.exit(2) request_files_from_mirrors(_commandlineoptions.filestoretrieve, manifestdict)
def main(): # 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 will check that the files are in the release # find the list of files manifestfilelist = uppirlib.get_filenames_in_release(manifestdict) print manifestfilelist # ensure the requested files are in there... for filename in _commandlineoptions.filestoretrieve: if filename not in manifestfilelist: print "File:",filename,"is not listed in the manifest." sys.exit(2) request_files_from_mirrors(_commandlineoptions.filestoretrieve, manifestdict)
def main(): # 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 will check that the files are in the release # find the list of files manifestfilelist = uppirlib.get_filenames_in_release(manifestdict) print manifestfilelist # ensure the requested files are in there... for filename in _commandlineoptions.filestoretrieve: if filename not in manifestfilelist: print "File:", filename, "is not listed in the manifest." sys.exit(2) request_files_from_mirrors(_commandlineoptions.filestoretrieve, manifestdict)
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)