added: logs

This commit is contained in:
lla-dane
2025-05-24 00:30:19 +05:30
committed by varun-r-mallya
parent b3137aa159
commit e868f77f93
5 changed files with 78 additions and 8 deletions

View File

@ -1,8 +1,11 @@
import logging
from typing import (
Optional,
)
# logger = logging.getLogger("libp2p.network.swarm")
from loguru import (
logger,
)
from multiaddr import (
Multiaddr,
)
@ -55,8 +58,6 @@ from .exceptions import (
SwarmException,
)
logger = logging.getLogger("libp2p.network.swarm")
def create_default_stream_handler(network: INetworkService) -> StreamHandlerFn:
async def stream_handler(stream: INetStream) -> None:
@ -130,6 +131,7 @@ class Swarm(Service, INetworkService):
:return: muxed connection
"""
if peer_id in self.connections:
logger.info("WE ARE RETURNING, PEER ALREADAY EXISTS")
# If muxed connection already exists for peer_id,
# set muxed connection equal to existing muxed connection
return self.connections[peer_id]
@ -150,6 +152,7 @@ class Swarm(Service, INetworkService):
# Try all known addresses
for multiaddr in addrs:
try:
logger.info("HANDSHAKE GOING TO HAPPEN")
return await self.dial_addr(multiaddr, peer_id)
except SwarmException as e:
exceptions.append(e)
@ -224,8 +227,11 @@ class Swarm(Service, INetworkService):
logger.debug("attempting to open a stream to peer %s", peer_id)
swarm_conn = await self.dial_peer(peer_id)
logger.info("INETCONN CREATED")
net_stream = await swarm_conn.new_stream()
logger.info("INETSTREAM CREATED")
logger.debug("successfully opened a stream to peer %s", peer_id)
return net_stream