Big rename of files and types in storage
This commit is contained in:
parent
745a34b43e
commit
cf8bd49abe
|
@ -9,7 +9,7 @@ import (
|
|||
"github.com/anacrolix/torrent/metainfo"
|
||||
)
|
||||
|
||||
type boltDBPiece struct {
|
||||
type boltPiece struct {
|
||||
db *bbolt.DB
|
||||
p metainfo.Piece
|
||||
ih metainfo.Hash
|
||||
|
@ -17,19 +17,19 @@ type boltDBPiece struct {
|
|||
}
|
||||
|
||||
var (
|
||||
_ PieceImpl = (*boltDBPiece)(nil)
|
||||
_ PieceImpl = (*boltPiece)(nil)
|
||||
dataBucketKey = []byte("data")
|
||||
)
|
||||
|
||||
func (me *boltDBPiece) pc() PieceCompletionGetSetter {
|
||||
func (me *boltPiece) pc() PieceCompletionGetSetter {
|
||||
return boltPieceCompletion{me.db}
|
||||
}
|
||||
|
||||
func (me *boltDBPiece) pk() metainfo.PieceKey {
|
||||
func (me *boltPiece) pk() metainfo.PieceKey {
|
||||
return metainfo.PieceKey{me.ih, me.p.Index()}
|
||||
}
|
||||
|
||||
func (me *boltDBPiece) Completion() Completion {
|
||||
func (me *boltPiece) Completion() Completion {
|
||||
c, err := me.pc().Get(me.pk())
|
||||
switch err {
|
||||
case bbolt.ErrDatabaseNotOpen:
|
||||
|
@ -41,14 +41,14 @@ func (me *boltDBPiece) Completion() Completion {
|
|||
return c
|
||||
}
|
||||
|
||||
func (me *boltDBPiece) MarkComplete() error {
|
||||
func (me *boltPiece) MarkComplete() error {
|
||||
return me.pc().Set(me.pk(), true)
|
||||
}
|
||||
|
||||
func (me *boltDBPiece) MarkNotComplete() error {
|
||||
func (me *boltPiece) MarkNotComplete() error {
|
||||
return me.pc().Set(me.pk(), false)
|
||||
}
|
||||
func (me *boltDBPiece) ReadAt(b []byte, off int64) (n int, err error) {
|
||||
func (me *boltPiece) ReadAt(b []byte, off int64) (n int, err error) {
|
||||
err = me.db.View(func(tx *bbolt.Tx) error {
|
||||
db := tx.Bucket(dataBucketKey)
|
||||
if db == nil {
|
||||
|
@ -74,13 +74,13 @@ func (me *boltDBPiece) ReadAt(b []byte, off int64) (n int, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func (me *boltDBPiece) chunkKey(index int) (ret [26]byte) {
|
||||
func (me *boltPiece) chunkKey(index int) (ret [26]byte) {
|
||||
copy(ret[:], me.key[:])
|
||||
binary.BigEndian.PutUint16(ret[24:], uint16(index))
|
||||
return
|
||||
}
|
||||
|
||||
func (me *boltDBPiece) WriteAt(b []byte, off int64) (n int, err error) {
|
||||
func (me *boltPiece) WriteAt(b []byte, off int64) (n int, err error) {
|
||||
err = me.db.Update(func(tx *bbolt.Tx) error {
|
||||
db, err := tx.CreateBucketIfNotExists(dataBucketKey)
|
||||
if err != nil {
|
|
@ -12,17 +12,17 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// Chosen to match the usual chunk size in a torrent client. This way,
|
||||
// most chunk writes are to exactly one full item in bbolt DB.
|
||||
// Chosen to match the usual chunk size in a torrent client. This way, most chunk writes are to
|
||||
// exactly one full item in bbolt DB.
|
||||
chunkSize = 1 << 14
|
||||
)
|
||||
|
||||
type boltDBClient struct {
|
||||
type boltClient struct {
|
||||
db *bbolt.DB
|
||||
}
|
||||
|
||||
type boltDBTorrent struct {
|
||||
cl *boltDBClient
|
||||
type boltTorrent struct {
|
||||
cl *boltClient
|
||||
ih metainfo.Hash
|
||||
}
|
||||
|
||||
|
@ -32,19 +32,19 @@ func NewBoltDB(filePath string) ClientImplCloser {
|
|||
})
|
||||
expect.Nil(err)
|
||||
db.NoSync = true
|
||||
return &boltDBClient{db}
|
||||
return &boltClient{db}
|
||||
}
|
||||
|
||||
func (me *boltDBClient) Close() error {
|
||||
func (me *boltClient) Close() error {
|
||||
return me.db.Close()
|
||||
}
|
||||
|
||||
func (me *boltDBClient) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error) {
|
||||
return &boltDBTorrent{me, infoHash}, nil
|
||||
func (me *boltClient) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (TorrentImpl, error) {
|
||||
return &boltTorrent{me, infoHash}, nil
|
||||
}
|
||||
|
||||
func (me *boltDBTorrent) Piece(p metainfo.Piece) PieceImpl {
|
||||
ret := &boltDBPiece{
|
||||
func (me *boltTorrent) Piece(p metainfo.Piece) PieceImpl {
|
||||
ret := &boltPiece{
|
||||
p: p,
|
||||
db: me.cl.db,
|
||||
ih: me.ih,
|
||||
|
@ -54,4 +54,4 @@ func (me *boltDBTorrent) Piece(p metainfo.Piece) PieceImpl {
|
|||
return ret
|
||||
}
|
||||
|
||||
func (boltDBTorrent) Close() error { return nil }
|
||||
func (boltTorrent) Close() error { return nil }
|
|
@ -7,6 +7,7 @@ import (
|
|||
)
|
||||
|
||||
type mapPieceCompletion struct {
|
||||
// TODO: Can probably improve the synchronization here.
|
||||
mu sync.Mutex
|
||||
m map[metainfo.PieceKey]bool
|
||||
}
|
Loading…
Reference in New Issue