Pulled in latest version of libraries, added Socks5 config
This commit is contained in:
@@ -35,6 +35,13 @@
|
||||
#URL is CASE SENSITIVE
|
||||
BaseURL = "domain.com/subroute/" # MUST be in the format (if you have a subdomain, and must have trailing slash) "yoursubdomain.domain.org/subroute/"
|
||||
|
||||
[socksProxy]
|
||||
SocksProxyEnabled = false #bool, either false or true
|
||||
# Sets usage of Socks5 Proxy. Authentication should be included in the url if needed.
|
||||
# Examples: socks5://demo:demo@192.168.99.100:1080
|
||||
# http://proxy.domain.com:3128
|
||||
SocksProxyURL = ""
|
||||
|
||||
[EncryptionPolicy]
|
||||
|
||||
DisableEncryption = false
|
||||
|
@@ -221,6 +221,9 @@ func CreateInitialTorrentArray(tclient *torrent.Client, TorrentLocalArray []*Sto
|
||||
singleTorrent.SetMaxEstablishedConns(0)
|
||||
continue
|
||||
}
|
||||
if singleTorrentFromStorage.TorrentStatus == "ForceStart" {
|
||||
AddTorrentToForceStart(singleTorrentFromStorage, singleTorrent, db)
|
||||
}
|
||||
if len(torrentQueues.ActiveTorrents) == 0 && len(torrentQueues.QueuedTorrents) == 0 { // If empty, run through all the torrents and assign them
|
||||
if len(torrentQueues.ActiveTorrents) < Config.MaxActiveTorrents {
|
||||
if singleTorrentFromStorage.TorrentStatus == "Completed" || singleTorrentFromStorage.TorrentStatus == "Seeding" {
|
||||
|
@@ -199,6 +199,45 @@ func StopTorrent(singleTorrent *torrent.Torrent, torrentLocalStorage *Storage.To
|
||||
Logger.WithFields(logrus.Fields{"Torrent Name": torrentLocalStorage.TorrentName}).Info("Torrent Stopped Success!")
|
||||
}
|
||||
|
||||
//AddTorrentToForceStart forces torrent to be high priority on start
|
||||
func AddTorrentToForceStart(torrentLocalStorage *Storage.TorrentLocal, singleTorrent *torrent.Torrent, db *storm.DB) {
|
||||
torrentQueues := Storage.FetchQueues(db)
|
||||
for index, torrentHash := range torrentQueues.ActiveTorrents {
|
||||
if torrentHash == singleTorrent.InfoHash().String() { //If torrent already in active remove from active
|
||||
torrentQueues.ActiveTorrents = append(torrentQueues.ActiveTorrents[:index], torrentQueues.ActiveTorrents[index+1:]...)
|
||||
}
|
||||
}
|
||||
for index, queuedTorrentHash := range torrentQueues.QueuedTorrents { //Removing from the queued torrents if in queued torrents
|
||||
if queuedTorrentHash == singleTorrent.InfoHash().String() {
|
||||
torrentQueues.QueuedTorrents = append(torrentQueues.QueuedTorrents[:index], torrentQueues.QueuedTorrents[index+1:]...)
|
||||
}
|
||||
}
|
||||
singleTorrent.NewReader()
|
||||
singleTorrent.SetMaxEstablishedConns(80)
|
||||
torrentQueues.ActiveTorrents = append(torrentQueues.ActiveTorrents, singleTorrent.InfoHash().String())
|
||||
torrentLocalStorage.TorrentStatus = "ForceStart"
|
||||
torrentLocalStorage.MaxConnections = 80
|
||||
for _, file := range singleTorrent.Files() {
|
||||
for _, sentFile := range torrentLocalStorage.TorrentFilePriority {
|
||||
if file.DisplayPath() == sentFile.TorrentFilePath {
|
||||
switch sentFile.TorrentFilePriority {
|
||||
case "High":
|
||||
file.SetPriority(torrent.PiecePriorityHigh)
|
||||
case "Normal":
|
||||
file.SetPriority(torrent.PiecePriorityNormal)
|
||||
case "Cancel":
|
||||
file.SetPriority(torrent.PiecePriorityNone)
|
||||
default:
|
||||
file.SetPriority(torrent.PiecePriorityNormal)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Logger.WithFields(logrus.Fields{"Torrent Name": torrentLocalStorage.TorrentName}).Info("Adding Torrent to ForceStart Queue")
|
||||
Storage.UpdateStorageTick(db, *torrentLocalStorage)
|
||||
Storage.UpdateQueues(db, torrentQueues)
|
||||
}
|
||||
|
||||
//AddTorrentToActive adds a torrent to the active slice
|
||||
func AddTorrentToActive(torrentLocalStorage *Storage.TorrentLocal, singleTorrent *torrent.Torrent, db *storm.DB) {
|
||||
torrentQueues := Storage.FetchQueues(db)
|
||||
@@ -238,6 +277,7 @@ func AddTorrentToActive(torrentLocalStorage *Storage.TorrentLocal, singleTorrent
|
||||
}
|
||||
}
|
||||
Logger.WithFields(logrus.Fields{"Torrent Name": torrentLocalStorage.TorrentName}).Info("Adding Torrent to Active Queue (Manual Call)")
|
||||
Storage.UpdateStorageTick(db, *torrentLocalStorage)
|
||||
Storage.UpdateQueues(db, torrentQueues)
|
||||
}
|
||||
|
||||
@@ -274,6 +314,12 @@ func DeleteTorrentFromQueues(torrentHash string, db *storm.DB) {
|
||||
Logger.Info("Removing Torrent from Queued", torrentHash)
|
||||
}
|
||||
}
|
||||
for x, torrentHashActive := range torrentQueues.ForcedTorrents { //FOR EXTRA CAUTION deleting it from all queues in case a mistake occurred.
|
||||
if torrentHash == torrentHashActive {
|
||||
torrentQueues.ForcedTorrents = append(torrentQueues.ForcedTorrents[:x], torrentQueues.ForcedTorrents[x+1:]...)
|
||||
Logger.Info("Removing Torrent from Forced: ", torrentHash)
|
||||
}
|
||||
}
|
||||
Storage.UpdateQueues(db, torrentQueues)
|
||||
Logger.WithFields(logrus.Fields{"Torrent Hash": torrentHash, "TorrentQueues": torrentQueues}).Info("Removing Torrent from all Queues")
|
||||
}
|
||||
|
12
main.go
12
main.go
@@ -550,18 +550,18 @@ func main() {
|
||||
Logger.WithFields(logrus.Fields{"infoHash": singleTorrent.InfoHash().String()}).Info("Found matching torrent to start")
|
||||
oldTorrentInfo := Storage.FetchTorrentFromStorage(db, singleTorrent.InfoHash().String())
|
||||
Logger.WithFields(logrus.Fields{"Torrent": oldTorrentInfo.TorrentName}).Info("Changing database to torrent running with 80 max connections")
|
||||
oldTorrentInfo.TorrentStatus = "Running"
|
||||
oldTorrentInfo.TorrentStatus = "ForceStart"
|
||||
oldTorrentInfo.MaxConnections = 80
|
||||
Storage.UpdateStorageTick(db, oldTorrentInfo) //Updating the torrent status
|
||||
Engine.AddTorrentToActive(&oldTorrentInfo, singleTorrent, db)
|
||||
Engine.AddTorrentToForceStart(&oldTorrentInfo, singleTorrent, db)
|
||||
|
||||
}
|
||||
torrentQueues = Storage.FetchQueues(db)
|
||||
if len(torrentQueues.ActiveTorrents) > Config.MaxActiveTorrents { //Since we are starting a new torrent stop the first torrent in the que if running is full
|
||||
if len(torrentQueues.ActiveTorrents) > Config.MaxActiveTorrents { //Since we are starting a new torrent stop the last torrent in the que if running is full
|
||||
//removeTorrent := torrentQueues.ActiveTorrents[len(torrentQueues.ActiveTorrents)-1]
|
||||
removeTorrent := torrentQueues.ActiveTorrents[:1]
|
||||
removeTorrent := torrentQueues.ActiveTorrents[len(torrentQueues.ActiveTorrents)-1]
|
||||
for _, singleTorrent := range runningTorrents {
|
||||
if singleTorrent.InfoHash().String() == removeTorrent[0] {
|
||||
if singleTorrent.InfoHash().String() == removeTorrent {
|
||||
oldTorrentInfo := Storage.FetchTorrentFromStorage(db, singleTorrent.InfoHash().String())
|
||||
Engine.RemoveTorrentFromActive(&oldTorrentInfo, singleTorrent, db)
|
||||
Storage.UpdateStorageTick(db, oldTorrentInfo)
|
||||
@@ -638,7 +638,7 @@ func main() {
|
||||
}
|
||||
|
||||
})
|
||||
if Config.UseProxy {
|
||||
if Config.UseReverseProxy {
|
||||
err := http.ListenAndServe(httpAddr, handlers.ProxyHeaders(router))
|
||||
if err != nil {
|
||||
Logger.WithFields(logrus.Fields{"error": err}).Fatal("Unable to listen on the http Server!")
|
||||
|
@@ -42,7 +42,7 @@ func GenerateClientConfigFile(config FullClientSettings, authString string) {
|
||||
`
|
||||
}
|
||||
|
||||
if config.UseProxy {
|
||||
if config.UseReverseProxy {
|
||||
clientFile = `
|
||||
ClientAuthString = "` + authString + `"
|
||||
` + webUIAuth + `
|
||||
|
@@ -21,9 +21,11 @@ var Logger *logrus.Logger
|
||||
type ClientConnectSettings struct {
|
||||
HTTPAddr string
|
||||
HTTPAddrIP string
|
||||
UseProxy bool
|
||||
UseReverseProxy bool
|
||||
UseSocksProxy bool
|
||||
WebsocketClientPort string
|
||||
BaseURL string
|
||||
SocksProxyURL string
|
||||
ClientUsername string
|
||||
ClientPassword string
|
||||
PushBulletToken string `json:"-"`
|
||||
@@ -119,6 +121,7 @@ func FullClientSettingsNew() FullClientSettings {
|
||||
|
||||
var httpAddr string
|
||||
var baseURL string
|
||||
var socksProxyURLBase string
|
||||
var websocketClientPort string
|
||||
var logLevel logrus.Level
|
||||
//logging
|
||||
@@ -151,6 +154,10 @@ func FullClientSettingsNew() FullClientSettings {
|
||||
baseURL = viper.GetString("reverseProxy.BaseURL")
|
||||
fmt.Println("WebsocketClientPort", viper.GetString("serverConfig.ServerPort"))
|
||||
}
|
||||
socksProxySet := viper.GetBool("socksProxy.ProxyEnabled")
|
||||
if socksProxySet {
|
||||
socksProxyURLBase = viper.GetString("reverseProxy.BaseURL")
|
||||
}
|
||||
//Client Authentication
|
||||
clientAuthEnabled := viper.GetBool("goTorrentWebUI.WebUIAuth")
|
||||
var webUIUser string
|
||||
@@ -247,11 +254,13 @@ func FullClientSettingsNew() FullClientSettings {
|
||||
ClientConnectSettings: ClientConnectSettings{
|
||||
HTTPAddr: httpAddr,
|
||||
HTTPAddrIP: httpAddrIP,
|
||||
UseProxy: proxySet,
|
||||
UseReverseProxy: proxySet,
|
||||
UseSocksProxy: socksProxySet,
|
||||
WebsocketClientPort: websocketClientPort,
|
||||
ClientUsername: webUIUser,
|
||||
ClientPassword: webUIPasswordHash,
|
||||
BaseURL: baseURL,
|
||||
SocksProxyURL: socksProxyURLBase,
|
||||
PushBulletToken: pushBulletToken,
|
||||
},
|
||||
TFileUploadFolder: "uploadedTorrents",
|
||||
|
@@ -22,6 +22,7 @@ type TorrentQueues struct {
|
||||
ID int `storm:"id,unique"` //storm requires unique ID (will be 5)
|
||||
ActiveTorrents []string
|
||||
QueuedTorrents []string
|
||||
ForcedTorrents []string
|
||||
}
|
||||
|
||||
//IssuedTokensList contains a slice of all the tokens issues to applications
|
||||
@@ -79,7 +80,7 @@ type TorrentLocal struct {
|
||||
TempStoragePath string //The absolute path of where the torrent is temporarily stored as it is downloaded
|
||||
TorrentMoved bool //If completed has the torrent been moved to the end location
|
||||
TorrentName string
|
||||
TorrentStatus string //"Stopped", "Running"
|
||||
TorrentStatus string //"Stopped", "Running", "ForceStart"
|
||||
TorrentUploadLimit bool //if true this torrent will bypass the upload storage limit (effectively unlimited)
|
||||
MaxConnections int //Max connections that the torrent can have to it at one time
|
||||
TorrentType string //magnet or .torrent file
|
||||
|
Reference in New Issue
Block a user