@@ -165,7 +165,8 @@ namespace protocol_session {
165165 const FullPieceArrived<ConnectionIdType> & fullPieceArrived,
166166 const SentPayment<ConnectionIdType> & sentPayment,
167167 const protocol_wire::BuyerTerms & terms,
168- const TorrentPieceInformation & information) {
168+ const TorrentPieceInformation & information,
169+ const AllSellersGone & allSellersGone) {
169170
170171 // Prepare for exiting current state
171172 switch (_mode) {
@@ -208,7 +209,8 @@ namespace protocol_session {
208209 fullPieceArrived,
209210 sentPayment,
210211 terms,
211- information);
212+ information,
213+ allSellersGone);
212214 }
213215
214216 template <class ConnectionIdType >
@@ -431,6 +433,37 @@ namespace protocol_session {
431433 return true ;
432434 }
433435
436+ template <class ConnectionIdType >
437+ void Session<ConnectionIdType>::disconnectSlowSellers(const std::chrono::duration<double > & limit) {
438+ switch (_mode) {
439+
440+ case SessionMode::not_set:
441+
442+ assert (_observing == nullptr && _buying == nullptr && _selling == nullptr );
443+ throw exception::SessionModeNotSetException ();
444+ break ;
445+
446+ case SessionMode::observing:
447+
448+ assert (_observing != nullptr && _buying == nullptr && _selling == nullptr );
449+ break ;
450+
451+ case SessionMode::buying:
452+
453+ assert (_observing == nullptr && _buying != nullptr && _selling == nullptr );
454+ _buying->disconnectSlowSellers (limit);
455+ break ;
456+
457+ case SessionMode::selling:
458+
459+ assert (_observing == nullptr && _buying == nullptr && _selling != nullptr );
460+ break ;
461+
462+ default :
463+ assert (false );
464+ }
465+ }
466+
434467 template <class ConnectionIdType >
435468 status::Connection<ConnectionIdType> Session<ConnectionIdType>::connectionStatus(const ConnectionIdType & id) const noexcept {
436469
@@ -517,73 +550,6 @@ namespace protocol_session {
517550
518551 }
519552
520- template <class ConnectionIdType >
521- void Session<ConnectionIdType>::validPieceReceivedOnConnection(const ConnectionIdType & id, int index) {
522-
523- switch (_mode) {
524-
525- case SessionMode::not_set:
526-
527- assert (_observing == nullptr && _buying == nullptr && _selling == nullptr );
528- throw exception::SessionModeNotSetException ();
529-
530- case SessionMode::observing:
531-
532- assert (_observing != nullptr && _buying == nullptr && _selling == nullptr );
533- throw exception::ModeIncompatibleOperation ();
534- break ;
535-
536- case SessionMode::buying:
537-
538- assert (_observing == nullptr && _buying != nullptr && _selling == nullptr );
539- _buying->validPieceReceivedOnConnection (id, index);
540- break ;
541-
542- case SessionMode::selling:
543-
544- assert (_observing == nullptr && _buying == nullptr && _selling != nullptr );
545- throw exception::ModeIncompatibleOperation ();
546- break ;
547-
548- default :
549- assert (false );
550- }
551-
552- }
553-
554- template <class ConnectionIdType >
555- void Session<ConnectionIdType>::invalidPieceReceivedOnConnection(const ConnectionIdType & id, int index) {
556-
557- switch (_mode) {
558-
559- case SessionMode::not_set:
560-
561- throw exception::SessionModeNotSetException ();
562-
563- case SessionMode::observing:
564-
565- assert (_observing != nullptr && _buying == nullptr && _selling == nullptr );
566- throw exception::ModeIncompatibleOperation ();
567- break ;
568-
569- case SessionMode::buying:
570-
571- assert (_observing == nullptr && _buying != nullptr && _selling == nullptr );
572- _buying->invalidPieceReceivedOnConnection (id, index);
573- break ;
574-
575- case SessionMode::selling:
576-
577- assert (_observing == nullptr && _buying == nullptr && _selling != nullptr );
578- throw exception::ModeIncompatibleOperation ();
579- break ;
580-
581- default :
582- assert (false );
583- }
584-
585- }
586-
587553 template <class ConnectionIdType >
588554 void Session<ConnectionIdType>::pieceDownloaded(int index) {
589555
@@ -689,7 +655,7 @@ namespace protocol_session {
689655 }
690656
691657 template <class ConnectionIdType >
692- void Session<ConnectionIdType>::pieceLoaded(const ConnectionIdType & id, const protocol_wire::PieceData & data, int index) {
658+ void Session<ConnectionIdType>::pieceLoaded(const protocol_wire::PieceData & data, int index) {
693659
694660 switch (_mode) {
695661
@@ -712,7 +678,7 @@ namespace protocol_session {
712678 case SessionMode::selling:
713679
714680 assert (_observing == nullptr && _buying == nullptr && _selling != nullptr );
715- _selling->pieceLoaded (id, data, index);
681+ _selling->pieceLoaded (data, index);
716682 break ;
717683
718684 default :
@@ -915,6 +881,28 @@ namespace protocol_session {
915881 _buying->receivedFullPiece (id, data);
916882 }
917883
884+ template <class ConnectionIdType >
885+ void Session<ConnectionIdType>::remoteMessageOverflow(const ConnectionIdType & id) {
886+
887+ assert (hasConnection (id));
888+
889+ if (_buying != nullptr ) {
890+ _buying->remoteMessageOverflow (id);
891+ } else if (_selling != nullptr ) {
892+ _selling->remoteMessageOverflow (id);
893+ }
894+ }
895+
896+ template <class ConnectionIdType >
897+ void Session<ConnectionIdType>::localMessageOverflow(const ConnectionIdType & id) {
898+ // This callback will come from the connection state machine if we try to send too many payments
899+ // or as a seller, too many pieces.
900+ // This should not happen if our implementation is correct
901+ assert (hasConnection (id));
902+ std::clog << " Error: localMessageOverflow on connection " << id << std::endl;
903+ assert (false );
904+ }
905+
918906 template <class ConnectionIdType >
919907 detail::Connection<ConnectionIdType> * Session<ConnectionIdType>::createConnection(const ConnectionIdType & id, const SendMessageOnConnectionCallbacks & sendMessageCallbacks) {
920908
@@ -932,7 +920,9 @@ namespace protocol_session {
932920 [this , id](const Coin::Signature & s) { this ->receivedInvalidPayment (id, s); },
933921 [this , id]() { this ->sellerHasJoined (id); },
934922 [this , id]() { this ->sellerHasInterruptedContract (id); },
935- [this , id](const protocol_wire::PieceData & p) { this ->receivedFullPiece (id, p); });
923+ [this , id](const protocol_wire::PieceData & p) { this ->receivedFullPiece (id, p); },
924+ [this , id]() { this ->remoteMessageOverflow (id); },
925+ [this , id]() { this ->localMessageOverflow (id); });
936926 }
937927
938928 template <class ConnectionIdType >
0 commit comments