@@ -28,7 +28,6 @@ namespace node {
2828
2929using namespace system ;
3030using namespace network ;
31- using namespace network ::messages::peer;
3231using namespace std ::chrono;
3332using namespace std ::placeholders;
3433
@@ -147,7 +146,16 @@ bool protocol_block_out_106::handle_receive_get_data(const code& ec,
147146 if (stopped (ec))
148147 return false ;
149148
150- if (!message->any_block ())
149+ if (!node_witness_ && message->any_witness ())
150+ {
151+ LOGR (" Unsupported witness get_data from [" << opposite () << " ]." );
152+ stop (network::error::protocol_violation);
153+ return false ;
154+ }
155+
156+ constexpr auto only = get_data::selector::blocks;
157+ const auto blocks = emplace_shared<inventory_items>(message->select (only));
158+ if (blocks->empty ())
151159 return true ;
152160
153161 if (busy_)
@@ -158,32 +166,22 @@ bool protocol_block_out_106::handle_receive_get_data(const code& ec,
158166 }
159167
160168 busy_ = true ;
161- send_block (error::success, zero, message );
169+ send_block (error::success, blocks );
162170 return true ;
163171}
164172
165173// Outbound (block).
166174// ----------------------------------------------------------------------------
167175
168- void protocol_block_out_106::send_block (const code& ec, size_t index,
169- const get_data::cptr& message ) NOEXCEPT
176+ void protocol_block_out_106::send_block (const code& ec,
177+ const inventory_items_ptr& items ) NOEXCEPT
170178{
171179 BC_ASSERT (stranded ());
172180 if (stopped (ec))
173181 return ;
174182
175- // Skip over non-block requests.
176- const auto & items = message->items ;
177- for (; index < items.size () && !items.at (index).is_block_type (); ++index);
178-
179- // No more block requests.
180- if (index == items.size ())
181- {
182- busy_ = false ;
183- return ;
184- }
185-
186- const auto & item = items.at (index);
183+ if (items->empty ()) return ;
184+ const auto item = pop (*items);
187185 const auto witness = item.is_witness_type ();
188186 if (!node_witness_ && witness)
189187 {
@@ -206,13 +204,14 @@ void protocol_block_out_106::send_block(const code& ec, size_t index,
206204 }
207205
208206 span<microseconds>(events::block_usecs, start);
209- SEND (block{ ptr }, send_block, _1, add1 (index), message);
207+ if (items->empty ()) busy_ = false ;
208+ SEND (messages::peer::block{ ptr }, send_block, _1, items);
210209}
211210
212211// utilities
213212// ----------------------------------------------------------------------------
214213
215- inventory protocol_block_out_106::create_inventory (
214+ protocol_block_out_106:: inventory protocol_block_out_106::create_inventory (
216215 const get_blocks& locator) const NOEXCEPT
217216{
218217 // Empty response implies complete (success).
@@ -222,7 +221,7 @@ inventory protocol_block_out_106::create_inventory(
222221 return inventory::factory
223222 (
224223 archive ().get_blocks (locator.start_hashes , locator.stop_hash ,
225- max_get_blocks), type_id::block
224+ messages::peer:: max_get_blocks), type_id::block
226225 );
227226}
228227
0 commit comments