re-ordering; logic fix in validateAnnounceQuery

This commit is contained in:
Jimmy Zelinskie 2013-07-19 23:00:33 -04:00
parent fc39a4aed3
commit dae48d0c3b

View file

@ -6,7 +6,6 @@ package server
import ( import (
"errors" "errors"
"fmt"
"log" "log"
"net/http" "net/http"
"path" "path"
@ -45,6 +44,13 @@ func (s *Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
return return
} }
if s.conf.Slots && user.Slots != -1 && left != 0 {
if user.UsedSlots >= user.Slots {
fail(errors.New("You've run out of download slots."), w, r)
return
}
}
tx, err := s.dataStore.Begin() tx, err := s.dataStore.Begin()
if err != nil { if err != nil {
log.Panicf("server: %s", err) log.Panicf("server: %s", err)
@ -55,24 +61,10 @@ func (s *Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
log.Panicf("server: %s", err) log.Panicf("server: %s", err)
} }
} else if torrent.Pruned {
e := fmt.Errorf("This torrent does not exist (pruned: %t, left: %d)", torrent.Pruned, left)
fail(e, w, r)
return
}
if s.conf.Slots && user.Slots != -1 && left != 0 {
if user.UsedSlots >= user.Slots {
fail(errors.New("You've run out of download slots."), w, r)
return
}
} }
_, isLeecher := torrent.Leechers[peerID] _, isLeecher := torrent.Leechers[peerID]
_, isSeeder := torrent.Seeders[peerID] _, isSeeder := torrent.Seeders[peerID]
completed := "completed" == event
if event == "stopped" || event == "paused" { if event == "stopped" || event == "paused" {
if left == 0 { if left == 0 {
err := tx.RmSeeder(torrent.ID, peerID) err := tx.RmSeeder(torrent.ID, peerID)
@ -89,7 +81,7 @@ func (s *Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
log.Panicf("server: %s", err) log.Panicf("server: %s", err)
} }
} }
} else if completed { } else if event == "completed" {
err := tx.Snatch(user.ID, torrent.ID) err := tx.Snatch(user.ID, torrent.ID)
if err != nil { if err != nil {
log.Panicf("server: %s", err) log.Panicf("server: %s", err)
@ -117,10 +109,10 @@ func (s *Server) validateAnnounceQuery(r *http.Request) (compact bool, numWant i
if infohash == "" || if infohash == "" ||
peerID == "" || peerID == "" ||
ip == "" || ip == "" ||
portErr == nil || portErr != nil ||
uploadedErr == nil || uploadedErr != nil ||
downloadedErr == nil || downloadedErr != nil ||
leftErr == nil { leftErr != nil {
return false, 0, "", "", "", "", 0, 0, 0, 0, errors.New("Malformed request") return false, 0, "", "", "", "", 0, 0, 0, 0, errors.New("Malformed request")
} }
return return