From 8432c1b5b3340013db0ff13bb0b61a6acf04421b Mon Sep 17 00:00:00 2001 From: deranjer Date: Sat, 20 Jan 2018 22:52:21 -0500 Subject: [PATCH] Adding favicon, optimizing Torrent Status checking --- config.toml | 2 +- engine/engine.go | 20 ++----------- engine/engineMaths.go | 32 ++++++++++++++------- main.go | 28 +++++++----------- public/static/favicon/goTorrentFavicon.ico | Bin 0 -> 1150 bytes templates/home.tmpl | 11 ++----- 6 files changed, 38 insertions(+), 55 deletions(-) create mode 100644 public/static/favicon/goTorrentFavicon.ico diff --git a/config.toml b/config.toml index de5eee81..d823812c 100644 --- a/config.toml +++ b/config.toml @@ -4,7 +4,7 @@ ServerPort = ":8000" #leave format as is it expects a string with colon ServerAddr = "" #blank will bind to default IP address, usually fine to leave be LogLevel = "Warn" # Options = Debug, Info, Warn, Error, Fatal, Panic - LogOutput = "stdout" #Options = file, stdout #file will print it to logs/server.log + LogOutput = "file" #Options = file, stdout #file will print it to logs/server.log SeedRatioStop = 1.50 #automatically stops the torrent after it reaches this seeding ratio #Relative or absolute path accepted, the server will convert any relative path to an absolute path. diff --git a/engine/engine.go b/engine/engine.go index fe2c4772..1689d04b 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -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 diff --git a/engine/engineMaths.go b/engine/engineMaths.go index 6fd2b57d..3dc0c2c2 100644 --- a/engine/engineMaths.go +++ b/engine/engineMaths.go @@ -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" + } } } diff --git a/main.go b/main.go index 24447cd4..508206a0 100644 --- a/main.go +++ b/main.go @@ -304,12 +304,12 @@ func main() { for _, singleSelection := range TorrentListCommands { if singleTorrent.InfoHash().String() == singleSelection { Logger.WithFields(logrus.Fields{"selection": singleSelection}).Info("Matched for stopping torrents") - tempTorrentLocal := Storage.TorrentLocal{} - tempTorrentLocal.Hash = singleTorrent.InfoHash().String() //required since this is the ID that stormdb requires - tempTorrentLocal.TorrentStatus = "Stopped" + oldTorrentInfo := Storage.FetchTorrentFromStorage(db, singleTorrent.InfoHash().String()) + oldTorrentInfo.TorrentStatus = "Stopped" + oldTorrentInfo.MaxConnections = 0 oldMax := singleTorrent.SetMaxEstablishedConns(0) //Forcing the max amount of connections allowed to zero effectively stopping it Logger.WithFields(logrus.Fields{"oldMaxConnections": oldMax, "torrent": singleTorrent}).Info("Forcing connections to zero for torrent") - Storage.UpdateStorageTick(db, tempTorrentLocal) //Updating the torrent status + Storage.UpdateStorageTick(db, oldTorrentInfo) //Updating the torrent status } } } @@ -341,19 +341,13 @@ func main() { for _, singleSelection := range msg.Payload { if singleTorrent.InfoHash().String() == singleSelection { Logger.WithFields(logrus.Fields{"infoHash": singleTorrent.InfoHash().String()}).Debug("Found matching torrent to start") - tempTorrentLocal := Storage.TorrentLocal{} - tempTorrentLocal.Hash = singleTorrent.InfoHash().String() //required since this is the ID that stormdb requires - tempTorrentLocal.TorrentStatus = "Running" //Setting the status back to running - oldTorrentInfo := Storage.FetchTorrentFromStorage(db, singleTorrent.InfoHash().String()) //Fetching the old max connections setting from the database - if oldTorrentInfo.MaxConnections == 0 { //if somehow the old max was set at zero change it to 80 - oldTorrentInfo.MaxConnections = 80 - Storage.UpdateStorageTick(db, oldTorrentInfo) - } - - oldMax := singleTorrent.SetMaxEstablishedConns(oldTorrentInfo.MaxConnections) //Forcing the max amount of connections allowed to zero effectively stopping it - Logger.WithFields(logrus.Fields{"Previous Max Connections": oldMax}).Debug("Setting max connection from zero to") - singleTorrent.DownloadAll() //forcing a download all just in case TODO.. might reset priorities of file dl - Storage.UpdateStorageTick(db, tempTorrentLocal) //Updating the torrent status + oldTorrentInfo := Storage.FetchTorrentFromStorage(db, singleTorrent.InfoHash().String()) + oldTorrentInfo.TorrentStatus = "Running" + oldTorrentInfo.MaxConnections = 80 + oldMax := singleTorrent.SetMaxEstablishedConns(80) + Logger.WithFields(logrus.Fields{"Previous Max Connections": oldMax, "Torrent": oldTorrentInfo.TorrentName}).Info("Setting max connection from zero to") + singleTorrent.DownloadAll() //forcing a download all just in case TODO.. might reset priorities of file dl + Storage.UpdateStorageTick(db, oldTorrentInfo) //Updating the torrent status } } } diff --git a/public/static/favicon/goTorrentFavicon.ico b/public/static/favicon/goTorrentFavicon.ico new file mode 100644 index 0000000000000000000000000000000000000000..732b17254b2de304a63fd7ad7b4abd8c055ceeee GIT binary patch literal 1150 zcmbW0&nrYx6vywpH!GSSJ!5Kym_qp{EM{S4p$H2L3mavjl#(RnHApsolO_v4#~^k{ zjWDJe#SEzl*;t_X3p8Knyyr~~GcxYHGw*fo{hV{|z275*iGFswpns3(Fbm-nLR6EH zi#)oYUcV2M5R%g*$G>7rkf>HK2UUovx7?bESSxykCQFJ!-*BdXVytDDHfCHnkVFd2iaq@heljRuMc=nG( zed+wQhh9`{mtj6R3(r - torrent-project - + goTorrent + - - -
- - - -