Exemple #1
0
def GetworkProxy_main(cb):
    log.info("Stratum proxy version %s Connecting to Pool..." % version.VERSION)
        
    # Connect to Stratum pool
    f = SocketTransportClientFactory(settings.HOSTNAME, settings.LISTEN_SOCKET_TRANSPORT,
                debug=False, proxy=None, event_handler=client_service.ClientMiningService)
    
    job_registry = jobs.JobRegistry(f, cmd='', no_midstate=settings.GW_DISABLE_MIDSTATE, real_target=settings.GW_SEND_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)
    
    # Cleanup properly on shutdown
    reactor.addSystemEventTrigger('before', 'shutdown', on_shutdown, f)

    # Block until proxy connects to the pool
    yield f.on_connect
    
    # Setup getwork listener
    gw_site = Site(getwork_listener.Root(job_registry, workers,
		stratum_host=settings.HOSTNAME, stratum_port=settings.LISTEN_SOCKET_TRANSPORT,
		custom_lp=False, custom_stratum=False,
		custom_user=False, custom_password=False
		))
    gw_site.noisy = False
    reactor.listenTCP(settings.GW_PORT, gw_site, interface='0.0.0.0')
    
    log.info("Getwork Proxy is online, Port: %d" % (settings.GW_PORT))
Exemple #2
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(
        "-----------------------------------------------------------------------"
    )
Exemple #3
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)
    # Setup periodic checks for a new version
    #test_update()

    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,
                                    scrypt_target=args.scrypt_target,
                                    no_midstate=args.no_midstate,
                                    real_target=args.real_target,
                                    use_old_target=args.old_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:
        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)
    #    stratum_listener.StratumProxyService._set_custom_user(args.custom_user, args.custom_password)
    #    reactor.listenTCP(args.stratum_port, SocketTransportFactory(debug=False, event_handler=ServiceEventHandler), interface=args.stratum_host)

    # 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':
        log.warning("PROXY IS LISTENING ON ALL IPs ON PORT %d (getwork)" %
                    args.getwork_port)
    else:
        log.warning("LISTENING FOR MINERS ON http://%s:%d (getwork) " % \
                 (args.getwork_host, args.getwork_port))
    log.warning(
        "-----------------------------------------------------------------------"
    )
Exemple #4
0
    coinbaser = SimpleCoinbaser(sia_rpc, getattr(settings, 'CENTRAL_WALLET'))
    (yield coinbaser.on_load)

    # Connect to Sia Daemon via Factory
    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)
    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)

    registry = TemplateRegistry(BlockTemplate, coinbaser, sia_rpc,
                                getattr(settings, 'INSTANCE_ID'),
                                MiningSubscription.on_template,
                                Interfaces.share_manager.on_network_block)

    # Template registry is the main interface between Stratum service
    # and pool core logic
    Interfaces.set_template_registry(job_registry)

    # Set up polling mechanism for detecting new block on the network
    # This is just failsafe solution when -blocknotify
    # mechanism is not working properly