def parse_options(): """ <Side Effects> All relevant data is added to _commandlineoptions <Exceptions> These are handled by optparse internally. I believe it will print / exit itself without raising exceptions further. I do print an error and exit if there are extra args... <Returns> None """ global _commandlineoptions global _logfo # should be true unless we're initing twice... assert _commandlineoptions == None parser = optparse.OptionParser() parser.add_option("", "--ip", dest="ip", type="string", metavar="IP", default='0', help="Listen for clients on the following IP (default is the public facing IP)") parser.add_option("", "--port", dest="port", type="int", metavar="portnum", default=62294, help="Use the following port to serve RAID-PIR clients (default 62294)") parser.add_option("", "--http", dest="http", action="store_true", default=False, help="Serve legacy clients via HTTP (default False)") parser.add_option("", "--httpport", dest="httpport", type="int", default=80, help="Serve HTTP clients on this port (default 80)") parser.add_option("-f", "--files", dest="files", type="string", metavar="dir", default=None, help="The base directory where all mirror files are located.") parser.add_option("-d", "--database", dest="database", metavar="filename", type="string", default=None, help="Read this database file.") parser.add_option("", "--retrievemanifestfrom", dest="retrievemanifestfrom", type="string", metavar="vendorIP:port", default="", help="Specifies the vendor to retrieve the manifest from (default None).") parser.add_option("-m", "--manifestfile", dest="manifestfilename", type="string", default="manifest.dat", help="The manifest file to use (default manifest.dat).") parser.add_option("", "--daemon", dest="daemonize", action="store_true", default=False, help="Detach from terminal and run in the background") parser.add_option("", "--logfile", dest="logfilename", type="string", default="mirror.log", help="The file to write log data to (default mirror.log).") parser.add_option("", "--announcedelay", dest="mirrorlistadvertisedelay", type="int", default=60, help="How many seconds should I wait between vendor notifications? (default 60).") parser.add_option("", "--precompute", dest="use_precomputed_data", action="store_true", default=False, help="Use 4Russian precomputation to speedup PIR responses.") parser.add_option("", "--vendorip", dest="vendorip", type="string", metavar="IP", default=None, help="Vendor IP for overwriting the value from manifest") # let's parse the args (_commandlineoptions, remainingargs) = parser.parse_args() # check the arguments if _commandlineoptions.ip == "0": # use external ip, if none is specified _commandlineoptions.ip = getmyip.getmyip() if _commandlineoptions.port <= 0 or _commandlineoptions.port > 65535: print("Specified port number out of range") sys.exit(1) if _commandlineoptions.httpport <= 0 or _commandlineoptions.httpport > 65535: print("Specified HTTP port number out of range") sys.exit(1) if _commandlineoptions.mirrorlistadvertisedelay < 0: print("Mirror advertise delay must be positive") sys.exit(1) if remainingargs: print("Unknown options", remainingargs) sys.exit(1) if not (_commandlineoptions.database == None) ^ (_commandlineoptions.files == None): print("Must specify either files or database") sys.exit(1) # try to open the log file... _logfo = open(_commandlineoptions.logfilename, 'a')
def parse_options(): """ <Side Effects> All relevant data is added to _commandlineoptions <Exceptions> These are handled by optparse internally. I believe it will print / exit itself without raising exceptions further. I do print an error and exit if there are extra args... <Returns> None """ global _commandlineoptions global _logfo # should be true unless we're initing twice... assert _commandlineoptions == None parser = optparse.OptionParser() parser.add_option( "", "--ip", dest="ip", type="string", metavar="IP", default='0', help= "Listen for clients on the following IP (default is the public facing IP)" ) parser.add_option( "", "--port", dest="port", type="int", metavar="portnum", default=62294, help="Use the following port to serve RAID-PIR clients (default 62294)" ) parser.add_option("", "--http", dest="http", action="store_true", default=False, help="Serve legacy clients via HTTP (default False)") parser.add_option("", "--httpport", dest="httpport", type="int", default=80, help="Serve HTTP clients on this port (default 80)") parser.add_option( "-f", "--files", dest="files", type="string", metavar="dir", default=None, help="The base directory where all mirror files are located.") parser.add_option("-d", "--database", dest="database", metavar="filename", type="string", default=None, help="Read this database file.") parser.add_option( "", "--retrievemanifestfrom", dest="retrievemanifestfrom", type="string", metavar="vendorIP:port", default="", help= "Specifies the vendor to retrieve the manifest from (default None).") parser.add_option("-m", "--manifestfile", dest="manifestfilename", type="string", default="manifest.dat", help="The manifest file to use (default manifest.dat).") parser.add_option("", "--daemon", dest="daemonize", action="store_true", default=False, help="Detach from terminal and run in the background") parser.add_option( "", "--logfile", dest="logfilename", type="string", default="mirror.log", help="The file to write log data to (default mirror.log).") parser.add_option( "", "--announcedelay", dest="mirrorlistadvertisedelay", type="int", default=60, help= "How many seconds should I wait between vendor notifications? (default 60)." ) parser.add_option( "", "--precompute", dest="use_precomputed_data", action="store_true", default=False, help="Use 4Russian precomputation to speedup PIR responses.") parser.add_option("", "--vendorip", dest="vendorip", type="string", metavar="IP", default=None, help="Vendor IP for overwriting the value from manifest") # let's parse the args (_commandlineoptions, remainingargs) = parser.parse_args() # check the arguments if _commandlineoptions.ip == "0": # use external ip, if none is specified _commandlineoptions.ip = getmyip.getmyip() if _commandlineoptions.port <= 0 or _commandlineoptions.port > 65535: print("Specified port number out of range") sys.exit(1) if _commandlineoptions.httpport <= 0 or _commandlineoptions.httpport > 65535: print("Specified HTTP port number out of range") sys.exit(1) if _commandlineoptions.mirrorlistadvertisedelay < 0: print("Mirror advertise delay must be positive") sys.exit(1) if remainingargs: print("Unknown options", remainingargs) sys.exit(1) if not (_commandlineoptions.database == None) ^ (_commandlineoptions.files == None): print("Must specify either files or database") sys.exit(1) # try to open the log file... _logfo = open(_commandlineoptions.logfilename, 'a')
def parse_options(): """ <Purpose> Parses command line arguments. <Arguments> None <Side Effects> All relevant data is added to _commandlineoptions <Exceptions> These are handled by optparse internally. I believe it will print / exit itself without raising exceptions further. I do print an error and exit if there are extra args... <Returns> None """ global _commandlineoptions global _logfo # should be true unless we're initing twice... assert(_commandlineoptions==None) parser = optparse.OptionParser() parser.add_option("","--ip", dest="ip", type="string", metavar="IP", default=getmyip.getmyip(), help="Listen for clients on the following IP (default is the public facing IP)") parser.add_option("","--port", dest="port", type="int", metavar="portnum", default=62294, help="Use the following port to serve upPIR clients (default 62294)") parser.add_option("","--http", dest="http", action="store_true", default=False, help="Serve legacy clients via HTTP (default False)") parser.add_option("","--httpport", dest="httpport", type="int", default=80, help="Serve HTTP clients on this port (default 80)") parser.add_option("","--mirrorroot", dest="mirrorroot", type="string", metavar="dir", default=".", help="The base directory where all mirror files live under") parser.add_option("","--retrievemanifestfrom", dest="retrievemanifestfrom", type="string", metavar="vendorIP:port", default="", help="Specifies the vendor to retrieve the manifest from (default None).") parser.add_option("","--manifestfile", dest="manifestfilename", type="string", default="manifest.dat", help="The manifest file to use (default manifest.dat).") parser.add_option("","--foreground", dest="daemonize", action="store_false", default=True, help="Do not detach from the terminal and run in the background") parser.add_option("","--logfile", dest="logfilename", type="string", default="mirror.log", help="The file to write log data to (default mirror.log).") parser.add_option("","--announcedelay", dest="mirrorlistadvertisedelay", type="int", default=60, help="How many seconds should I wait between vendor notifications? (default 60).") # let's parse the args (_commandlineoptions, remainingargs) = parser.parse_args() # check the arguments if _commandlineoptions.port <=0 or _commandlineoptions.port >65535: print "Specified port number out of range" sys.exit(1) if _commandlineoptions.httpport <=0 or _commandlineoptions.httpport >65535: print "Specified HTTP port number out of range" sys.exit(1) if _commandlineoptions.mirrorlistadvertisedelay < 0: print "Mirror advertise delay must be positive" sys.exit(1) if remainingargs: print "Unknown options",remainingargs sys.exit(1) # try to open the log file... _logfo = open(_commandlineoptions.logfilename, 'a')
# this is a few simple integration tests for an upPIR mirror. Uses any local # mirror # if everything passes, there is no output import socket import session import getmyip mirrortocheck = getmyip.getmyip() def get_response(requeststring): s = socket.socket() s.connect((mirrortocheck,62294)) session.sendmessage(s,requeststring) return session.recvmessage(s) # We don't know the size so we won't test it 'working'... # are you friendly? assert('HI!' == get_response('HELLO')) # too short of a string (len 0) assert('Invalid request length' == get_response('XORBLOCK')) # too short of a string (len 0) assert('Invalid request type' == get_response('ajskdfjsad'))
# this is a few simple integration tests for an upPIR mirror. Uses any local # mirror # if everything passes, there is no output import socket import session import getmyip mirrortocheck = getmyip.getmyip() def get_response(requeststring): s = socket.socket() s.connect((mirrortocheck, 62294)) session.sendmessage(s, requeststring) return session.recvmessage(s) # We don't know the size so we won't test it 'working'... # are you friendly? assert ('HI!' == get_response('HELLO')) # too short of a string (len 0) assert ('Invalid request length' == get_response('XORBLOCK')) # too short of a string (len 0) assert ('Invalid request type' == get_response('ajskdfjsad'))