Files
mochi/frontend/options.go
Lawrence, Rendall 96653c45a3 add filter_private_ips option to discard private IPs.
Might be used when tracker is behind reverse proxy and one of provided
addresses in `real_ip_header` is private/local address.

Additional changes:

* check if provided address is not multicast/broadcast
* configure `http.Server.ReadHeaderTimeout` with `http.ReadTimeout` to mitigate Slowloris
* update dependencies
* minor docs fixes
2022-07-23 15:49:22 +03:00

57 lines
1.7 KiB
Go

package frontend
import "github.com/sot-tech/mochi/pkg/log"
var logger = log.NewLogger("frontend configurator")
// ParseOptions is the configuration used to parse an Announce Request.
//
// If AllowIPSpoofing is true, IPs provided via params will be used.
type ParseOptions struct {
AllowIPSpoofing bool `cfg:"allow_ip_spoofing"`
FilterPrivateIPs bool `cfg:"filter_private_ips"`
MaxNumWant uint32 `cfg:"max_numwant"`
DefaultNumWant uint32 `cfg:"default_numwant"`
MaxScrapeInfoHashes uint32 `cfg:"max_scrape_infohashes"`
}
// Validate sanity checks values set in a config and returns a new config with
// default values replacing anything that is invalid.
func (op ParseOptions) Validate() ParseOptions {
valid := op
if op.MaxNumWant <= 0 {
valid.MaxNumWant = defaultMaxNumWant
logger.Warn().
Str("name", "MaxNumWant").
Uint32("provided", op.MaxNumWant).
Uint32("default", valid.MaxNumWant).
Msg("falling back to default configuration")
}
if op.DefaultNumWant <= 0 {
valid.DefaultNumWant = defaultDefaultNumWant
logger.Warn().
Str("name", "DefaultNumWant").
Uint32("provided", op.DefaultNumWant).
Uint32("default", valid.DefaultNumWant).
Msg("falling back to default configuration")
}
if op.MaxScrapeInfoHashes <= 0 {
valid.MaxScrapeInfoHashes = defaultMaxScrapeInfoHashes
logger.Warn().
Str("name", "MaxScrapeInfoHashes").
Uint32("provided", op.MaxScrapeInfoHashes).
Uint32("default", valid.MaxScrapeInfoHashes).
Msg("falling back to default configuration")
}
return valid
}
// Default parser config constants.
const (
defaultMaxNumWant = 100
defaultDefaultNumWant = 50
defaultMaxScrapeInfoHashes = 50
)