Beispiel #1
0
def main(argv=None):
    if argv:
        init_config(argv)
    config = config_file.read_config()
    gevent.monkey.patch_all(ssl=False, thread=True)
    try:
        gevent.monkey.patch_ssl()
    except:
        LOGGER.exception('failed to patch ssl')
    greenlets = []
    if config['dns_server']['enabled']:
        dns_server_address = (config['dns_server']['ip'], config['dns_server']['port'])
        dns_server = fqdns.HandlerDatagramServer(dns_server_address, networking.DNS_HANDLER)
        greenlets.append(gevent.spawn(dns_server.serve_forever))
    if config['http_gateway']['enabled']:
        http_gateway.server_greenlet = gevent.spawn(http_gateway.serve_forever)
        greenlets.append(http_gateway.server_greenlet)
    if config['tcp_gateway']['enabled']:
        tcp_gateway.server_greenlet = gevent.spawn(tcp_gateway.serve_forever)
        greenlets.append(tcp_gateway.server_greenlet)
    if config['http_manager']['enabled']:
        httpd.server_greenlet = gevent.spawn(httpd.serve_forever)
        greenlets.append(httpd.server_greenlet)
    greenlets.append(gevent.spawn(proxy_client.init_proxies, config))
    for greenlet in greenlets:
        try:
            greenlet.join()
        except KeyboardInterrupt:
            return
        except:
            LOGGER.exception('greenlet join failed')
            return
Beispiel #2
0
def serve_udp():
    address = ('10.25.1.1', 12345)
    server = fqdns.HandlerDatagramServer(address, handle_udp)
    LOGGER.info('udp server started at %r', address)
    try:
        server.serve_forever()
    except:
        LOGGER.exception('udp server failed')
    finally:
        LOGGER.info('udp server stopped')