mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
feat: implement get_remote_address via delegation pattern
This commit is contained in:
@ -1,3 +1,7 @@
|
||||
from typing import (
|
||||
Optional,
|
||||
)
|
||||
|
||||
from libp2p.abc import (
|
||||
IRawConnection,
|
||||
)
|
||||
@ -42,3 +46,7 @@ class RawConnection(IRawConnection):
|
||||
|
||||
async def close(self) -> None:
|
||||
await self.stream.close()
|
||||
|
||||
def get_remote_address(self) -> Optional[tuple[str, int]]:
|
||||
"""Delegate to the underlying stream's get_remote_address method."""
|
||||
return self.stream.get_remote_address()
|
||||
|
||||
@ -78,6 +78,10 @@ class NetStream(INetStream):
|
||||
async def reset(self) -> None:
|
||||
await self.muxed_stream.reset()
|
||||
|
||||
def get_remote_address(self) -> Optional[tuple[str, int]]:
|
||||
"""Delegate to the underlying muxed stream."""
|
||||
return self.muxed_stream.get_remote_address()
|
||||
|
||||
# TODO: `remove`: Called by close and write when the stream is in specific states.
|
||||
# It notifies `ClosedStream` after `SwarmConn.remove_stream` is called.
|
||||
# Reference: https://github.com/libp2p/go-libp2p-swarm/blob/99831444e78c8f23c9335c17d8f7c700ba25ca14/swarm_stream.go # noqa: E501
|
||||
|
||||
Reference in New Issue
Block a user