revert to old engine

This commit is contained in:
nikk gitanes
2021-07-20 07:44:44 +03:00
parent 8355ad3794
commit 2ec43233fb
16 changed files with 98 additions and 878 deletions

1
.gitignore vendored
View File

@@ -28,4 +28,3 @@ toolchains/
/src/google.golang.org/ /src/google.golang.org/
/toolchain/ /toolchain/
/test/ /test/
/web/.env.development

View File

@@ -41,14 +41,13 @@ OUTPUT="${ROOT}/dist/TorrServer"
#### Build web #### Build web
echo "Build web" echo "Build web"
$GOBIN run gen_web.go $GOBIN run gen_web.go || exit 1
#### Build server #### Build server
echo "Build server" echo "Build server"
cd "${ROOT}/server" || exit 1 cd "${ROOT}/server" || exit 1
$GOBIN clean -i -r -cache #--modcache $GOBIN clean -i -r -cache #--modcache
$GOBIN mod tidy $GOBIN mod tidy
$GOBIN mod download
BUILD_FLAGS="-ldflags=${LDFLAGS}" BUILD_FLAGS="-ldflags=${LDFLAGS}"

View File

@@ -1,19 +1,21 @@
module server module server
replace (
github.com/anacrolix/dht v1.0.1 => github.com/YouROK/dht v0.0.0-20210323193211-11c03221cb67
github.com/anacrolix/torrent v1.2.6 => github.com/yourok/torrent v0.0.0-20210427182412-1ef78c0fb02c
)
go 1.16 go 1.16
replace github.com/anacrolix/dht/v2 v2.9.1 => github.com/anacrolix/dht/v2 v2.10.0
require ( require (
github.com/alexflint/go-arg v1.3.0 github.com/alexflint/go-arg v1.3.0
github.com/anacrolix/dht/v2 v2.10.0 // indirect github.com/anacrolix/missinggo v1.1.0
github.com/anacrolix/missinggo v1.3.0 github.com/anacrolix/torrent v1.2.6
github.com/anacrolix/torrent v1.29.1
github.com/gin-contrib/cors v1.3.1 github.com/gin-contrib/cors v1.3.1
github.com/gin-contrib/location v0.0.2 github.com/gin-contrib/location v0.0.2
github.com/gin-gonic/gin v1.7.1 github.com/gin-gonic/gin v1.6.3
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.8.1
go.etcd.io/bbolt v1.3.5 go.etcd.io/bbolt v1.3.5
golang.org/x/time v0.0.0-20210220033141-f8bda1e9f3ba golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
) )

File diff suppressed because it is too large Load Diff

View File

@@ -28,8 +28,6 @@ type BTSets struct {
EnableDebug bool // print logs EnableDebug bool // print logs
// BT Config // BT Config
AcceptPeerCon bool
AnnTorrentsToDht bool
EnableIPv6 bool EnableIPv6 bool
DisableTCP bool DisableTCP bool
DisableUTP bool DisableUTP bool
@@ -40,9 +38,9 @@ type BTSets struct {
DownloadRateLimit int // in kb, 0 - inf DownloadRateLimit int // in kb, 0 - inf
UploadRateLimit int // in kb, 0 - inf UploadRateLimit int // in kb, 0 - inf
ConnectionsLimit int ConnectionsLimit int
//DhtConnectionLimit int // 0 - inf DhtConnectionLimit int // 0 - inf
PeersListenPort int PeersListenPort int
//Strategy int // 0 - RequestStrategyDuplicateRequestTimeout, 1 - RequestStrategyFuzzing, 2 - RequestStrategyFastest Strategy int // 0 - RequestStrategyDuplicateRequestTimeout, 1 - RequestStrategyFuzzing, 2 - RequestStrategyFastest
} }
func (v *BTSets) String() string { func (v *BTSets) String() string {
@@ -121,14 +119,12 @@ func loadBTSets() {
func SetDefault() { func SetDefault() {
sets := new(BTSets) sets := new(BTSets)
sets.AcceptPeerCon = true
sets.AnnTorrentsToDht = true
sets.EnableDebug = false sets.EnableDebug = false
sets.DisableUTP = true sets.DisableUTP = true
sets.CacheSize = 96 * 1024 * 1024 // 96 MB sets.CacheSize = 96 * 1024 * 1024 // 96 MB
sets.PreloadCache = 0 sets.PreloadCache = 0
sets.ConnectionsLimit = 23 sets.ConnectionsLimit = 23
//sets.DhtConnectionLimit = 500 sets.DhtConnectionLimit = 500
sets.RetrackersMode = 1 sets.RetrackersMode = 1
sets.TorrentDisconnectTimeout = 30 sets.TorrentDisconnectTimeout = 30
sets.ReaderReadAHead = 95 // 95% preload sets.ReaderReadAHead = 95 // 95% preload

View File

@@ -63,8 +63,6 @@ func (bt *BTServer) configure() {
peerID := "-qB4320-" peerID := "-qB4320-"
cliVers := userAgent //"uTorrent/2210(25302)" cliVers := userAgent //"uTorrent/2210(25302)"
bt.config.AcceptPeerConnections = settings.BTsets.AcceptPeerCon
bt.config.PeriodicallyAnnounceTorrentsToDht = settings.BTsets.AnnTorrentsToDht
bt.config.Debug = settings.BTsets.EnableDebug bt.config.Debug = settings.BTsets.EnableDebug
bt.config.DisableIPv6 = settings.BTsets.EnableIPv6 == false bt.config.DisableIPv6 = settings.BTsets.EnableIPv6 == false
bt.config.DisableTCP = settings.BTsets.DisableTCP bt.config.DisableTCP = settings.BTsets.DisableTCP
@@ -81,11 +79,13 @@ func (bt *BTServer) configure() {
bt.config.EstablishedConnsPerTorrent = settings.BTsets.ConnectionsLimit bt.config.EstablishedConnsPerTorrent = settings.BTsets.ConnectionsLimit
// Encryption/Obfuscation // Encryption/Obfuscation
bt.config.HeaderObfuscationPolicy = torrent.HeaderObfuscationPolicy{ bt.config.EncryptionPolicy = torrent.EncryptionPolicy{
RequirePreferred: settings.BTsets.ForceEncrypt, ForceEncryption: settings.BTsets.ForceEncrypt,
Preferred: true,
} }
if settings.BTsets.DhtConnectionLimit > 0 {
bt.config.ConnTracker.SetMaxEntries(settings.BTsets.DhtConnectionLimit)
}
if settings.BTsets.DownloadRateLimit > 0 { if settings.BTsets.DownloadRateLimit > 0 {
bt.config.DownloadRateLimiter = utils.Limit(settings.BTsets.DownloadRateLimit * 1024) bt.config.DownloadRateLimiter = utils.Limit(settings.BTsets.DownloadRateLimit * 1024)
} }

View File

@@ -8,6 +8,8 @@ import (
"sync" "sync"
"time" "time"
"github.com/anacrolix/torrent"
"server/log" "server/log"
"server/settings" "server/settings"
) )
@@ -82,4 +84,6 @@ func (p *DiskPiece) Release() {
p.piece.Complete = false p.piece.Complete = false
os.Remove(p.name) os.Remove(p.name)
p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone)
} }

View File

@@ -4,6 +4,8 @@ import (
"io" "io"
"sync" "sync"
"time" "time"
"github.com/anacrolix/torrent"
) )
type MemPiece struct { type MemPiece struct {
@@ -67,4 +69,6 @@ func (p *MemPiece) Release() {
} }
p.piece.Size = 0 p.piece.Size = 0
p.piece.Complete = false p.piece.Complete = false
p.piece.cache.torrent.Piece(p.piece.Id).SetPriority(torrent.PiecePriorityNone)
} }

View File

@@ -1,9 +1,7 @@
package torrstor package torrstor
import ( import (
"github.com/anacrolix/torrent"
"github.com/anacrolix/torrent/storage" "github.com/anacrolix/torrent/storage"
"server/settings" "server/settings"
) )
@@ -75,7 +73,4 @@ func (p *Piece) Release() {
} else { } else {
p.dPiece.Release() p.dPiece.Release()
} }
p.cache.torrent.Piece(p.Id).SetPriority(torrent.PiecePriorityNone)
p.cache.torrent.Piece(p.Id).UpdateCompletion()
} }

View File

@@ -30,11 +30,7 @@ func (s *Storage) OpenTorrent(info *metainfo.Info, infoHash metainfo.Hash) (stor
ch := NewCache(s.capacity, s) ch := NewCache(s.capacity, s)
ch.Init(info, infoHash) ch.Init(info, infoHash)
s.caches[infoHash] = ch s.caches[infoHash] = ch
//return ch, nil return ch, nil
return storage2.TorrentImpl{
Piece: ch.Piece,
Close: ch.Close,
}, nil
} }
func (s *Storage) CloseHash(hash metainfo.Hash) { func (s *Storage) CloseHash(hash metainfo.Hash) {

View File

@@ -24,7 +24,8 @@ func ParseFile(file multipart.File) (*torrent.TorrentSpec, error) {
return nil, err return nil, err
} }
mag := minfo.Magnet(nil, &info) mag := minfo.Magnet(info.Name, minfo.HashInfoBytes())
// mag := minfo.Magnet(nil, &info)
return &torrent.TorrentSpec{ return &torrent.TorrentSpec{
InfoBytes: minfo.InfoBytes, InfoBytes: minfo.InfoBytes,
Trackers: [][]string{mag.Trackers}, Trackers: [][]string{mag.Trackers},
@@ -105,7 +106,8 @@ func fromHttp(link string) (*torrent.TorrentSpec, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
mag := minfo.Magnet(nil, &info) mag := minfo.Magnet(info.Name, minfo.HashInfoBytes())
// mag := minfo.Magnet(nil, &info)
return &torrent.TorrentSpec{ return &torrent.TorrentSpec{
InfoBytes: minfo.InfoBytes, InfoBytes: minfo.InfoBytes,
@@ -128,7 +130,8 @@ func fromFile(path string) (*torrent.TorrentSpec, error) {
return nil, err return nil, err
} }
mag := minfo.Magnet(nil, &info) mag := minfo.Magnet(info.Name, minfo.HashInfoBytes())
// mag := minfo.Magnet(nil, &info)
return &torrent.TorrentSpec{ return &torrent.TorrentSpec{
InfoBytes: minfo.InfoBytes, InfoBytes: minfo.InfoBytes,
Trackers: [][]string{mag.Trackers}, Trackers: [][]string{mag.Trackers},

View File

@@ -28,7 +28,8 @@ func getTorrents(c *gin.Context) {
mi := metainfo.MetaInfo{ mi := metainfo.MetaInfo{
AnnounceList: ts.Trackers, AnnounceList: ts.Trackers,
} }
mag := mi.Magnet(&ts.InfoHash, &metainfo.Info{Name: ts.DisplayName}) mag := mi.Magnet(ts.DisplayName, ts.InfoHash)
// mag := mi.Magnet(&ts.InfoHash, &metainfo.Info{Name: ts.DisplayName})
http += "<p><a href='" + mag.String() + "'>magnet:?xt=urn:btih:" + mag.InfoHash.HexString() + "</a></p>" http += "<p><a href='" + mag.String() + "'>magnet:?xt=urn:btih:" + mag.InfoHash.HexString() + "</a></p>"
} }
http += "</div>" http += "</div>"

View File

@@ -8,8 +8,6 @@ export default function SecondarySettingsComponent({ settings, inputForm }) {
const { t } = useTranslation() const { t } = useTranslation()
const { const {
AcceptPeerCon,
AnnTorrentsToDht,
RetrackersMode, RetrackersMode,
TorrentDisconnectTimeout, TorrentDisconnectTimeout,
EnableIPv6, EnableIPv6,
@@ -23,6 +21,7 @@ export default function SecondarySettingsComponent({ settings, inputForm }) {
DownloadRateLimit, DownloadRateLimit,
UploadRateLimit, UploadRateLimit,
ConnectionsLimit, ConnectionsLimit,
DhtConnectionLimit,
PeersListenPort, PeersListenPort,
} = settings || {} } = settings || {}
@@ -86,15 +85,15 @@ export default function SecondarySettingsComponent({ settings, inputForm }) {
label={t('SettingsDialog.DHT')} label={t('SettingsDialog.DHT')}
labelPlacement='start' labelPlacement='start'
/> />
<FormControlLabel <TextField
control={<Switch checked={AnnTorrentsToDht} onChange={inputForm} id='AnnTorrentsToDht' color='secondary' />} onChange={inputForm}
label={t('SettingsDialog.AnnTorrentsToDht')} margin='normal'
labelPlacement='start' id='DhtConnectionLimit'
/> label={t('SettingsDialog.DhtConnectionLimit')}
<FormControlLabel value={DhtConnectionLimit}
control={<Switch checked={AcceptPeerCon} onChange={inputForm} id='AcceptPeerCon' color='secondary' />} type='number'
label={t('SettingsDialog.AcceptPeerCon')} variant='outlined'
labelPlacement='start' fullWidth
/> />
<br /> <br />
<TextField <TextField

View File

@@ -1,12 +1,11 @@
export default { export default {
AcceptPeerCon: true,
AnnTorrentsToDht: true,
CacheSize: 96, CacheSize: 96,
ReaderReadAHead: 95, ReaderReadAHead: 95,
UseDisk: false, UseDisk: false,
UploadRateLimit: 0, UploadRateLimit: 0,
TorrentsSavePath: '', TorrentsSavePath: '',
ConnectionsLimit: 23, ConnectionsLimit: 23,
DhtConnectionLimit: 500,
DisableDHT: false, DisableDHT: false,
DisablePEX: false, DisablePEX: false,
DisableTCP: false, DisableTCP: false,
@@ -21,5 +20,6 @@ export default {
PreloadCache: 0, PreloadCache: 0,
RemoveCacheOnDrop: false, RemoveCacheOnDrop: false,
RetrackersMode: 1, RetrackersMode: 1,
Strategy: 0,
TorrentDisconnectTimeout: 30, TorrentDisconnectTimeout: 30,
} }

View File

@@ -84,8 +84,6 @@
"Seconds": "Seconds", "Seconds": "Seconds",
"SelectSeason": "Select Season", "SelectSeason": "Select Season",
"SettingsDialog": { "SettingsDialog": {
"AcceptPeerCon": "Accept Peer Connections",
"AnnTorrentsToDht": "Periodically Announce Torrents to DHT",
"AddRetrackers": "Add retrackers", "AddRetrackers": "Add retrackers",
"AdditionalSettings": "Additional Settings", "AdditionalSettings": "Additional Settings",
"CacheBeforeReaderDesc": "from cache will be saved before currently played frame", "CacheBeforeReaderDesc": "from cache will be saved before currently played frame",

View File

@@ -84,8 +84,6 @@
"Seconds": "Секунды", "Seconds": "Секунды",
"SelectSeason": "Выбор сезона", "SelectSeason": "Выбор сезона",
"SettingsDialog": { "SettingsDialog": {
"AcceptPeerCon": "Принимать входящие соединения",
"AnnTorrentsToDht": "Анонсировать торренты по DHT",
"AddRetrackers": "Добавлять", "AddRetrackers": "Добавлять",
"AdditionalSettings": "Дополнительные настройки", "AdditionalSettings": "Дополнительные настройки",
"CacheBeforeReaderDesc": "от кеша будет оставаться позади воспроизводимого кадра", "CacheBeforeReaderDesc": "от кеша будет оставаться позади воспроизводимого кадра",