-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config option to accept private network addresses from introducers (
#15543) * Add configuration option to accept private network addresses from introducers * Add tests for the enable_private_networks config option * Fix lint and such * Test state of private networks in address manager after init * Check for None on address_manager
- Loading branch information
1 parent
3a914ce
commit 8fd44c1
Showing
3 changed files
with
103 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from __future__ import annotations | ||
|
||
from logging import Logger | ||
from typing import Tuple | ||
|
||
import pytest | ||
|
||
from chia.full_node.full_node_api import FullNodeAPI | ||
from chia.server.node_discovery import FullNodeDiscovery | ||
from chia.server.peer_store_resolver import PeerStoreResolver | ||
from chia.server.server import ChiaServer | ||
from chia.simulator.block_tools import BlockTools | ||
from chia.util.default_root import SIMULATOR_ROOT_PATH | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_enable_private_networks( | ||
two_nodes: Tuple[FullNodeAPI, FullNodeAPI, ChiaServer, ChiaServer, BlockTools], | ||
) -> None: | ||
chia_server = two_nodes[2] | ||
|
||
# Missing `enable_private_networks` config entry in introducer_peer should default to False for back compat | ||
discovery0 = FullNodeDiscovery( | ||
chia_server, | ||
0, | ||
PeerStoreResolver( | ||
SIMULATOR_ROOT_PATH, | ||
chia_server.config, | ||
selected_network=chia_server.config["selected_network"], | ||
peers_file_path_key="peers_file_path", | ||
legacy_peer_db_path_key="db/peer_table_node.sqlite", | ||
default_peers_file_path="db/peers.dat", | ||
), | ||
{"host": "introducer.chia.net", "port": 8444}, | ||
[], | ||
0, | ||
chia_server.config["selected_network"], | ||
None, | ||
Logger("node_discovery_tests"), | ||
) | ||
assert discovery0 is not None | ||
assert discovery0.enable_private_networks is False | ||
await discovery0.initialize_address_manager() | ||
assert discovery0.address_manager is not None | ||
assert discovery0.address_manager.allow_private_subnets is False | ||
|
||
# Test with enable_private_networks set to False in Config | ||
discovery1 = FullNodeDiscovery( | ||
chia_server, | ||
0, | ||
PeerStoreResolver( | ||
SIMULATOR_ROOT_PATH, | ||
chia_server.config, | ||
selected_network=chia_server.config["selected_network"], | ||
peers_file_path_key="peers_file_path", | ||
legacy_peer_db_path_key="db/peer_table_node.sqlite", | ||
default_peers_file_path="db/peers.dat", | ||
), | ||
{"host": "introducer.chia.net", "port": 8444, "enable_private_networks": False}, | ||
[], | ||
0, | ||
chia_server.config["selected_network"], | ||
None, | ||
Logger("node_discovery_tests"), | ||
) | ||
assert discovery1 is not None | ||
assert discovery1.enable_private_networks is False | ||
await discovery1.initialize_address_manager() | ||
assert discovery1.address_manager is not None | ||
assert discovery1.address_manager.allow_private_subnets is False | ||
|
||
# Test with enable_private_networks set to True in Config | ||
discovery2 = FullNodeDiscovery( | ||
chia_server, | ||
0, | ||
PeerStoreResolver( | ||
SIMULATOR_ROOT_PATH, | ||
chia_server.config, | ||
selected_network=chia_server.config["selected_network"], | ||
peers_file_path_key="peers_file_path", | ||
legacy_peer_db_path_key="db/peer_table_node.sqlite", | ||
default_peers_file_path="db/peers.dat", | ||
), | ||
{"host": "introducer.chia.net", "port": 8444, "enable_private_networks": True}, | ||
[], | ||
0, | ||
chia_server.config["selected_network"], | ||
None, | ||
Logger("node_discovery_tests"), | ||
) | ||
assert discovery2 is not None | ||
assert discovery2.enable_private_networks is True | ||
await discovery2.initialize_address_manager() | ||
assert discovery2.address_manager is not None | ||
assert discovery2.address_manager.allow_private_subnets is True |