Skip to content

Commit

Permalink
set short timeouts in GetTorrent, NewTorrent and Preload log
Browse files Browse the repository at this point in the history
  • Loading branch information
tsynik committed Jun 7, 2024
1 parent 47a2982 commit b6328d6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 5 additions & 1 deletion server/torr/apihelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,13 @@ func SaveTorrentToDB(torr *Torrent) {

func GetTorrent(hashHex string) *Torrent {
hash := metainfo.NewHashFromHex(hashHex)
timeout := time.Second * time.Duration(sets.BTsets.TorrentDisconnectTimeout)
if timeout > time.Minute {
timeout = time.Minute
}
tor := bts.GetTorrent(hash)
if tor != nil {
tor.AddExpiredTime(time.Minute)
tor.AddExpiredTime(timeout)
return tor
}

Expand Down
6 changes: 5 additions & 1 deletion server/torr/preload.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ func (t *Torrent) Preload(index int, size int64) {
}

if t.Info() != nil {
timeout := time.Second * time.Duration(settings.BTsets.TorrentDisconnectTimeout)
if timeout > time.Minute {
timeout = time.Minute
}
// Запуск лога в отдельном потоке
go func() {
for t.Stat == state.TorrentPreload {
stat := fmt.Sprint(file.Torrent().InfoHash().HexString(), " ", utils2.Format(float64(t.PreloadedBytes)), "/", utils2.Format(float64(t.PreloadSize)), " Speed:", utils2.Format(t.DownloadSpeed), " Peers:", t.Torrent.Stats().ActivePeers, "/", t.Torrent.Stats().TotalPeers, " [Seeds:", t.Torrent.Stats().ConnectedSeeders, "]")
log.TLogln("Preload:", stat)
t.AddExpiredTime(time.Second * time.Duration(settings.BTsets.TorrentDisconnectTimeout))
t.AddExpiredTime(timeout)
time.Sleep(time.Second)
}
}()
Expand Down
7 changes: 6 additions & 1 deletion server/torr/torrent.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,19 @@ func NewTorrent(spec *torrent.TorrentSpec, bt *BTServer) (*Torrent, error) {
return tor, nil
}

timeout := time.Second * time.Duration(settings.BTsets.TorrentDisconnectTimeout)
if timeout > time.Minute {
timeout = time.Minute
}

torr := new(Torrent)
torr.Torrent = goTorrent
torr.Stat = state.TorrentAdded
torr.lastTimeSpeed = time.Now()
torr.bt = bt
torr.closed = goTorrent.Closed()
torr.TorrentSpec = spec
torr.AddExpiredTime(time.Second * time.Duration(settings.BTsets.TorrentDisconnectTimeout))
torr.AddExpiredTime(timeout)
torr.Timestamp = time.Now().Unix()

go torr.watch()
Expand Down

0 comments on commit b6328d6

Please sign in to comment.