fixed pre commit hook issues in autonat

This commit is contained in:
Winter-Soren
2025-04-25 23:02:30 +05:30
committed by Paul Robinson
parent 9655c88788
commit 1730999e38
2 changed files with 41 additions and 27 deletions

View File

@ -57,9 +57,11 @@ class AutoNATService:
Initialize the AutoNAT service. Initialize the AutoNAT service.
Args: Args:
----
host (BasicHost): The libp2p host instance that provides networking host (BasicHost): The libp2p host instance that provides networking
capabilities for the AutoNAT service, including peer discovery capabilities for the AutoNAT service, including peer discovery
and connection management. and connection management.
""" """
self.host = host self.host = host
self.peerstore: IPeerStore = host.get_peerstore() self.peerstore: IPeerStore = host.get_peerstore()
@ -91,12 +93,15 @@ class AutoNATService:
appropriate handlers based on the message type. appropriate handlers based on the message type.
Args: Args:
----
request (bytes | Message): The request bytes that need to be parsed request (bytes | Message): The request bytes that need to be parsed
and handled by the AutoNAT service, or a Message object directly. and handled by the AutoNAT service, or a Message object directly.
Returns: Returns
-------
Message: The response message containing the result of the request. Message: The response message containing the result of the request.
Returns an error response if the request type is not recognized. Returns an error response if the request type is not recognized.
""" """
if isinstance(request, bytes): if isinstance(request, bytes):
message = Message() message = Message()
@ -124,12 +129,15 @@ class AutoNATService:
and recording the results of these connection attempts. and recording the results of these connection attempts.
Args: Args:
----
message (Message): The request message containing the dial request message (Message): The request message containing the dial request
parameters and peer information. parameters and peer information.
Returns: Returns
-------
Message: The response message containing the dial results, including Message: The response message containing the dial results, including
success/failure status for each attempted peer connection. success/failure status for each attempted peer connection.
""" """
response = Message() response = Message()
response.type = Type.Value("DIAL_RESPONSE") response.type = Type.Value("DIAL_RESPONSE")
@ -164,12 +172,15 @@ class AutoNATService:
NAT traversal capabilities. NAT traversal capabilities.
Args: Args:
----
peer_id (ID): The identifier of the peer to attempt to dial for peer_id (ID): The identifier of the peer to attempt to dial for
NAT traversal testing. NAT traversal testing.
Returns: Returns
-------
bool: True if the dial was successful and a connection could be bool: True if the dial was successful and a connection could be
established, False if the connection attempt failed. established, 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])
@ -185,11 +196,13 @@ class AutoNATService:
Retrieves the current NAT status of the node based on previous Retrieves the current NAT status of the node based on previous
dial attempts and their results. dial attempts and their results.
Returns: Returns
-------
int: The current status as an integer: int: The current status as an integer:
- 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

View File

@ -32,7 +32,8 @@ class AutoNATStub:
"""AutoNAT service definition""" """AutoNAT service definition"""
def __init__(self, channel: grpc.Channel) -> None: def __init__(self, channel: grpc.Channel) -> None:
"""Initialize the AutoNAT stub. """
Initialize the AutoNAT stub.
Args: Args:
---- ----