Skip to content

Commit

Permalink
Validate protocol version on handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
haorldbchi authored and arvidn committed Mar 28, 2024
1 parent 00f7e4f commit 967b362
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions chia/server/ws_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,15 @@ async def perform_handshake(
if inbound_handshake.network_id != network_id:
raise ProtocolError(Err.INCOMPATIBLE_NETWORK_ID)

inbound_node_type = NodeType(inbound_handshake.node_type)
if inbound_handshake.protocol_version != protocol_version:
self.log.warning(
f"protocol version mismatch: incoming={inbound_handshake.protocol_version} our={protocol_version}"
)

self.version = inbound_handshake.software_version
self.protocol_version = Version(inbound_handshake.protocol_version)
self.peer_server_port = inbound_handshake.server_port
self.connection_type = inbound_node_type
self.connection_type = NodeType(inbound_handshake.node_type)
# "1" means capability is enabled
self.peer_capabilities = known_active_capabilities(inbound_handshake.capabilities)
else:
Expand All @@ -251,12 +255,16 @@ async def perform_handshake(
if inbound_handshake.network_id != network_id:
raise ProtocolError(Err.INCOMPATIBLE_NETWORK_ID)

inbound_node_type = NodeType(inbound_handshake.node_type)
if inbound_handshake.protocol_version != protocol_version:
self.log.warning(
f"protocol version mismatch: incoming={inbound_handshake.protocol_version} our={protocol_version}"
)

await self._send_message(outbound_handshake)
self.version = inbound_handshake.software_version
self.protocol_version = Version(inbound_handshake.protocol_version)
self.peer_server_port = inbound_handshake.server_port
self.connection_type = inbound_node_type
self.connection_type = NodeType(inbound_handshake.node_type)
# "1" means capability is enabled
self.peer_capabilities = known_active_capabilities(inbound_handshake.capabilities)

Expand Down

0 comments on commit 967b362

Please sign in to comment.