mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 13:36:09 +05:00
migrate to old gotorrent
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/anacrolix/torrent"
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
|
||||
"server/log"
|
||||
sets "server/settings"
|
||||
)
|
||||
|
||||
@@ -3,10 +3,10 @@ package torr
|
||||
import (
|
||||
"log"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/torrent"
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
|
||||
"server/settings"
|
||||
"server/torr/storage/torrstor"
|
||||
"server/torr/utils"
|
||||
@@ -78,25 +78,29 @@ func (bt *BTServer) configure() {
|
||||
bt.config.HTTPUserAgent = userAgent
|
||||
bt.config.ExtendedHandshakeClientVersion = cliVers
|
||||
bt.config.EstablishedConnsPerTorrent = settings.BTsets.ConnectionsLimit
|
||||
bt.config.UpnpID = "YouROK/TorrServer"
|
||||
// bt.config.UpnpID = "YouROK/TorrServer"
|
||||
|
||||
//bt.config.DropMutuallyCompletePeers = true
|
||||
//bt.config.DropDuplicatePeerIds = true
|
||||
|
||||
// Encryption/Obfuscation
|
||||
bt.config.HeaderObfuscationPolicy = torrent.HeaderObfuscationPolicy{
|
||||
RequirePreferred: settings.BTsets.ForceEncrypt,
|
||||
Preferred: true,
|
||||
// bt.config.HeaderObfuscationPolicy = torrent.HeaderObfuscationPolicy{
|
||||
// RequirePreferred: settings.BTsets.ForceEncrypt,
|
||||
// Preferred: true,
|
||||
// }
|
||||
|
||||
bt.config.EncryptionPolicy = torrent.EncryptionPolicy{
|
||||
ForceEncryption: settings.BTsets.ForceEncrypt,
|
||||
}
|
||||
|
||||
switch settings.BTsets.Strategy {
|
||||
case 1: // RequestStrategyFuzzing
|
||||
bt.config.DefaultRequestStrategy = torrent.RequestStrategyFuzzing()
|
||||
case 2: // RequestStrategyFastest
|
||||
bt.config.DefaultRequestStrategy = torrent.RequestStrategyFastest()
|
||||
default: // RequestStrategyDuplicateRequestTimeout
|
||||
bt.config.DefaultRequestStrategy = torrent.RequestStrategyDuplicateRequestTimeout(5 * time.Second)
|
||||
}
|
||||
// switch settings.BTsets.Strategy {
|
||||
// case 1: // RequestStrategyFuzzing
|
||||
// bt.config.DefaultRequestStrategy = torrent.RequestStrategyFuzzing()
|
||||
// case 2: // RequestStrategyFastest
|
||||
// bt.config.DefaultRequestStrategy = torrent.RequestStrategyFastest()
|
||||
// default: // RequestStrategyDuplicateRequestTimeout
|
||||
// bt.config.DefaultRequestStrategy = torrent.RequestStrategyDuplicateRequestTimeout(5 * time.Second)
|
||||
// }
|
||||
|
||||
if settings.BTsets.DhtConnectionLimit > 0 {
|
||||
bt.config.ConnTracker.SetMaxEntries(settings.BTsets.DhtConnectionLimit)
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/anacrolix/torrent"
|
||||
|
||||
"server/log"
|
||||
"server/settings"
|
||||
"server/torr/storage/state"
|
||||
@@ -193,12 +194,9 @@ func (c *Cache) getRemPieces() []*Piece {
|
||||
fill += p.Size
|
||||
}
|
||||
piece := c.torrent.Piece(id)
|
||||
state := piece.State()
|
||||
state := c.torrent.PieceState(id)
|
||||
if len(ranges) > 0 {
|
||||
if !inRanges(ranges, id) {
|
||||
if state.Priority != torrent.PiecePriorityNone {
|
||||
piece.SetPriority(torrent.PiecePriorityNone)
|
||||
}
|
||||
if p.Size > 0 {
|
||||
piecesRemove = append(piecesRemove, p)
|
||||
}
|
||||
@@ -207,10 +205,6 @@ func (c *Cache) getRemPieces() []*Piece {
|
||||
piece.SetPriority(torrent.PiecePriorityNormal)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if state.Priority != torrent.PiecePriorityNone {
|
||||
piece.SetPriority(torrent.PiecePriorityNone)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,9 +98,5 @@ func (p *Piece) Release() {
|
||||
p.Size = 0
|
||||
p.complete = false
|
||||
|
||||
//Костыль чтобы двиг понял что куска нет, иногда загружает его по новый хз почему
|
||||
pce := p.cache.torrent.Piece(p.Id)
|
||||
pce.SetPriority(torrent.PiecePriorityNone)
|
||||
pce.UpdateCompletion()
|
||||
pce.SetPriority(torrent.PiecePriorityNone)
|
||||
p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone)
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/anacrolix/torrent"
|
||||
|
||||
"server/log"
|
||||
"server/settings"
|
||||
)
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/anacrolix/missinggo/httptoo"
|
||||
"github.com/anacrolix/torrent"
|
||||
|
||||
sets "server/settings"
|
||||
"server/torr/state"
|
||||
)
|
||||
|
||||
@@ -300,9 +300,9 @@ func (t *Torrent) Preload(index int, size int64) {
|
||||
isComplete := true
|
||||
if readerPieceBefore >= pieceFileStart {
|
||||
for i := pieceFileStart; i < readerPieceBefore; i++ {
|
||||
if !t.Piece(i).State().Complete {
|
||||
if !t.PieceState(i).Complete {
|
||||
isComplete = false
|
||||
if t.Piece(i).State().Priority == torrent.PiecePriorityNone {
|
||||
if t.PieceState(i).Priority == torrent.PiecePriorityNone {
|
||||
t.Piece(i).SetPriority(torrent.PiecePriorityNormal)
|
||||
}
|
||||
}
|
||||
@@ -310,9 +310,9 @@ func (t *Torrent) Preload(index int, size int64) {
|
||||
}
|
||||
if readerPieceAfter <= pieceFileEnd {
|
||||
for i := readerPieceAfter; i <= pieceFileEnd; i++ {
|
||||
if !t.Piece(i).State().Complete {
|
||||
if !t.PieceState(i).Complete {
|
||||
isComplete = false
|
||||
if t.Piece(i).State().Priority == torrent.PiecePriorityNone {
|
||||
if t.PieceState(i).Priority == torrent.PiecePriorityNone {
|
||||
t.Piece(i).SetPriority(torrent.PiecePriorityNormal)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ func ParseLink(link string) (*torrent.TorrentSpec, error) {
|
||||
}
|
||||
|
||||
func fromMagnet(link string) (*torrent.TorrentSpec, error) {
|
||||
mag, err := metainfo.ParseMagnetUri(link)
|
||||
mag, err := metainfo.ParseMagnetURI(link)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user