From f0a7ea609523e663d02ad832bfa669c7cbbb3f38 Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Thu, 18 Feb 2021 19:32:07 +0100 Subject: reordered SthSource functions --- sth.go | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'sth.go') diff --git a/sth.go b/sth.go index 810bd58..cff0736 100644 --- a/sth.go +++ b/sth.go @@ -58,6 +58,23 @@ func NewActiveSthSource(cli trillian.TrillianLogClient, lp *LogParameters) (*Act return &s, nil } +func (s *ActiveSthSource) Run(ctx context.Context) { + schedule.Every(ctx, s.logParameters.Interval, func(ctx context.Context) { + // get the next stable sth + ictx, _ := context.WithTimeout(ctx, s.logParameters.Deadline) + sth, err := s.Latest(ictx) + if err != nil { + glog.Warningf("cannot rotate without new sth: Latest: %v", err) + return + } + // rotate + s.mutex.Lock() + defer s.mutex.Unlock() + s.rotate(sth) + // TODO: persist cosigned STH? + }) +} + func (s *ActiveSthSource) Latest(ctx context.Context) (*StItem, error) { trsp, err := s.client.GetLatestSignedLogRoot(ctx, &trillian.GetLatestSignedLogRootRequest{ LogId: s.logParameters.TreeId, @@ -105,23 +122,6 @@ func (s *ActiveSthSource) AddCosignature(_ context.Context, costh *StItem) error return nil } -func (s *ActiveSthSource) Run(ctx context.Context) { - schedule.Every(ctx, s.logParameters.Interval, func(ctx context.Context) { - // get the next stable sth - ictx, _ := context.WithTimeout(ctx, s.logParameters.Deadline) - sth, err := s.Latest(ictx) - if err != nil { - glog.Warningf("cannot rotate without new sth: Latest: %v", err) - return - } - // rotate - s.mutex.Lock() - defer s.mutex.Unlock() - s.rotate(sth) - // TODO: persist cosigned STH? - }) -} - // rotate rotates the log's cosigned and stable STH. The caller must aquire the // source's read-write lock if there are concurrent reads and/or writes. func (s *ActiveSthSource) rotate(fixedSth *StItem) { -- cgit v1.2.3