From 68019955914e830bfb8bca80d523a1548927390d Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Sat, 21 Aug 2021 10:15:11 +0300 Subject: [PATCH 01/13] fix read a head on not readed reader --- server/torr/storage/torrstor/reader.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/torr/storage/torrstor/reader.go b/server/torr/storage/torrstor/reader.go index c3113b3..b4188ba 100644 --- a/server/torr/storage/torrstor/reader.go +++ b/server/torr/storage/torrstor/reader.go @@ -94,6 +94,12 @@ func (r *Reader) Read(p []byte) (n int, err error) { } func (r *Reader) SetReadahead(length int64) { + if time.Now().Unix() > r.lastAccess+60 && r.cache != nil && len(r.cache.readers) > 1 { + //fix read a head on not readed reader + r.Reader.SetReadahead(0) + r.readahead = 0 + return + } if r.cache != nil && length > r.cache.capacity { length = r.cache.capacity } @@ -114,7 +120,7 @@ func (r *Reader) Close() { // this struct close in cache r.isClosed = true if len(r.file.Torrent().Files()) > 0 { - r.Reader.Close() + r.Reader.Close() } go r.cache.getRemPieces() } @@ -139,6 +145,7 @@ func (r *Reader) getPieceNum(offset int64) int { func (r *Reader) getOffsetRange() (int64, int64) { if time.Now().Unix() > r.lastAccess+60 && len(r.cache.readers) > 1 { + r.SetReadahead(0) return r.file.Offset(), r.file.Offset() } From 671f215ccb886a691973f5bbc6313072f2f2a14e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Sat, 21 Aug 2021 13:03:44 +0000 Subject: [PATCH 02/13] Bump github.com/gin-gonic/gin from 1.6.3 to 1.7.0 in /server Bumps [github.com/gin-gonic/gin](https://github.com/gin-gonic/gin) from 1.6.3 to 1.7.0. - [Release notes](https://github.com/gin-gonic/gin/releases) - [Changelog](https://github.com/gin-gonic/gin/blob/master/CHANGELOG.md) - [Commits](https://github.com/gin-gonic/gin/compare/v1.6.3...v1.7.0) --- updated-dependencies: - dependency-name: github.com/gin-gonic/gin dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- server/go.mod | 5 +++-- server/go.sum | 7 +++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/go.mod b/server/go.mod index f418d79..e880da5 100644 --- a/server/go.mod +++ b/server/go.mod @@ -12,7 +12,7 @@ require ( github.com/anacrolix/torrent v1.30.3 github.com/gin-contrib/cors v1.3.1 github.com/gin-contrib/location v0.0.2 - github.com/gin-gonic/gin v1.6.3 + github.com/gin-gonic/gin v1.7.0 github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 github.com/pkg/errors v0.9.1 go.etcd.io/bbolt v1.3.6 @@ -42,7 +42,7 @@ require ( github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.13.0 // indirect github.com/go-playground/universal-translator v0.17.0 // indirect - github.com/go-playground/validator/v10 v10.2.0 // indirect + github.com/go-playground/validator/v10 v10.4.1 // indirect github.com/golang/protobuf v1.4.3 // indirect github.com/google/btree v1.0.1 // indirect github.com/huandu/xstrings v1.3.2 // indirect @@ -58,6 +58,7 @@ require ( github.com/ugorji/go/codec v1.1.7 // indirect github.com/willf/bitset v1.1.11 // indirect github.com/willf/bloom v2.0.3+incompatible // indirect + golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b // indirect golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e // indirect diff --git a/server/go.sum b/server/go.sum index 09389ef..7ee5009 100644 --- a/server/go.sum +++ b/server/go.sum @@ -231,8 +231,9 @@ github.com/gin-contrib/location v0.0.2/go.mod h1:NGoidiRlf0BlA/VKSVp+g3cuSMeTmip github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= github.com/gin-gonic/gin v1.5.0/go.mod h1:Nd6IXA8m5kNZdNEHMBd93KT+mdY3+bewLgRvmCsR2Do= -github.com/gin-gonic/gin v1.6.3 h1:ahKqKTFpO5KTPHxWZjEdPScmYaGtLo8Y4DMHoEsnp14= github.com/gin-gonic/gin v1.6.3/go.mod h1:75u5sXoLsGZoRN5Sgbi1eraJ4GU3++wFwWzhwvtwp4M= +github.com/gin-gonic/gin v1.7.0 h1:jGB9xAJQ12AIGNB4HguylppmDK1Am9ppF7XnGXXJuoU= +github.com/gin-gonic/gin v1.7.0/go.mod h1:jD2toBW3GZUr5UMcdrwQA10I7RuaFOl/SGeDjXkfUtY= github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0= github.com/glycerine/go-unsnap-stream v0.0.0-20180323001048-9f0cb55181dd/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= github.com/glycerine/go-unsnap-stream v0.0.0-20181221182339-f9677308dec2/go.mod h1:/20jfyN9Y5QPEAprSgKAUr+glWDY39ZiUEAYOEv5dsE= @@ -256,8 +257,9 @@ github.com/go-playground/locales v0.13.0/go.mod h1:taPMhCMXrRLJO55olJkUXHZBHCxTM github.com/go-playground/universal-translator v0.16.0/go.mod h1:1AnU7NaIRDWWzGEKwgtJRd2xk99HeFyHw3yid4rvQIY= github.com/go-playground/universal-translator v0.17.0 h1:icxd5fm+REJzpZx7ZfpaD876Lmtgy7VtROAbHHXk8no= github.com/go-playground/universal-translator v0.17.0/go.mod h1:UkSxE5sNxxRwHyU+Scu5vgOQjsIJAF8j9muTVoKLVtA= -github.com/go-playground/validator/v10 v10.2.0 h1:KgJ0snyC2R9VXYN2rneOtQcw5aHQB1Vv0sFl1UcHBOY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= +github.com/go-playground/validator/v10 v10.4.1 h1:pH2c5ADXtd66mxoE0Zm9SUhxE20r7aM3F26W0hOn+GE= +github.com/go-playground/validator/v10 v10.4.1/go.mod h1:nlOn6nFhuKACm19sB/8EGNn9GlaMV7XkbRSipzJ0Ii4= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= @@ -712,6 +714,7 @@ golang.org/x/crypto v0.0.0-20200709230013-948cd5f35899/go.mod h1:LzIPMQfyMNhhGPh golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b h1:7mWr3k41Qtv8XlltBkDkl8LoP3mpSgBW8BUoxtEdbXg= golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= From a0dffeb258d7bc413598acb484ec7504b6f15874 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Sun, 22 Aug 2021 09:42:47 +0300 Subject: [PATCH 03/13] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ba17256..728f639 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,9 @@ # Test binary, build with `go test -c` *.test +# Mac stuff +.DS_Store + # Output of the go coverage tool, specifically when used with LiteIDE *.out From 7da927024129ad1de010e70c51749d4981d242b9 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Sun, 22 Aug 2021 10:56:51 +0300 Subject: [PATCH 04/13] update reader and wait timeout --- server/go.mod | 2 +- server/go.sum | 4 ++-- server/torr/torrent.go | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/server/go.mod b/server/go.mod index e880da5..f244bce 100644 --- a/server/go.mod +++ b/server/go.mod @@ -2,7 +2,7 @@ module server go 1.17 -replace github.com/anacrolix/torrent v1.30.3 => github.com/tsynik/torrent v1.2.7-0.20210821095616-85838c0c0326 +replace github.com/anacrolix/torrent v1.30.3 => github.com/tsynik/torrent v1.2.7-0.20210822073550-ce6a587148fe exclude github.com/willf/bitset v1.2.0 diff --git a/server/go.sum b/server/go.sum index 7ee5009..9ae04b5 100644 --- a/server/go.sum +++ b/server/go.sum @@ -656,8 +656,8 @@ github.com/tinylib/msgp v1.1.1/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDW github.com/tinylib/msgp v1.1.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tsynik/torrent v1.2.7-0.20210821095616-85838c0c0326 h1:hF9Xtv58WoBJ9Sls0lO/s6/Y41VXpLOQJ7UX2AiApgk= -github.com/tsynik/torrent v1.2.7-0.20210821095616-85838c0c0326/go.mod h1:6qxhn+CsyQ9b35j3ETXGDMLh4z2vTTutGx3ZnllNcCo= +github.com/tsynik/torrent v1.2.7-0.20210822073550-ce6a587148fe h1:sTueflLuNKGBsoLz0RFAqaDb9BMxceIXY8Su5jVht8M= +github.com/tsynik/torrent v1.2.7-0.20210822073550-ce6a587148fe/go.mod h1:6qxhn+CsyQ9b35j3ETXGDMLh4z2vTTutGx3ZnllNcCo= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= diff --git a/server/torr/torrent.go b/server/torr/torrent.go index b7167db..535eaa1 100644 --- a/server/torr/torrent.go +++ b/server/torr/torrent.go @@ -100,8 +100,8 @@ func (t *Torrent) WaitInfo() bool { return false } - // Close torrent if not info while 10 minutes - tm := time.NewTimer(time.Minute * 10) + // Close torrent if not info while 5 minutes + tm := time.NewTimer(time.Minute * 5) select { case <-t.Torrent.GotInfo(): From 1df58691e6a7fac159072aa8e49584773a5fb544 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Sun, 22 Aug 2021 11:18:52 +0300 Subject: [PATCH 05/13] fix rewind and update wrappers --- server/go.mod | 2 +- server/go.sum | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/go.mod b/server/go.mod index f244bce..58a0f07 100644 --- a/server/go.mod +++ b/server/go.mod @@ -2,7 +2,7 @@ module server go 1.17 -replace github.com/anacrolix/torrent v1.30.3 => github.com/tsynik/torrent v1.2.7-0.20210822073550-ce6a587148fe +replace github.com/anacrolix/torrent v1.30.3 => github.com/tsynik/torrent v1.2.7-0.20210822081106-f50bd5065818 exclude github.com/willf/bitset v1.2.0 diff --git a/server/go.sum b/server/go.sum index 9ae04b5..29200e8 100644 --- a/server/go.sum +++ b/server/go.sum @@ -656,8 +656,8 @@ github.com/tinylib/msgp v1.1.1/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDW github.com/tinylib/msgp v1.1.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tsynik/torrent v1.2.7-0.20210822073550-ce6a587148fe h1:sTueflLuNKGBsoLz0RFAqaDb9BMxceIXY8Su5jVht8M= -github.com/tsynik/torrent v1.2.7-0.20210822073550-ce6a587148fe/go.mod h1:6qxhn+CsyQ9b35j3ETXGDMLh4z2vTTutGx3ZnllNcCo= +github.com/tsynik/torrent v1.2.7-0.20210822081106-f50bd5065818 h1:8FwSi/4QLjNRNwFtqx2YX2z8kZlMC+n3oe6PcUKorw8= +github.com/tsynik/torrent v1.2.7-0.20210822081106-f50bd5065818/go.mod h1:6qxhn+CsyQ9b35j3ETXGDMLh4z2vTTutGx3ZnllNcCo= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= From 56fe6725719a0109e3b0759d72b5092c7cde1512 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Sun, 22 Aug 2021 12:04:39 +0300 Subject: [PATCH 06/13] add mutex on api --- server/torr/apihelper.go | 46 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 1a46ef3..20a1089 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -1,11 +1,13 @@ package torr import ( + "fmt" "io" "io/ioutil" "os" "path/filepath" "sort" + "sync" "time" "github.com/anacrolix/torrent" @@ -16,7 +18,8 @@ import ( ) var ( - bts *BTServer + bts *BTServer + lockApi sync.Mutex ) func InitApiHelper(bt *BTServer) { @@ -24,6 +27,8 @@ func InitApiHelper(bt *BTServer) { } func LoadTorrent(tor *Torrent) *Torrent { + lockApi.Lock() + defer lockApi.Unlock() if tor.TorrentSpec == nil { return nil } @@ -41,6 +46,8 @@ func LoadTorrent(tor *Torrent) *Torrent { } func AddTorrent(spec *torrent.TorrentSpec, title, poster string, data string) (*Torrent, error) { + lockApi.Lock() + defer lockApi.Unlock() torr, err := NewTorrent(spec, bts) if err != nil { log.TLogln("error add torrent:", err) @@ -80,6 +87,8 @@ func SaveTorrentToDB(torr *Torrent) { } func GetTorrent(hashHex string) *Torrent { + lockApi.Lock() + defer lockApi.Unlock() hash := metainfo.NewHashFromHex(hashHex) tor := bts.GetTorrent(hash) if tor != nil { @@ -91,6 +100,9 @@ func GetTorrent(hashHex string) *Torrent { if tr != nil { tor = tr go func() { + lockApi.Lock() + defer lockApi.Unlock() + fmt.Println("Add torrent") tr, _ := NewTorrent(tor.TorrentSpec, bts) if tr != nil { tr.Title = tor.Title @@ -106,6 +118,9 @@ func GetTorrent(hashHex string) *Torrent { } func SetTorrent(hashHex, title, poster, data string) *Torrent { + lockApi.Lock() + defer lockApi.Unlock() + hash := metainfo.NewHashFromHex(hashHex) torr := bts.GetTorrent(hash) torrDb := GetTorrentDB(hash) @@ -141,6 +156,8 @@ func SetTorrent(hashHex, title, poster, data string) *Torrent { } func RemTorrent(hashHex string) { + lockApi.Lock() + defer lockApi.Unlock() hash := metainfo.NewHashFromHex(hashHex) if sets.BTsets.UseDisk && hashHex != "" && hashHex != "/" { name := filepath.Join(sets.BTsets.TorrentsSavePath, hashHex) @@ -158,6 +175,8 @@ func RemTorrent(hashHex string) { } func ListTorrent() []*Torrent { + lockApi.Lock() + defer lockApi.Unlock() btlist := bts.ListTorrents() dblist := ListTorrentsDB() @@ -184,6 +203,8 @@ func ListTorrent() []*Torrent { } func DropTorrent(hashHex string) { + lockApi.Lock() + defer lockApi.Unlock() hash := metainfo.NewHashFromHex(hashHex) bts.RemoveTorrent(hash) } @@ -192,21 +213,42 @@ func SetSettings(set *sets.BTSets) { if sets.ReadOnly { return } + lockApi.Lock() + defer lockApi.Unlock() + fmt.Println("drop all") + dropAllTorrent() + time.Sleep(time.Second * 2) + fmt.Println("disconect") bts.Disconnect() sets.SetBTSets(set) + fmt.Println("connect") bts.Connect() + fmt.Println("end set settings") } func SetDefSettings() { if sets.ReadOnly { return } + lockApi.Lock() + defer lockApi.Unlock() + dropAllTorrent() bts.Disconnect() sets.SetDefault() bts.Connect() + time.Sleep(time.Second * 5) +} + +func dropAllTorrent() { + for _, torr := range bts.torrents { + torr.drop() + <-torr.closed + } } func Shutdown() { + lockApi.Lock() + defer lockApi.Unlock() bts.Disconnect() sets.CloseDB() log.TLogln("Received shutdown. Quit") @@ -218,6 +260,8 @@ func WriteStatus(w io.Writer) { } func Preload(torr *Torrent, index int) { + lockApi.Lock() + lockApi.Unlock() cache := float32(sets.BTsets.CacheSize) preload := float32(sets.BTsets.PreloadCache) size := int64((cache / 100.0) * preload) From f8014e98537103e21c1b5c9541229641b6f78505 Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Sun, 22 Aug 2021 18:55:28 +0300 Subject: [PATCH 07/13] hope finally fix rewind --- server/go.mod | 2 +- server/go.sum | 4 ++-- server/torr/apihelper.go | 11 +++++------ server/torr/storage/torrstor/cache.go | 7 ++++--- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/server/go.mod b/server/go.mod index 58a0f07..14185ab 100644 --- a/server/go.mod +++ b/server/go.mod @@ -2,7 +2,7 @@ module server go 1.17 -replace github.com/anacrolix/torrent v1.30.3 => github.com/tsynik/torrent v1.2.7-0.20210822081106-f50bd5065818 +replace github.com/anacrolix/torrent v1.30.3 => github.com/tsynik/torrent v1.2.7-0.20210822152206-0c6be3586d70 exclude github.com/willf/bitset v1.2.0 diff --git a/server/go.sum b/server/go.sum index 29200e8..27b9c09 100644 --- a/server/go.sum +++ b/server/go.sum @@ -656,8 +656,8 @@ github.com/tinylib/msgp v1.1.1/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDW github.com/tinylib/msgp v1.1.2/go.mod h1:+d+yLhGm8mzTaHzB+wgMYrodPfmZrzkirds8fDWklFE= github.com/tinylib/msgp v1.1.5/go.mod h1:eQsjooMTnV42mHu917E26IogZ2930nFyBQdofk10Udg= github.com/tmc/grpc-websocket-proxy v0.0.0-20170815181823-89b8d40f7ca8/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U= -github.com/tsynik/torrent v1.2.7-0.20210822081106-f50bd5065818 h1:8FwSi/4QLjNRNwFtqx2YX2z8kZlMC+n3oe6PcUKorw8= -github.com/tsynik/torrent v1.2.7-0.20210822081106-f50bd5065818/go.mod h1:6qxhn+CsyQ9b35j3ETXGDMLh4z2vTTutGx3ZnllNcCo= +github.com/tsynik/torrent v1.2.7-0.20210822152206-0c6be3586d70 h1:zcj/875ut7qO4xSePJHWPjlYJzaSKtXngythxng8glo= +github.com/tsynik/torrent v1.2.7-0.20210822152206-0c6be3586d70/go.mod h1:6qxhn+CsyQ9b35j3ETXGDMLh4z2vTTutGx3ZnllNcCo= github.com/ttacon/chalk v0.0.0-20160626202418-22c06c80ed31/go.mod h1:onvgF043R+lC5RZ8IT9rBXDaEDnpnw/Cl+HFiw+v/7Q= github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c/go.mod h1:hzIxponao9Kjc7aWznkXaL4U4TWaDSs8zcsY4Ka08nM= github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo= diff --git a/server/torr/apihelper.go b/server/torr/apihelper.go index 20a1089..7752654 100644 --- a/server/torr/apihelper.go +++ b/server/torr/apihelper.go @@ -1,7 +1,6 @@ package torr import ( - "fmt" "io" "io/ioutil" "os" @@ -102,7 +101,7 @@ func GetTorrent(hashHex string) *Torrent { go func() { lockApi.Lock() defer lockApi.Unlock() - fmt.Println("Add torrent") + log.TLogln("Add torrent") tr, _ := NewTorrent(tor.TorrentSpec, bts) if tr != nil { tr.Title = tor.Title @@ -215,15 +214,15 @@ func SetSettings(set *sets.BTSets) { } lockApi.Lock() defer lockApi.Unlock() - fmt.Println("drop all") + log.TLogln("drop all") dropAllTorrent() time.Sleep(time.Second * 2) - fmt.Println("disconect") + log.TLogln("disconect") bts.Disconnect() sets.SetBTSets(set) - fmt.Println("connect") + log.TLogln("connect") bts.Connect() - fmt.Println("end set settings") + log.TLogln("end set settings") } func SetDefSettings() { diff --git a/server/torr/storage/torrstor/cache.go b/server/torr/storage/torrstor/cache.go index 4620798..a2522f9 100644 --- a/server/torr/storage/torrstor/cache.go +++ b/server/torr/storage/torrstor/cache.go @@ -199,6 +199,7 @@ func (c *Cache) cleanPieces() { rems := (c.filled-c.capacity)/c.pieceLength + 1 for _, p := range remPieces { c.removePiece(p) + c.torrent.Piece(p.Id).UpdateCompletion() rems-- if rems <= 0 { utils.FreeOSMemGC() @@ -239,7 +240,7 @@ func (c *Cache) getRemPieces() []*Piece { } } - c.updatePriority() + c.clearPriority() c.muReaders.Lock() for r, _ := range c.readers { @@ -328,10 +329,10 @@ func (c *Cache) CloseReader(r *Reader) { r.Close() delete(r.cache.readers, r) r.cache.muReaders.Unlock() - go c.updatePriority() + go c.clearPriority() } -func (c *Cache) updatePriority() { +func (c *Cache) clearPriority() { time.Sleep(time.Second) ranges := make([]Range, 0) c.muReaders.Lock() From 001a3c292b079d492821e6755cf1d495ffbf377e Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Sun, 22 Aug 2021 19:37:47 +0300 Subject: [PATCH 08/13] safe UpdateCompletion() on Release() --- server/torr/storage/torrstor/cache.go | 2 +- server/torr/storage/torrstor/diskpiece.go | 2 +- server/torr/storage/torrstor/mempiece.go | 2 +- server/torr/storage/torrstor/piece.go | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/server/torr/storage/torrstor/cache.go b/server/torr/storage/torrstor/cache.go index a2522f9..ccdbd0e 100644 --- a/server/torr/storage/torrstor/cache.go +++ b/server/torr/storage/torrstor/cache.go @@ -199,7 +199,7 @@ func (c *Cache) cleanPieces() { rems := (c.filled-c.capacity)/c.pieceLength + 1 for _, p := range remPieces { c.removePiece(p) - c.torrent.Piece(p.Id).UpdateCompletion() + //c.torrent.Piece(p.Id).UpdateCompletion() // safe call in Piece.Release() rems-- if rems <= 0 { utils.FreeOSMemGC() diff --git a/server/torr/storage/torrstor/diskpiece.go b/server/torr/storage/torrstor/diskpiece.go index f716fe7..77e602b 100644 --- a/server/torr/storage/torrstor/diskpiece.go +++ b/server/torr/storage/torrstor/diskpiece.go @@ -85,5 +85,5 @@ func (p *DiskPiece) Release() { os.Remove(p.name) - p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) + //p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) } diff --git a/server/torr/storage/torrstor/mempiece.go b/server/torr/storage/torrstor/mempiece.go index 6b69724..edefb9f 100644 --- a/server/torr/storage/torrstor/mempiece.go +++ b/server/torr/storage/torrstor/mempiece.go @@ -70,5 +70,5 @@ func (p *MemPiece) Release() { p.piece.Size = 0 p.piece.Complete = false - p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) + //p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) } diff --git a/server/torr/storage/torrstor/piece.go b/server/torr/storage/torrstor/piece.go index dc8c643..ace950c 100644 --- a/server/torr/storage/torrstor/piece.go +++ b/server/torr/storage/torrstor/piece.go @@ -73,9 +73,9 @@ func (p *Piece) Release() { } else { p.dPiece.Release() } -// if !p.cache.isClosed { -// p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone) -// // fix remove pieces hash -// p.cache.torrent.Piece(p.Id).UpdateCompletion() -// } + if !p.cache.isClosed { + p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone) + // fix remove pieces hash and rewind + p.cache.torrent.Piece(p.Id).UpdateCompletion() + } } From 3011ec55094514240d8396918cd8057ffab870fa Mon Sep 17 00:00:00 2001 From: nikk gitanes Date: Sun, 22 Aug 2021 19:58:21 +0300 Subject: [PATCH 09/13] fix last commit --- server/torr/storage/torrstor/diskpiece.go | 3 ++- server/torr/storage/torrstor/mempiece.go | 3 ++- server/torr/storage/torrstor/piece.go | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/server/torr/storage/torrstor/diskpiece.go b/server/torr/storage/torrstor/diskpiece.go index 77e602b..fe29bd3 100644 --- a/server/torr/storage/torrstor/diskpiece.go +++ b/server/torr/storage/torrstor/diskpiece.go @@ -85,5 +85,6 @@ func (p *DiskPiece) Release() { os.Remove(p.name) - //p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) + p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) + p.piece.cache.torrent.Piece(p.piece.Id).UpdateCompletion() } diff --git a/server/torr/storage/torrstor/mempiece.go b/server/torr/storage/torrstor/mempiece.go index edefb9f..3fdc873 100644 --- a/server/torr/storage/torrstor/mempiece.go +++ b/server/torr/storage/torrstor/mempiece.go @@ -70,5 +70,6 @@ func (p *MemPiece) Release() { p.piece.Size = 0 p.piece.Complete = false - //p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) + p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) + p.piece.cache.torrent.Piece(p.piece.Id).UpdateCompletion() } diff --git a/server/torr/storage/torrstor/piece.go b/server/torr/storage/torrstor/piece.go index ace950c..dc8c643 100644 --- a/server/torr/storage/torrstor/piece.go +++ b/server/torr/storage/torrstor/piece.go @@ -73,9 +73,9 @@ func (p *Piece) Release() { } else { p.dPiece.Release() } - if !p.cache.isClosed { - p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone) - // fix remove pieces hash and rewind - p.cache.torrent.Piece(p.Id).UpdateCompletion() - } +// if !p.cache.isClosed { +// p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone) +// // fix remove pieces hash +// p.cache.torrent.Piece(p.Id).UpdateCompletion() +// } } From e648d35168879660b0643923d74a06e0af204640 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Sun, 22 Aug 2021 20:41:17 +0300 Subject: [PATCH 10/13] refactor --- server/torr/storage/torrstor/diskpiece.go | 5 ----- server/torr/storage/torrstor/mempiece.go | 5 ----- server/torr/storage/torrstor/piece.go | 10 +++++----- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/server/torr/storage/torrstor/diskpiece.go b/server/torr/storage/torrstor/diskpiece.go index fe29bd3..b20de74 100644 --- a/server/torr/storage/torrstor/diskpiece.go +++ b/server/torr/storage/torrstor/diskpiece.go @@ -8,8 +8,6 @@ import ( "sync" "time" - "github.com/anacrolix/torrent" - "server/log" "server/settings" ) @@ -84,7 +82,4 @@ func (p *DiskPiece) Release() { p.piece.Complete = false os.Remove(p.name) - - p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) - p.piece.cache.torrent.Piece(p.piece.Id).UpdateCompletion() } diff --git a/server/torr/storage/torrstor/mempiece.go b/server/torr/storage/torrstor/mempiece.go index 3fdc873..acb3074 100644 --- a/server/torr/storage/torrstor/mempiece.go +++ b/server/torr/storage/torrstor/mempiece.go @@ -4,8 +4,6 @@ import ( "io" "sync" "time" - - "github.com/anacrolix/torrent" ) type MemPiece struct { @@ -69,7 +67,4 @@ func (p *MemPiece) Release() { } p.piece.Size = 0 p.piece.Complete = false - - p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone) - p.piece.cache.torrent.Piece(p.piece.Id).UpdateCompletion() } diff --git a/server/torr/storage/torrstor/piece.go b/server/torr/storage/torrstor/piece.go index dc8c643..f91aac4 100644 --- a/server/torr/storage/torrstor/piece.go +++ b/server/torr/storage/torrstor/piece.go @@ -1,6 +1,7 @@ package torrstor import ( + "github.com/anacrolix/torrent" "github.com/anacrolix/torrent/storage" "server/settings" ) @@ -73,9 +74,8 @@ func (p *Piece) Release() { } else { p.dPiece.Release() } -// if !p.cache.isClosed { -// p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone) -// // fix remove pieces hash -// p.cache.torrent.Piece(p.Id).UpdateCompletion() -// } + if !p.cache.isClosed { + p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone) + p.cache.torrent.Piece(p.Id).UpdateCompletion() + } } From 941bcb670a69cb3cd67ada8853c4c9bd32dc7b7b Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Sun, 22 Aug 2021 20:41:28 +0300 Subject: [PATCH 11/13] remove comment --- server/torr/storage/torrstor/cache.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/torr/storage/torrstor/cache.go b/server/torr/storage/torrstor/cache.go index ccdbd0e..e887841 100644 --- a/server/torr/storage/torrstor/cache.go +++ b/server/torr/storage/torrstor/cache.go @@ -199,7 +199,6 @@ func (c *Cache) cleanPieces() { rems := (c.filled-c.capacity)/c.pieceLength + 1 for _, p := range remPieces { c.removePiece(p) - //c.torrent.Piece(p.Id).UpdateCompletion() // safe call in Piece.Release() rems-- if rems <= 0 { utils.FreeOSMemGC() From 9c22a4160d31f654bdf28c304c2e782a173da5b9 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Sun, 22 Aug 2021 20:43:56 +0300 Subject: [PATCH 12/13] MatriX.104 --- server/version/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/version/version.go b/server/version/version.go index 88e6dc9..f75295b 100644 --- a/server/version/version.go +++ b/server/version/version.go @@ -1,3 +1,3 @@ package version -const Version = "MatriX.103.DHT" +const Version = "MatriX.104" From 51e02b1b94ab7842e1e23a72da7d250b0d904b77 Mon Sep 17 00:00:00 2001 From: YouROK <8yourok8@mail.ru> Date: Sun, 22 Aug 2021 20:45:46 +0300 Subject: [PATCH 13/13] docker golang 1.17.0 --- docker-all.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-all.sh b/docker-all.sh index 882a0f4..37a26d5 100755 --- a/docker-all.sh +++ b/docker-all.sh @@ -6,5 +6,5 @@ ROOT=${PWD} echo "Build web" go run gen_web.go -sudo docker run --rm -v "$PWD":/usr/src/torr -v ~/go/pkg/mod:/go/pkg/mod -w /usr/src/torr golang:1.16.7-stretch ./build-all.sh +sudo docker run --rm -v "$PWD":/usr/src/torr -v ~/go/pkg/mod:/go/pkg/mod -w /usr/src/torr golang:1.17.0-stretch ./build-all.sh sudo chmod 0777 ./dist/* \ No newline at end of file