Add AllowIPSpoofing configuration

This commit is contained in:
Justin Li 2014-07-23 13:08:52 -04:00
parent bd1fa3eb24
commit 14843b9e89
5 changed files with 19 additions and 14 deletions

View file

@ -50,6 +50,7 @@ type Config struct {
Freeleech bool `json:"freeleech"`
Whitelist bool `json:"whitelist"`
PurgeInactiveTorrents bool `json:"purge_inactive_torrents"`
AllowIPSpoofing bool `json:"allow_ip_spoofing"`
Announce Duration `json:"announce"`
MinAnnounce Duration `json:"min_announce"`
@ -77,6 +78,7 @@ var DefaultConfig = Config{
Freeleech: false,
Whitelist: false,
PurgeInactiveTorrents: true,
AllowIPSpoofing: true,
Announce: Duration{30 * time.Minute},
MinAnnounce: Duration{15 * time.Minute},

View file

@ -14,6 +14,7 @@
"freeleech": false,
"whitelist": false,
"purge_inactive_torrents": true,
"allow_ip_spoofing": true,
"announce": "30m",
"min_announce": "15m",

View file

@ -122,22 +122,24 @@ func (q Query) RequestedPeerCount(fallback int) int {
}
// RequestedIP returns the requested IP address from a Query.
func (q Query) RequestedIP(r *http.Request) (net.IP, error) {
if ipstr, ok := q.Params["ip"]; ok {
if ip := net.ParseIP(ipstr); ip != nil {
return ip, nil
func (q Query) RequestedIP(r *http.Request, allowSpoofing bool) (net.IP, error) {
if allowSpoofing {
if ipstr, ok := q.Params["ip"]; ok {
if ip := net.ParseIP(ipstr); ip != nil {
return ip, nil
}
}
}
if ipstr, ok := q.Params["ipv4"]; ok {
if ip := net.ParseIP(ipstr); ip != nil {
return ip, nil
if ipstr, ok := q.Params["ipv4"]; ok {
if ip := net.ParseIP(ipstr); ip != nil {
return ip, nil
}
}
}
if ipstr, ok := q.Params["ipv6"]; ok {
if ip := net.ParseIP(ipstr); ip != nil {
return ip, nil
if ipstr, ok := q.Params["ipv6"]; ok {
if ip := net.ParseIP(ipstr); ip != nil {
return ip, nil
}
}
}

View file

@ -35,7 +35,7 @@ func NewAnnounce(cfg *config.Config, r *http.Request, p httprouter.Params) (*mod
return nil, models.ErrMalformedRequest
}
ip, err := q.RequestedIP(r)
ip, err := q.RequestedIP(r, cfg.AllowIPSpoofing)
if err != nil {
return nil, models.ErrMalformedRequest
}

View file

@ -48,7 +48,7 @@ func (w *Writer) WriteAnnounce(res *models.AnnounceResponse) error {
}
}
} else if res.IPv4Peers != nil || res.IPv6Peers != nil {
dict["peers"] = peersList(res.IPv6Peers, res.IPv4Peers)
dict["peers"] = peersList(res.IPv4Peers, res.IPv6Peers)
}
bencoder := bencode.NewEncoder(w)