if addr := cl.ListenAddr(); addr != nil {
fmt.Fprintf(w, "Listening on %s\n", cl.ListenAddr())
} else {
- fmt.Println(w, "Not listening!")
+ fmt.Fprintln(w, "Not listening!")
}
fmt.Fprintf(w, "Peer ID: %q\n", cl.peerID)
fmt.Fprintf(w, "Handshaking: %d\n", cl.handshaking)
fmt.Fprintf(w, "DHT announces: %d\n", cl.dHT.NumConfirmedAnnounces)
fmt.Fprintf(w, "Outstanding transactions: %d\n", dhtStats.NumOutstandingTransactions)
}
- cl.downloadStrategy.WriteStatus(w)
fmt.Fprintln(w)
for _, t := range cl.sortedTorrents() {
if t.Name() == "" {
return
}
pieceOff := pp.Integer(off % int64(t.usualPieceSize()))
- pieceLeft := int(t.PieceLength(pp.Integer(index)) - pieceOff)
+ pieceLeft := int(t.PieceLength(index) - pieceOff)
if pieceLeft <= 0 {
err = io.EOF
return
}
}
- if cl.downloadStrategy == nil {
- cl.downloadStrategy = &defaultDownloadStrategy{}
- }
-
// Returns the laddr string to listen on for the next Listen call.
listenAddr := func() string {
if addr := cl.ListenAddr(); addr != nil {
ok = cn.Cancel(r)
if ok {
postedCancels.Add(1)
- cl.downloadStrategy.DeleteRequest(t, r)
}
return
}
if !cn.RequestPending(r) {
return
}
- cl.downloadStrategy.DeleteRequest(t, r)
delete(cn.Requests, r)
}
}
}()
}
- cl.downloadStrategy.TorrentStarted(t)
}
// Storage cannot be changed once it's set.
panic(err)
}
delete(me.torrents, infoHash)
- me.downloadStrategy.TorrentStopped(t)
return
}
}
ps.Close()
log.Printf("finished DHT peer scrape for %s: %d peers", t, len(allAddrs))
-
}
}
defer me.replenishConnRequests(t, c)
+ piece := t.Pieces[req.Index]
+
// Do we actually want this chunk?
if _, ok := t.Pieces[req.Index].PendingChunkSpecs[req.chunkSpec]; !ok {
unusedDownloadedChunksCount.Add(1)
}
// Record that we have the chunk.
- delete(t.Pieces[req.Index].PendingChunkSpecs, req.chunkSpec)
- if len(t.Pieces[req.Index].PendingChunkSpecs) == 0 {
+ delete(piece.PendingChunkSpecs, req.chunkSpec)
+ if len(piece.PendingChunkSpecs) == 0 {
for _, c := range t.Conns {
c.pieceRequestOrder.DeletePiece(int(req.Index))
}
me.queuePieceCheck(t, req.Index)
}
- // Unprioritize the chunk.
- me.downloadStrategy.TorrentGotChunk(t, req)
-
// Cancel pending requests for this chunk.
for _, c := range t.Conns {
if me.connCancel(t, c, req) {
}
}
- me.downloadStrategy.AssertNotRequested(t, req)
-
return nil
}
p.PendingChunkSpecs = nil
p.complete = true
p.Event.Broadcast()
- me.downloadStrategy.TorrentGotPiece(t, int(piece))
} else {
if len(p.PendingChunkSpecs) == 0 {
- t.pendAllChunkSpecs(piece)
+ t.pendAllChunkSpecs(int(piece))
}
if p.Priority != piecePriorityNone {
me.openNewConns(t)
})
// TODO: Cancel requests for this piece.
for r := range conn.Requests {
- if r.Index == piece {
+ if int(r.Index) == piece {
panic("wat")
}
}
conn.pieceRequestOrder.DeletePiece(int(piece))
}
- if t.wantPiece(int(piece)) && conn.PeerHasPiece(piece) {
+ if t.wantPiece(int(piece)) && conn.PeerHasPiece(pp.Integer(piece)) {
t.connPendPiece(conn, int(piece))
me.replenishConnRequests(t, conn)
}
if !t.haveInfo() {
return -1
}
- for i := pp.Integer(0); i < pp.Integer(t.numPieces()); i++ {
+ for i := 0; i < t.numPieces(); i++ {
left += int64(t.PieceNumPendingBytes(i))
}
return
}
func (t *torrent) piecePartiallyDownloaded(index int) bool {
- return t.PieceNumPendingBytes(pp.Integer(index)) != t.PieceLength(pp.Integer(index))
+ return t.PieceNumPendingBytes(index) != t.PieceLength(index)
}
func numChunksForPiece(chunkSize int, pieceSize int) int {
}
func (t *torrent) lastPieceSize() int {
- return int(t.PieceLength(pp.Integer(t.numPieces() - 1)))
+ return int(t.PieceLength(t.numPieces() - 1))
}
func (t *torrent) numPieces() int {
}
func (t *torrent) pieceChunks(piece int) (css []chunkSpec) {
- css = make([]chunkSpec, 0, (t.PieceLength(pp.Integer(piece))+chunkSize-1)/chunkSize)
+ css = make([]chunkSpec, 0, (t.PieceLength(piece)+chunkSize-1)/chunkSize)
var cs chunkSpec
- for left := t.PieceLength(pp.Integer(piece)); left != 0; left -= cs.Length {
+ for left := t.PieceLength(piece); left != 0; left -= cs.Length {
cs.Length = left
if cs.Length > chunkSize {
cs.Length = chunkSize
return
}
-func (t *torrent) pendAllChunkSpecs(index pp.Integer) {
+func (t *torrent) pendAllChunkSpecs(index int) {
piece := t.Pieces[index]
if piece.PendingChunkSpecs == nil {
piece.PendingChunkSpecs = make(
Source peerSource
}
-func (t *torrent) PieceLength(piece pp.Integer) (len_ pp.Integer) {
+func (t *torrent) PieceLength(piece int) (len_ pp.Integer) {
if int(piece) == t.numPieces()-1 {
len_ = pp.Integer(t.Length() % t.Info.PieceLength)
}