Ejemplo n.º 1
0
    def stop(self):
        for k, wallet in self.wallets.items():
            wallet.stop_threads()
        DaemonThread.stop(self)


# def _eintr_retry(func, *args):
#     """restart a system call interrupted by EINTR"""
#     while True:
#         try:
#             return func(*args)
#         except (OSError, select.error) as e:
#                 raise
Ejemplo n.º 2
0
    def __init__(self, config, network):
        DaemonThread.__init__(self)
        self.config = config
        self.network = network
        self.cmd_runner = Commands(self.config, self.network)

        host = config.get('rpchost', '0.0.0.0')
        port = config.get('rpcport', 8000)
        self.server = SimpleJSONRPCServer((host, port),
                                          requestHandler=RequestHandler,
                                          logRequests=False)
        with open(lockfile(config), 'w') as f:
            f.write(repr(self.server.socket.getsockname()))
        self.server.timeout = 0.1
        for cmdname in known_commands:
            # rpc直接调用命令 --hetao
            self.server.register_function(getattr(self.cmd_runner, cmdname),
                                          cmdname)
        self.server.register_function(self.ping, 'ping')
        self.server.register_function(self.run_daemon, 'daemon')
Ejemplo n.º 3
0
 def stop(self):
     for k, wallet in self.wallets.items():
         wallet.stop_threads()
     DaemonThread.stop(self)
Ejemplo n.º 4
0
    def __init__(self, config=None):
        if config is None:
            config = {}  # Do not use mutables as default values!
        DaemonThread.__init__(self)
        self.config = SimpleConfig(config) if isinstance(config,
                                                         dict) else config
        self.num_server = 8 if not self.config.get('oneserver') else 0
        self.blockchain = get_blockchain(self.config, self)
        # A deque of interface header requests, processed left-to-right
        self.bc_requests = deque()
        # Server for addresses and transactions
        self.default_server = self.config.get('server')
        # Sanitize default server
        try:
            deserialize_server(self.default_server)
        except:
            self.default_server = None
        if not self.default_server:
            default_servers = self.config.get('default_servers')
            if not default_servers:
                raise ValueError('No servers have been specified')
            self.default_server = pick_random_server(default_servers)

        self.lock = Lock()
        self.pending_sends = []
        self.message_id = 0
        self.debug = False
        self.irc_servers = {}  # returned by interface (list from irc)

        self.banner = ''
        self.fee = None
        self.relay_fee = None
        self.heights = {}
        self.merkle_roots = {}
        self.utxo_roots = {}

        # catchup counter, used to track catchup progress before chain is verified and headers saved
        self.catchup_progress = 0

        # callbacks passed with subscriptions
        self.subscriptions = defaultdict(list)
        self.sub_cache = {}
        self.callbacks = defaultdict(list)

        dir_path = os.path.join(self.config.path, 'certs')
        if not os.path.exists(dir_path):
            os.mkdir(dir_path)

        # subscriptions and requests
        self.subscribed_addresses = set()
        # Requests from client we've not seen a response to
        self.unanswered_requests = {}
        # retry times
        self.server_retry_time = time.time()
        self.nodes_retry_time = time.time()
        # kick off the network.  interface is the main server we are currently
        # communicating with.  interfaces is the set of servers we are connecting
        # to or have an ongoing connection with
        self.interface = None
        self.interfaces = {}
        self.auto_connect = self.config.get('auto_connect', False)
        self.connecting = set()
        self.socket_queue = Queue.Queue()
        self.online_servers = {}
        self._set_online_servers()
        self.start_network(
            deserialize_server(self.default_server)[2],
            deserialize_proxy(self.config.get('proxy')))