FedP2P/storage/map-piece-completion.go

35 lines
606 B
Go
Raw Normal View History

package storage
import (
"sync"
"github.com/anacrolix/torrent/metainfo"
)
type mapPieceCompletion struct {
2021-09-02 08:21:56 +08:00
// TODO: Generics
2021-05-05 10:38:26 +08:00
m sync.Map
}
var _ PieceCompletion = (*mapPieceCompletion)(nil)
2017-05-22 10:15:48 +08:00
func NewMapPieceCompletion() PieceCompletion {
2021-05-05 10:38:26 +08:00
return &mapPieceCompletion{}
2017-05-22 10:15:48 +08:00
}
func (*mapPieceCompletion) Close() error { return nil }
func (me *mapPieceCompletion) Get(pk metainfo.PieceKey) (c Completion, err error) {
2021-05-05 10:38:26 +08:00
v, ok := me.m.Load(pk)
if ok {
c.Complete = v.(bool)
}
c.Ok = ok
return
}
func (me *mapPieceCompletion) Set(pk metainfo.PieceKey, b bool) error {
2021-05-05 10:38:26 +08:00
me.m.Store(pk, b)
2016-07-12 14:45:22 +08:00
return nil
}