func (s *scheduler) FindParent(ctx context.Context, peer *resource.Peer, blocklist set.SafeSet) (*resource.Peer, bool) {
	// Filter the parent that can be scheduled
	parents := s.filterParents(peer, blocklist)
	if len(parents) == 0 {
		peer.Log.Info("can not find parents")
		return nil, false
	}

	// Sort parents by evaluation score
	taskTotalPieceCount := peer.Task.TotalPieceCount.Load()
	sort.Slice(
		parents,
		func(i, j int) bool {
			return s.evaluator.Evaluate(peer, parents[i], taskTotalPieceCount) > s.evaluator.Evaluate(peer, parents[j], taskTotalPieceCount)
		},
	)

	peer.Log.Infof("find parent %s successful", parents[0].ID)
	return parents[0], true
}
// FindParent finds parent that best matches the evaluation
FindParent finds parent that best matches the evaluation
// FindParent finds parent that best matches the evaluation
func (s *scheduler) FindParent(ctx context.Context, peer *resource.Peer, blocklist set.SafeSet) (*resource.Peer, bool) {
	parents := s.filterParents(peer, blocklist)
	if len(parents) == 0 {
		peer.Log.Info("can not find parents")
		return nil, false
	}
	taskTotalPieceCount := peer.Task.TotalPieceCount.Load()
	sort.Slice(
		parents,
		func(i, j int) bool {
			return s.evaluator.Evaluate(peer, parents[i], taskTotalPieceCount) > s.evaluator.Evaluate(peer, parents[j], taskTotalPieceCount)
		},
	)
	peer.Log.Infof("find parent %s successful", parents[0].ID)
	return parents[0], true
}
func ( s * scheduler ) FindParent ( ctx context . Context , peer * resource . Peer , blocklist set . SafeSet ) ( * resource . Peer , bool ) { parents := s . filterParents ( peer , blocklist ) if len ( parents ) == 0 { peer . Log . Info ( " " ) return nil , false } taskTotalPieceCount := peer . Task . TotalPieceCount . Load ( ) sort . Slice ( parents , func ( i , j int ) bool { return s . evaluator . Evaluate ( peer , parents [ i ] , taskTotalPieceCount ) > s . evaluator . Evaluate ( peer , parents [ j ] , taskTotalPieceCount ) } , ) peer . Log . Infof ( " " , parents [ 0 ] . ID ) return parents [ 0 ] , true }
FindParent finds parent that best matches the evaluation
FindParent finds parent that best matches the evaluation
// Filter the parent that can be scheduled // Sort parents by evaluation score