fix(torrent): suppress noisy UPnP AddPortMapping warnings
The anacrolix/torrent client maps the listen port on the router via UPnP/NAT-PMP for inbound peers. Many home routers reject AddPortMapping with '500 Internal Server Error' and the lib retries every lease cycle, spamming the daemon log. The rejection is harmless (downloads work over DHT + outbound peers), so wrap the log handlers and drop just that line while keeping the mapping attempts for routers that do support it.
This commit is contained in:
parent
3a8c466067
commit
2b47cb0656
1 changed files with 27 additions and 0 deletions
|
|
@ -23,6 +23,23 @@ import (
|
||||||
"golang.org/x/time/rate"
|
"golang.org/x/time/rate"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// portfwdFilterHandler wraps anacrolix/log handlers and drops the noisy
|
||||||
|
// UPnP/NAT-PMP port-mapping warnings (e.g. "error: AddPortMapping: 500 Internal
|
||||||
|
// Server Error") that home routers emit when they reject the mapping. Everything
|
||||||
|
// else passes through unchanged.
|
||||||
|
type portfwdFilterHandler struct {
|
||||||
|
inner []alog.Handler
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h portfwdFilterHandler) Handle(r alog.Record) {
|
||||||
|
if strings.Contains(r.Text(), "AddPortMapping") {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
for _, inner := range h.inner {
|
||||||
|
inner.Handle(r)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var defaultTrackers = []string{
|
var defaultTrackers = []string{
|
||||||
// Tier 1: ngosang/trackerslist "best" + newtrackon "stable"
|
// Tier 1: ngosang/trackerslist "best" + newtrackon "stable"
|
||||||
"udp://tracker.opentrackr.org:1337/announce",
|
"udp://tracker.opentrackr.org:1337/announce",
|
||||||
|
|
@ -126,6 +143,16 @@ func NewTorrentDownloader(cfg TorrentConfig) (*TorrentDownloader, error) {
|
||||||
tcfg.Seed = cfg.SeedEnabled
|
tcfg.Seed = cfg.SeedEnabled
|
||||||
tcfg.NoUpload = !cfg.SeedEnabled
|
tcfg.NoUpload = !cfg.SeedEnabled
|
||||||
tcfg.Logger = alog.Default.FilterLevel(alog.Warning)
|
tcfg.Logger = alog.Default.FilterLevel(alog.Warning)
|
||||||
|
// Drop the noisy UPnP/NAT-PMP port-mapping warnings. The library attempts to
|
||||||
|
// map the listen port on the router for inbound peers (best-effort, only
|
||||||
|
// helps on routers that support it). Many home routers reject AddPortMapping
|
||||||
|
// with "500 Internal Server Error" and the lib retries on every lease cycle,
|
||||||
|
// spamming the log. The rejection is harmless (download works over DHT +
|
||||||
|
// outbound peers), so suppress just that line while keeping the attempts for
|
||||||
|
// routers that do support it.
|
||||||
|
tcfg.Logger.SetHandlers(portfwdFilterHandler{
|
||||||
|
inner: append([]alog.Handler(nil), alog.Default.Handlers...),
|
||||||
|
})
|
||||||
|
|
||||||
// No browser-facing WebTorrent peer; daemon never seeds via WSS.
|
// No browser-facing WebTorrent peer; daemon never seeds via WSS.
|
||||||
tcfg.DisableWebtorrent = true
|
tcfg.DisableWebtorrent = true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue