added getter for connected peers

This commit is contained in:
mystical-prog
2024-11-04 21:54:10 +05:30
committed by Paul Robinson
parent a10b8fdb91
commit 847dfa6577
2 changed files with 9 additions and 0 deletions

View File

@ -145,6 +145,9 @@ class BasicHost(IHost):
addrs.append(addr.encapsulate(p2p_part))
return addrs
def get_connected_peers(self) -> List[ID]:
return list(self.get_network().connections.keys())
@asynccontextmanager
async def run(
self, listen_addrs: Sequence[multiaddr.Multiaddr]

View File

@ -71,6 +71,12 @@ class IHost(ABC):
:return: all the multiaddr addresses this host is listening to
"""
@abstractmethod
def get_connected_peers(self) -> List[ID]:
"""
:return: all the ids of peers this host is currently connected to
"""
@abstractmethod
def run(
self, listen_addrs: Sequence[multiaddr.Multiaddr]