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