diff --git a/server/go.mod b/server/go.mod index b215726..145c99a 100644 --- a/server/go.mod +++ b/server/go.mod @@ -18,7 +18,7 @@ require ( github.com/kljensen/snowball v0.8.0 github.com/pkg/browser v0.0.0-20210911075715-681adbf594b8 github.com/pkg/errors v0.9.1 - go.etcd.io/bbolt v1.3.7 + go.etcd.io/bbolt v1.3.8 golang.org/x/image v0.13.0 golang.org/x/time v0.3.0 gopkg.in/vansante/go-ffprobe.v2 v2.1.1 @@ -40,7 +40,7 @@ require ( github.com/anacrolix/upnp v0.1.3 // indirect github.com/anacrolix/utp v0.2.0 // indirect github.com/benbjohnson/immutable v0.4.3 // indirect - github.com/bits-and-blooms/bitset v1.9.0 // indirect + github.com/bits-and-blooms/bitset v1.10.0 // indirect github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 // indirect github.com/bytedance/sonic v1.10.2 // indirect github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect @@ -49,7 +49,7 @@ require ( github.com/dustin/go-humanize v1.0.1 // indirect github.com/edsrzf/mmap-go v1.1.0 // indirect github.com/frankban/quicktest v1.14.6 // indirect - github.com/gabriel-vasile/mimetype v1.4.2 // indirect + github.com/gabriel-vasile/mimetype v1.4.3 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect @@ -60,7 +60,7 @@ require ( github.com/json-iterator/go v1.1.12 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/leodido/go-urn v1.2.4 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/mschoch/smat v0.2.0 // indirect diff --git a/server/go.sum b/server/go.sum index 2b3588c..4aaabdc 100644 --- a/server/go.sum +++ b/server/go.sum @@ -88,6 +88,7 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r github.com/bits-and-blooms/bitset v1.2.0/go.mod h1:gIdJ4wp64HaoK2YrL1Q5/N7Y16edYb8uY+O0FJTyyDA= github.com/bits-and-blooms/bitset v1.9.0 h1:g1YivPG8jOtrN013Fe8OBXubkiTwvm7/vG2vXz03ANU= github.com/bits-and-blooms/bitset v1.9.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/bits-and-blooms/bitset v1.10.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bradfitz/iter v0.0.0-20140124041915-454541ec3da2/go.mod h1:PyRFw1Lt2wKX4ZVSQ2mk+PeDa1rxyObEDlApuIsUKuo= github.com/bradfitz/iter v0.0.0-20190303215204-33e6a9893b0c/go.mod h1:PyRFw1Lt2wKX4ZVSQ2mk+PeDa1rxyObEDlApuIsUKuo= github.com/bradfitz/iter v0.0.0-20191230175014-e8f45d346db8 h1:GKTyiRCL6zVf5wWaqKnf+7Qs6GbEPfd4iMOitWzXJx8= @@ -126,6 +127,8 @@ github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7z github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q7OhCmWKU= github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= +github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= +github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= github.com/gin-contrib/cors v1.4.0 h1:oJ6gwtUl3lqV0WEIwM/LxPF1QZ5qe2lGWdY2+bz7y0g= github.com/gin-contrib/cors v1.4.0/go.mod h1:bs9pNM0x/UsmHPBWT2xZz9ROh8xYjYkiURUfmBoMlcs= github.com/gin-contrib/location v0.0.2 h1:QZKh1+K/LLR4KG/61eIO3b7MLuKi8tytQhV6texLgP4= @@ -241,6 +244,8 @@ github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Ky github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= @@ -337,6 +342,7 @@ github.com/willf/bitset v1.1.10/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPy github.com/yuin/goldmark v1.4.1/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= go.etcd.io/bbolt v1.3.7 h1:j+zJOnnEjF/kyHlDDgGnVL/AIqIJPq8UoB2GSNfkUfQ= go.etcd.io/bbolt v1.3.7/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= +go.etcd.io/bbolt v1.3.8/go.mod h1:N9Mkw9X8x5fupy0IKsmuqVtoGDyxsaDlbk4Rd05IAQw= go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk= go.opencensus.io v0.22.3/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= diff --git a/server/torr/storage/torrstor/cache.go b/server/torr/storage/torrstor/cache.go index efe861d..5a16480 100644 --- a/server/torr/storage/torrstor/cache.go +++ b/server/torr/storage/torrstor/cache.go @@ -241,7 +241,17 @@ func (c *Cache) getRemPieces() []*Piece { } c.clearPriority() + c.setLoadPriority(ranges) + sort.Slice(piecesRemove, func(i, j int) bool { + return piecesRemove[i].Accessed < piecesRemove[j].Accessed + }) + + c.filled = fill + return piecesRemove +} + +func (c *Cache) setLoadPriority(ranges []Range) { c.muReaders.Lock() for r := range c.readers { if !r.isUse { @@ -253,10 +263,7 @@ func (c *Cache) getRemPieces() []*Piece { readerPos := r.getReaderPiece() readerRAHPos := r.getReaderRAHPiece() end := r.getPiecesRange().End - count := int(64 << 20 / c.pieceLength) // 64 MB window - if count > 64 { - count = 64 - } + count := settings.BTsets.ConnectionsLimit / len(c.readers) // max concurrent loading blocks limit := 0 for i := readerPos; i < end && limit < count; i++ { if !c.pieces[i].Complete { @@ -276,13 +283,6 @@ func (c *Cache) getRemPieces() []*Piece { } } c.muReaders.Unlock() - - sort.Slice(piecesRemove, func(i, j int) bool { - return piecesRemove[i].Accessed < piecesRemove[j].Accessed - }) - - c.filled = fill - return piecesRemove } func (c *Cache) isIdInFileBE(ranges []Range, id int) bool { @@ -361,3 +361,10 @@ func (c *Cache) clearPriority() { } } } + +func (c *Cache) GetCapacity() int64 { + if c == nil { + return 0 + } + return c.capacity +} diff --git a/server/torr/torrent.go b/server/torr/torrent.go index 548b16d..694602e 100644 --- a/server/torr/torrent.go +++ b/server/torr/torrent.go @@ -193,18 +193,21 @@ func (t *Torrent) progressEvent() { } func (t *Torrent) updateRA() { - t.muTorrent.Lock() - defer t.muTorrent.Unlock() - if t.Torrent != nil && t.Torrent.Info() != nil { - pieceLen := t.Torrent.Info().PieceLength - adj := pieceLen * int64(t.Torrent.Stats().ActivePeers) / int64(1+t.cache.Readers()) - if adj < pieceLen { - adj = pieceLen - //} else if adj > pieceLen*4 { - // adj = pieceLen * 4 - } - go t.cache.AdjustRA(adj) - } + // t.muTorrent.Lock() + // defer t.muTorrent.Unlock() + // if t.Torrent != nil && t.Torrent.Info() != nil { + // pieceLen := t.Torrent.Info().PieceLength + // adj := pieceLen * int64(t.Torrent.Stats().ActivePeers) / int64(1+t.cache.Readers()) + // switch { + // case adj < pieceLen: + // adj = pieceLen + // case adj > pieceLen*4: + // adj = pieceLen * 4 + // } + // go t.cache.AdjustRA(adj) + // } + adj := int64(16 << 20) // 16 MB fixed RA + go t.cache.AdjustRA(adj) } func (t *Torrent) expired() bool { diff --git a/server/version/version.go b/server/version/version.go index 4a19911..2a175d9 100644 --- a/server/version/version.go +++ b/server/version/version.go @@ -6,7 +6,7 @@ import ( // "github.com/anacrolix/torrent" ) -const Version = "MatriX.126.XO" +const Version = "MatriX.127.XO" func GetTorrentVersion() string { bi, ok := debug.ReadBuildInfo() diff --git a/server/web/api/m3u.go b/server/web/api/m3u.go index 22aa259..6952ba5 100644 --- a/server/web/api/m3u.go +++ b/server/web/api/m3u.go @@ -69,7 +69,7 @@ func playList(c *gin.Context) { name := strings.ReplaceAll(c.Param("fname"), `/`, "") // strip starting / from param if name == "" { name = tor.Name() + ".m3u" - } else { + } else if !strings.HasSuffix(strings.ToLower(name), ".m3u") && !strings.HasSuffix(strings.ToLower(name), ".m3u8") { name += ".m3u" } diff --git a/server/web/api/stream.go b/server/web/api/stream.go index 575a93b..c8fcce2 100644 --- a/server/web/api/stream.go +++ b/server/web/api/stream.go @@ -124,7 +124,7 @@ func stream(c *gin.Context) { name := strings.ReplaceAll(c.Param("fname"), `/`, "") // strip starting / from param if name == "" { name = tor.Name() + ".m3u" - } else if !strings.HasSuffix(strings.ToLower(name), ".m3u") { + } else if !strings.HasSuffix(strings.ToLower(name), ".m3u") && !strings.HasSuffix(strings.ToLower(name), ".m3u8") { name += ".m3u" } m3ulist := "#EXTM3U\n" + getM3uList(tor.Status(), utils2.GetScheme(c)+"://"+c.Request.Host, fromlast) @@ -207,8 +207,14 @@ func streamNoAuth(c *gin.Context) { // return m3u if query if m3u { + name := strings.ReplaceAll(c.Param("fname"), `/`, "") // strip starting / from param + if name == "" { + name = tor.Name() + ".m3u" + } else if !strings.HasSuffix(strings.ToLower(name), ".m3u") && !strings.HasSuffix(strings.ToLower(name), ".m3u8") { + name += ".m3u" + } m3ulist := "#EXTM3U\n" + getM3uList(tor.Status(), utils2.GetScheme(c)+"://"+c.Request.Host, fromlast) - sendM3U(c, tor.Name()+".m3u", tor.Hash().HexString(), m3ulist) + sendM3U(c, name, tor.Hash().HexString(), m3ulist) return } else // return play if query