// CheckForKnownPtr implements the BlockCache interface for BlockCacheStandard.
970738
func (b *BlockCacheStandard) CheckForKnownPtr(tlf tlf.ID, block *FileBlock) (
	BlockPointer, error) {
	if block.IsInd {
		return BlockPointer{}, NotDirectFileBlockError{}
	}

	if b.ids == nil {
		return BlockPointer{}, nil
	}

	key := idCacheKey{tlf, block.GetHash()}
	tmp, ok := b.ids.Get(key)
	if !ok {
		return BlockPointer{}, nil
	}

	ptr, ok := tmp.(BlockPointer)
	if !ok {
		return BlockPointer{}, fmt.Errorf("Unexpected cached id: %v", tmp)
	}
	return ptr, nil
}
1104136
func (v *VARIANT) ToIUnknown() *IUnknown {
	if v.VT != VT_UNKNOWN {
		return nil
	}
	return (*IUnknown)(unsafe.Pointer(uintptr(v.Val)))
}
154764
func (f *lightFetcher) checkKnownNode(p *peer, n *fetcherTreeNode) bool {
	if n.known {
		return true
	}
	td := f.chain.GetTd(n.hash, n.number)
	if td == nil {
		return false
	}
	header := f.chain.GetHeader(n.hash, n.number)
	// check the availability of both header and td because reads are not protected by chain db mutex
	// Note: returning false is always safe here
	if header == nil {
		return false
	}

	fp := f.peers[p]
	if fp == nil {
		p.Log().Debug("Unknown peer to check known nodes")
		return false
	}
	if !f.checkAnnouncedHeaders(fp, []*types.Header{header}, []*big.Int{td}) {
		p.Log().Debug("Inconsistent announcement")
		go f.pm.removePeer(p.id)
	}
	if fp.confirmedTd != nil {
		f.updateMaxConfirmedTd(fp.confirmedTd)
	}
	return n.known
}
1031672
func (r *ChannelRouter) IsKnownEdge(chanID lnwire.ShortChannelID) bool {
	_, _, exists, isZombie, _ := r.cfg.Graph.HasChannelEdge(chanID.ToUint64())
	return exists || isZombie
}
29865
func ParseKnownHost(
	ctx types.Context,
	text string) (*types.TLSKnownHost, error) {

	m := knownHostRX.FindStringSubmatch(text)
	if len(m) == 0 {
		return nil, nil
	}

	ctx.WithFields(map[string]interface{}{
		"khHost": m[1],
		"khAlg":  m[2],
		"khSig":  m[3],
	}).Debug("parsing known_hosts file fields")

	buf, err := hex.DecodeString(strings.Replace(m[3], ":", "", -1))
	if err != nil {
		return nil, goof.WithError(
			"error decoding known host fingerprint", err)
	}
	return &types.TLSKnownHost{
		Host:        m[1],
		Alg:         m[2],
		Fingerprint: buf,
	}, nil
}
1224506
func (n *LiteralNode) IsUnknown() bool {
	return IsUnknown(Variable{
		Type:  n.Typex,
		Value: n.Value,
	})
}
345206
func (fbo *folderBlockOps) cacheBlockIfNotYetDirtyLocked(
	ctx context.Context, lState *kbfssync.LockState, ptr data.BlockPointer,
	file data.Path, block data.Block) error {
	fbo.blockLock.AssertLocked(lState)
	df := fbo.getOrCreateDirtyFileLocked(lState, file)
	needsCaching, isSyncing := df.SetBlockDirty(ptr)

	if needsCaching {
		err := fbo.config.DirtyBlockCache().Put(
			ctx, fbo.id(), ptr, file.Branch, block)
		if err != nil {
			return err
		}
	}

	if isSyncing {
		fbo.doDeferWrite = true
	}
	return nil
}
1263827
func IsUnknown(err error) bool {
	_, ok := getImplementer(err).(ErrUnknown)
	return ok
}
81760
func identifyForReview(mctx libkb.MetaContext, assertion string,
	successCh chan<- struct{},
	trackFailCh chan<- struct{},
	errCh chan<- error) {
	// Goroutines that are blocked on otherwise unreachable channels are not GC'd.
	// So use ctx to clean up.
	sendSuccess := func() {
		mctx.Debug("identifyForReview(%v) -> success", assertion)
		select {
		case successCh <- struct{}{}:
		case <-mctx.Ctx().Done():
		}
	}
	sendTrackFail := func() {
		mctx.Debug("identifyForReview(%v) -> fail", assertion)
		select {
		case trackFailCh <- struct{}{}:
		case <-mctx.Ctx().Done():
		}
	}
	sendErr := func(err error) {
		mctx.Debug("identifyForReview(%v) -> err %v", assertion, err)
		select {
		case errCh <- err:
		case <-mctx.Ctx().Done():
		}
	}

	mctx.Debug("identifyForReview(%v)", assertion)
	reason := fmt.Sprintf("Identify transaction recipient: %s", assertion)
	eng := engine.NewResolveThenIdentify2(mctx.G(), &keybase1.Identify2Arg{
		UserAssertion:         assertion,
		CanSuppressUI:         true,
		NoErrorOnTrackFailure: true, // take heed
		Reason:                keybase1.IdentifyReason{Reason: reason},
		IdentifyBehavior:      keybase1.TLFIdentifyBehavior_RESOLVE_AND_CHECK,
	})
	err := engine.RunEngine2(mctx, eng)
	if err != nil {
		sendErr(err)
		return
	}
	idRes, err := eng.Result(mctx)
	if err != nil {
		sendErr(err)
		return
	}
	if idRes == nil {
		sendErr(fmt.Errorf("missing identify result"))
		return
	}
	mctx.Debug("identifyForReview: uv: %v", idRes.Upk.Current.ToUserVersion())
	if idRes.TrackBreaks != nil {
		sendTrackFail()
		return
	}
	sendSuccess()
}
694095
func (c *DbClient) GetDataForPrefix(prefix string) []*decoder.FileDataEntry {
	c.Lock()
	defer c.Unlock()

	var keyValues []*decoder.FileDataEntry
	for _, file := range c.db {
		for key, value := range file {
			if strings.HasPrefix(key, prefix) {
				keyValues = append(keyValues, &decoder.FileDataEntry{
					Key:   key,
					Value: value.data,
				})
			}
		}
	}
	return keyValues
}
1018495
func (s *session) getCompPtr(level int) internalKey {
	if level >= len(s.stCompPtrs) {
		return nil
	}
	return s.stCompPtrs[level]
}
1174528
func (b *blockManager) checkHeaderSanity(blockHeader *wire.BlockHeader,
	maxTimestamp time.Time, reorgAttempt bool) error {
	diff, err := b.calcNextRequiredDifficulty(
		blockHeader.Timestamp, reorgAttempt)
	if err != nil {
		return err
	}
	stubBlock := btcutil.NewBlock(&wire.MsgBlock{
		Header: *blockHeader,
	})
	err = blockchain.CheckProofOfWork(stubBlock,
		blockchain.CompactToBig(diff))
	if err != nil {
		return err
	}
	// Ensure the block time is not too far in the future.
	if blockHeader.Timestamp.After(maxTimestamp) {
		return fmt.Errorf("block timestamp of %v is too far in the "+
			"future", blockHeader.Timestamp)
	}
	return nil
}
20889
func Unknown(err error) error {
	if err == nil || IsUnknown(err) {
		return err
	}
	return errUnknown{err}
}
1083856
func (l *Limiter) GetForwardedForIndexFromBehind() int {
	l.RLock()
	defer l.RUnlock()
	return l.forwardedForIndex
}
836592
func isKnown(t Type) bool {
	switch t {
	case TypeProtocolVersion,
		TypeOrigin, TypeSessionName,
		TypeSessionInformation, TypeURI,
		TypeEmail, TypePhone,
		TypeConnectionData, TypeBandwidth,
		TypeTiming, TypeRepeatTimes,
		TypeTimeZones, TypeEncryptionKey,
		TypeAttribute, TypeMediaDescription:
		return true
	default:
		return false
	}
}
67546
func (Attr *FloatAttribute) CheckSysValFromString(rawVal string) ([]byte, error) {
	f, err := strconv.ParseFloat(rawVal, 64)
	if err != nil {
		return nil, err
	}

	ret := PackFloatToBytes(f)
	return ret, nil
}
1295247
func (s *attrStore) BlockData(i uint64) (m map[uint64]map[string]interface{}, err error) {
	m = make(map[uint64]map[string]interface{})

	// Start read-only transaction.
	err = s.db.View(func(tx *bolt.Tx) error {
		// Move to the start of the block.
		min := u64tob(i * attrBlockSize)
		max := u64tob((i + 1) * attrBlockSize)
		cur := tx.Bucket([]byte("attrs")).Cursor()
		for k, v := cur.Seek(min); k != nil; k, v = cur.Next() {
			// Exit if we're past the end of the block.
			if bytes.Compare(k, max) != -1 {
				break
			}

			// Decode attribute map and associate with id.
			attrs, err := pilosa.DecodeAttrs(v)
			if err != nil {
				return errors.Wrap(err, "decoding attrs")
			}
			m[btou64(k)] = attrs

		}
		return nil
	})
	if err != nil {
		return nil, errors.Wrap(err, "getting block data")
	}
	return m, nil
}