// The current state of a piece.
type PieceState struct {
- Priority PiecePriority
storage.Completion
+ Priority PiecePriority
// The piece is being hashed, or is queued for hash. Deprecated: Use those fields instead.
Checking bool
// fit.
MarkComplete() error
MarkNotComplete() error
- // Returns true if the piece is complete.
+ // Returns the state of a piece. Typically, this is implemented in some kind of storage to avoid
+ // rehashing, and cheap checks are performed here. (The implementation maintains a cache in
+ // Torrent).
Completion() Completion
}
-// TODO: Yo where the fuck is the documentation.
+// Completion state of a piece.
type Completion struct {
+ Err error
+ // The state is known or cached.
+ Ok bool
+ // If Ok, whether the data is correct.
Complete bool
- Ok bool
- Err error
}
// Allows a storage backend to override hashing (i.e. if it can do it more efficiently than the torrent client can)
}
type ResourcePiecesOpts struct {
+ Capacity TorrentCapacity
// After marking a piece complete, don't bother deleting its incomplete blobs.
LeaveIncompleteChunks bool
// Sized puts require being able to stream from a statement executed on another connection.
// Without them, we buffer the entire read and then put that.
NoSizedPuts bool
- Capacity TorrentCapacity
}
func NewResourcePieces(p PieceProvider) ClientImpl {
}
type chunk struct {
- offset int64
instance resource.Instance
+ offset int64
}
type chunks []chunk
if err != nil {
panic(err)
}
- chunks = append(chunks, chunk{offset, i})
+ chunks = append(chunks, chunk{i, offset})
}
sort.Slice(chunks, func(i, j int) bool {
return chunks[i].offset < chunks[j].offset
// separately.
func (t *Torrent) setInfo(info *metainfo.Info) error {
if err := validateInfo(info); err != nil {
- return fmt.Errorf("bad info: %s", err)
+ return fmt.Errorf("bad info: %w", err)
}
if t.storageOpener != nil {
var err error
ctx := log.ContextWithLogger(context.Background(), t.logger)
t.storage, err = t.storageOpener.OpenTorrent(ctx, info, *t.canonicalShortInfohash())
if err != nil {
- return fmt.Errorf("error opening torrent storage: %s", err)
+ return fmt.Errorf("error opening torrent storage: %w", err)
}
}
t.nameMu.Lock()
if t.info != nil {
return nil
}
- if err := t.setInfo(&info); err != nil {
- return err
+ err = t.setInfo(&info)
+ if err != nil {
+ return
}
t.onSetInfo()
return nil