"github.com/anacrolix/torrent/metainfo"
)
-type boltDBPiece struct {
+type boltPiece struct {
db *bbolt.DB
p metainfo.Piece
ih metainfo.Hash
}
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:
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 {
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 {
)
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
}
})
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,
return ret
}
-func (boltDBTorrent) Close() error { return nil }
+func (boltTorrent) Close() error { return nil }