|
14 | 14 | from chia.rpc.rpc_server import StateChangedProtocol, default_get_connections
|
15 | 15 | from chia.server.server import ChiaServer
|
16 | 16 | from chia.server.ws_connection import WSChiaConnection
|
| 17 | +from chia.util.network import is_localhost |
17 | 18 |
|
18 | 19 | log = logging.getLogger(__name__)
|
19 | 20 |
|
@@ -43,6 +44,7 @@ def server(self) -> ChiaServer:
|
43 | 44 | def __init__(self, root_path: Path, config: dict[str, Any], constants: ConsensusConstants):
|
44 | 45 | self.log = log
|
45 | 46 | self.root_path = root_path
|
| 47 | + self.config = config |
46 | 48 | self._shut_down = False
|
47 | 49 | num_threads = config["num_threads"]
|
48 | 50 | self.log.info(f"Initializing solver with {num_threads} threads")
|
@@ -74,7 +76,16 @@ def get_connections(self, request_node_type: Optional[NodeType]) -> list[dict[st
|
74 | 76 | return default_get_connections(server=self.server, request_node_type=request_node_type)
|
75 | 77 |
|
76 | 78 | async def on_connect(self, connection: WSChiaConnection) -> None:
|
77 |
| - pass |
| 79 | + if is_localhost(connection.peer_info.host): |
| 80 | + self.log.info(f"Accepting localhost connection from {connection.connection_type}: {connection.get_peer_logging()}") |
| 81 | + return |
| 82 | + |
| 83 | + trusted_peers = self.config.get("trusted_peers", {}) |
| 84 | + if self.server.is_trusted_peer(connection, trusted_peers): |
| 85 | + self.log.info(f"Accepting trusted peer connection from {connection.connection_type}: {connection.get_peer_logging()}") |
| 86 | + return |
| 87 | + self.log.warning(f"Rejecting untrusted connection from {connection.connection_type}: {connection.get_peer_logging()}") |
| 88 | + await connection.close() |
78 | 89 |
|
79 | 90 | async def on_disconnect(self, connection: WSChiaConnection) -> None:
|
80 | 91 | self.log.info(f"peer disconnected {connection.get_peer_logging()}")
|
|
0 commit comments