Skip to content

Commit 3dc35d0

Browse files
committed
solver trusted peers
1 parent 0d99e59 commit 3dc35d0

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

chia/solver/solver.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
from chia.rpc.rpc_server import StateChangedProtocol, default_get_connections
1515
from chia.server.server import ChiaServer
1616
from chia.server.ws_connection import WSChiaConnection
17+
from chia.util.network import is_localhost
1718

1819
log = logging.getLogger(__name__)
1920

@@ -43,6 +44,7 @@ def server(self) -> ChiaServer:
4344
def __init__(self, root_path: Path, config: dict[str, Any], constants: ConsensusConstants):
4445
self.log = log
4546
self.root_path = root_path
47+
self.config = config
4648
self._shut_down = False
4749
num_threads = config["num_threads"]
4850
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
7476
return default_get_connections(server=self.server, request_node_type=request_node_type)
7577

7678
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()
7889

7990
async def on_disconnect(self, connection: WSChiaConnection) -> None:
8091
self.log.info(f"peer disconnected {connection.get_peer_logging()}")

0 commit comments

Comments
 (0)