Skip to content

Commit cdd88ea

Browse files
committed
dash: wire NodeImpl::handle() version routing so slice-B reception is reachable
The slice-A handle() was a no-op that dropped all inbound messages, leaving the new handle_version() reception (and its live #646 min-protocol gate) unreachable -- a dormant seam. Route the unknown-peer version handshake into handle_version() (mirrors pool::NodeBridge), close on self/dup, and mark the peer stable on the negotiated type. Full Legacy/Actual established-peer dispatch rides a later slice. This makes the #646 discrimination genuinely live on the handshake path. test_dash_node 9/9.
1 parent 86098e5 commit cdd88ea

1 file changed

Lines changed: 40 additions & 4 deletions

File tree

src/impl/dash/node.hpp

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,46 @@ class NodeImpl : public pool::BaseNode<dash::Config, dash::ShareChain, dash::Pee
210210
// pure-virtual INetwork contract.
211211
void disconnect() override { }
212212

213-
// ICommunicator: the message-dispatch entry point. Slice A drops inbound
214-
// messages (no-op) to satisfy the pure-virtual contract; the reception slice
215-
// (B) replaces this with the real Legacy/Actual protocol routing.
216-
void handle(std::unique_ptr<RawMessage> /*rmsg*/, const NetService& /*service*/) override { }
213+
// ICommunicator: the message-dispatch entry point. Slice B wires the real
214+
// version-handshake routing so handle_version() (and its live #646 gate) is
215+
// actually reachable -- mirrors the pool::NodeBridge unknown-peer branch
216+
// (src/pool/node.hpp). Full Legacy/Actual established-peer message dispatch
217+
// (shares, txs, getaddrs) rides a later slice; until then, post-handshake
218+
// messages are dropped. The handshake + min-protocol discrimination is live.
219+
void handle(std::unique_ptr<RawMessage> rmsg, const NetService& service) override
220+
{
221+
// Guard: the peer may have been removed by a prior error/timeout while an
222+
// async_read callback was still in-flight for the same socket.
223+
if (!m_connections.contains(service))
224+
return;
225+
auto peer = m_connections[service];
226+
peer->m_timeout->restart();
227+
228+
if (peer->type() == pool::PeerConnectionType::unknown)
229+
{
230+
// The first message from an unknown peer MUST be `version`.
231+
if (rmsg->m_command.compare(0, 7, "version") != 0)
232+
return error("expected version message", service);
233+
234+
std::optional<pool::PeerConnectionType> peer_type;
235+
try {
236+
peer_type = handle_version(std::move(rmsg), peer);
237+
} catch (const std::exception& ex) {
238+
error(ex.what(), service);
239+
return;
240+
}
241+
if (!peer_type.has_value()) {
242+
// self- or duplicate-connection: graceful close.
243+
close_connection(service);
244+
return;
245+
}
246+
peer->stable(*peer_type, PEER_TIMEOUT_TIME);
247+
return;
248+
}
249+
250+
// Established peer: full Legacy/Actual message dispatch rides a later
251+
// slice; post-handshake messages are dropped for now.
252+
}
217253

218254
// BaseNode pure-virtuals. Slice A provides minimal stubs so NodeImpl is a
219255
// concrete, instantiable type for the KAT; the reception/handshake slice (B)

0 commit comments

Comments
 (0)