Don't return an HTTP error for "bad request" tracker errors
This commit is contained in:
parent
ba1ad7f5bf
commit
6c7abdfa2d
2 changed files with 4 additions and 4 deletions
|
@ -17,6 +17,7 @@ import (
|
||||||
"github.com/chihaya/chihaya/config"
|
"github.com/chihaya/chihaya/config"
|
||||||
"github.com/chihaya/chihaya/stats"
|
"github.com/chihaya/chihaya/stats"
|
||||||
"github.com/chihaya/chihaya/tracker"
|
"github.com/chihaya/chihaya/tracker"
|
||||||
|
"github.com/chihaya/chihaya/tracker/models"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (int, error)
|
type ResponseHandler func(http.ResponseWriter, *http.Request, httprouter.Params) (int, error)
|
||||||
|
@ -33,7 +34,7 @@ func makeHandler(handler ResponseHandler) httprouter.Handle {
|
||||||
httpCode, err := handler(w, r, p)
|
httpCode, err := handler(w, r, p)
|
||||||
stats.RecordEvent(stats.HandledRequest)
|
stats.RecordEvent(stats.HandledRequest)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil && err != models.ErrBadRequest {
|
||||||
stats.RecordEvent(stats.ErroredRequest)
|
stats.RecordEvent(stats.ErroredRequest)
|
||||||
http.Error(w, err.Error(), httpCode)
|
http.Error(w, err.Error(), httpCode)
|
||||||
}
|
}
|
||||||
|
|
|
@ -147,6 +147,8 @@ func updateSwarm(c Conn, w Writer, ann *models.Announce, p *models.Peer, t *mode
|
||||||
func handleEvent(c Conn, w Writer, ann *models.Announce, p *models.Peer, u *models.User, t *models.Torrent) (snatched bool, err error) {
|
func handleEvent(c Conn, w Writer, ann *models.Announce, p *models.Peer, u *models.User, t *models.Torrent) (snatched bool, err error) {
|
||||||
switch {
|
switch {
|
||||||
case ann.Event == "stopped" || ann.Event == "paused":
|
case ann.Event == "stopped" || ann.Event == "paused":
|
||||||
|
// updateSwarm checks if the peer is active on the torrent,
|
||||||
|
// so one of these branches must be followed.
|
||||||
if t.InSeederPool(p) {
|
if t.InSeederPool(p) {
|
||||||
err = c.DeleteSeeder(t.Infohash, p.ID)
|
err = c.DeleteSeeder(t.Infohash, p.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -162,9 +164,6 @@ func handleEvent(c Conn, w Writer, ann *models.Announce, p *models.Peer, u *mode
|
||||||
}
|
}
|
||||||
delete(t.Leechers, p.ID)
|
delete(t.Leechers, p.ID)
|
||||||
stats.RecordPeerEvent(stats.DeletedLeech, p.IPv6())
|
stats.RecordPeerEvent(stats.DeletedLeech, p.IPv6())
|
||||||
} else {
|
|
||||||
err = models.ErrBadRequest
|
|
||||||
w.WriteError(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case ann.Event == "completed":
|
case ann.Event == "completed":
|
||||||
|
|
Loading…
Reference in a new issue