diff --git a/main.go b/main.go index 518976af..7df9860e 100644 --- a/main.go +++ b/main.go @@ -44,7 +44,7 @@ const ( ) var ( - version = "x.x.x" + version = "0.0.0-dev" debugMqtt = false ) diff --git a/status.go b/status.go index f67cda28..cbd1cfe2 100644 --- a/status.go +++ b/status.go @@ -31,10 +31,11 @@ import ( // Status contains info about the sketches running on the device type Status struct { - id string - mqttClient mqtt.Client - Sketches map[string]*SketchStatus `json:"sketches"` - messagesSent int + id string + mqttClient mqtt.Client + Sketches map[string]*SketchStatus `json:"sketches"` + messagesSent int + firstMessageAt time.Time } // SketchBinding represents a pair (SketchName,SketchId) @@ -121,7 +122,18 @@ func (s *Status) Raw(topic, msg string) { if s.mqttClient == nil { return } + + if s.messagesSent < 10 { + // first 10 messages are virtually free + s.firstMessageAt = time.Now() + } + if s.messagesSent > 1000 { + // if started more than one day ago, reset the counter + if time.Since(s.firstMessageAt) > 24*time.Hour { + s.messagesSent = 0 + } + fmt.Println("rate limiting: " + strconv.Itoa(s.messagesSent)) introducedDelay := time.Duration(s.messagesSent/1000) * time.Second if introducedDelay > 20*time.Second { diff --git a/updater/updater.go b/updater/updater.go index 70bd628f..bf59b12c 100644 --- a/updater/updater.go +++ b/updater/updater.go @@ -232,9 +232,19 @@ func (u *Updater) update() error { return err } + // this is the version publically available (GA) v1, _ := semver.Make(u.Info.Version) + // this is the version of the actual binary at start v2, _ := semver.Make(u.CurrentVersion) + if len(v2.Pre) > 0 { + log.Println("Prerelease versions:") + for _, pre := range v2.Pre { + if pre.String() == "dev" { + return errors.New("dev version") + } + } + } if v1.Compare(v2) <= 0 { return errors.New("already at latest version") }