func (s *Service) handleBeginOfPiece(ctx context.Context, peer *resource.Peer) {
	switch peer.FSM.Current() {
	case resource.PeerStateBackToSource:
		// Back to the source download process, peer directly returns
		peer.Log.Info("peer back to source")
		return
	case resource.PeerStateReceivedTiny:
		// When the task is tiny,
		// the peer has already returned to piece data when registering
		peer.Log.Info("file type is tiny, peer has already returned to piece data when registering")
		if err := peer.FSM.Event(resource.PeerEventDownload); err != nil {
			peer.Log.Errorf("peer fsm event failed: %v", err)
			return
		}
	case resource.PeerStateReceivedSmall:
		// When the task is small,
		// the peer has already returned to the parent when registering
		peer.Log.Info("file type is small, peer has already returned to the parent when registering")
		if err := peer.FSM.Event(resource.PeerEventDownload); err != nil {
			peer.Log.Errorf("peer fsm event failed: %v", err)
			return
		}
	case resource.PeerStateReceivedNormal:
		if err := peer.FSM.Event(resource.PeerEventDownload); err != nil {
			peer.Log.Errorf("peer fsm event failed: %v", err)
			return
		}

		// It’s not a case of back-to-source or small task downloading,
		// to help peer to schedule the parent node
		blocklist := set.NewSafeSet()
		blocklist.Add(peer.ID)
		s.scheduler.ScheduleParent(ctx, peer, blocklist)
	default:
		peer.Log.Warnf("peer state is %s when receive the begin of piece", peer.FSM.Current())
	}
}
// handleBeginOfPiece handles begin of piece
handleBeginOfPiece handles begin of piece
// handleBeginOfPiece handles begin of piece
func (s *Service) handleBeginOfPiece(ctx context.Context, peer *resource.Peer) {
	switch peer.FSM.Current() {
	case resource.PeerStateBackToSource:
		peer.Log.Info("peer back to source")
		return
	case resource.PeerStateReceivedTiny:
		peer.Log.Info("file type is tiny, peer has already returned to piece data when registering")
		if err := peer.FSM.Event(resource.PeerEventDownload); err != nil {
			peer.Log.Errorf("peer fsm event failed: %v", err)
			return
		}
	case resource.PeerStateReceivedSmall:
		peer.Log.Info("file type is small, peer has already returned to the parent when registering")
		if err := peer.FSM.Event(resource.PeerEventDownload); err != nil {
			peer.Log.Errorf("peer fsm event failed: %v", err)
			return
		}
	case resource.PeerStateReceivedNormal:
		if err := peer.FSM.Event(resource.PeerEventDownload); err != nil {
			peer.Log.Errorf("peer fsm event failed: %v", err)
			return
		}
		blocklist := set.NewSafeSet()
		blocklist.Add(peer.ID)
		s.scheduler.ScheduleParent(ctx, peer, blocklist)
	default:
		peer.Log.Warnf("peer state is %s when receive the begin of piece", peer.FSM.Current())
	}
}
func ( s * Service ) handleBeginOfPiece ( ctx context . Context , peer * resource . Peer ) { switch peer . FSM . Current ( ) { case resource . PeerStateBackToSource : peer . Log . Info ( " " ) return case resource . PeerStateReceivedTiny : peer . Log . Info ( " " ) if err := peer . FSM . Event ( resource . PeerEventDownload ) ; err != nil { peer . Log . Errorf ( " " , err ) return } case resource . PeerStateReceivedSmall : peer . Log . Info ( " " ) if err := peer . FSM . Event ( resource . PeerEventDownload ) ; err != nil { peer . Log . Errorf ( " " , err ) return } case resource . PeerStateReceivedNormal : if err := peer . FSM . Event ( resource . PeerEventDownload ) ; err != nil { peer . Log . Errorf ( " " , err ) return } blocklist := set . NewSafeSet ( ) blocklist . Add ( peer . ID ) s . scheduler . ScheduleParent ( ctx , peer , blocklist ) default : peer . Log . Warnf ( " " , peer . FSM . Current ( ) ) } }
handleBeginOfPiece handles begin of piece
handleBeginOfPiece handles begin of piece
// Back to the source download process, peer directly returns // When the task is tiny, // the peer has already returned to piece data when registering // When the task is small, // the peer has already returned to the parent when registering // It’s not a case of back-to-source or small task downloading, // to help peer to schedule the parent node