@@ -92,6 +92,7 @@ void protocol_block_in_31800::stopping(const code& ec) NOEXCEPT
9292
9393bool protocol_block_in_31800::is_idle () const NOEXCEPT
9494{
95+ BC_ASSERT (stranded ());
9596 return map_->empty ();
9697}
9798
@@ -116,22 +117,14 @@ bool protocol_block_in_31800::handle_event(const code&, chase event_,
116117 // If this channel has divisible work, split it and stop.
117118 // There are no channels reporting work, either stalled or done.
118119 // This is initiated by any channel notifying chase::starved.
119- if (map_->size () > one)
120- {
121- POST (do_split, peer_t {});
122- }
123-
120+ POST (do_stall, peer_t {});
124121 break ;
125122 }
126123 case chase::purge:
127124 {
128125 // If have work clear it and stop.
129126 // This is initiated by chase::regressed/disorganized.
130- if (map_->size () > one)
131- {
132- POST (do_purge, peer_t {});
133- }
134-
127+ POST (do_purge, peer_t {});
135128 break ;
136129 }
137130 case chase::download:
@@ -162,38 +155,44 @@ bool protocol_block_in_31800::handle_event(const code&, chase event_,
162155 return true ;
163156}
164157
158+ void protocol_block_in_31800::do_report (count_t sequence) NOEXCEPT
159+ {
160+ BC_ASSERT (stranded ());
161+
162+ // Uses application logging since it outputs to a runtime option.
163+ LOGA (" Work report [" << sequence << " ] is (" << map_->size () << " ) for ["
164+ << opposite () << " ]." );
165+ }
166+
165167void protocol_block_in_31800::do_get_downloads (count_t ) NOEXCEPT
166168{
167169 BC_ASSERT (stranded ());
168170
169- if (stopped ())
171+ if (stopped () || ! is_idle () )
170172 return ;
171173
172- if (is_idle ())
173- {
174- // Assume performance was stopped due to exhaustion.
175- start_performance ();
176- get_hashes (BIND (handle_get_hashes, _1, _2, _3));
177- }
174+ // Assume performance was stopped due to exhaustion.
175+ start_performance ();
176+ get_hashes (BIND (handle_get_hashes, _1, _2, _3));
178177}
179178
180179void protocol_block_in_31800::do_purge (peer_t ) NOEXCEPT
181180{
182181 BC_ASSERT (stranded ());
183182
184- if (! map_->empty ())
185- {
186- LOGV ( " Purge work ( " << map_-> size () << " ) from [ " << opposite () << " ]. " );
187- map_->clear ( );
188- stop (error::sacrificed_channel );
189- }
183+ if (map_->empty ())
184+ return ;
185+
186+ LOGV ( " Purge work ( " << map_->size () << " ) from [ " << opposite () << " ]. " );
187+ map_-> clear ( );
188+ stop (error::sacrificed_channel);
190189}
191190
192- void protocol_block_in_31800::do_split (peer_t ) NOEXCEPT
191+ void protocol_block_in_31800::do_stall (peer_t ) NOEXCEPT
193192{
194193 BC_ASSERT (stranded ());
195194
196- if (stopped ())
195+ if (stopped () || (map_-> size () <= one) )
197196 return ;
198197
199198 LOGV (" Divide work (" << map_->size () << " ) from [" << opposite () << " ]." );
@@ -203,13 +202,18 @@ void protocol_block_in_31800::do_split(peer_t) NOEXCEPT
203202 stop (error::sacrificed_channel);
204203}
205204
206- void protocol_block_in_31800::do_report ( count_t sequence ) NOEXCEPT
205+ void protocol_block_in_31800::do_split ( peer_t ) NOEXCEPT
207206{
208207 BC_ASSERT (stranded ());
209208
210- // Uses application logging since it outputs to a runtime option.
211- LOGA (" Work report [" << sequence << " ] is (" << map_->size () << " ) for ["
212- << opposite () << " ]." );
209+ if (stopped () || (map_->size () <= one))
210+ return ;
211+
212+ LOGV (" Split work (" << map_->size () << " ) from [" << opposite () << " ]." );
213+ restore (chaser_check::split (map_));
214+ restore (map_);
215+ map_ = chaser_check::empty_map ();
216+ stop (error::sacrificed_channel);
213217}
214218
215219// request hashes
0 commit comments