|
25 | 25 | #include "coin/transaction.hpp" |
26 | 26 |
|
27 | 27 | #include <pool/node.hpp> |
| 28 | +#include <pool/protocol.hpp> |
28 | 29 | #include <core/reply_matcher.hpp> |
29 | 30 | #include <c2pool/storage/sharechain_storage.hpp> |
30 | 31 |
|
31 | 32 | #include <boost/asio/thread_pool.hpp> |
32 | 33 | #include <boost/asio/steady_timer.hpp> |
33 | 34 |
|
34 | 35 | #include <atomic> |
| 36 | +#include <functional> |
35 | 37 | #include <map> |
36 | 38 | #include <memory> |
37 | 39 | #include <mutex> |
@@ -97,6 +99,14 @@ class NodeImpl : public pool::BaseNode<dash::Config, dash::ShareChain, dash::Pee |
97 | 99 | // daemon. Reception-slice protocol handlers look up tx hashes here. |
98 | 100 | std::map<uint256, coin::Transaction> m_known_txs; |
99 | 101 |
|
| 102 | + // Wire-message parser used by the Legacy/Actual dispatch protocols to turn |
| 103 | + // a RawMessage into a typed message variant. Mirrors dgb::NodeImpl::m_handler. |
| 104 | + dash::Handler m_handler; |
| 105 | + |
| 106 | + // Callback fired when a bestblock message is received from a peer; wired by |
| 107 | + // the work layer (slice .4) to trigger a work refresh. Mirrors dgb. |
| 108 | + std::function<void(const uint256&)> m_on_bestblock; |
| 109 | + |
100 | 110 | // Thread pool for parallel share_init_verify (X11 CPU work). Keeps the |
101 | 111 | // expensive crypto off the io_context thread. |
102 | 112 | boost::asio::thread_pool m_verify_pool{4}; |
@@ -309,6 +319,27 @@ class NodeImpl : public pool::BaseNode<dash::Config, dash::ShareChain, dash::Pee |
309 | 319 | : pool::PeerConnectionType::legacy; |
310 | 320 | } |
311 | 321 |
|
| 322 | + // ── Reception-slice (B) dispatch surface ─────────────────── |
| 323 | + // Declarations consumed by the Legacy/Actual protocol handlers |
| 324 | + // (protocol_legacy.cpp / protocol_actual.cpp). The bodies of |
| 325 | + // processing_shares() and handle_get_share() live in the node.cpp |
| 326 | + // translation unit (slice .4) and are intentionally link-deferred here; |
| 327 | + // the dispatch layer object-compiles against these declarations. |
| 328 | + void processing_shares(HandleSharesData& data, NetService addr); |
| 329 | + std::vector<dash::ShareType> handle_get_share(std::vector<uint256> hashes, |
| 330 | + uint64_t parents, std::vector<uint256> stops, NetService peer_addr); |
| 331 | + |
| 332 | + // Completes a pending async share request when a sharereply arrives. |
| 333 | + // Inline (mirrors dgb) so the reply-matcher plumbing needs no node.cpp. |
| 334 | + void got_share_reply(uint256 id, dash::ShareReplyData shares) |
| 335 | + { |
| 336 | + try { m_share_getter.got_response(id, shares); } |
| 337 | + catch (const std::invalid_argument&) { /* request already timed out */ } |
| 338 | + } |
| 339 | + |
| 340 | + // Register a callback fired when a bestblock message is received from a peer. |
| 341 | + void set_on_bestblock(std::function<void(const uint256&)> fn) { m_on_bestblock = std::move(fn); } |
| 342 | + |
312 | 343 | // ── Tracker accessors ─────────────────────────────────────────────── |
313 | 344 |
|
314 | 345 | /// Direct tracker access — compute-thread-only (already holds the exclusive |
@@ -379,4 +410,53 @@ class NodeImpl : public pool::BaseNode<dash::Config, dash::ShareChain, dash::Pee |
379 | 410 | } |
380 | 411 | }; |
381 | 412 |
|
| 413 | +// ── Sharechain-p2p dispatch layer (slice S8-p2p.2) ────────────────── |
| 414 | +// Namespace-only port of the dgb reference (src/impl/dgb/node.hpp:647). The |
| 415 | +// version-handshake reception rides NodeImpl::handle_version above; the two |
| 416 | +// established-peer protocols below dispatch the 12 post-handshake messages. |
| 417 | +// Both Legacy and Actual register the identical handler set; the divergence |
| 418 | +// between them lives in the handler BODIES (protocol_legacy.cpp vs |
| 419 | +// protocol_actual.cpp), byte-parity with dgb. handle_message() bodies + the |
| 420 | +// 12 HANDLER() bodies are defined in those two .cpp translation units. |
| 421 | + |
| 422 | +class Legacy : public pool::Protocol<NodeImpl> |
| 423 | +{ |
| 424 | +public: |
| 425 | + void handle_message(std::unique_ptr<RawMessage> rmsg, NodeImpl::peer_ptr peer) override; |
| 426 | + |
| 427 | + ADD_HANDLER(addrs, dash::message_addrs); |
| 428 | + ADD_HANDLER(addrme, dash::message_addrme); |
| 429 | + ADD_HANDLER(ping, dash::message_ping); |
| 430 | + ADD_HANDLER(getaddrs, dash::message_getaddrs); |
| 431 | + ADD_HANDLER(shares, dash::message_shares); |
| 432 | + ADD_HANDLER(sharereq, dash::message_sharereq); |
| 433 | + ADD_HANDLER(sharereply, dash::message_sharereply); |
| 434 | + ADD_HANDLER(bestblock, dash::message_bestblock); |
| 435 | + ADD_HANDLER(have_tx, dash::message_have_tx); |
| 436 | + ADD_HANDLER(losing_tx, dash::message_losing_tx); |
| 437 | + ADD_HANDLER(remember_tx, dash::message_remember_tx); |
| 438 | + ADD_HANDLER(forget_tx, dash::message_forget_tx); |
| 439 | +}; |
| 440 | + |
| 441 | +class Actual : public pool::Protocol<NodeImpl> |
| 442 | +{ |
| 443 | +public: |
| 444 | + void handle_message(std::unique_ptr<RawMessage> rmsg, NodeImpl::peer_ptr peer) override; |
| 445 | + |
| 446 | + ADD_HANDLER(addrs, dash::message_addrs); |
| 447 | + ADD_HANDLER(addrme, dash::message_addrme); |
| 448 | + ADD_HANDLER(ping, dash::message_ping); |
| 449 | + ADD_HANDLER(getaddrs, dash::message_getaddrs); |
| 450 | + ADD_HANDLER(shares, dash::message_shares); |
| 451 | + ADD_HANDLER(sharereq, dash::message_sharereq); |
| 452 | + ADD_HANDLER(sharereply, dash::message_sharereply); |
| 453 | + ADD_HANDLER(bestblock, dash::message_bestblock); |
| 454 | + ADD_HANDLER(have_tx, dash::message_have_tx); |
| 455 | + ADD_HANDLER(losing_tx, dash::message_losing_tx); |
| 456 | + ADD_HANDLER(remember_tx, dash::message_remember_tx); |
| 457 | + ADD_HANDLER(forget_tx, dash::message_forget_tx); |
| 458 | +}; |
| 459 | + |
| 460 | +using Node = pool::NodeBridge<NodeImpl, Legacy, Actual>; |
| 461 | + |
382 | 462 | } // namespace dash |
0 commit comments