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)