Adding favicon, optimizing Torrent Status checking

This commit is contained in:
2018-01-20 22:52:21 -05:00
parent 83a03b3ef6
commit 8432c1b5b3
6 changed files with 38 additions and 55 deletions

View File

@@ -157,6 +157,7 @@ func CreateRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Sto
for _, singleTorrentFromStorage := range TorrentLocalArray {
var singleTorrent *torrent.Torrent
var TempHash metainfo.Hash
tickUpdateStruct := Storage.TorrentLocal{} //we are shoving the tick updates into a torrentlocal struct to pass to storage happens at the end of the routine
fullClientDB := new(ClientDB)
//singleTorrentStorageInfo := Storage.FetchTorrentFromStorage(db, TempHash.String()) //pulling the single torrent info from storage ()
@@ -186,7 +187,7 @@ func CreateRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Sto
TempHash = singleTorrent.InfoHash()
if (singleTorrent.BytesCompleted() == singleTorrent.Length()) && (singleTorrentFromStorage.TorrentMoved == false) { //if we are done downloading and havent moved torrent yet
MoveAndLeaveSymlink(config, singleTorrent, db)
MoveAndLeaveSymlink(config, singleTorrent, db) //can take some time to move file so running this in another thread TODO make this a goroutine and skip this block if the routine is still running
}
fullStruct := singleTorrent.Stats()
@@ -231,23 +232,8 @@ func CreateRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Sto
fullClientDB.TotalUploadedSize = HumanizeBytes(float32(fullClientDB.TotalUploadedBytes))
fullClientDB.UploadRatio = CalculateUploadRatio(singleTorrent, fullClientDB) //calculate the upload ratio
if float64(fullClientDB.TotalUploadedBytes)/float64(singleTorrent.BytesCompleted()) >= config.SeedRatioStop { //if our upload ratio is over or eq our limit set in config
singleTorrent.SetMaxEstablishedConns(0) //forcing a stop
fullClientDB.Status = "Stopped"
}
CalculateTorrentStatus(singleTorrent, fullClientDB, config, singleTorrentFromStorage)
if singleTorrentFromStorage.TorrentStatus != "Stopped" { //if the torrent is not stopped, try to discern the status of the torrent
singleTorrent.SetMaxEstablishedConns(80)
fullClientDB.MaxConnections = 80
singleTorrent.DownloadAll() // forcing the client to download all pieces
CalculateTorrentStatus(singleTorrent, fullClientDB) //calculate the status of the torrent, ie downloading seeding etc
} else {
fullClientDB.Status = "Stopped"
fullClientDB.MaxConnections = 0
singleTorrent.SetMaxEstablishedConns(0) //since it was stopped forcing the connections to zero
}
tickUpdateStruct := Storage.TorrentLocal{} //we are shoving the tick updates into a torrentlocal struct to pass to storage
tickUpdateStruct.UploadRatio = fullClientDB.UploadRatio
tickUpdateStruct.UploadedBytes = fullClientDB.TotalUploadedBytes
tickUpdateStruct.TorrentStatus = fullClientDB.Status

View File

@@ -5,6 +5,7 @@ import (
"time"
"github.com/anacrolix/torrent"
"github.com/deranjer/goTorrent/storage"
)
func secondsToMinutes(inSeconds int64) string {
@@ -85,16 +86,25 @@ func CalculateUploadRatio(t *torrent.Torrent, c *ClientDB) string {
}
//CalculateTorrentStatus is used to determine what the STATUS column of the frontend will display ll2
func CalculateTorrentStatus(t *torrent.Torrent, c *ClientDB) { //TODO redo all of this to allow for stopped torrents
if t.Seeding() && t.Stats().ActivePeers > 0 && t.BytesMissing() == 0 {
c.Status = "Seeding"
} else if t.Stats().ActivePeers > 0 && t.BytesMissing() > 0 {
c.Status = "Downloading"
} else if t.Stats().ActivePeers == 0 && t.BytesMissing() == 0 {
c.Status = "Completed"
} else if t.Stats().ActivePeers == 0 && t.BytesMissing() > 0 {
c.Status = "Awaiting Peers"
} else {
c.Status = "Unknown"
func CalculateTorrentStatus(t *torrent.Torrent, c *ClientDB, config FullClientSettings, tFromStorage *storage.TorrentLocal) { //TODO redo all of this to allow for stopped torrents
if (tFromStorage.TorrentStatus == "Stopped") || (float64(c.TotalUploadedBytes)/float64(t.BytesCompleted()) >= config.SeedRatioStop) {
c.Status = "Stopped"
c.MaxConnections = 0
t.SetMaxEstablishedConns(0)
} else { //Only has 2 states in storage, stopped or running, so we know it should be running, and the websocket request handled updating the database with connections and status
c.MaxConnections = 80
t.SetMaxEstablishedConns(80) //TODO this should not be needed but apparently is needed
t.DownloadAll() //ensure that we are setting the torrent to download
if t.Seeding() && t.Stats().ActivePeers > 0 && t.BytesMissing() == 0 {
c.Status = "Seeding"
} else if t.Stats().ActivePeers > 0 && t.BytesMissing() > 0 {
c.Status = "Downloading"
} else if t.Stats().ActivePeers == 0 && t.BytesMissing() == 0 {
c.Status = "Completed"
} else if t.Stats().ActivePeers == 0 && t.BytesMissing() > 0 {
c.Status = "Awaiting Peers"
} else {
c.Status = "Unknown"
}
}
}