models: Use a uint16 for port numbers
This commit is contained in:
parent
d9a7611eee
commit
e3aff35532
3 changed files with 11 additions and 11 deletions
|
@ -89,7 +89,7 @@ func (s *Server) serveAnnounce(w http.ResponseWriter, r *http.Request, p httprou
|
|||
stats.RecordEvent(stats.Announce)
|
||||
|
||||
writer := &Writer{w}
|
||||
ann, err := newAnnounce(s.config, r, p)
|
||||
ann, err := s.newAnnounce(r, p)
|
||||
if err != nil {
|
||||
return handleTorrentError(err, writer)
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ func (s *Server) serveScrape(w http.ResponseWriter, r *http.Request, p httproute
|
|||
stats.RecordEvent(stats.Scrape)
|
||||
|
||||
writer := &Writer{w}
|
||||
scrape, err := newScrape(s.config, r, p)
|
||||
scrape, err := s.newScrape(r, p)
|
||||
if err != nil {
|
||||
return handleTorrentError(err, writer)
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
// newAnnounce parses an HTTP request and generates a models.Announce.
|
||||
func newAnnounce(cfg *config.Config, r *http.Request, p httprouter.Params) (*models.Announce, error) {
|
||||
func (s *Server) newAnnounce(r *http.Request, p httprouter.Params) (*models.Announce, error) {
|
||||
q, err := query.New(r.URL.RawQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -26,7 +26,7 @@ func newAnnounce(cfg *config.Config, r *http.Request, p httprouter.Params) (*mod
|
|||
|
||||
compact := q.Params["compact"] != "0"
|
||||
event, _ := q.Params["event"]
|
||||
numWant := requestedPeerCount(q, cfg.NumWantFallback)
|
||||
numWant := requestedPeerCount(q, s.config.NumWantFallback)
|
||||
|
||||
infohash, exists := q.Params["info_hash"]
|
||||
if !exists {
|
||||
|
@ -38,7 +38,7 @@ func newAnnounce(cfg *config.Config, r *http.Request, p httprouter.Params) (*mod
|
|||
return nil, models.ErrMalformedRequest
|
||||
}
|
||||
|
||||
ipv4, ipv6, err := requestedIP(q, r, &cfg.NetConfig)
|
||||
ipv4, ipv6, err := requestedIP(q, r, &s.config.NetConfig)
|
||||
if err != nil {
|
||||
return nil, models.ErrMalformedRequest
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ func newAnnounce(cfg *config.Config, r *http.Request, p httprouter.Params) (*mod
|
|||
}
|
||||
|
||||
return &models.Announce{
|
||||
Config: cfg,
|
||||
Config: s.config,
|
||||
Compact: compact,
|
||||
Downloaded: downloaded,
|
||||
Event: event,
|
||||
|
@ -75,13 +75,13 @@ func newAnnounce(cfg *config.Config, r *http.Request, p httprouter.Params) (*mod
|
|||
NumWant: numWant,
|
||||
Passkey: p.ByName("passkey"),
|
||||
PeerID: peerID,
|
||||
Port: port,
|
||||
Port: uint16(port),
|
||||
Uploaded: uploaded,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// newScrape parses an HTTP request and generates a models.Scrape.
|
||||
func newScrape(cfg *config.Config, r *http.Request, p httprouter.Params) (*models.Scrape, error) {
|
||||
func (s *Server) newScrape(r *http.Request, p httprouter.Params) (*models.Scrape, error) {
|
||||
q, err := query.New(r.URL.RawQuery)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -96,7 +96,7 @@ func newScrape(cfg *config.Config, r *http.Request, p httprouter.Params) (*model
|
|||
}
|
||||
|
||||
return &models.Scrape{
|
||||
Config: cfg,
|
||||
Config: s.config,
|
||||
|
||||
Passkey: p.ByName("passkey"),
|
||||
Infohashes: q.Infohashes,
|
||||
|
|
|
@ -71,7 +71,7 @@ type Peer struct {
|
|||
// Always has length net.IPv4len if IPv4, and net.IPv6len if IPv6
|
||||
IP net.IP `json:"ip,omitempty"`
|
||||
|
||||
Port uint64 `json:"port"`
|
||||
Port uint16 `json:"port"`
|
||||
|
||||
Uploaded uint64 `json:"uploaded"`
|
||||
Downloaded uint64 `json:"downloaded"`
|
||||
|
@ -133,7 +133,7 @@ type Announce struct {
|
|||
NumWant int `json:"numwant"`
|
||||
Passkey string `json:"passkey"`
|
||||
PeerID string `json:"peer_id"`
|
||||
Port uint64 `json:"port"`
|
||||
Port uint16 `json:"port"`
|
||||
Uploaded uint64 `json:"uploaded"`
|
||||
|
||||
Torrent *Torrent `json:"-"`
|
||||
|
|
Loading…
Reference in a new issue