コード例 #1
0
		f.write("WorkQueueSizeClear = (0x1000, 0x2000)")
		f.write("WorkQueueSizeLongpoll = (0x1000, 0x2000)")
		f.write("MinimumTxnUpdateWait = 5")
		f.write("TxnUpdateRetryWait = 1")
		f.write("IdleSleepTime = 0.1")
		f.write("TrackerAddr = {}".format(address))
		f.write("UpstreamURI = {}".format(uri))
		f.write("DelayLogForUpstream = True")
		f.write("UpstreamBitcoindNode = ('127.0.0.1', {})".format(p2p_port))
		f.write("UpstreamNetworkId = b'{}'".format(network_id))
		f.write("SecretUser = ''")
		f.write("GotWorkURI = ''")
		f.write("GotWorkTarget = 0x0000ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
		f.write("POT = 0")
		f.write("Greedy = False")
		f.write("JSONRPCAddresses = (('::ffff:176.119.27.170', 8344),)")
		f.write("StratumAddresses = (('::ffff:176.119.27.170', 3333),)")
		f.write("BitcoinNodeAddresses = (('::ffff:176.119.27.170', {}),)".format(upstream_port))
		f.write("TrustedForwarders = ('::ffff:127.0.0.1',)")
		f.write("ShareLogging = ({'type': 'logfile', 'filename': 'share-logfile', 'format': "{time} {Q(remoteHost)} {username} {YN(not(rejectReason))} {dash(YN(upstreamResult))} {dash(rejectReason)} {solution}\n),)")
		f.write("Authentication =  ({'module': 'allowall',},)")
		f.write("LogFile = 'filename.log')
		f.close()
		return True
	except:
		return False
		
rpcsrv = Server(('127.0.0.1':9001))
rpcsrv.add_handler(change_coin)
rpcsrv.serve_forever()
コード例 #2
0
ファイル: Remote.py プロジェクト: showlabor/onebutton
class Remote(Module):
    """Remote module - make possible to control OneButton through json-rpc"""

    def __init__(self, **kwargs):
        Module.__init__(self, **kwargs)

        self._server = Server((self._cfg.get('address', ''), self._cfg.get('port', 9000)))

        self._registerHandlers()

        self._server_proc = Thread(target=self._server.serve)
        self._server_proc.daemon = True
        self._server_proc.start()

    def _exec(self, cmd):
        return subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=self._logerr).communicate()[0]

    def _registerHandlers(self):
        functions = self.list()
        for name, f in functions.items():
            log.debug("Remote: add handler for %s - %s" % (f['function'], name))
            self._server.add_handler(getattr(self, name), f['function'])

    def stop(self):
        log.info("Stopping '%s'" % self._cfg.get('name', '[unknown Remote]'))
        self._server.shutdown()

    # Remote jsonrpc functions
    @jsonrpc()
    def version(self):
        return self._control.version()

    @jsonrpc()
    def list(self):
        out = {}
        functions = [getattr(self, f) for f in dir(self) if callable(getattr(self, f)) and hasattr(getattr(self, f), '_jsonrpc')]
        for f in functions:
            name = '%s.%s' % (f._jsonrpc, f.__name__) if f._jsonrpc else f.__name__
            args = [a for a in f.__code__.co_varnames if a != 'self']
            out[f.__name__] = {'function': name, 'arguments': args}
        return out

    @jsonrpc('system')
    def poweroff(self):
        log.info("Remote: poweroff")
        return self._exec(['sudo', 'poweroff'])

    @jsonrpc('system')
    def reboot(self):
        log.info("Remote: reboot")
        return self._exec(['sudo', 'reboot'])

    @jsonrpc('onebutton')
    def upgrade(self, version = None):
        log.info("Remote: upgrade")
        # TODO: command to upgarade
        return version

    @jsonrpc('onebutton')
    def versions(self):
        log.info("Remote: versions")
        # TODO: command to check available versions
        return ['0.1-alpha', '0.2-alpha', '0.3-alpha']

    @jsonrpc('onebutton')
    def restart(self):
        log.info("Remote: restart")
        return self._control.stop()

    @jsonrpc('audio')
    def volumeIn(self, dev = None, left = None, right = None):
        log.info("Remote: volumeIn dev:%s l:%d r:%d" % (dev, left, right))
        # TODO: get & set
        return [0, 0]

    @jsonrpc('audio')
    def volumeOut(self, dev = None, left = None, right = None):
        log.info("Remote: volumeOut dev:%s l:%d r:%d" % (dev, left, right))
        # TODO: get & set
        return [0, 0]
コード例 #3
0
def test_set_up():
    # Because 'setUp' on unittests are called multiple times
    # and starting a server each time is inefficient / a headache

    # Starting normal server
    server = Server(('', 8000))
    server.add_handler(summation, 'sum')
    server.add_handler(summation, 'notify_sum')
    server.add_handler(notify_hello)
    server.add_handler(subtract)
    server.add_handler(update)
    server.add_handler(get_data)
    server.add_handler(summation, 'namespace.sum')
    server_proc = Thread(target=server.serve)
    server_proc.daemon = True
    server_proc.start()

    #Starting secure server
    server2 = Server(('', 8001))
    server2.add_handler(summation, 'sum')
    server_proc2 = Thread(target=server2.serve)
    server_proc2.daemon = True
    server_proc2.start()

    time.sleep(1)  # give it time to start up
コード例 #4
0
ファイル: tests.py プロジェクト: jianmink/jsonrpctcp
def test_set_up():
    # Because 'setUp' on unittests are called multiple times
    # and starting a server each time is inefficient / a headache
    
    # Starting normal server
    server = Server(('', 8000))
    server.add_handler(summation, 'sum')
    server.add_handler(summation, 'notify_sum')
    server.add_handler(notify_hello)
    server.add_handler(subtract)
    server.add_handler(update)
    server.add_handler(get_data)
    server.add_handler(summation, 'namespace.sum')
    server_proc = Thread(target=server.serve)
    server_proc.daemon = True
    server_proc.start()
    
    #Starting secure server
    server2 = Server(('', 8001))
    server2.add_handler(summation, 'sum')
    server_proc2 = Thread(target=server2.serve)
    server_proc2.daemon = True
    server_proc2.start()
    
    time.sleep(1) # give it time to start up