mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 08:31:52 +03:00
Before calling gethostbyname(); check if host is an address (#8765)
* Before calling gethostbyname(), check to see if we already have an address. That prevents an unnecessary call, and also allows for specifying IPv6 addresses which otherwise cause exceptions here. * Also recognize addresses when passed to timelord spawn_process, so that IPv6 addresses can be used. * Missed importing PeerInfo * Adjust style to match requirements and existing code * Cast PeerInfo port to uint16
This commit is contained in:
parent
ccb2442ae8
commit
0a2294841d
@ -9,7 +9,11 @@ def start_reconnect_task(server: ChiaServer, peer_info_arg: PeerInfo, log, auth:
|
||||
"""
|
||||
Start a background task that checks connection and reconnects periodically to a peer.
|
||||
"""
|
||||
peer_info = PeerInfo(socket.gethostbyname(peer_info_arg.host), peer_info_arg.port)
|
||||
# If peer_info_arg is already an address, use it, otherwise resolve it here.
|
||||
if peer_info_arg.is_valid():
|
||||
peer_info = peer_info_arg
|
||||
else:
|
||||
peer_info = PeerInfo(socket.gethostbyname(peer_info_arg.host), peer_info_arg.port)
|
||||
|
||||
async def connection_check():
|
||||
while True:
|
||||
|
@ -8,9 +8,11 @@ from typing import Dict, List
|
||||
|
||||
import pkg_resources
|
||||
|
||||
from chia.types.peer_info import PeerInfo
|
||||
from chia.util.chia_logging import initialize_logging
|
||||
from chia.util.config import load_config
|
||||
from chia.util.default_root import DEFAULT_ROOT_PATH
|
||||
from chia.util.ints import uint16
|
||||
from chia.util.setproctitle import setproctitle
|
||||
|
||||
active_processes: List = []
|
||||
@ -49,7 +51,11 @@ async def spawn_process(host: str, port: int, counter: int):
|
||||
try:
|
||||
dirname = path_to_vdf_client.parent
|
||||
basename = path_to_vdf_client.name
|
||||
resolved = socket.gethostbyname(host)
|
||||
check_addr = PeerInfo(host, uint16(port))
|
||||
if check_addr.is_valid():
|
||||
resolved = host
|
||||
else:
|
||||
resolved = socket.gethostbyname(host)
|
||||
proc = await asyncio.create_subprocess_shell(
|
||||
f"{basename} {resolved} {port} {counter}",
|
||||
stdout=asyncio.subprocess.PIPE,
|
||||
|
@ -395,7 +395,12 @@ class WalletNode:
|
||||
self.config["full_node_peer"]["port"],
|
||||
)
|
||||
peers = [c.get_peer_info() for c in self.server.get_full_node_connections()]
|
||||
full_node_resolved = PeerInfo(socket.gethostbyname(full_node_peer.host), full_node_peer.port)
|
||||
# If full_node_peer is already an address, use it, otherwise
|
||||
# resolve it here.
|
||||
if full_node_peer.is_valid():
|
||||
full_node_resolved = full_node_peer
|
||||
else:
|
||||
full_node_resolved = PeerInfo(socket.gethostbyname(full_node_peer.host), full_node_peer.port)
|
||||
if full_node_peer in peers or full_node_resolved in peers:
|
||||
self.log.info(f"Will not attempt to connect to other nodes, already connected to {full_node_peer}")
|
||||
for connection in self.server.get_full_node_connections():
|
||||
|
Loading…
Reference in New Issue
Block a user