From 6e5ba2c7553001f9240075046befe5f9f76a4eb2 Mon Sep 17 00:00:00 2001 From: deranjer Date: Fri, 8 Jun 2018 18:19:51 -0400 Subject: [PATCH] Ready for new release with new engine, will start bugfixes --- config.toml | 2 +- engine/engine.go | 5 +++++ engine/engineHelpers.go | 14 ++++++++++++++ main.go | 4 ++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/config.toml b/config.toml index da101dd4..62d3c81e 100644 --- a/config.toml +++ b/config.toml @@ -16,7 +16,7 @@ UploadRateLimit = "Unlimited" #Options are "Low", "Medium", "High", "Unlimited" #Unlimited is default DownloadRateLimit = "Unlimited" #Maximum number of allowed active torrents, the rest will be queued - MaxActiveTorrents = 2 + MaxActiveTorrents = 5 [goTorrentWebUI] #Basic goTorrentWebUI authentication (not terribly secure, implemented in JS, password is hashed to SHA256, not salted, basically don't depend on this if you require very good security) diff --git a/engine/engine.go b/engine/engine.go index 09d13e7d..c74cd378 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -32,6 +32,10 @@ func CreateServerPushMessage(message ServerPushMessage, conn *websocket.Conn) { conn.WriteJSON(message) } +func QueueJSONMessage(conn *websocket.Conn){ + +} + //RefreshSingleRSSFeed refreshing a single RSS feed to send to the client (so no updating database) mainly by updating the torrent list to display any changes func RefreshSingleRSSFeed(db *storm.DB, RSSFeed Storage.SingleRSSFeed) Storage.SingleRSSFeed { //Todo.. duplicate as cron job... any way to merge these to reduce duplication? singleRSSFeed := Storage.SingleRSSFeed{URL: RSSFeed.URL, Name: RSSFeed.Name} @@ -376,6 +380,7 @@ func CreateRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Sto RunningTorrentArray = append(RunningTorrentArray, *fullClientDB) } + ValidateQueues(db, config, tclient) //Ensure we don't have too many in activeQueue return RunningTorrentArray } diff --git a/engine/engineHelpers.go b/engine/engineHelpers.go index db46308c..0be36bed 100644 --- a/engine/engineHelpers.go +++ b/engine/engineHelpers.go @@ -319,6 +319,20 @@ func RemoveDuplicatesFromQueues(db *storm.DB) { Storage.UpdateQueues(db, torrentQueues) } +//ValidateQueues is a sanity check that runs every tick to make sure the queues are in order... tried to avoid this but seems to be required +func ValidateQueues(db *storm.DB, config Settings.FullClientSettings, tclient *torrent.Client) { + torrentQueues := Storage.FetchQueues(db) + for len(torrentQueues.ActiveTorrents) > config.MaxActiveTorrents { + removeTorrent := torrentQueues.ActiveTorrents[:1] + for _, singleTorrent := range tclient.Torrents() { + if singleTorrent.InfoHash().String() == removeTorrent[0] { + singleTorrentFromStorage := Storage.FetchTorrentFromStorage(db, removeTorrent[0]) + RemoveTorrentFromActive(&singleTorrentFromStorage, singleTorrent, db) + } + } + } +} + //CalculateTorrentStatus is used to determine what the STATUS column of the frontend will display ll2 func CalculateTorrentStatus(t *torrent.Torrent, c *ClientDB, config Settings.FullClientSettings, tFromStorage *storage.TorrentLocal, bytesCompleted int64, totalSize int64, torrentQueues Storage.TorrentQueues, db *storm.DB) { if tFromStorage.TorrentStatus == "Stopped" { diff --git a/main.go b/main.go index 080c98b9..94985db4 100644 --- a/main.go +++ b/main.go @@ -51,7 +51,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) { func handleAuthentication(conn *websocket.Conn, db *storm.DB) { msg := Engine.Message{} err := conn.ReadJSON(&msg) - conn.WriteJSON(msg) //TODO just for testing, remove + //conn.WriteJSON(msg) //TODO just for testing, remove payloadData, ok := msg.Payload.(map[string]interface{}) clientAuthToken, tokenOk := payloadData["ClientAuthString"].(string) fmt.Println("ClientAuthToken:", clientAuthToken, "TokenOkay", tokenOk, "PayloadData", payloadData, "PayloadData Okay?", ok) @@ -284,7 +284,7 @@ func main() { Logger.WithFields(logrus.Fields{"message": msg}).Debug("Client Requested TorrentList Update") go func() { //running updates in separate thread so can still accept commands - TorrentLocalArray = Storage.FetchAllStoredTorrents(db) //Required to re-read th database since we write to the DB and this will pull the changes from it + TorrentLocalArray = Storage.FetchAllStoredTorrents(db) //Required to re-read the database since we write to the DB and this will pull the changes from it RunningTorrentArray = Engine.CreateRunningTorrentArray(tclient, TorrentLocalArray, PreviousTorrentArray, Config, db) //Updates the RunningTorrentArray with the current client data as well PreviousTorrentArray = RunningTorrentArray torrentlistArray := Engine.TorrentList{MessageType: "torrentList", ClientDBstruct: RunningTorrentArray, Totaltorrents: len(RunningTorrentArray)}