本文整理汇总了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
}
示例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
}
示例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
}
示例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
}
示例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
}
示例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,
}
}
}
示例7: Contains
func (w *Wantlist) Contains(k *cid.Cid) (*Entry, bool) {
e, ok := w.set[k.KeyString()]
return e, ok
}
示例8: CidToDsKey
func CidToDsKey(k *cid.Cid) ds.Key {
return NewKeyFromBinary(k.KeyString())
}
示例9: addCache
func (b *arccache) addCache(c *cid.Cid, has bool) {
b.arc.Add(c.KeyString(), has)
}
示例10: Cancel
func (m *impl) Cancel(k *cid.Cid) {
delete(m.wantlist, k.KeyString())
m.addEntry(k, 0, true)
}