@@ -28,7 +28,8 @@ namespace detail {
2828 const SentPayment<ConnectionIdType> & sentPayment,
2929 const protocol_wire::BuyerTerms & terms,
3030 const TorrentPieceInformation & information,
31- const AllSellersGone & allSellersGone)
31+ const AllSellersGone & allSellersGone,
32+ std::chrono::duration<double > maxTimeToServicePiece)
3233 : _session(session)
3334 , _removedConnection(removedConnection)
3435 , _fullPieceArrived(fullPieceArrived)
@@ -37,7 +38,8 @@ namespace detail {
3738 , _terms(terms)
3839 , _numberOfMissingPieces(0 )
3940 , _allSellersGone(allSellersGone)
40- , _maxConcurrentRequests(4 ) {
41+ , _maxConcurrentRequests(4 )
42+ , _maxTimeToServicePiece(maxTimeToServicePiece) {
4143 // , _lastStartOfSendingInvitations(0) {
4244
4345 // Setup pieces
@@ -86,20 +88,6 @@ namespace detail {
8688 removeConnection (id, DisconnectCause::client);
8789 }
8890
89- template <class ConnectionIdType >
90- void Buying<ConnectionIdType>::disconnectSlowSellers(const std::chrono::duration<double > & limit) {
91-
92- for (auto mapping : _sellers) {
93- auto seller = mapping.second ;
94-
95- if (seller.isGone ()) continue ;
96-
97- if (seller.servicingPieceHasTimedOut (limit)) {
98- removeConnection (seller.connection ()->connectionId (), DisconnectCause::seller_servicing_piece_has_timed_out);
99- }
100- }
101- }
102-
10391 template <class ConnectionIdType >
10492 void Buying<ConnectionIdType>::validPieceReceivedOnConnection(detail::Seller<ConnectionIdType> &seller, int index) {
10593 // Cannot happen when stopped, as there are no connections
@@ -286,8 +274,8 @@ namespace detail {
286274 // Only process if we are active
287275 if (_session->_state == SessionState::started) {
288276
277+ // Disconnect timed out sellers
289278 // Allocate pieces if we are downloading
290- // Timeout sellers if they have not seviced a piece in time.
291279 // Reset state to allow restarting downloading after all sellers are gone
292280 if (_state == BuyingState::downloading) {
293281
@@ -296,8 +284,16 @@ namespace detail {
296284 // Reference to seller
297285 detail::Seller<ConnectionIdType> & s = mapping.second ;
298286
287+ if (s.isGone ()) continue ;
288+
289+ // Disconnect if seller timed-out servicing request
290+ if (s.servicingPieceHasTimedOut (_maxTimeToServicePiece)) {
291+ removeConnection (s.connection ()->connectionId (), DisconnectCause::seller_servicing_piece_has_timed_out);
292+ continue ;
293+ }
294+
299295 // A seller may be waiting to be assigned a new piece
300- if (!s. isGone () && s.piecesAwaitingArrival ().size () == 0 ) {
296+ if (s.piecesAwaitingArrival ().size () == 0 ) {
301297
302298 // This can happen when a seller has previously uploaded a valid piece,
303299 // but there were no unassigned pieces at that time,
0 commit comments