diff --git a/cmd/rv/main.go b/cmd/rv/main.go index fb8dd4b1..a93a1fb4 100644 --- a/cmd/rv/main.go +++ b/cmd/rv/main.go @@ -54,7 +54,6 @@ USAGE package main import ( - "fmt" "io" "os" "runtime/pprof" @@ -199,7 +198,7 @@ func run(rv *revid.Revid, ns *netsender.Sender, l *logger.Logger, nl *netlogger. continue } case modeBurst: - err = burst(l, rv, ns) + err = rv.Burst() if err != nil { l.Log(logger.Warning, pkg+"could not start burst", "error", err.Error()) ns.SetMode(modePaused, &vs) @@ -254,21 +253,3 @@ func readPin(rv *revid.Revid) func(pin *netsender.Pin) error { return nil } } - -// burst starts revid, waits for time specified in the Config.BurstPeriod -// field, and then stops revid. -// -// TODO: move this functionality to the revid API into a Revid.Burst(time) method. -func burst(l *logger.Logger, r *revid.Revid, s *netsender.Sender) error { - l.Log(logger.Info, pkg+"starting burst") - - err := r.Start() - if err != nil { - return fmt.Errorf("could not start revid: %w", err) - } - - time.Sleep(time.Duration(r.Config().BurstPeriod) * time.Second) - l.Log(logger.Info, pkg+"stopping burst") - r.Stop() - return nil -} diff --git a/revid/revid.go b/revid/revid.go index 4d0866d2..5af91f73 100644 --- a/revid/revid.go +++ b/revid/revid.go @@ -492,6 +492,23 @@ func (r *Revid) Stop() { r.running = false } +// Burst starts revid, waits for time specified, and then stops revid. +func (r *Revid) Burst() error { + r.cfg.Logger.Log(logger.Info, pkg+"starting burst") + + err := r.Start() + if err != nil { + return fmt.Errorf("could not start revid: %w", err) + } + + dur := time.Duration(r.cfg.BurstPeriod) * time.Second + time.Sleep(dur) + + r.cfg.Logger.Log(logger.Info, pkg+"stopping burst") + r.Stop() + return nil +} + func (r *Revid) IsRunning() bool { r.mu.Lock() defer r.mu.Unlock()