Session manager owns peer manager

This commit is contained in:
Neil Booth 2018-07-28 09:22:19 +08:00
parent 010ef08320
commit 5ee5a54f5a
2 changed files with 10 additions and 11 deletions

View File

@ -102,22 +102,18 @@ class Controller(ServerBase):
self.bp.lookup_utxos) self.bp.lookup_utxos)
self.chain_state = ChainState(env, self.tasks, daemon, self.bp, self.chain_state = ChainState(env, self.tasks, daemon, self.bp,
notifications) notifications)
self.peer_mgr = PeerManager(env, self.tasks, self.chain_state)
self.session_mgr = SessionManager(env, self.tasks, self.chain_state, self.session_mgr = SessionManager(env, self.tasks, self.chain_state,
self.mempool, self.peer_mgr, self.mempool, notifications,
notifications, self.shutdown_event) self.shutdown_event)
async def start_servers(self): async def start_servers(self):
'''Start the RPC server and wait for the mempool to synchronize. Then '''Start the RPC server and wait for the mempool to synchronize. Then
start the peer manager and serving external clients. start serving external clients.
''' '''
await self.session_mgr.start_rpc_server() await self.session_mgr.start_rpc_server()
await self.bp.catch_up_to_daemon() await self.bp.catch_up_to_daemon()
await self.mempool.start_and_wait_for_sync() await self.mempool.start_and_wait_for_sync()
await self.session_mgr.start_serving() await self.session_mgr.start_serving()
# Peer discovery should start after we start serving because
# we connect to ourself
self.peer_mgr.start_peer_discovery()
async def shutdown(self): async def shutdown(self):
'''Perform the shutdown sequence.''' '''Perform the shutdown sequence.'''
@ -125,5 +121,5 @@ class Controller(ServerBase):
await self.session_mgr.shutdown() await self.session_mgr.shutdown()
# Flush chain state to disk # Flush chain state to disk
await self.chain_state.shutdown() await self.chain_state.shutdown()
# Cancel all tasks; this shuts down the peer manager and prefetcher # Cancel all tasks; this shuts down the prefetcher
await self.tasks.cancel_all(wait=True) await self.tasks.cancel_all(wait=True)

View File

@ -97,14 +97,14 @@ class SessionManager(object):
CATCHING_UP, LISTENING, PAUSED, SHUTTING_DOWN = range(4) CATCHING_UP, LISTENING, PAUSED, SHUTTING_DOWN = range(4)
def __init__(self, env, tasks, chain_state, mempool, peer_mgr, def __init__(self, env, tasks, chain_state, mempool, notifications,
notifications, shutdown_event): shutdown_event):
env.max_send = max(350000, env.max_send) env.max_send = max(350000, env.max_send)
self.env = env self.env = env
self.tasks = tasks self.tasks = tasks
self.chain_state = chain_state self.chain_state = chain_state
self.mempool = mempool self.mempool = mempool
self.peer_mgr = peer_mgr self.peer_mgr = PeerManager(env, tasks, chain_state)
self.shutdown_event = shutdown_event self.shutdown_event = shutdown_event
self.logger = util.class_logger(__name__, self.__class__.__name__) self.logger = util.class_logger(__name__, self.__class__.__name__)
self.servers = {} self.servers = {}
@ -419,6 +419,9 @@ class SessionManager(object):
self.logger.info('drop clients matching: {}' self.logger.info('drop clients matching: {}'
.format(self.env.drop_client.pattern)) .format(self.env.drop_client.pattern))
await self._start_external_servers() await self._start_external_servers()
# Peer discovery should start after the external servers
# because we connect to ourself
self.peer_mgr.start_peer_discovery()
self.tasks.create_task(self._housekeeping()) self.tasks.create_task(self._housekeeping())
async def shutdown(self): async def shutdown(self):