// GetStreamManager returns a StreamManager based on the db headers, or nil if the type is unsupported
// Can be used to lock only certain entries instead of calling
773038
func (db *Database) GetStreamManager() (*StreamManager, error) {
	if db.Header.FileHeaders != nil {
		if db.Header.IsKdbx4() {
			return NewStreamManager(
				db.Content.InnerHeader.InnerRandomStreamID,
				db.Content.InnerHeader.InnerRandomStreamKey,
			)
		}

		return NewStreamManager(
			db.Header.FileHeaders.InnerRandomStreamID,
			db.Header.FileHeaders.ProtectedStreamKey,
		)
	}
	return nil, nil
}
928419
func (registry streamRegistry) GetRouter(id MessageStreamID) Router {
	registry.streamGuard.RLock()
	stream, exists := registry.routers[id]
	registry.streamGuard.RUnlock()

	if exists {
		return stream
	}
	return nil
}
993134
func (l *Live) GetStream(streamName string) *Stream {
	if "" == streamName {
		return nil
	}

	var credentials *StreamCredentials
	if nil != l.streamCert {
		credentials = l.streamCert.Clone()
	}

	return &Stream{
		domainName:     l.liveReq.DomainName,
		appName:        l.liveReq.AppName,
		StreamName:     streamName,
		videoCenterDns: l.videoCenterDns,
		streamCert:     credentials,
		signOn:         nil != l.streamCert,
		live:           l,
	}
}
327658
func getDescriptionManager(session *mgo.Session) *mgo.Collection {
	return db.GetCollection(session, descriptionCollectionName)
}
179732
func (s *storageImpl) GetReader(c context.Context, ref *api.ObjectRef) (r gs.Reader, err error) {
	defer func() { err = grpcutil.GRPCifyAndLogErr(c, err) }()

	if err = common.ValidateObjectRef(ref, common.KnownHash); err != nil {
		return nil, errors.Annotate(err, "bad ref").Err()
	}

	cfg, err := s.settings(c)
	if err != nil {
		return nil, err
	}

	r, err = s.getGS(c).Reader(c, cfg.ObjectPath(ref), 0)
	if err != nil {
		ann := errors.Annotate(err, "can't read the object")
		if gs.StatusCode(err) == http.StatusNotFound {
			ann.Tag(grpcutil.NotFoundTag)
		}
		return nil, ann.Err()
	}
	return r, nil
}
1158920
func (l *Client) GetStreams(stream string) ([]*Stream, error) {
	res := ApiResp{}
	data := []*Stream{}

	// make the request
	err := l.Get(parseLyticsURL(routeSchemaStreams, nil), nil, nil, &res, &data)
	if err != nil {
		return data, err
	}

	return data, nil
}
141525
func (b *Blockchain) GetCommonAncestor(bestHeader, prevBestHeader StoredHeader) (*StoredHeader, error) {
	var err error
	rollback := func(parent StoredHeader, n int) (StoredHeader, error) {
		for i := 0; i < n; i++ {
			parent, err = b.db.GetPreviousHeader(parent.header)
			if err != nil {
				return parent, err
			}
		}
		return parent, nil
	}

	majority := bestHeader
	minority := prevBestHeader
	if bestHeader.height > prevBestHeader.height {
		majority, err = rollback(majority, int(bestHeader.height-prevBestHeader.height))
		if err != nil {
			return nil, err
		}
	} else if prevBestHeader.height > bestHeader.height {
		minority, err = rollback(minority, int(prevBestHeader.height-bestHeader.height))
		if err != nil {
			return nil, err
		}
	}

	for {
		majorityHash := majority.header.BlockHash()
		minorityHash := minority.header.BlockHash()
		if majorityHash.IsEqual(&minorityHash) {
			return &majority, nil
		}
		majority, err = b.db.GetPreviousHeader(majority.header)
		if err != nil {
			return nil, err
		}
		minority, err = b.db.GetPreviousHeader(minority.header)
		if err != nil {
			return nil, err
		}
	}
}
1033204
func (r *Registry) FileManager() *FileManager {
	return r.Get(r.content().FileManager.Reference()).(*FileManager)
}
1033311
func (c *Client) GetMempoolEntry(txHash string) (*btcjson.GetMempoolEntryResult, error) {
	return c.GetMempoolEntryAsync(txHash).Receive()
}
339938
func DispatchStreamHandler(
	h StreamHandler,
	stream *ServerStream,
) (err error) {
	return InvokeStreamHandler(StreamInvokeRequest{
		Stream:  stream,
		Handler: h,
	})
}
21735
func (registry streamRegistry) GetStreamName(streamID MessageStreamID) string {
	switch streamID {
	case LogInternalStreamID:
		return LogInternalStream

	case WildcardStreamID:
		return WildcardStream

	case InvalidStreamID:
		return InvalidStream

	case TraceInternalStreamID:
		return TraceInternalStream

	default:
		registry.nameGuard.RLock()
		name, exists := registry.name[streamID]
		registry.nameGuard.RUnlock()

		if exists {
			return name // ### return, found ###
		}
	}
	return ""
}
716727
func GetHandlerManager(ctx ttnlog.Interface, appID string) (*grpc.ClientConn, *handlerclient.ManagerClient) {
	ctx.WithField("Handler", viper.GetString("handler-id")).Info("Discovering Handler...")
	dscConn, client := GetDiscovery(ctx)
	defer dscConn.Close()
	handlerAnnouncement, err := client.Get(GetContext(ctx), &discovery.GetRequest{
		ServiceName: "handler",
		ID:          viper.GetString("handler-id"),
	})
	if err != nil {
		ctx.WithError(errors.FromGRPCError(err)).Fatal("Could not find Handler")
	}

	token := TokenForScope(ctx, scope.App(appID))

	ctx.WithField("Handler", handlerAnnouncement.NetAddress).Info("Connecting with Handler...")
	hdlConn, err := handlerAnnouncement.Dial(nil)
	if err != nil {
		ctx.WithError(err).Fatal("Could not connect to Handler")
	}
	managerClient, err := handlerclient.NewManagerClient(hdlConn, token)
	if err != nil {
		ctx.WithError(err).Fatal("Could not create Handler Manager")
	}
	return hdlConn, managerClient
}
915623
func (reader *PluginConfigReader) GetStreamMap(key string, defaultValue string) map[MessageStreamID]string {
	value, err := reader.WithError.GetStreamMap(key, defaultValue)
	reader.Errors.Push(err)
	return value
}
413558
func (s *storageImpl) getLogEntriesIter(c context.Context, st *getStrategy, cb storage.GetCallback) error {
	// Get our maximum byte limit. If we are externally constrained via MaxBytes,
	// apply that limit too.
	// Get an archive reader.
	var (
		offset = st.startOffset
		length = st.length()
	)

	log.Fields{
		"offset": offset,
		"length": length,
		"path":   s.Stream,
	}.Debugf(c, "Creating stream reader for range.")
	storageReader, err := s.Client.NewReader(s.Stream, int64(offset), length)
	if err != nil {
		log.WithError(err).Errorf(c, "Failed to create stream Reader.")
		return errors.Annotate(err, "failed to create stream Reader").Err()
	}
	defer func() {
		if tmpErr := storageReader.Close(); tmpErr != nil {
			// (Non-fatal)
			log.WithError(tmpErr).Warningf(c, "Error closing stream Reader.")
		}
	}()

	// Count how many bytes we've read.
	cr := iotools.CountingReader{Reader: storageReader}

	// Iteratively update our strategy's start offset each time we read a complete
	// frame.
	var (
		rio       = recordio.NewReader(&cr, maxStreamRecordSize)
		buf       bytes.Buffer
		remaining = st.count
	)
	for {
		// Reset the count so we know how much we read for this frame.
		cr.Count = 0

		sz, r, err := rio.ReadFrame()
		if err != nil {
			return errors.Annotate(err, "failed to read frame").Err()
		}

		buf.Reset()
		buf.Grow(int(sz))

		switch amt, err := buf.ReadFrom(r); {
		case err != nil:
			log.Fields{
				log.ErrorKey:  err,
				"frameOffset": offset,
				"frameSize":   sz,
			}.Errorf(c, "Failed to read frame data.")
			return errors.Annotate(err, "failed to read frame data").Err()

		case amt != sz:
			// If we didn't buffer the complete frame, we hit a premature EOF.
			return errors.Annotate(io.EOF, "incomplete frame read").Err()
		}

		// If we read from offset 0, the first frame will be the log stream's
		// descriptor, which we can discard.
		discardFrame := (offset == 0)
		offset += uint64(cr.Count)
		if discardFrame {
			continue
		}

		// Punt this log entry to our callback, if appropriate.
		entry := storage.MakeEntry(buf.Bytes(), -1)
		switch idx, err := entry.GetStreamIndex(); {
		case err != nil:
			log.Fields{
				log.ErrorKey:  err,
				"frameOffset": offset,
				"frameSize":   sz,
			}.Errorf(c, "Failed to get log entry index.")
			return errors.Annotate(err, "failed to get log entry index").Err()

		case idx < st.startIndex:
			// Skip this entry, as it's before the first requested entry.
			continue
		}

		// We want to punt this entry, but we also want to re-use our Buffer. Clone
		// its data so it is independent.
		entry.D = make([]byte, len(entry.D))
		copy(entry.D, buf.Bytes())
		if !cb(entry) {
			return nil
		}

		// Enforce our limit, if one is supplied.
		if remaining > 0 {
			remaining--
			if remaining == 0 {
				return nil
			}
		}
	}
}
873716
func (c *UIConfig) GetHeader(ctx context.Context, header string) (string, error) {
	c.l.RLock()
	defer c.l.RUnlock()

	config, err := c.get(ctx)
	if err != nil {
		return "", err
	}
	if config == nil {
		return "", nil
	}

	value := config.Headers.Get(header)
	return value, nil
}
691441
func (r *Registry) EventManager() *EventManager {
	return r.Get(r.content().EventManager.Reference()).(*EventManager)
}
1264589
func (goPlatform *Platform) GetMetadataProvider(code []byte) platforms.MetadataProvider {
	return &ccmetadata.TargzMetadataProvider{Code: code}
}