fixed autonat file for pre-commit hook issues

This commit is contained in:
Winter-Soren
2025-05-02 22:54:04 +05:30
committed by Paul Robinson
parent 86dce72ae0
commit 1bed3304c7

View File

@ -66,6 +66,7 @@ class AutoNATService:
The libp2p host instance that provides networking capabilities The libp2p host instance that provides networking capabilities
for the AutoNAT service, including peer discovery and connection for the AutoNAT service, including peer discovery and connection
management. management.
""" """
self.host = host self.host = host
self.peerstore: IPeerStore = host.get_peerstore() self.peerstore: IPeerStore = host.get_peerstore()
@ -80,6 +81,7 @@ class AutoNATService:
---------- ----------
stream : NetStream stream : NetStream
The network stream to handle for AutoNAT protocol communication. The network stream to handle for AutoNAT protocol communication.
""" """
try: try:
request_bytes = await stream.read() request_bytes = await stream.read()
@ -108,6 +110,7 @@ class AutoNATService:
The response message containing the result of processing the The response message containing the result of processing the
request. Returns an error response if the request type is not request. Returns an error response if the request type is not
recognized. recognized.
""" """
if isinstance(request, bytes): if isinstance(request, bytes):
message = Message() message = Message()
@ -142,6 +145,7 @@ class AutoNATService:
Message Message
The response message containing the results of the dial The response message containing the results of the dial
attempts, including success/failure status for each peer. attempts, including success/failure status for each peer.
""" """
response = Message() response = Message()
response.type = Type.Value("DIAL_RESPONSE") response.type = Type.Value("DIAL_RESPONSE")
@ -162,9 +166,6 @@ class AutoNATService:
peer_info.success = success peer_info.success = success
dial_response.peers.append(peer_info) dial_response.peers.append(peer_info)
# Initialize the dial_response field if it doesn't exist
if not hasattr(response, "dial_response"):
response.dial_response = DialResponse()
response.dial_response.CopyFrom(dial_response) response.dial_response.CopyFrom(dial_response)
return response return response
@ -182,6 +183,7 @@ class AutoNATService:
bool bool
True if the connection was successfully established, True if the connection was successfully established,
False if the connection attempt failed. False if the connection attempt failed.
""" """
try: try:
stream = await self.host.new_stream(peer_id, [AUTONAT_PROTOCOL_ID]) stream = await self.host.new_stream(peer_id, [AUTONAT_PROTOCOL_ID])
@ -201,6 +203,7 @@ class AutoNATService:
- AutoNATStatus.UNKNOWN (0): Status not yet determined - AutoNATStatus.UNKNOWN (0): Status not yet determined
- AutoNATStatus.PUBLIC (1): Node is publicly reachable - AutoNATStatus.PUBLIC (1): Node is publicly reachable
- AutoNATStatus.PRIVATE (2): Node is behind NAT - AutoNATStatus.PRIVATE (2): Node is behind NAT
""" """
return self.status return self.status