def main(args): ''' main function ''' try: options, arguments = getopt.getopt(args[1:], 'b:d:m:t:v') except getopt.error: sys.exit(USAGE) if arguments: sys.exit(USAGE) # Good-enough default message default_msg = { "timestamp": 0, "uuid": "", "internal_address": "", "real_address": "", "remote_address": "", "privacy_informed": 0, "privacy_can_collect": 0, "privacy_can_publish": 0, "latency": 0.0, "connect_time": 0.0, "download_speed": 0.0, "upload_speed": 0.0, "neubot_version": "", "platform": "", } bcknd = None datadir = None msg = default_msg timestamp = None for name, value in options: if name == '-b': bcknd = value elif name == '-d': datadir = value if name == '-m': msg = value elif name == '-t': timestamp = float(value) elif name == '-v': logging.getLogger().setLevel(logging.DEBUG) if bcknd: BACKEND.use_backend(bcknd) if datadir: FILESYS.datadir = datadir if msg != default_msg: msg = json.loads(msg) if timestamp: time.time = lambda: timestamp FILESYS.datadir_init() BACKEND.bittorrent_store(msg) BACKEND.speedtest_store(msg)
def main(args): """ Starts the server module """ if not system.has_enough_privs(): sys.exit("FATAL: you must be root") try: options, arguments = getopt.getopt(args[1:], "b:D:dv") except getopt.error: sys.exit(USAGE) if arguments: sys.exit(USAGE) backend = "mlab" for name, value in options: if name == "-b": backend = value elif name == "-D": name, value = value.split("=", 1) if name not in VALID_MACROS: sys.exit(USAGE) SETTINGS[name] = int(value) elif name == "-d": SETTINGS["server.daemonize"] = 0 elif name == "-v": CONFIG["verbose"] = 1 logging.debug("server: using backend: %s... in progress", backend) if backend == "mlab": FILESYS.datadir_init() BACKEND.use_backend("mlab") elif backend == "neubot": DATABASE.connect() BACKEND.use_backend("neubot") else: BACKEND.use_backend("null") logging.debug("server: using backend: %s... complete", backend) for name, value in SETTINGS.items(): CONFIG[name] = value conf = CONFIG.copy() # # Configure our global HTTP server and make # sure that we don't provide filesystem access # even by mistake. # conf["http.server.rootdir"] = "" HTTP_SERVER.configure(conf) # # New-new style: don't bother with abstraction and start the f*****g # server by invoking its listen() method. # if CONFIG["server.raw"]: logging.debug("server: starting raw server... in progress") RAW_SERVER_EX.listen((":: 0.0.0.0", 12345), CONFIG["prefer_ipv6"], 0, "") logging.debug("server: starting raw server... complete") # # New-style modules are started just setting a # bunch of conf[] variables and then invoking # their run() method in order to kick them off. # if conf["server.negotiate"]: negotiate.run(POLLER, conf) if conf["server.bittorrent"]: conf["bittorrent.listen"] = True conf["bittorrent.negotiate"] = True bittorrent.run(POLLER, conf) if conf["server.speedtest"]: # conf['speedtest.listen'] = 1 # Not yet # conf['speedtest.negotiate'] = 1 # Not yet neubot.speedtest.wrapper.run(POLLER, conf) # Migrating from old style to new style if conf["server.rendezvous"]: # conf["rendezvous.listen"] = True # Not yet neubot.rendezvous.server.run() # # Historically Neubot runs on port 9773 and # 8080 but we would like to switch to port 80 # in the long term period, because it's rare # that they filter it. # OTOH it looks like it's not possible to # do that easily w/ M-Lab because the port # is already taken. # address = ":: 0.0.0.0" ports = (80, 8080, 9773) for port in ports: HTTP_SERVER.listen((address, port)) # # Start server-side API for Nagios plugin # to query the state of the server. # functionalities. # if conf["server.sapi"]: server = ServerSideAPI(POLLER) server.configure(conf) HTTP_SERVER.register_child(server, "/sapi") # # Create localhost-only debug server # if CONFIG["server.debug"]: logging.info("server: Starting debug server at {127.0.0.1,::1}:9774") server = DebugAPI(POLLER) server.configure(conf) server.listen(("127.0.0.1 ::1", 9774)) # # Go background and drop privileges, # then enter into the main loop. # if conf["server.daemonize"]: LOG.redirect() system.go_background() system.drop_privileges() POLLER.loop()
def main(args): """ Starts the server module """ # By default, use mlab backend FILESYS.datadir_init() BACKEND.use_backend('mlab') # # Register descriptions in main() only so that # we don't advertise the name of knobs that aren't # relevant in the current context. # CONFIG.register_descriptions({ "server.bittorrent": "Start up BitTorrent test and negotiate server", "server.daemonize": "Become a daemon and run in background", 'server.debug': 'Run the localhost-only debug server', "server.negotiate": "Turn on negotiation infrastructure", "server.rendezvous": "Start up rendezvous server", "server.sapi": "Turn on Server-side API", "server.speedtest": "Start up Speedtest test and negotiate server", }) common.main("server", "Neubot server-side component", args) conf = CONFIG.copy() # # Configure our global HTTP server and make # sure that we don't provide filesystem access # even by mistake. # conf["http.server.rootdir"] = "" HTTP_SERVER.configure(conf) # # New-style modules are started just setting a # bunch of conf[] variables and then invoking # their run() method in order to kick them off. # if conf["server.negotiate"]: negotiate.run(POLLER, conf) if conf["server.bittorrent"]: conf["bittorrent.listen"] = True conf["bittorrent.negotiate"] = True bittorrent.run(POLLER, conf) if conf['server.speedtest']: #conf['speedtest.listen'] = 1 # Not yet #conf['speedtest.negotiate'] = 1 # Not yet neubot.speedtest.wrapper.run(POLLER, conf) # Migrating from old style to new style if conf["server.rendezvous"]: #conf["rendezvous.listen"] = True # Not yet neubot.rendezvous.server.run() # # Historically Neubot runs on port 9773 and # 8080 but we would like to switch to port 80 # in the long term period, because it's rare # that they filter it. # OTOH it looks like it's not possible to # do that easily w/ M-Lab because the port # is already taken. # address = "" ports = (80, 8080, 9773) for port in ports: HTTP_SERVER.listen((address, port)) # # Start server-side API for Nagios plugin # to query the state of the server. # functionalities. # if conf["server.sapi"]: server = ServerSideAPI(POLLER) server.configure(conf) HTTP_SERVER.register_child(server, "/sapi") # # Create localhost-only debug server # if CONFIG['server.debug']: LOG.info('server: Starting debug server at {127.0.0.1,::1}:9774') server = DebugAPI(POLLER) server.configure(conf) server.listen(('127.0.0.1 ::1', 9774)) # # Go background and drop privileges, # then enter into the main loop. # if conf["server.daemonize"]: system.change_dir() system.go_background() system.write_pidfile() LOG.redirect() system.drop_privileges(LOG.error) POLLER.loop()