當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Cid.KeyString方法代碼示例

本文整理匯總了Golang中gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid.Cid.KeyString方法的典型用法代碼示例。如果您正苦於以下問題:Golang Cid.KeyString方法的具體用法?Golang Cid.KeyString怎麽用?Golang Cid.KeyString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid.Cid的用法示例。


在下文中一共展示了Cid.KeyString方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Providers

func (rs *s) Providers(c *cid.Cid) []pstore.PeerInfo {
	rs.delayConf.Query.Wait() // before locking

	rs.lock.RLock()
	defer rs.lock.RUnlock()
	k := c.KeyString()

	var ret []pstore.PeerInfo
	records, ok := rs.providers[k]
	if !ok {
		return ret
	}
	for _, r := range records {
		if time.Now().Sub(r.Created) > rs.delayConf.ValueVisibility.Get() {
			ret = append(ret, r.Peer)
		}
	}

	for i := range ret {
		j := rand.Intn(i + 1)
		ret[i], ret[j] = ret[j], ret[i]
	}

	return ret
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:25,代碼來源:centralized_server.go

示例2: Remove

func (w *Wantlist) Remove(c *cid.Cid) bool {
	k := c.KeyString()
	e, ok := w.set[k]
	if !ok {
		return false
	}

	e.RefCnt--
	if e.RefCnt <= 0 {
		delete(w.set, k)
		return true
	}
	return false
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:14,代碼來源:wantlist.go

示例3: Add

func (w *Wantlist) Add(c *cid.Cid, priority int) bool {
	k := c.KeyString()
	if e, ok := w.set[k]; ok {
		e.RefCnt++
		return false
	}

	w.set[k] = &Entry{
		Cid:      c,
		Priority: priority,
		RefCnt:   1,
	}

	return true
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:15,代碼來源:wantlist.go

示例4: hasCached

// if ok == false has is inconclusive
// if ok == true then has respons to question: is it contained
func (b *arccache) hasCached(k *cid.Cid) (has bool, ok bool) {
	b.total.Inc()
	if k == nil {
		log.Error("nil cid in arccache")
		// Return cache invalid so the call to blockstore happens
		// in case of invalid key and correct error is created.
		return false, false
	}

	h, ok := b.arc.Get(k.KeyString())
	if ok {
		b.hits.Inc()
		return h.(bool), true
	}
	return false, false
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:18,代碼來源:arc_cache.go

示例5: Announce

func (rs *s) Announce(p pstore.PeerInfo, c *cid.Cid) error {
	rs.lock.Lock()
	defer rs.lock.Unlock()

	k := c.KeyString()

	_, ok := rs.providers[k]
	if !ok {
		rs.providers[k] = make(map[peer.ID]providerRecord)
	}
	rs.providers[k][p.ID] = providerRecord{
		Created: time.Now(),
		Peer:    p,
	}
	return nil
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:16,代碼來源:centralized_server.go

示例6: addEntry

func (m *impl) addEntry(c *cid.Cid, priority int, cancel bool) {
	k := c.KeyString()
	e, exists := m.wantlist[k]
	if exists {
		e.Priority = priority
		e.Cancel = cancel
	} else {
		m.wantlist[k] = Entry{
			Entry: &wantlist.Entry{
				Cid:      c,
				Priority: priority,
			},
			Cancel: cancel,
		}
	}
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:16,代碼來源:message.go

示例7: Contains

func (w *Wantlist) Contains(k *cid.Cid) (*Entry, bool) {
	e, ok := w.set[k.KeyString()]
	return e, ok
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:4,代碼來源:wantlist.go

示例8: CidToDsKey

func CidToDsKey(k *cid.Cid) ds.Key {
	return NewKeyFromBinary(k.KeyString())
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:3,代碼來源:key.go

示例9: addCache

func (b *arccache) addCache(c *cid.Cid, has bool) {
	b.arc.Add(c.KeyString(), has)
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:3,代碼來源:arc_cache.go

示例10: Cancel

func (m *impl) Cancel(k *cid.Cid) {
	delete(m.wantlist, k.KeyString())
	m.addEntry(k, 0, true)
}
開發者ID:qnib,項目名稱:go-ipfs,代碼行數:4,代碼來源:message.go


注:本文中的gx/ipfs/QmXfiyr2RWEXpVDdaYnD2HNiBk6UBddsvEP4RPfXb6nGqY/go-cid.Cid.KeyString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。