func (cn *Peer) writeStatus(w io.Writer, t *Torrent) {
// \t isn't preserved in <pre> blocks?
+ if cn.closed.IsSet() {
+ fmt.Fprint(w, "CLOSED: ")
+ }
fmt.Fprintln(w, cn.connStatusString())
fmt.Fprintf(w, " last msg: %s, connected: %s, last helpful: %s, itime: %s, etime: %s\n",
eventAgeString(cn.lastMessageReceived),
return cn.t.requestStrategy.shouldRequestWithoutBias(cn.requestStrategyConnection())
}
-func (cn *Peer) iterPendingPieces(f func(pieceIndex) bool) bool {
+func (cn *Peer) iterPendingPieces(f func(pieceIndex) bool) {
if !cn.t.haveInfo() {
- return false
+ return
+ }
+ if cn.closed.IsSet() {
+ return
}
- return cn.t.requestStrategy.iterPendingPieces(cn, f)
+ cn.t.requestStrategy.iterPendingPieces(cn, f)
}
func (cn *Peer) iterPendingPiecesUntyped(f iter.Callback) {
cn.iterPendingPieces(func(i pieceIndex) bool { return f(i) })
package torrent
import (
+ "context"
+ "errors"
"fmt"
"strings"
"sync"
pp "github.com/anacrolix/torrent/peer_protocol"
"github.com/anacrolix/torrent/segments"
"github.com/anacrolix/torrent/webseed"
- "github.com/pkg/errors"
)
type webseedPeer struct {
func (ws *webseedPeer) doRequest(r Request) {
webseedRequest := ws.client.NewRequest(ws.intoSpec(r))
ws.activeRequests[r] = webseedRequest
- ws.requesterCond.L.Unlock()
- ws.requestResultHandler(r, webseedRequest)
- ws.requesterCond.L.Lock()
+ func() {
+ ws.requesterCond.L.Unlock()
+ defer ws.requesterCond.L.Lock()
+ ws.requestResultHandler(r, webseedRequest)
+ }()
delete(ws.activeRequests, r)
}
}
func (ws *webseedPeer) onClose() {
+ ws.peer.logger.Print("closing")
+ for _, r := range ws.activeRequests {
+ r.Cancel()
+ }
ws.requesterCond.Broadcast()
}
ws.peer.t.cl.lock()
defer ws.peer.t.cl.unlock()
if result.Err != nil {
- ws.peer.logger.Printf("Request %v rejected: %v", r, result.Err)
+ if !errors.Is(result.Err, context.Canceled) {
+ ws.peer.logger.Printf("Request %v rejected: %v", r, result.Err)
+ }
// Always close for now. We need to filter out temporary errors, but this is a nightmare in
// Go. Currently a bad webseed URL can starve out the good ones due to the chunk selection
// algorithm.
const closeOnAllErrors = false
- if closeOnAllErrors || strings.Contains(errors.Cause(result.Err).Error(), "unsupported protocol scheme") {
+ if closeOnAllErrors || strings.Contains(result.Err.Error(), "unsupported protocol scheme") {
ws.peer.close()
} else {
ws.peer.remoteRejectedRequest(r)