mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2025-12-31 20:36:24 +00:00
refactor(app): 804 refactored find_free_port() in address_validation.py
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
import argparse
|
||||
import random
|
||||
import secrets
|
||||
import socket
|
||||
|
||||
import multiaddr
|
||||
import trio
|
||||
@ -25,6 +24,7 @@ from libp2p.peer.peerinfo import (
|
||||
info_from_p2p_addr,
|
||||
)
|
||||
from libp2p.utils.address_validation import (
|
||||
find_free_port,
|
||||
get_available_interfaces,
|
||||
)
|
||||
|
||||
@ -32,13 +32,6 @@ PROTOCOL_ID = TProtocol("/echo/1.0.0")
|
||||
MAX_READ_LEN = 2**32 - 1
|
||||
|
||||
|
||||
def find_free_port():
|
||||
"""Find a free port on localhost."""
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||
s.bind(("", 0)) # Bind to a free port provided by the OS
|
||||
return s.getsockname()[1]
|
||||
|
||||
|
||||
async def _echo_stream_handler(stream: INetStream) -> None:
|
||||
try:
|
||||
peer_id = stream.muxed_conn.peer_id
|
||||
|
||||
Reference in New Issue
Block a user