mirror of
https://github.com/Chia-Network/chia-blockchain.git
synced 2024-09-21 08:31:52 +03:00
Merge release/1.4.0's 6171703
into main
This commit is contained in:
commit
11b68de354
@ -14,6 +14,7 @@ from chia.types.peer_info import PeerInfo
|
||||
from chia.util.byte_types import hexstr_to_bytes
|
||||
from chia.util.ints import uint16
|
||||
from chia.util.json_util import dict_to_json_str
|
||||
from chia.util.network import select_port
|
||||
from chia.util.ws_message import create_payload, create_payload_dict, format_response, pong
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@ -329,7 +330,13 @@ async def start_rpc_server(
|
||||
|
||||
site = web.TCPSite(runner, self_hostname, int(rpc_port), ssl_context=rpc_server.ssl_context)
|
||||
await site.start()
|
||||
rpc_port = runner.addresses[0][1]
|
||||
|
||||
#
|
||||
# On a dual-stack system, we want to get the (first) IPv4 port unless
|
||||
# prefer_ipv6 is set in which case we use the IPv6 port
|
||||
#
|
||||
if rpc_port == 0:
|
||||
rpc_port = select_port(root_path, runner.addresses)
|
||||
|
||||
async def cleanup():
|
||||
await rpc_server.stop()
|
||||
|
@ -30,7 +30,7 @@ from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.types.peer_info import PeerInfo
|
||||
from chia.util.errors import Err, ProtocolError
|
||||
from chia.util.ints import uint16
|
||||
from chia.util.network import is_in_network, is_localhost
|
||||
from chia.util.network import is_in_network, is_localhost, select_port
|
||||
from chia.util.ssl_check import verify_ssl_certs_and_keys
|
||||
|
||||
max_message_size = 50 * 1024 * 1024 # 50MB
|
||||
@ -267,13 +267,19 @@ class ChiaServer:
|
||||
# this port from the socket itself and update self._port.
|
||||
self.site = web.TCPSite(
|
||||
self.runner,
|
||||
host="0.0.0.0",
|
||||
host="", # should listen to both IPv4 and IPv6 on a dual-stack system
|
||||
port=int(self._port),
|
||||
shutdown_timeout=3,
|
||||
ssl_context=ssl_context,
|
||||
)
|
||||
await self.site.start()
|
||||
self._port = self.runner.addresses[0][1]
|
||||
#
|
||||
# On a dual-stack system, we want to get the (first) IPv4 port unless
|
||||
# prefer_ipv6 is set in which case we use the IPv6 port
|
||||
#
|
||||
if self._port == 0:
|
||||
self._port = select_port(self.root_path, self.runner.addresses)
|
||||
|
||||
self.log.info(f"Started listening on port: {self._port}")
|
||||
|
||||
async def incoming_connection(self, request):
|
||||
|
@ -1,9 +1,11 @@
|
||||
import socket
|
||||
from pathlib import Path
|
||||
from ipaddress import ip_address, IPv4Network, IPv6Network
|
||||
from typing import Iterable, List, Tuple, Union, Any, Optional, Dict
|
||||
from chia.server.outbound_message import NodeType
|
||||
from chia.types.blockchain_format.sized_bytes import bytes32
|
||||
from chia.types.peer_info import PeerInfo
|
||||
from chia.util.config import load_config
|
||||
from chia.util.ints import uint16
|
||||
|
||||
|
||||
@ -84,3 +86,21 @@ def is_trusted_inner(peer_host: str, peer_node_id: bytes32, trusted_peers: Dict,
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def select_port(root_path: Path, addresses: List[Any]) -> uint16:
|
||||
global_config = load_config(root_path, "config.yaml")
|
||||
prefer_ipv6 = global_config.get("prefer_ipv6", False)
|
||||
selected_port: uint16
|
||||
for address_string, port, *_ in addresses:
|
||||
address = ip_address(address_string)
|
||||
if address.version == 6 and prefer_ipv6:
|
||||
selected_port = port
|
||||
break
|
||||
elif address.version == 4 and not prefer_ipv6:
|
||||
selected_port = port
|
||||
break
|
||||
else:
|
||||
selected_port = addresses[0][1] # no matches, just use the first one in the list
|
||||
|
||||
return selected_port
|
||||
|
Loading…
Reference in New Issue
Block a user