Skip to content
This repository was archived by the owner on Oct 11, 2024. It is now read-only.

Commit 04b4354

Browse files
committed
gometalinter
1 parent 94f7508 commit 04b4354

File tree

8 files changed

+63
-22
lines changed

8 files changed

+63
-22
lines changed

cmd/keytransparency-monitor/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ import (
3535
"google.golang.org/grpc/credentials"
3636
"google.golang.org/grpc/reflection"
3737

38-
"github.com/google/keytransparency/core/monitor/storage"
3938
cmon "github.com/google/keytransparency/core/monitor"
39+
"github.com/google/keytransparency/core/monitor/storage"
4040
kpb "github.com/google/keytransparency/core/proto/keytransparency_v1_types"
4141
"github.com/google/keytransparency/impl/monitor/client"
4242
spb "github.com/google/keytransparency/impl/proto/keytransparency_v1_service"

core/monitor/monitor.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ import (
2525
ktpb "github.com/google/keytransparency/core/proto/keytransparency_v1_types"
2626

2727
"github.com/google/trillian"
28+
tcrypto "github.com/google/trillian/crypto"
2829
"github.com/google/trillian/merkle"
2930
"github.com/google/trillian/merkle/hashers"
30-
tcrypto "github.com/google/trillian/crypto"
3131
)
3232

3333
// Monitor holds the internal state for a monitor accessing the mutations API
@@ -63,11 +63,14 @@ func New(logTree, mapTree *trillian.Tree, signer *tcrypto.Signer, store *storage
6363
}, nil
6464
}
6565

66+
// Process processes a mutation response received from the keytransparency
67+
// server. Processing includes verifying, signing and storing the resulting
68+
// monitoring response.
6669
func (m *Monitor) Process(resp *ktpb.GetMutationsResponse) error {
6770
var smr *trillian.SignedMapRoot
6871
var err error
6972
seen := time.Now().Unix()
70-
errs := m.VerifyMutationsResponse(resp)
73+
errs := m.verifyMutationsResponse(resp)
7174
if len(errs) == 0 {
7275
glog.Infof("Successfully verified mutations response for epoch: %v", resp.Epoch)
7376
smr, err = m.signMapRoot(resp)

core/monitor/storage/storage.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,45 @@ import (
2222
)
2323

2424
var (
25+
// ErrAlreadyStored is raised if the caller tries storing a response which
26+
// has already been stored.
2527
ErrAlreadyStored = errors.New("already stored epoch")
26-
ErrNotFound = errors.New("data for epoch not found")
28+
// ErrNotFound is raised if the caller tries to retrieve data for an epoch
29+
// which has not been processed and stored yet.
30+
ErrNotFound = errors.New("data for epoch not found")
2731
)
2832

33+
// MonitoringResult stores all data
2934
type MonitoringResult struct {
30-
// in case of success this contains the map root signed by the monitor
35+
// Smr contains the map root signed by the monitor in case all verifications
36+
// have passed.
3137
Smr *trillian.SignedMapRoot
32-
// response contains the original mutations API response from the server
33-
// in case at least one verification step failed
38+
// Seen is the the unix timestamp at which the mutations response has been
39+
// received.
40+
Seen int64
41+
// Errors contains a string representation of the verifications steps that
42+
// failed.
43+
Errors []error
44+
// Response contains the original mutations API response from the server
45+
// in case at least one verification step failed.
3446
Response *ktpb.GetMutationsResponse
35-
Seen int64
36-
Errors []error
3747
}
3848

49+
// Storage is an in-memory store for the monitoring results.
3950
type Storage struct {
40-
store map[int64]*MonitoringResult
51+
store map[int64]*MonitoringResult
4152
latest int64
4253
}
4354

55+
// New initializes a
4456
func New() *Storage {
4557
return &Storage{
4658
store: make(map[int64]*MonitoringResult),
4759
}
4860
}
4961

62+
// Set internally stores the given data as a MonitoringResult which can be
63+
// retrieved by Get.
5064
func (s *Storage) Set(epoch int64,
5165
seenNanos int64,
5266
smr *trillian.SignedMapRoot,
@@ -63,17 +77,20 @@ func (s *Storage) Set(epoch int64,
6377
Response: response,
6478
Errors: errorList,
6579
}
66-
s.latest=epoch
80+
s.latest = epoch
6781
return nil
6882
}
6983

84+
// Get returns the MonitoringResult for the given epoch. It returns an error
85+
// if the result does not exist.
7086
func (s *Storage) Get(epoch int64) (*MonitoringResult, error) {
7187
if result, ok := s.store[epoch]; ok {
7288
return result, nil
7389
}
7490
return nil, ErrNotFound
7591
}
7692

93+
// LatestEpoch is a convenience method to retrieve the latest stored epoch.
7794
func (s *Storage) LatestEpoch() int64 {
7895
return s.latest
7996
}

core/monitor/verify.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ import (
2121
ktpb "github.com/google/keytransparency/core/proto/keytransparency_v1_types"
2222
)
2323

24-
// VerifyResponse verifies a response received by the GetMutations API.
24+
// verifyMutationsResponse verifies a response received by the GetMutations API.
2525
// Additionally to the response it takes a complete list of mutations. The list
2626
// of received mutations may differ from those included in the initial response
2727
// because of the max. page size. If any verification check failed it returns
2828
// an error.
29-
func (m *Monitor) VerifyMutationsResponse(in *ktpb.GetMutationsResponse) []error {
29+
func (m *Monitor) verifyMutationsResponse(in *ktpb.GetMutationsResponse) []error {
3030
return nil
3131
}

impl/monitor/client/client.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
package client
1616

1717
//
18-
// This file contains Monitor's grpc client logic: poll mutations from the
18+
// This file contains Monitor'c grpc client logic: poll mutations from the
1919
// kt-server mutations API and page if necessary.
2020
//
2121

@@ -44,7 +44,7 @@ type Client struct {
4444
// New initializes a new mutations API monitoring client.
4545
func New(client mupb.MutationServiceClient, pollPeriod time.Duration) *Client {
4646
return &Client{
47-
client: client,
47+
client: client,
4848
pollPeriod: pollPeriod,
4949
}
5050
}
@@ -80,10 +80,10 @@ func (c *Client) StartPolling(startEpoch int64) (<-chan *ktpb.GetMutationsRespon
8080
return response, errChan
8181
}
8282

83-
func (s *Client) pollMutations(ctx context.Context,
83+
func (c *Client) pollMutations(ctx context.Context,
8484
queryEpoch int64,
8585
opts ...grpc.CallOption) (*ktpb.GetMutationsResponse, error) {
86-
response, err := s.client.GetMutations(ctx, &ktpb.GetMutationsRequest{
86+
response, err := c.client.GetMutations(ctx, &ktpb.GetMutationsRequest{
8787
PageSize: pageSize,
8888
Epoch: queryEpoch,
8989
}, opts...)
@@ -94,7 +94,7 @@ func (s *Client) pollMutations(ctx context.Context,
9494
// Page if necessary: query all mutations in the current epoch
9595
for response.GetNextPageToken() != "" {
9696
req := &ktpb.GetMutationsRequest{PageSize: pageSize}
97-
resp, err := s.client.GetMutations(ctx, req, opts...)
97+
resp, err := c.client.GetMutations(ctx, req, opts...)
9898
if err != nil {
9999
return nil, err
100100
}

impl/monitor/server.go

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,24 @@
1+
// Copyright 2017 Google Inc. All Rights Reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// Package monitor implements the monitor service. A monitor repeatedly polls a
16+
// key-transparency server's Mutations API and signs Map Roots if it could
17+
// reconstruct
18+
// clients can query.
19+
20+
// Package monitor contains an implementation of a Monitor server which can be
21+
// queried for monitoring results.
122
package monitor
223

324
import (
@@ -67,8 +88,8 @@ func (s *Server) getResponseByRevision(epoch int64) (*mopb.GetMonitoringResponse
6788
}
6889

6990
if len(res.Errors) > 0 {
70-
for _, err := range resp.Errors {
71-
resp.Errors = append(resp.Errors, err)
91+
for _, err := range res.Errors {
92+
resp.Errors = append(resp.Errors, err.Error())
7293
}
7394
// data to replay the verification steps:
7495
resp.ErrorData = res.Response

vendor/github.com/pelletier/go-toml/tomltree_write.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/spf13/viper/viper.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)