From a2fbd0ee8017362e22f79764212d1e9b0795d5ba Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Tue, 17 May 2022 06:39:52 +0300 Subject: [PATCH 1/8] decrease timeouts and add client check on add new torrent --- server/torr/apihelper.go | 8 ++++---- server/torr/torrent.go | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 272f654..93d9ee2 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -196,12 +196,12 @@ func SetSettings(set *sets.BTSets) { sets.SetBTSets(set) log.TLogln("drop all torrents") dropAllTorrent() - time.Sleep(time.Second * 2) + time.Sleep(time.Second * 1) log.TLogln("disconect") bts.Disconnect() log.TLogln("connect") bts.Connect() - time.Sleep(time.Second * 2) + time.Sleep(time.Second * 1) log.TLogln("end set settings") } @@ -212,12 +212,12 @@ func SetDefSettings() { sets.SetDefault() log.TLogln("drop all torrents") dropAllTorrent() - time.Sleep(time.Second * 2) + time.Sleep(time.Second * 1) log.TLogln("disconect") bts.Disconnect() log.TLogln("connect") bts.Connect() - time.Sleep(time.Second * 2) + time.Sleep(time.Second * 1) log.TLogln("end set default settings") } diff --git a/server/torr/torrent.go b/server/torr/torrent.go index 535eaa1..7be01c4 100644 --- a/server/torr/torrent.go +++ b/server/torr/torrent.go @@ -50,8 +50,8 @@ type Torrent struct { } func NewTorrent(spec *torrent.TorrentSpec, bt *BTServer) (*Torrent, error) { - // TODO panic when settings sets - if bt == nil { + // https://github.com/anacrolix/torrent/issues/747 + if bt == nil || bt.client == nil { return nil, errors.New("BT client not connected") } switch settings.BTsets.RetrackersMode { From 2df81cac786d42d36d3ececfdb5c4bf1bd9b2535 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Wed, 25 May 2022 05:27:20 +0300 Subject: [PATCH 2/8] Auto detect public IPs if not provided by user adopted code from anacrolix/confluence https://github.com/anacrolix/confluence/commit/3c7a0c445dada1b5f9bdeef8ac49967e2c169688 --- server/go.mod | 1 + server/go.sum | 2 ++ server/torr/btserver.go | 17 +++++++++++++---- server/web/server.go | 4 ++-- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/go.mod b/server/go.mod index 8cb9c58..569f8b3 100644 --- a/server/go.mod +++ b/server/go.mod @@ -12,6 +12,7 @@ require ( github.com/anacrolix/dms v1.4.0 github.com/anacrolix/log v0.13.1 github.com/anacrolix/missinggo v1.3.0 + github.com/anacrolix/publicip v0.2.0 github.com/anacrolix/torrent v1.43.1 github.com/gin-contrib/cors v1.3.1 github.com/gin-contrib/location v0.0.2 diff --git a/server/go.sum b/server/go.sum index 50fe36b..b5ffe10 100644 --- a/server/go.sum +++ b/server/go.sum @@ -66,6 +66,8 @@ github.com/anacrolix/mmsg v1.0.0 h1:btC7YLjOn29aTUAExJiVUhQOuf/8rhm+/nWCMAnL3Hg= github.com/anacrolix/mmsg v1.0.0/go.mod h1:x8kRaJY/dCrY9Al0PEcj1mb/uFHwP6GCJ9fLl4thEPc= github.com/anacrolix/multiless v0.3.0 h1:5Bu0DZncjE4e06b9r1Ap2tUY4Au0NToBP5RpuEngSis= github.com/anacrolix/multiless v0.3.0/go.mod h1:TrCLEZfIDbMVfLoQt5tOoiBS/uq4y8+ojuEVVvTNPX4= +github.com/anacrolix/publicip v0.2.0 h1:n/BmRxXRlOT/wQFd6Xhu57r9uTU+Xvb9MyEkLooh3TU= +github.com/anacrolix/publicip v0.2.0/go.mod h1:67G1lVkLo8UjdEcJkwScWVTvlJ35OCDsRJoWXl/wi4g= github.com/anacrolix/stm v0.2.0/go.mod h1:zoVQRvSiGjGoTmbM0vSLIiaKjWtNPeTvXUSdJQA4hsg= github.com/anacrolix/stm v0.3.0 h1:peQncJSNJtk1YBrFbW0DLKYqll+sa0kOk8EvXRcO+wA= github.com/anacrolix/stm v0.3.0/go.mod h1:spImf/rXwiAUoYYJK1YCZeWkpaHZ3kzjGFjwK5OStfU= diff --git a/server/torr/btserver.go b/server/torr/btserver.go index bd88442..2f8d78d 100644 --- a/server/torr/btserver.go +++ b/server/torr/btserver.go @@ -1,12 +1,14 @@ package torr import ( + "context" "fmt" "log" "net" "strconv" "sync" + "github.com/anacrolix/publicip" "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/metainfo" @@ -58,7 +60,7 @@ func (bt *BTServer) Connect() error { bt.mu.Lock() defer bt.mu.Unlock() var err error - bt.configure() + bt.configure(context.TODO()) bt.client, err = torrent.NewClient(bt.config) bt.torrents = make(map[metainfo.Hash]*Torrent) InitApiHelper(bt) @@ -75,7 +77,7 @@ func (bt *BTServer) Disconnect() { } } -func (bt *BTServer) configure() { +func (bt *BTServer) configure(ctx context.Context) (err error) { blocklist, _ := utils.ReadBlockedIP() bt.config = torrent.NewDefaultClientConfig() @@ -147,7 +149,10 @@ func (bt *BTServer) configure() { } } if bt.config.PublicIp4 == nil { - bt.config.PublicIp4 = getPublicIp4() + bt.config.PublicIp4, err = publicip.Get4(ctx) + if err != nil { + log.Printf("error getting public ipv4 address: %v", err) + } } if bt.config.PublicIp4 != nil { log.Println("PublicIp4:", bt.config.PublicIp4) @@ -160,11 +165,15 @@ func (bt *BTServer) configure() { } } if bt.config.PublicIp6 == nil { - bt.config.PublicIp6 = getPublicIp6() + bt.config.PublicIp6, err = publicip.Get6(ctx) + if err != nil { + log.Printf("error getting public ipv6 address: %v", err) + } } if bt.config.PublicIp6 != nil { log.Println("PublicIp6:", bt.config.PublicIp6) } + return err } func (bt *BTServer) GetTorrent(hash torrent.InfoHash) *Torrent { diff --git a/server/web/server.go b/server/web/server.go index 1909c84..6a75da6 100644 --- a/server/web/server.go +++ b/server/web/server.go @@ -30,7 +30,7 @@ func Start(port string) { log.TLogln("Start TorrServer") ips := getLocalIps() if len(ips) > 0 { - log.TLogln("IPs:", ips) + log.TLogln("Local IPs:", ips) } err := BTS.Connect() if err != nil { @@ -102,7 +102,7 @@ func getLocalIps() []string { case *net.IPAddr: ip = v.IP } - if !ip.IsLoopback() { + if !ip.IsLoopback() && !ip.IsLinkLocalUnicast() && !ip.IsLinkLocalMulticast() { list = append(list, ip.String()) } } From 3af05667318f5d1d3888ede5e32d76b47d33f4d2 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Wed, 25 May 2022 07:47:50 +0300 Subject: [PATCH 3/8] change startup public ip params --- server/cmd/main.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/cmd/main.go b/server/cmd/main.go index 5686239..9c08831 100644 --- a/server/cmd/main.go +++ b/server/cmd/main.go @@ -32,8 +32,8 @@ type args struct { DontKill bool `arg:"-k" help:"don't kill server on signal"` UI bool `arg:"-u" help:"open torrserver page in browser"` TorrentsDir string `arg:"-t" help:"autoload torrents from dir"` - IPv4 string `arg:"-4" help:"set public IPv4 addr"` - IPv6 string `arg:"-6" help:"set public IPv6 addr"` + PubIPv4 string `arg:"-4" help:"set public IPv4 addr"` + PubIPv6 string `arg:"-6" help:"set public IPv6 addr"` } func (args) Version() string { @@ -74,12 +74,12 @@ func main() { }() } - if params.IPv4 != "" { - settings.PubIPv4 = params.IPv4 + if params.PubIPv4 != "" { + settings.PubIPv4 = params.PubIPv4 } - if params.IPv6 != "" { - settings.PubIPv6 = params.IPv6 + if params.PubIPv6 != "" { + settings.PubIPv6 = params.PubIPv6 } if params.TorrentsDir != "" { From 50c0860b9beffa64b3d616d34c8cc94827a9aff4 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Wed, 25 May 2022 10:09:00 +0300 Subject: [PATCH 4/8] add DLNA server name and debug log options to web --- server/dlna/dlna.go | 5 +++++ server/settings/btsets.go | 3 ++- .../Settings/SecondarySettingsComponent.jsx | 18 ++++++++++++++++++ web/src/components/Settings/SettingsDialog.jsx | 2 +- web/src/components/Settings/defaultSettings.js | 1 + web/src/locales/en/translation.json | 3 +++ web/src/locales/ru/translation.json | 3 +++ web/src/locales/ua/translation.json | 3 +++ 8 files changed, 36 insertions(+), 2 deletions(-) diff --git a/server/dlna/dlna.go b/server/dlna/dlna.go index 6c45aea..59a033e 100644 --- a/server/dlna/dlna.go +++ b/server/dlna/dlna.go @@ -140,6 +140,11 @@ func onBrowseMeta(path string, rootObjectPath string, host, userAgent string) (r func getDefaultFriendlyName() string { logger := log.Default.WithNames("dlna") + + if settings.BTsets.FriendlyName != "" { + return settings.BTsets.FriendlyName + } + ret := "TorrServer" userName := "" user, err := user.Current() diff --git a/server/settings/btsets.go b/server/settings/btsets.go index 68a6008..bad2116 100644 --- a/server/settings/btsets.go +++ b/server/settings/btsets.go @@ -28,7 +28,8 @@ type BTSets struct { EnableDebug bool // print logs // DLNA - EnableDLNA bool + EnableDLNA bool + FriendlyName string // BT Config EnableIPv6 bool diff --git a/web/src/components/Settings/SecondarySettingsComponent.jsx b/web/src/components/Settings/SecondarySettingsComponent.jsx index 8f977a7..56d2638 100644 --- a/web/src/components/Settings/SecondarySettingsComponent.jsx +++ b/web/src/components/Settings/SecondarySettingsComponent.jsx @@ -10,8 +10,10 @@ export default function SecondarySettingsComponent({ settings, inputForm }) { const { RetrackersMode, TorrentDisconnectTimeout, + EnableDebug, EnableDLNA, EnableIPv6, + FriendlyName, ForceEncrypt, DisableTCP, DisableUTP, @@ -139,6 +141,22 @@ export default function SecondarySettingsComponent({ settings, inputForm }) { label={t('SettingsDialog.DLNA')} labelPlacement='start' /> + + } + label={t('SettingsDialog.EnableDebug')} + labelPlacement='start' + />
{t('SettingsDialog.RetrackersMode')}