From 374ec482cd63cb63eeced60313000e3b9de5d1f4 Mon Sep 17 00:00:00 2001 From: Niko Storni Date: Thu, 4 Jun 2020 21:29:02 +0200 Subject: [PATCH] make timeout configurable don't republish thumbs that were published from previous channels --- config.json.example | 8 +++++++- configs/configs.go | 14 +++++++++----- main.go | 14 +++++++------- util/{ => ml}/multiplelock.go | 0 util/slice.go | 10 ++++++++++ 5 files changed, 33 insertions(+), 13 deletions(-) rename util/{ => ml}/multiplelock.go (100%) create mode 100644 util/slice.go diff --git a/config.json.example b/config.json.example index 0b572cd..0bba6e8 100644 --- a/config.json.example +++ b/config.json.example @@ -13,5 +13,11 @@ }, "channel_id": "", "publish_address": "", - "reflector_server": "reflector.lbry.com:5567" + "reflector_server": "reflector.lbry.com:5567", + "lbrynet_timeout": 300, + "previous_channel_ids": [ + "4c971f1076e39845c1643cdcf41d2287e1ea4961", + "f2cf43b86b9d70175dc22dbb9ff7806241d90780", + "2ad860f494345417824e30eb85f4ce7d1fea9cff" + ] } \ No newline at end of file diff --git a/configs/configs.go b/configs/configs.go index 2531d3d..5da10ec 100644 --- a/configs/configs.go +++ b/configs/configs.go @@ -1,6 +1,8 @@ package configs import ( + "time" + "github.com/lbryio/lbry.go/v2/extras/errors" "github.com/tkanos/gonfig" ) @@ -12,11 +14,13 @@ type DbConfig struct { Password string `json:"password"` } type Configs struct { - Chainquery DbConfig `json:"chainquery"` - Speech DbConfig `json:"speech"` - ChannelID string `json:"channel_id"` - PublishAddress string `json:"publish_address"` - ReflectorServer string `json:"reflector_server"` + Chainquery DbConfig `json:"chainquery"` + Speech DbConfig `json:"speech"` + ChannelID string `json:"channel_id"` + PublishAddress string `json:"publish_address"` + ReflectorServer string `json:"reflector_server"` + LbrynetTimeout time.Duration `json:"lbrynet_timeout"` + PreviousChannelIds []string `json:"previous_channel_ids"` } var Configuration *Configs diff --git a/main.go b/main.go index e4fb276..2530169 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ import ( "voidwalker/blobsdownloader" "voidwalker/chainquery" "voidwalker/configs" - ml "voidwalker/util" + ml2 "voidwalker/util/ml" "github.com/gabriel-vasile/mimetype" "github.com/gin-contrib/cors" @@ -38,8 +38,8 @@ var cqApi *chainquery.CQApi var downloadsDir string var uploadsDir string var blobsDir string -var viewLock ml.MultipleLock -var publishLock ml.MultipleLock +var viewLock ml2.MultipleLock +var publishLock ml2.MultipleLock func main() { err := configs.Init("./config.json") @@ -63,8 +63,8 @@ func main() { uploadsDir = usr.HomeDir + "/Uploads/" downloadsDir = usr.HomeDir + "/Downloads/" blobsDir = usr.HomeDir + "/.lbrynet/blobfiles/" - viewLock = ml.NewMultipleLock() - publishLock = ml.NewMultipleLock() + viewLock = ml2.NewMultipleLock() + publishLock = ml2.NewMultipleLock() cache = &sync.Map{} @@ -297,7 +297,7 @@ func publish(c *gin.Context) { return } for _, claim := range *resolveRsp { - if claim.SigningChannel != nil && claim.SigningChannel.ClaimID == channelID { + if claim.SigningChannel != nil && util.InSlice(claim.SigningChannel.ClaimID, configs.Configuration.PreviousChannelIds) { baseUrl := "https://spee.ch/" + claim.ClaimID[0:1] + "/" + checkSum[:16] extendedUrl := baseUrl + mimeType.Extension() response := PublishResponse{ @@ -420,5 +420,5 @@ type ClaimData struct { func initLbrynet() { daemon = jsonrpc.NewClient("") - daemon.SetRPCTimeout(1 * time.Minute) + daemon.SetRPCTimeout(configs.Configuration.LbrynetTimeout * time.Minute) } diff --git a/util/multiplelock.go b/util/ml/multiplelock.go similarity index 100% rename from util/multiplelock.go rename to util/ml/multiplelock.go diff --git a/util/slice.go b/util/slice.go new file mode 100644 index 0000000..1b7c0bc --- /dev/null +++ b/util/slice.go @@ -0,0 +1,10 @@ +package util + +func StringInSlice(a string, list []string) bool { + for _, b := range list { + if b == a { + return true + } + } + return false +}