kubo/pin/indirect.go
Jeromy 1f9ec4e3ed update to libp2p 4.0.1 and propogate other changes
License: MIT
Signed-off-by: Jeromy <why@ipfs.io>
2016-10-05 22:12:43 -07:00

40 lines
732 B
Go

package pin
import (
key "gx/ipfs/QmYEoKZXHoAToWfhGF3vryhMn3WWhE1o2MasQ8uzY5iDi9/go-key"
)
type indirectPin struct {
refCounts map[key.Key]uint64
}
func newIndirectPin() *indirectPin {
return &indirectPin{
refCounts: make(map[key.Key]uint64),
}
}
func (i *indirectPin) Increment(k key.Key) {
i.refCounts[k]++
}
func (i *indirectPin) Decrement(k key.Key) {
if i.refCounts[k] == 0 {
log.Warningf("pinning: bad call: asked to unpin nonexistent indirect key: %v", k)
return
}
i.refCounts[k]--
if i.refCounts[k] == 0 {
delete(i.refCounts, k)
}
}
func (i *indirectPin) HasKey(k key.Key) bool {
_, found := i.refCounts[k]
return found
}
func (i *indirectPin) GetRefs() map[key.Key]uint64 {
return i.refCounts
}