lnworker.peers: follow-up b5811e8072

somehow I forgot writes...
This commit is contained in:
SomberNight 2020-04-15 22:41:16 +02:00
parent 223b62554e
commit 95fa5d37c3
No known key found for this signature in database
GPG key ID: B33B5F232C6271E9

View file

@ -189,7 +189,8 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]):
self.logger.info('handshake failure from incoming connection') self.logger.info('handshake failure from incoming connection')
return return
peer = Peer(self, node_id, transport) peer = Peer(self, node_id, transport)
self._peers[node_id] = peer with self.lock:
self._peers[node_id] = peer
await self.taskgroup.spawn(peer.main_loop()) await self.taskgroup.spawn(peer.main_loop())
try: try:
# FIXME: server.close(), server.wait_closed(), etc... ? # FIXME: server.close(), server.wait_closed(), etc... ?
@ -233,12 +234,13 @@ class LNWorker(Logger, NetworkRetryManager[LNPeerAddr]):
self.logger.info(f"adding peer {peer_addr}") self.logger.info(f"adding peer {peer_addr}")
peer = Peer(self, node_id, transport) peer = Peer(self, node_id, transport)
await self.taskgroup.spawn(peer.main_loop()) await self.taskgroup.spawn(peer.main_loop())
self._peers[node_id] = peer with self.lock:
self._peers[node_id] = peer
return peer return peer
def peer_closed(self, peer: Peer) -> None: def peer_closed(self, peer: Peer) -> None:
if peer.pubkey in self._peers: with self.lock:
self._peers.pop(peer.pubkey) self._peers.pop(peer.pubkey, None)
def num_peers(self) -> int: def num_peers(self) -> int:
return sum([p.is_initialized() for p in self.peers.values()]) return sum([p.is_initialized() for p in self.peers.values()])