- // 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
- }() {
- ws.peer.close()
- } else {
- ws.peer.remoteRejectedRequest(r)
- }
- } else {
- err := ws.peer.receiveChunk(&pp.Message{
- Type: pp.Piece,
- Index: r.Index,
- Begin: r.Begin,
- Piece: result.Bytes,
- })
- if err != nil {
- panic(err)
+ if !ws.peer.remoteRejectedRequest(ws.peer.t.requestIndexFromRequest(r)) {
+ panic("invalid reject")