aboutsummaryrefslogtreecommitdiff
path: root/sth.go
diff options
context:
space:
mode:
Diffstat (limited to 'sth.go')
-rw-r--r--sth.go34
1 files changed, 17 insertions, 17 deletions
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) {