// Adds and starts tracker scrapers for tracker URLs that aren't already
// running.
968982
func (t *Torrent) startMissingTrackerScrapers() {
	if t.cl.config.DisableTrackers {
		return
	}
	t.startScrapingTracker(t.metainfo.Announce)
	for _, tier := range t.metainfo.AnnounceList {
		for _, url := range tier {
			t.startScrapingTracker(url)
		}
	}
}
339410
func (h *ScraperHandler) handleGetScraperTargets(w http.ResponseWriter, r *http.Request) {
	ctx := r.Context()

	targets, err := h.ScraperStorageService.ListTargets(ctx)
	if err != nil {
		EncodeError(ctx, err, w)
		return
	}

	if err := encodeResponse(ctx, w, http.StatusOK, newListTargetsResponse(targets)); err != nil {
		logEncodingError(h.Logger, r, err)
		return
	}
}
965419
func (s *Service) UpdateTarget(ctx context.Context, update *influxdb.ScraperTarget, userID influxdb.ID) (target *influxdb.ScraperTarget, err error) {
	op := OpPrefix + influxdb.OpUpdateTarget
	if !update.ID.Valid() {
		return nil, &influxdb.Error{
			Code: influxdb.EInvalid,
			Op:   op,
			Msg:  "provided scraper target ID has invalid format",
		}
	}
	oldTarget, pe := s.loadScraperTarget(update.ID)
	if pe != nil {
		return nil, &influxdb.Error{
			Op:  op,
			Err: pe,
		}
	}
	if !update.OrgID.Valid() {
		update.OrgID = oldTarget.OrgID
	}
	if !update.BucketID.Valid() {
		update.BucketID = oldTarget.BucketID
	}
	if err = s.PutTarget(ctx, update); err != nil {
		return nil, &influxdb.Error{
			Op:  op,
			Err: pe,
		}
	}

	return update, nil
}
96536
func startRequestTracker(shutdownWait time.Duration) *requestTracker {
	rt := &requestTracker{
		C:              make(chan error, 1),
		commandChan:    make(chan int, 100),
		shutdownState:  running,
		shutdownWait:   shutdownWait,
		shutdownReason: &atomic.Value{},
	}
	go rt.trackerLoop()
	return rt
}
788246
func (state *ServicesState) TrackNewServices(fn func() []service.Service, looper director.Looper) {
	looper.Loop(func() error {
		for _, container := range fn() {
			state.ServiceMsgs <- container
		}
		return nil
	})
}
1277401
func AddAllRouteEdges(g osgraph.MutableUniqueGraph) {
	for _, node := range g.(graph.Graph).Nodes() {
		if routeNode, ok := node.(*routegraph.RouteNode); ok {
			AddRouteEdges(g, routeNode)
		}
	}
}
635433
func (extr *ContentExtractor) addSiblings(topNode *goquery.Selection) *goquery.Selection {
	if extr.config.debug {
		log.Println("Starting to add siblings")
	}
	baselinescoreSiblingsPara := extr.getSiblingsScore(topNode)
	results := extr.walkSiblings(topNode)
	for _, currentNode := range results {
		ps := extr.getSiblingsContent(currentNode, float64(baselinescoreSiblingsPara))
		for _, p := range ps {
			nodes := make([]*html.Node, len(topNode.Nodes)+1)
			nodes[0] = p.Get(0)
			for i, node := range topNode.Nodes {
				nodes[i+1] = node
			}
			topNode.Nodes = nodes
		}
	}
	return topNode
}
1068720
func ConvertTracker(request *http.Request, tracker remoteworkitem.Tracker) *app.Tracker {
	trackerStringType := remoteworkitem.APIStringTypeTrackers
	selfURL := rest.AbsoluteURL(request, app.TrackerHref(tracker.ID))
	t := &app.Tracker{
		Type: trackerStringType,
		ID:   &tracker.ID,
		Attributes: &app.TrackerAttributes{
			URL:  tracker.URL,
			Type: tracker.Type,
		},
		Links: &app.GenericLinks{
			Self: &selfURL,
		},
	}
	return t
}
825987
func (c *Collector) OnScraped(f ScrapedCallback) {
	c.lock.Lock()
	if c.scrapedCallbacks == nil {
		c.scrapedCallbacks = make([]ScrapedCallback, 0, 4)
	}
	c.scrapedCallbacks = append(c.scrapedCallbacks, f)
	c.lock.Unlock()
}
191892
func AddRouteEdges(g osgraph.MutableUniqueGraph, node *routegraph.RouteNode) {
	syntheticService := &corev1.Service{}
	syntheticService.Namespace = node.Namespace
	syntheticService.Name = node.Spec.To.Name

	serviceNode := kubegraph.FindOrCreateSyntheticServiceNode(g, syntheticService)
	g.AddEdge(node, serviceNode, ExposedThroughRouteEdgeKind)

	for _, svc := range node.Spec.AlternateBackends {
		syntheticService := &corev1.Service{}
		syntheticService.Namespace = node.Namespace
		syntheticService.Name = svc.Name

		serviceNode := kubegraph.FindOrCreateSyntheticServiceNode(g, syntheticService)
		g.AddEdge(node, serviceNode, ExposedThroughRouteEdgeKind)
	}
}
342758
func (u *Ui) TrackProgress(src string, currentSize, totalSize int64, stream io.ReadCloser) io.ReadCloser {
	pl := &TrackProgressParameters{
		Src:         src,
		CurrentSize: currentSize,
		TotalSize:   totalSize,
	}
	var trackingID string
	if err := u.client.Call("Ui.NewTrackProgress", pl, &trackingID); err != nil {
		log.Printf("Error in Ui.NewTrackProgress RPC call: %s", err)
		return stream
	}
	cli := &ProgressTrackingClient{
		id:     trackingID,
		client: u.client,
		stream: stream,
	}
	return cli
}
1219902
func (s *Service) ListTargets(ctx context.Context, filter influxdb.ScraperTargetFilter) (list []influxdb.ScraperTarget, err error) {
	list = make([]influxdb.ScraperTarget, 0)
	s.scraperTargetKV.Range(func(_, v interface{}) bool {
		target, ok := v.(influxdb.ScraperTarget)
		if !ok {
			err = &influxdb.Error{
				Code: influxdb.EInvalid,
				Msg:  fmt.Sprintf("type %T is not a scraper target", v),
			}
			return false
		}
		if filter.IDs != nil {
			if _, ok := filter.IDs[target.ID]; !ok {
				return true
			}
		}
		if filter.Name != nil && target.Name != *filter.Name {
			return true
		}
		if filter.Org != nil {
			o, orgErr := s.findOrganizationByName(ctx, *filter.Org)
			if orgErr != nil {
				err = orgErr
				return false
			}
			if target.OrgID != o.ID {
				return true
			}
		}
		if filter.OrgID != nil {
			o, orgErr := s.FindOrganizationByID(ctx, *filter.OrgID)
			if orgErr != nil {
				err = orgErr
				return true
			}
			if target.OrgID != o.ID {
				return true
			}
		}
		list = append(list, target)
		return true
	})
	return list, err
}
800129
func (s *SGMailV3) SetTrackingSettings(trackingSettings *TrackingSettings) *SGMailV3 {
	s.TrackingSettings = trackingSettings
	return s
}
365007
func (r *SearchRequest) TrackTotalHits(trackTotalHits interface{}) *SearchRequest {
	r.searchSource = r.searchSource.TrackTotalHits(trackTotalHits)
	return r
}
52688
func StartTracing(serviceName string) io.Closer {
	factory, ok := tracingBackendFactories[*tracingServer]
	if !ok {
		return fail(serviceName)
	}

	tracer, closer, err := factory(serviceName)
	if err != nil {
		log.Error(vterrors.Wrapf(err, "failed to create a %s tracer", *tracingServer))
		return &nilCloser{}
	}

	spanFactory = tracer

	log.Infof("successfully started tracing with [%s]", *tracingServer)

	return closer
}
12087
func (registry *streamRegistry) AddAllWildcardProducersToAllRouters() {
	registry.ForEachStream(
		func(streamID MessageStreamID, router Router) {
			registry.AddWildcardProducersToRouter(router)
		})
}
757315
func (c *Crawler) collectUrls() error {
	defer func() {
		c.logFunc(LogInfo, "waiting for goroutines to complete...")
		c.wg.Wait()
		c.logFunc(LogInfo, "crawler done.")
	}()

	for {
		// By checking this after each channel reception, there is a bug if the worker
		// wants to reenqueue following an error or a redirection. The pushPopRefCount
		// temporarily gets to zero before the new URL is enqueued. Check the length
		// of the enqueue channel to see if this is really over, or just this temporary
		// state.
		//
		// Check if refcount is zero - MUST be before the select statement, so that if
		// no valid seeds are enqueued, the crawler stops.
		if c.pushPopRefCount == 0 && len(c.enqueue) == 0 {
			c.logFunc(LogInfo, "sending STOP signals...")
			close(c.stop)
			return nil
		}

		select {
		case res := <-c.push:
			// Received a response, check if it contains URLs to enqueue
			if res.visited {
				c.visits++
				if c.Options.MaxVisits > 0 && c.visits >= c.Options.MaxVisits {
					// Limit reached, request workers to stop
					c.logFunc(LogInfo, "sending STOP signals...")
					close(c.stop)
					return ErrMaxVisits
				}
			}
			if res.idleDeath {
				// The worker timed out from its Idle TTL delay, remove from active workers
				delete(c.workers, res.host)
				c.logFunc(LogInfo, "worker for host %s cleared on idle policy", res.host)
			} else {
				c.enqueueUrls(c.toURLContexts(res.harvestedURLs, res.ctx.url))
				c.pushPopRefCount--
			}

		case enq := <-c.enqueue:
			// Received a command to enqueue a URL, proceed
			ctxs := c.toURLContexts(enq, nil)
			c.logFunc(LogTrace, "receive url(s) to enqueue %v", toStringArrayContextURL(ctxs))
			c.enqueueUrls(ctxs)
		case <-c.stop:
			return ErrInterrupted
		}
	}
}