diff --git a/engine/engine.go b/engine/engine.go index c74cd378..84e0fa22 100644 --- a/engine/engine.go +++ b/engine/engine.go @@ -32,8 +32,8 @@ func CreateServerPushMessage(message ServerPushMessage, conn *websocket.Conn) { conn.WriteJSON(message) } -func QueueJSONMessage(conn *websocket.Conn){ - +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 @@ -332,8 +332,8 @@ func CreateRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Sto PercentDone := fmt.Sprintf("%.2f", float32(calculatedCompletedSize)/float32(calculatedTotalSize)) fullClientDB.TorrentHash = TempHash fullClientDB.PercentDone = PercentDone - fullClientDB.DataBytesRead = fullStruct.ConnStats.BytesReadData //used for calculations not passed to client calculating up/down speed - fullClientDB.DataBytesWritten = fullStruct.ConnStats.BytesWrittenData //used for calculations not passed to client calculating up/down speed + fullClientDB.DataBytesRead = fullStruct.ConnStats.BytesReadData.Int64() //used for calculations not passed to client calculating up/down speed + fullClientDB.DataBytesWritten = fullStruct.ConnStats.BytesWrittenData.Int64() //used for calculations not passed to client calculating up/down speed fullClientDB.ActivePeers = activePeersString + " / (" + totalPeersString + ")" fullClientDB.TorrentHashString = TempHash.String() fullClientDB.TorrentName = singleTorrentFromStorage.TorrentName @@ -347,7 +347,7 @@ func CreateRunningTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Sto TempHash := singleTorrent.InfoHash() if previousElement.TorrentHashString == TempHash.String() { //matching previous to new CalculateTorrentSpeed(singleTorrent, fullClientDB, previousElement, calculatedCompletedSize) - fullClientDB.TotalUploadedBytes = singleTorrentFromStorage.UploadedBytes + (fullStruct.ConnStats.BytesWrittenData - previousElement.DataBytesWritten) + fullClientDB.TotalUploadedBytes = singleTorrentFromStorage.UploadedBytes + (fullStruct.ConnStats.BytesWrittenData.Int64() - previousElement.DataBytesWritten) } } } diff --git a/engine/engineHelpers.go b/engine/engineHelpers.go index 0be36bed..abc3e087 100644 --- a/engine/engineHelpers.go +++ b/engine/engineHelpers.go @@ -109,7 +109,7 @@ func CalculateTorrentSpeed(t *torrent.Torrent, c *ClientDB, oc ClientDB, complet dt := float32(now.Sub(oc.UpdatedAt)) // get the delta time length between now and last updated db := float32(bytes - oc.BytesCompleted) //getting the delta bytes rate := db * (float32(time.Second) / dt) // converting into seconds - dbU := float32(bytesUpload - oc.DataBytesWritten) + dbU := float32(bytesUpload.Int64() - oc.DataBytesWritten) rateUpload := dbU * (float32(time.Second) / dt) if rate >= 0 { rateMB := rate / 1024 / 1024 //creating MB to calculate ETA @@ -331,6 +331,27 @@ func ValidateQueues(db *storm.DB, config Settings.FullClientSettings, tclient *t } } } + torrentQueues = Storage.FetchQueues(db) + for _, singleTorrent := range tclient.Torrents() { //If we have a queued torrent that is missing data, and an active torrent that is seeding, then prioritize the missing data one + for _, queuedTorrent := range torrentQueues.QueuedTorrents { + if singleTorrent.InfoHash().String() == queuedTorrent { + if singleTorrent.BytesMissing() > 0 { + for _, activeTorrent := range torrentQueues.ActiveTorrents { + for _, singleActiveTorrent := range tclient.Torrents() { + if activeTorrent == singleActiveTorrent.InfoHash().String() { + if singleActiveTorrent.Seeding() == true { + singleTorrentFromStorage := Storage.FetchTorrentFromStorage(db, activeTorrent) + RemoveTorrentFromActive(&singleTorrentFromStorage, singleActiveTorrent, db) + singleTorrentFromStorage = Storage.FetchTorrentFromStorage(db, queuedTorrent) + AddTorrentToActive(&singleTorrentFromStorage, singleTorrent, db) + } + } + } + } + } + } + } + } } //CalculateTorrentStatus is used to determine what the STATUS column of the frontend will display ll2 diff --git a/settings/settings.go b/settings/settings.go index 45b518f6..4ab2f6ab 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -4,6 +4,7 @@ import ( "crypto/sha256" "fmt" "path/filepath" + "strconv" "strings" "golang.org/x/time/rate" @@ -34,7 +35,7 @@ type FullClientSettings struct { LoggingLevel logrus.Level LoggingOutput string Version int - TorrentConfig torrent.Config `json:"-"` + TorrentConfig torrent.ClientConfig `json:"-"` TFileUploadFolder string SeedRatioStop float64 DefaultMoveFolder string @@ -55,9 +56,9 @@ func defaultConfig() FullClientSettings { Config.HTTPAddr = ":8000" Config.SeedRatioStop = 1.50 - Config.TorrentConfig.DHTConfig = dht.ServerConfig{ - StartingNodes: dht.GlobalBootstrapAddrs, - } + //Config.TorrentConfig.DhtStartingNodes = dht.StartingNodesGetter{ + // StartingNodes: dht.GlobalBootstrapAddrs, + //} return Config } @@ -201,13 +202,17 @@ func FullClientSettingsNew() FullClientSettings { disableIPv6 := viper.GetBool("torrentClientConfig.DisableIPv6") debug := viper.GetBool("torrentClientConfig.Debug") - dhtServerConfig := dht.ServerConfig{ - StartingNodes: dht.GlobalBootstrapAddrs, - } - if viper.IsSet("DHTConfig") { - fmt.Println("Reading in custom DHT config") - dhtServerConfig = dhtServerSettings(dhtServerConfig) + //dhtServerConfig := dht.StartingNodesGetter() + + //if viper.IsSet("DHTConfig") { + // fmt.Println("Reading in custom DHT config") + // dhtServerConfig = dhtServerSettings(dhtServerConfig) + //} + httpAddrPortInt64, err := strconv.ParseInt(httpAddrPort, 10, 0) + if err != nil { + fmt.Println("Failed creating 64-bit integer for goTorrent Port!", err) } + httpAddrPortInt := int(httpAddrPortInt64) //converting to integer encryptionPolicy := torrent.EncryptionPolicy{ DisableEncryption: viper.GetBool("EncryptionPolicy.DisableEncryption"), @@ -215,22 +220,24 @@ func FullClientSettingsNew() FullClientSettings { PreferNoEncryption: viper.GetBool("EncryptionPolicy.PreferNoEncryption"), } - tConfig := torrent.Config{ - DataDir: dataDirAbs, - ListenAddr: listenAddr, - DisablePEX: disablePex, - NoDHT: noDHT, - DHTConfig: dhtServerConfig, - NoUpload: noUpload, - Seed: seed, - UploadRateLimiter: uploadRateLimiter, - DownloadRateLimiter: downloadRateLimiter, - PeerID: peerID, - DisableUTP: disableUTP, - DisableTCP: disableTCP, - DisableIPv6: disableIPv6, - Debug: debug, - EncryptionPolicy: encryptionPolicy, + tConfig := torrent.NewDefaultClientConfig() + + tConfig.DataDir = dataDirAbs + tConfig.ListenPort = httpAddrPortInt + tConfig.DisablePEX = disablePex + tConfig.NoDHT = noDHT + tConfig.NoUpload = noUpload + tConfig.Seed = seed + tConfig.UploadRateLimiter = uploadRateLimiter + tConfig.DownloadRateLimiter = downloadRateLimiter + tConfig.PeerID = peerID + tConfig.DisableUTP = disableUTP + tConfig.DisableTCP = disableTCP + tConfig.DisableIPv6 = disableIPv6 + tConfig.Debug = debug + tConfig.EncryptionPolicy = encryptionPolicy + if listenAddr != "" { + tConfig.SetListenAddr(listenAddr) //Setting the IP address to listen on } Config := FullClientSettings{ @@ -248,7 +255,7 @@ func FullClientSettingsNew() FullClientSettings { PushBulletToken: pushBulletToken, }, TFileUploadFolder: "uploadedTorrents", - TorrentConfig: tConfig, + TorrentConfig: *tConfig, DefaultMoveFolder: defaultMoveFolderAbs, TorrentWatchFolder: torrentWatchFolderAbs, MaxActiveTorrents: maxActiveTorrents,