"context"
"errors"
"fmt"
- "net/http"
- "strings"
"sync"
"github.com/RoaringBitmap/roaring"
func (ws *webseedPeer) onClose() {
ws.peer.logger.WithLevel(log.Debug).Print("closing")
+ ws.peer.deleteAllRequests()
for _, r := range ws.activeRequests {
r.Cancel()
}
ws.peer.t.cl.lock()
defer ws.peer.t.cl.unlock()
if result.Err != nil {
- if !errors.Is(result.Err, context.Canceled) {
+ if !errors.Is(result.Err, context.Canceled) && !ws.peer.closed.IsSet() {
ws.peer.logger.Printf("Request %v rejected: %v", r, result.Err)
- }
- // 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(result.Err.Error(), "unsupported protocol scheme") ||
- func() bool {
- var err webseed.ErrBadResponse
- if !errors.As(result.Err, &err) {
- return false
- }
- return err.Response.StatusCode == http.StatusNotFound
- }() {
+ // cfg := spew.NewDefaultConfig()
+ // cfg.DisableMethods = true
+ // cfg.Dump(result.Err)
+ log.Printf("closing %v", ws)
ws.peer.close()
- } else {
- ws.peer.remoteRejectedRequest(ws.peer.t.requestIndexFromRequest(r))
}
+ ws.peer.remoteRejectedRequest(ws.peer.t.requestIndexFromRequest(r))
} else {
err := ws.peer.receiveChunk(&pp.Message{
Type: pp.Piece,