aboutsummaryrefslogtreecommitdiff
path: root/sth.go
diff options
context:
space:
mode:
authorRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-18 19:32:07 +0100
committerRasmus Dahlberg <rasmus.dahlberg@kau.se>2021-02-18 19:32:07 +0100
commitf0a7ea609523e663d02ad832bfa669c7cbbb3f38 (patch)
treef64d1a63e6d66e3b52810e783b1d62e91256b9d5 /sth.go
parentf93ca569f1c892217786302e6a46682f015fda57 (diff)
reordered SthSource functions
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) {