示例#1
0
 def __init__(self, args, st_listen):
     if args.pid_file:
         fp = file(args.pid_file, 'w')
         fp.write(str(os.getpid()))
         fp.close()
     self.log = stratum.logger.get_logger('proxy%s' % args.stratum_port)
     st_listen.log = stratum.logger.get_logger(
         'proxy%s' %
         args.stratum_port)
     stp = StratumProxy(st_listen)
     stp.set_pool(
         args.host,
         args.port,
         args.custom_user,
         args.custom_password,
         timeout=args.pool_timeout)
     stp.connect()
     self.z = zmq.Context()
     self.control = threading.Thread(
         target=self.control,
         args=[
             stp,
             st_listen,
             args.control_listen,
             args.control_port,
             self.z])
     self.watcher = threading.Thread(
         target=self.watcher,
         args=[
             stp,
             st_listen])
     self.control.daemon = True
     self.watcher.daemon = True
     self.control.start()
     self.watcher.start()
     # Setup stratum listener
     if args.stratum_port > 0:
         st_listen.StratumProxyService._set_stratum_proxy(stp)
         st_listen.StratumProxyService._set_sharestats_module(
             args.sharestats_module)
         reactor_listen = reactor.listenTCP(
             args.stratum_port,
             SocketTransportFactory(
                 debug=False,
                 event_handler=ServiceEventHandler),
             interface=args.stratum_host)
         reactor.addSystemEventTrigger(
             'before',
             'shutdown',
             self.on_shutdown,
             stp.f)
         self.log.warning(
             "PROXY IS LISTENING ON ALL IPs ON PORT %d (stratum)" %
             (args.stratum_port))
示例#2
0
 def __init__(self):
     StratumServer.stp = StratumProxy(settings.POOL_HOST,
                                      settings.POOL_PORT,
                                      settings.POOL_USER,
                                      settings.POOL_PASS)
     # Setup stratum listener
     if settings.STRATUM_PORT > 0:
         self.f = SocketTransportFactory(debug=False,
                                         event_handler=ServiceEventHandler)
         reactor.addSystemEventTrigger('before', 'shutdown',
                                       self.on_shutdown,
                                       StratumServer.stp.f)
         log.info("Proxy is listening on port %d (stratum)" %
                  (settings.STRATUM_PORT))
     # Setup control listener
     if settings.CONTROL_PORT > 0:
         reactor.listenTCP(settings.CONTROL_PORT,
                           SocketTransportFactory(
                               debug=True,
                               event_handler=ServiceEventHandler),
                           interface=settings.CONTROL_HOST)
示例#3
0
def main():
    reactor.disconnectAll()
    failover = False
    if settings.POOL_FAILOVER_ENABLE:
        failover = settings.failover_pool
        settings.failover_pool = not settings.failover_pool

    pool_host = settings.POOL_HOST
    pool_port = settings.POOL_PORT
    if failover and settings.POOL_FAILOVER_ENABLE:
        pool_host = settings.POOL_HOST_FAILOVER
        pool_port = settings.POOL_PORT_FAILOVER

    log.warning("Monero Stratum proxy version: %s" % version.VERSION)
    log.warning("Trying to connect to Stratum pool at %s:%d" % (pool_host, pool_port))
        
    # Connect to Stratum pool, main monitoring connection
    f = SocketTransportClientFactory(pool_host, pool_port,
                debug=settings.DEBUG, proxy=None,
                event_handler=client_service.ClientMiningService)

    job_registry = jobs.JobRegistry(f)
    client_service.ClientMiningService.job_registry = job_registry
    client_service.ClientMiningService.reset_timeout()
    
    f.on_connect.addCallback(on_connect)
    f.on_disconnect.addCallback(on_disconnect)
    # Cleanup properly on shutdown
    reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown, f)

    # Block until proxy connect to the pool
    try:
        yield f.on_connect
    except TransportException:
        log.warning("First pool server must be online first time to start failover")
        return
    
    # Setup stratum listener
    stratum_listener.StratumProxyService._set_upstream_factory(f)
    stratum_listener.StratumProxyService._set_custom_user(settings.CUSTOM_USER, settings.CUSTOM_PASSWORD, settings.ENABLE_WORKER_ID, settings.WORKER_ID_FROM_IP)
    reactor.listenTCP(settings.STRATUM_PORT, SocketTransportFactory(debug=settings.DEBUG, event_handler=ServiceEventHandler), interface=settings.STRATUM_HOST)
    
    # Setup multicast responder
    reactor.listenMulticast(3333, multicast_responder.MulticastResponder((pool_host, pool_port), settings.STRATUM_PORT), listenMultiple=True)

    log.warning("-----------------------------------------------------------------------")
    if settings.STRATUM_HOST == '0.0.0.0':
        log.warning("PROXY IS LISTENING ON ALL IPs ON PORT %d (stratum)" % settings.STRATUM_PORT)
    else:
        log.warning("LISTENING FOR MINERS ON stratum+tcp://%s:%d (stratum)" % \
                 (settings.STRATUM_HOST, settings.STRATUM_PORT))
    log.warning("-----------------------------------------------------------------------")
示例#4
0
def main(args):
    if args.pid_file:
        fp = file(args.pid_file, 'w')
        fp.write(str(os.getpid()))
        fp.close()

    if args.port != 3333:
        '''User most likely provided host/port
        for getwork interface. Let's try to detect
        Stratum host/port of given getwork pool.'''

        try:
            new_host = (yield utils.detect_stratum(args.host, args.port))
        except:
            log.exception("Stratum host/port autodetection failed")
            new_host = None

        if new_host != None:
            args.host = new_host[0]
            args.port = new_host[1]

    log.warning("Stratum proxy version: %s" % version.VERSION)

    if args.tor:
        log.warning("Configuring Tor connection")
        args.proxy = '127.0.0.1:9050'
        args.host = 'pool57wkuu5yuhzb.onion'
        args.port = 3333

    if args.proxy:
        proxy = args.proxy.split(':')
        if len(proxy) < 2:
            proxy = (proxy, 9050)
        else:
            proxy = (proxy[0], int(proxy[1]))
        log.warning("Using proxy %s:%d" % proxy)
    else:
        proxy = None

    log.warning("Trying to connect to Stratum pool at %s:%d" %
                (args.host, args.port))

    # Connect to Stratum pool
    f = SocketTransportClientFactory(
        args.host,
        args.port,
        debug=args.verbose,
        proxy=proxy,
        event_handler=client_service.ClientMiningService)

    job_registry = jobs.JobRegistry(f,
                                    cmd=args.blocknotify_cmd,
                                    no_midstate=args.no_midstate,
                                    real_target=args.real_target)
    client_service.ClientMiningService.job_registry = job_registry
    client_service.ClientMiningService.reset_timeout()

    workers = worker_registry.WorkerRegistry(f)
    f.on_connect.addCallback(on_connect, workers, job_registry)
    f.on_disconnect.addCallback(on_disconnect, workers, job_registry)

    if args.test:
        f.on_connect.addCallback(test_launcher, job_registry)

    # Cleanup properly on shutdown
    reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown, f)

    # Block until proxy connect to the pool
    yield f.on_connect

    # Setup getwork listener
    if args.getwork_port > 0:
        reactor.listenTCP(args.getwork_port,
                          Site(
                              getwork_listener.Root(
                                  job_registry,
                                  workers,
                                  stratum_host=args.stratum_host,
                                  stratum_port=args.stratum_port,
                                  custom_lp=args.custom_lp,
                                  custom_stratum=args.custom_stratum,
                                  custom_user=args.custom_user,
                                  custom_password=args.custom_password)),
                          interface=args.getwork_host)

    # Setup stratum listener
    if args.stratum_port > 0:
        stratum_listener.StratumProxyService._set_upstream_factory(f)
        reactor.listenTCP(
            args.stratum_port,
            SocketTransportFactory(debug=False,
                                   event_handler=ServiceEventHandler))

    # Setup multicast responder
    reactor.listenMulticast(3333,
                            multicast_responder.MulticastResponder(
                                (args.host, args.port), args.stratum_port,
                                args.getwork_port),
                            listenMultiple=True)

    log.warning(
        "-----------------------------------------------------------------------"
    )
    if args.getwork_host == '0.0.0.0' and args.stratum_host == '0.0.0.0':
        log.warning(
            "PROXY IS LISTENING ON ALL IPs ON PORT %d (stratum) AND %d (getwork)"
            % (args.stratum_port, args.getwork_port))
    else:
        log.warning("LISTENING FOR MINERS ON http://%s:%d (getwork) and stratum+tcp://%s:%d (stratum)" % \
                 (args.getwork_host, args.getwork_port, args.stratum_host, args.stratum_port))
    log.warning(
        "-----------------------------------------------------------------------"
    )
示例#5
0
def main(args):
    if args.pid_file:
        fp = file(args.pid_file, 'w')
        fp.write(str(os.getpid()))
        fp.close()

    if args.port != 3333:
        '''User most likely provided host/port
        for getwork interface. Let's try to detect
        Stratum host/port of given getwork pool.'''

        try:
            new_host = (yield utils.detect_stratum(args.host, args.port))
        except:
            log.exception("Stratum host/port autodetection failed")
            new_host = None

        if new_host != None:
            args.host = new_host[0]
            args.port = new_host[1]

    log.warning("Stratum proxy version: %s" % version.VERSION)

    if args.tor:
        log.warning("Configuring Tor connection")
        args.proxy = '127.0.0.1:9050'
        args.host = 'ltcpool5brio2gaj.onion'
        args.port = 3333

    if args.proxy:
        proxy = args.proxy.split(':')
        if len(proxy) < 2:
            proxy = (proxy, 9050)
        else:
            proxy = (proxy[0], int(proxy[1]))
        log.warning("Using proxy %s:%d" % proxy)
    else:
        proxy = None

    log.warning("Trying to connect to Stratum pool at %s:%d" %
                (args.host, args.port))

    # Connect to Stratum pool
    f = SocketTransportClientFactory(
        args.host,
        args.port,
        debug=args.verbose,
        proxy=proxy,
        event_handler=client_service.ClientMiningService)

    job_registry = jobs.JobRegistry(f,
                                    cmd=args.blocknotify_cmd,
                                    pow_algo=args.pow_algo)
    client_service.ClientMiningService.job_registry = job_registry
    client_service.ClientMiningService.reset_timeout()

    workers = worker_registry.WorkerRegistry(f)
    f.on_connect.addCallback(on_connect, workers, job_registry)
    f.on_disconnect.addCallback(on_disconnect, workers, job_registry)

    if args.test:
        f.on_connect.addCallback(test_launcher, job_registry)

    # Cleanup properly on shutdown
    reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown, f)

    # Block until proxy connect to the pool
    yield f.on_connect

    # Setup getwork listener
    if args.getwork_port > 0:
        conn = reactor.listenTCP(
            args.getwork_port,
            Site(
                getwork_listener.Root(job_registry,
                                      workers,
                                      stratum_host=args.stratum_host,
                                      stratum_port=args.stratum_port,
                                      custom_lp=args.custom_lp,
                                      custom_stratum=args.custom_stratum,
                                      custom_user=args.custom_user,
                                      custom_password=args.custom_password)),
            interface=args.getwork_host)

        try:
            conn.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE,
                                   1)  # Enable keepalive packets
            conn.socket.setsockopt(
                socket.SOL_TCP, socket.TCP_KEEPIDLE,
                60)  # Seconds before sending keepalive probes
            conn.socket.setsockopt(
                socket.SOL_TCP, socket.TCP_KEEPINTVL,
                1)  # Interval in seconds between keepalive probes
            conn.socket.setsockopt(
                socket.SOL_TCP, socket.TCP_KEEPCNT,
                5)  # Failed keepalive probles before declaring other end dead
        except:
            pass  # Some socket features are not available on all platforms (you can guess which one)

    # Setup stratum listener
    if args.stratum_port > 0:
        stratum_listener.StratumProxyService._set_upstream_factory(f)
        reactor.listenTCP(
            args.stratum_port,
            SocketTransportFactory(debug=False,
                                   event_handler=ServiceEventHandler))

    # Setup multicast responder
    reactor.listenMulticast(3333,
                            multicast_responder.MulticastResponder(
                                (args.host, args.port), args.stratum_port,
                                args.getwork_port),
                            listenMultiple=True)

    log.warning(
        "-----------------------------------------------------------------------"
    )
    if args.getwork_host == '0.0.0.0' and args.stratum_host == '0.0.0.0':
        log.warning(
            "PROXY IS LISTENING ON ALL IPs ON PORT %d (stratum) AND %d (getwork)"
            % (args.stratum_port, args.getwork_port))
    else:
        log.warning("LISTENING FOR MINERS ON http://%s:%d (getwork) and stratum+tcp://%s:%d (stratum)" % \
                 (args.getwork_host, args.getwork_port, args.stratum_host, args.stratum_port))
    log.warning(
        "-----------------------------------------------------------------------"
    )
示例#6
0
def main():
    reactor.disconnectAll()
    failover = False
    if settings.POOL_FAILOVER_ENABLE:
        failover = settings.failover_pool
        settings.failover_pool = not settings.failover_pool

    pool_host = settings.POOL_HOST
    pool_port = settings.POOL_PORT
    if failover and settings.POOL_FAILOVER_ENABLE:
        pool_host = settings.POOL_HOST_FAILOVER
        pool_port = settings.POOL_PORT_FAILOVER

    log.warning("Monero Stratum proxy versao: %s" % version.VERSION)
    log.warning("Tentando se conectar a Stratum pool as %s:%d" %
                (pool_host, pool_port))

    # Connect to Stratum pool, main monitoring connection
    f = SocketTransportClientFactory(
        pool_host,
        pool_port,
        debug=settings.DEBUG,
        proxy=None,
        event_handler=client_service.ClientMiningService)

    job_registry = jobs.JobRegistry(f)
    client_service.ClientMiningService.job_registry = job_registry
    client_service.ClientMiningService.reset_timeout()

    f.on_connect.addCallback(on_connect)
    f.on_disconnect.addCallback(on_disconnect)
    # Cleanup properly on shutdown
    reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown, f)

    # Block until proxy connect to the pool
    try:
        yield f.on_connect
    except TransportException:
        log.warning(
            "O Pool Primaria deve estar conectada pela primeira vez para iniciar o failover"
        )
        return

    # Setup stratum listener
    stratum_listener.StratumProxyService._set_upstream_factory(f)
    stratum_listener.StratumProxyService._set_custom_user(
        settings.CUSTOM_USER, settings.CUSTOM_PASSWORD,
        settings.ENABLE_WORKER_ID, settings.WORKER_ID_FROM_IP)
    reactor.listenTCP(settings.STRATUM_PORT,
                      SocketTransportFactory(
                          debug=settings.DEBUG,
                          event_handler=ServiceEventHandler),
                      interface=settings.STRATUM_HOST)

    # Setup multicast responder
    reactor.listenMulticast(3333,
                            multicast_responder.MulticastResponder(
                                (pool_host, pool_port), settings.STRATUM_PORT),
                            listenMultiple=True)

    log.warning(
        "-----------------------------------------------------------------------"
    )
    if settings.STRATUM_HOST == '0.0.0.0':
        log.warning("PROXY esta escutando todos os IPS na porta %d (stratum)" %
                    settings.STRATUM_PORT)
    else:
        log.warning("esperando pelos mineiros/rigs em stratum+tcp://%s:%d (stratum)" % \
                 (settings.STRATUM_HOST, settings.STRATUM_PORT))
    log.warning(
        "-----------------------------------------------------------------------"
    )