Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const (
)

var (
version = "x.x.x"
version = "0.0.0-dev"
debugMqtt = false
)

Expand Down
20 changes: 16 additions & 4 deletions status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions updater/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 i, 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")
}
Expand Down