]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Big rename of files and types in storage
authorMatt Joiner <anacrolix@gmail.com>
Wed, 5 May 2021 02:05:02 +0000 (12:05 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 5 May 2021 02:05:02 +0000 (12:05 +1000)
storage/bolt-piece-completion.go [moved from storage/boltPieceCompletion.go with 100% similarity]
storage/bolt-piece-completion_test.go [moved from storage/boltpc_test.go with 100% similarity]
storage/bolt-piece.go [moved from storage/bolt_piece.go with 74% similarity]
storage/bolt.go [moved from storage/boltdb.go with 58% similarity]
storage/file-misc.go [moved from storage/file_misc.go with 100% similarity]
storage/file-misc_test.go [moved from storage/file_misc_test.go with 100% similarity]
storage/file-piece.go [moved from storage/file_piece.go with 100% similarity]
storage/map-piece-completion.go [moved from storage/completion_piece_map.go with 92% similarity]
storage/piece-completion.go [moved from storage/completion.go with 100% similarity]
storage/piece-resource.go [moved from storage/piece_resource.go with 100% similarity]

similarity index 74%
rename from storage/bolt_piece.go
rename to storage/bolt-piece.go
index 663ac35a7762623f81af93fce43e8c2dd6956661..867ef3a3d805173c9e74313b715cd313440051b0 100644 (file)
@@ -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 {
similarity index 58%
rename from storage/boltdb.go
rename to storage/bolt.go
index f95d2a607f8ccddb63e708984563d6b15a1e1ea1..af75061aea8a37a1b770cac79f7f7ba8df9a9cc9 100644 (file)
@@ -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 }
similarity index 100%
rename from storage/file_misc.go
rename to storage/file-misc.go
similarity index 100%
rename from storage/file_piece.go
rename to storage/file-piece.go
similarity index 92%
rename from storage/completion_piece_map.go
rename to storage/map-piece-completion.go
index e12aca7c7621ddbdde75947ecf77d5c8ffc6a242..52c57e98ac7ff3baada22d2244d9dcc8ce95519c 100644 (file)
@@ -7,6 +7,7 @@ import (
 )
 
 type mapPieceCompletion struct {
+       // TODO: Can probably improve the synchronization here.
        mu sync.Mutex
        m  map[metainfo.PieceKey]bool
 }