1 Star 0 Fork 0

祝雨昕 / go-bitswap

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
ledger.go 960 Bytes
一键复制 编辑 原始数据 按行查看 历史
祝雨昕 提交于 2022-04-05 15:58 . change
package decision
import (
"sync"
pb "gitee.com/yuviazhu/go-bitswap/message/pb"
wl "gitee.com/yuviazhu/go-bitswap/wantlist"
"github.com/ipfs/go-cid"
"github.com/libp2p/go-libp2p-core/peer"
)
func newLedger(p peer.ID) *ledger {
return &ledger{
wantList: wl.New(),
Partner: p,
}
}
// Keeps the wantlist for the partner. NOT threadsafe!
type ledger struct {
// Partner is the remote Peer.
Partner peer.ID
// wantList is a (bounded, small) set of keys that Partner desires.
wantList *wl.Wantlist
lk sync.RWMutex
}
func (l *ledger) Wants(k cid.Cid, priority int32, wantType pb.Message_Wantlist_WantType) {
log.Debugf("peer %s wants %s", l.Partner, k)
l.wantList.Add(k, priority, wantType)
}
func (l *ledger) CancelWant(k cid.Cid) bool {
return l.wantList.Remove(k)
}
func (l *ledger) WantListContains(k cid.Cid) (wl.Entry, bool) {
return l.wantList.Contains(k)
}
func (l *ledger) Entries() []wl.Entry {
return l.wantList.Entries()
}
1
https://gitee.com/yuviazhu/go-bitswap.git
git@gitee.com:yuviazhu/go-bitswap.git
yuviazhu
go-bitswap
go-bitswap
f20a32d77e37

搜索帮助