diff --git a/storage/boltPieceCompletion.go b/storage/bolt-piece-completion.go similarity index 100% rename from storage/boltPieceCompletion.go rename to storage/bolt-piece-completion.go diff --git a/storage/boltpc_test.go b/storage/bolt-piece-completion_test.go similarity index 100% rename from storage/boltpc_test.go rename to storage/bolt-piece-completion_test.go diff --git a/storage/bolt_piece.go b/storage/bolt-piece.go similarity index 74% rename from storage/bolt_piece.go rename to storage/bolt-piece.go index 663ac35a..867ef3a3 100644 --- a/storage/bolt_piece.go +++ b/storage/bolt-piece.go @@ -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 { diff --git a/storage/boltdb.go b/storage/bolt.go similarity index 58% rename from storage/boltdb.go rename to storage/bolt.go index f95d2a60..af75061a 100644 --- a/storage/boltdb.go +++ b/storage/bolt.go @@ -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 } diff --git a/storage/file_misc.go b/storage/file-misc.go similarity index 100% rename from storage/file_misc.go rename to storage/file-misc.go diff --git a/storage/file_misc_test.go b/storage/file-misc_test.go similarity index 100% rename from storage/file_misc_test.go rename to storage/file-misc_test.go diff --git a/storage/file_piece.go b/storage/file-piece.go similarity index 100% rename from storage/file_piece.go rename to storage/file-piece.go diff --git a/storage/completion_piece_map.go b/storage/map-piece-completion.go similarity index 92% rename from storage/completion_piece_map.go rename to storage/map-piece-completion.go index e12aca7c..52c57e98 100644 --- a/storage/completion_piece_map.go +++ b/storage/map-piece-completion.go @@ -7,6 +7,7 @@ import ( ) type mapPieceCompletion struct { + // TODO: Can probably improve the synchronization here. mu sync.Mutex m map[metainfo.PieceKey]bool } diff --git a/storage/completion.go b/storage/piece-completion.go similarity index 100% rename from storage/completion.go rename to storage/piece-completion.go diff --git a/storage/piece_resource.go b/storage/piece-resource.go similarity index 100% rename from storage/piece_resource.go rename to storage/piece-resource.go