chore: log cleanup

This commit is contained in:
Akash Mondal
2025-07-04 06:40:22 +00:00
committed by lla-dane
parent 03bf071739
commit 0f64bb49b5
7 changed files with 56 additions and 85 deletions

View File

@ -1,7 +1,6 @@
from enum import (
Enum,
)
import inspect
import trio
@ -165,25 +164,20 @@ class NetStream(INetStream):
data = await self.muxed_stream.read(n)
return data
except MuxedStreamEOF as error:
print("NETSTREAM: READ ERROR, RECEIVED EOF")
async with self._state_lock:
if self.__stream_state == StreamState.CLOSE_WRITE:
self.__stream_state = StreamState.CLOSE_BOTH
print("NETSTREAM: READ ERROR, REMOVING STREAM")
await self._remove()
elif self.__stream_state == StreamState.OPEN:
print("NETSTREAM: READ ERROR, NEW STATE -> CLOSE_READ")
self.__stream_state = StreamState.CLOSE_READ
raise StreamEOF() from error
except (MuxedStreamReset, QUICStreamClosedError, QUICStreamResetError) as error:
print("NETSTREAM: READ ERROR, MUXED STREAM RESET")
async with self._state_lock:
if self.__stream_state in [
StreamState.OPEN,
StreamState.CLOSE_READ,
StreamState.CLOSE_WRITE,
]:
print("NETSTREAM: READ ERROR, NEW STATE -> RESET")
self.__stream_state = StreamState.RESET
await self._remove()
raise StreamReset() from error
@ -222,8 +216,6 @@ class NetStream(INetStream):
async def close(self) -> None:
"""Close stream for writing."""
print("NETSTREAM: CLOSING STREAM, CURRENT STATE: ", self.__stream_state)
print("CALLED BY: ", inspect.stack()[1].function)
async with self._state_lock:
if self.__stream_state in [
StreamState.CLOSE_BOTH,
@ -243,7 +235,6 @@ class NetStream(INetStream):
async def reset(self) -> None:
"""Reset stream, closing both ends."""
print("NETSTREAM: RESETING STREAM")
async with self._state_lock:
if self.__stream_state == StreamState.RESET:
return

View File

@ -59,7 +59,6 @@ from .exceptions import (
)
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s [%(levelname)s] %(message)s",
handlers=[logging.StreamHandler(sys.stdout)],
)
@ -182,7 +181,13 @@ class Swarm(Service, INetworkService):
async def dial_addr(self, addr: Multiaddr, peer_id: ID) -> INetConn:
"""
Try to create a connection to peer_id with addr.
:param addr: the address we want to connect with
:param peer_id: the peer we want to connect to
:raises SwarmException: raised when an error occurs
:return: network connection
"""
# Dial peer (connection to peer does not yet exist)
# Transport dials peer (gets back a raw conn)
try:
raw_conn = await self.transport.dial(addr)
except OpenConnectionError as error:
@ -191,9 +196,19 @@ class Swarm(Service, INetworkService):
f"fail to open connection to peer {peer_id}"
) from error
if isinstance(self.transport, QUICTransport) and isinstance(
raw_conn, IMuxedConn
):
logger.info(
"Skipping upgrade for QUIC, QUIC connections are already multiplexed"
)
swarm_conn = await self.add_conn(raw_conn)
return swarm_conn
logger.debug("dialed peer %s over base transport", peer_id)
# Standard TCP flow - security then mux upgrade
# Per, https://discuss.libp2p.io/t/multistream-security/130, we first secure
# the conn and then mux the conn
try:
secured_conn = await self.upgrader.upgrade_security(raw_conn, True, peer_id)
except SecurityUpgradeFailure as error:
@ -227,6 +242,9 @@ class Swarm(Service, INetworkService):
logger.debug("attempting to open a stream to peer %s", peer_id)
swarm_conn = await self.dial_peer(peer_id)
dd = "Yes" if swarm_conn is None else "No"
print(f"Is swarm conn None: {dd}")
net_stream = await swarm_conn.new_stream()
logger.debug("successfully opened a stream to peer %s", peer_id)
@ -249,7 +267,7 @@ class Swarm(Service, INetworkService):
- Map multiaddr to listener
"""
# We need to wait until `self.listener_nursery` is created.
logger.debug("SWARM LISTEN CALLED")
logger.debug("Starting to listen")
await self.event_listener_nursery_created.wait()
success_count = 0