client.go | 6 +++++- torrent.go | 4 ++-- diff --git a/client.go b/client.go index f3f8a59960cb81a4ca9cb9ad8e084204ae491086..d9c929e3de0352628ce10e4fc7d1f423590d1b4a 100644 --- a/client.go +++ b/client.go @@ -92,6 +92,8 @@ piece.QueuedForHash = true go cl.verifyPiece(t, pieceIndex) } +// Queue a piece check if one isn't already queued, and the piece has never +// been checked before. func (cl *Client) queueFirstHash(t *torrent, piece int) { p := t.Pieces[piece] if p.EverHashed || p.Hashing || p.QueuedForHash { @@ -1196,7 +1198,8 @@ if c.PeerRequests == nil { c.PeerRequests = make(map[request]struct{}, maxRequests) } request := newRequest(msg.Index, msg.Begin, msg.Length) - // TODO: Requests should be satisfied from a dedicated upload routine. + // TODO: Requests should be satisfied from a dedicated upload + // routine. // c.PeerRequests[request] = struct{}{} p := make([]byte, msg.Length) n, err := t.Data.ReadAt(p, int64(t.PieceLength(0))*int64(msg.Index)+int64(msg.Begin)) @@ -1756,6 +1759,7 @@ func (me Torrent) ReadAt(p []byte, off int64) (n int, err error) { return me.cl.torrentReadAt(me.torrent, off, p) } +// Returns nil metainfo if it isn't in the cache. func (cl *Client) torrentCacheMetaInfo(ih InfoHash) (mi *metainfo.MetaInfo, err error) { f, err := os.Open(cl.torrentFileCachePath(ih)) if err != nil { diff --git a/torrent.go b/torrent.go index 53cb980c33771c891b4d5b955745719badce9ade..450f15fe35a043290f209009740d793ab71c65b0 100644 --- a/torrent.go +++ b/torrent.go @@ -47,7 +47,7 @@ WriteAt(p []byte, off int64) (n int, err error) WriteSectionTo(w io.Writer, off, n int64) (written int64, err error) } -// Is not aware of Client. +// Is not aware of Client. Maintains state of torrent for with-in a Client. type torrent struct { stateMu sync.Mutex closing chan struct{} @@ -77,7 +77,7 @@ Peers map[peersKey]Peer wantPeers sync.Cond // BEP 12 Multitracker Metadata Extension. The tracker.Client instances - // mirror their respective URLs from the announce-list key. + // mirror their respective URLs from the announce-list metainfo key. Trackers [][]tracker.Client DisplayName string MetaData []byte