From b72142ace5a395b32563f79babc26e46b4586cf8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 20 Sep 2017 13:40:22 +0100 Subject: [PATCH] Add vet linter (#240) --- linter-fast.json | 3 ++- linter.json | 3 ++- .../dendrite/clientapi/writers/createroom.go | 10 ++++---- .../dendrite-federation-api-server/main.go | 2 +- .../dendrite/common/config/config.go | 2 +- .../dendrite/common/keydb/server_key_table.go | 3 ++- .../dendrite/federationapi/readers/keys.go | 2 +- .../roomserver/input/authevents_test.go | 25 +++++++++++-------- .../dendrite/roomserver/state/state_test.go | 17 +++++++------ 9 files changed, 38 insertions(+), 29 deletions(-) diff --git a/linter-fast.json b/linter-fast.json index 2abb30aff..fce445f20 100644 --- a/linter-fast.json +++ b/linter-fast.json @@ -10,6 +10,7 @@ "ineffassign", "gas", "misspell", - "errcheck" + "errcheck", + "vet" ] } diff --git a/linter.json b/linter.json index 649e6a0e5..f8da97782 100644 --- a/linter.json +++ b/linter.json @@ -15,6 +15,7 @@ "gas", "misspell", "unparam", - "errcheck" + "errcheck", + "vet" ] } diff --git a/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go b/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go index 7d5d318db..99ba2ebdb 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go +++ b/src/github.com/matrix-org/dendrite/clientapi/writers/createroom.go @@ -163,12 +163,12 @@ func createRoom(req *http.Request, device *authtypes.Device, {"m.room.member", userID, membershipContent}, {"m.room.power_levels", "", common.InitialPowerLevelsContent(userID)}, // TODO: m.room.canonical_alias - {"m.room.join_rules", "", common.JoinRulesContent{"public"}}, // FIXME: Allow this to be changed - {"m.room.history_visibility", "", common.HistoryVisibilityContent{"joined"}}, // FIXME: Allow this to be changed - {"m.room.guest_access", "", common.GuestAccessContent{"can_join"}}, // FIXME: Allow this to be changed + {"m.room.join_rules", "", common.JoinRulesContent{JoinRule: "public"}}, // FIXME: Allow this to be changed + {"m.room.history_visibility", "", common.HistoryVisibilityContent{HistoryVisibility: "joined"}}, // FIXME: Allow this to be changed + {"m.room.guest_access", "", common.GuestAccessContent{GuestAccess: "can_join"}}, // FIXME: Allow this to be changed // TODO: Other initial state items - {"m.room.name", "", common.NameContent{r.Name}}, // FIXME: Only send the name event if a name is supplied, to avoid sending a false room name removal event - {"m.room.topic", "", common.TopicContent{r.Topic}}, + {"m.room.name", "", common.NameContent{Name: r.Name}}, // FIXME: Only send the name event if a name is supplied, to avoid sending a false room name removal event + {"m.room.topic", "", common.TopicContent{Topic: r.Topic}}, // TODO: invite events // TODO: 3pid invite events // TODO: m.room.aliases diff --git a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go index 151a7a9f4..b287ea629 100644 --- a/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go +++ b/src/github.com/matrix-org/dendrite/cmd/dendrite-federation-api-server/main.go @@ -67,7 +67,7 @@ func main() { keyRing := gomatrixserverlib.KeyRing{ KeyFetchers: []gomatrixserverlib.KeyFetcher{ // TODO: Use perspective key fetchers for production. - &gomatrixserverlib.DirectKeyFetcher{federation.Client}, + &gomatrixserverlib.DirectKeyFetcher{Client: federation.Client}, }, KeyDatabase: keyDB, } diff --git a/src/github.com/matrix-org/dendrite/common/config/config.go b/src/github.com/matrix-org/dendrite/common/config/config.go index 86234b8da..019774b45 100644 --- a/src/github.com/matrix-org/dendrite/common/config/config.go +++ b/src/github.com/matrix-org/dendrite/common/config/config.go @@ -413,7 +413,7 @@ func fingerprintPEM(data []byte) *gomatrixserverlib.TLSFingerprint { } if certDERBlock.Type == "CERTIFICATE" { digest := sha256.Sum256(certDERBlock.Bytes) - return &gomatrixserverlib.TLSFingerprint{digest[:]} + return &gomatrixserverlib.TLSFingerprint{SHA256: digest[:]} } } } diff --git a/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go b/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go index a459bd8c3..b1d6d65f5 100644 --- a/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go +++ b/src/github.com/matrix-org/dendrite/common/keydb/server_key_table.go @@ -97,7 +97,8 @@ func (s *serverKeyStatements) bulkSelectServerKeys( return nil, err } r := gomatrixserverlib.PublicKeyRequest{ - gomatrixserverlib.ServerName(serverName), gomatrixserverlib.KeyID(keyID), + ServerName: gomatrixserverlib.ServerName(serverName), + KeyID: gomatrixserverlib.KeyID(keyID), } results[r] = serverKeys } diff --git a/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go b/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go index fcca201e6..b28bdec99 100644 --- a/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go +++ b/src/github.com/matrix-org/dendrite/federationapi/readers/keys.go @@ -44,7 +44,7 @@ func localKeys(cfg config.Dendrite, validUntil time.Time) (*gomatrixserverlib.Se keys.VerifyKeys = map[gomatrixserverlib.KeyID]gomatrixserverlib.VerifyKey{ cfg.Matrix.KeyID: { - gomatrixserverlib.Base64String(publicKey), + Key: gomatrixserverlib.Base64String(publicKey), }, } diff --git a/src/github.com/matrix-org/dendrite/roomserver/input/authevents_test.go b/src/github.com/matrix-org/dendrite/roomserver/input/authevents_test.go index 3e4d194ba..0621a0842 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/input/authevents_test.go +++ b/src/github.com/matrix-org/dendrite/roomserver/input/authevents_test.go @@ -15,24 +15,29 @@ package input import ( - "github.com/matrix-org/dendrite/roomserver/types" "testing" + + "github.com/matrix-org/dendrite/roomserver/types" ) func benchmarkStateEntryMapLookup(entries, lookups int64, b *testing.B) { var list []types.StateEntry for i := int64(0); i < entries; i++ { - list = append(list, types.StateEntry{types.StateKeyTuple{ - types.EventTypeNID(i), - types.EventStateKeyNID(i), - }, types.EventNID(i)}) + list = append(list, types.StateEntry{ + StateKeyTuple: types.StateKeyTuple{ + EventTypeNID: types.EventTypeNID(i), + EventStateKeyNID: types.EventStateKeyNID(i), + }, + EventNID: types.EventNID(i), + }) } for i := 0; i < b.N; i++ { entryMap := stateEntryMap(list) for j := int64(0); j < lookups; j++ { entryMap.lookup(types.StateKeyTuple{ - types.EventTypeNID(j), types.EventStateKeyNID(j), + EventTypeNID: types.EventTypeNID(j), + EventStateKeyNID: types.EventStateKeyNID(j), }) } } @@ -56,9 +61,9 @@ func BenchmarkStateEntryMap1000Lookup10000(b *testing.B) { func TestStateEntryMap(t *testing.T) { entryMap := stateEntryMap([]types.StateEntry{ - {types.StateKeyTuple{1, 1}, 1}, - {types.StateKeyTuple{1, 3}, 2}, - {types.StateKeyTuple{2, 1}, 3}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 3}, EventNID: 2}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 2, EventStateKeyNID: 1}, EventNID: 3}, }) testCases := []struct { @@ -78,7 +83,7 @@ func TestStateEntryMap(t *testing.T) { } for _, testCase := range testCases { - keyTuple := types.StateKeyTuple{testCase.inputTypeNID, testCase.inputStateKey} + keyTuple := types.StateKeyTuple{EventTypeNID: testCase.inputTypeNID, EventStateKeyNID: testCase.inputStateKey} gotEventNID, gotOK := entryMap.lookup(keyTuple) if testCase.wantOK != gotOK { t.Fatalf("stateEntryMap lookup(%v): want ok to be %v, got %v", keyTuple, testCase.wantOK, gotOK) diff --git a/src/github.com/matrix-org/dendrite/roomserver/state/state_test.go b/src/github.com/matrix-org/dendrite/roomserver/state/state_test.go index 78d29f78d..67af18671 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/state/state_test.go +++ b/src/github.com/matrix-org/dendrite/roomserver/state/state_test.go @@ -15,8 +15,9 @@ package state import ( - "github.com/matrix-org/dendrite/roomserver/types" "testing" + + "github.com/matrix-org/dendrite/roomserver/types" ) func TestFindDuplicateStateKeys(t *testing.T) { @@ -25,18 +26,18 @@ func TestFindDuplicateStateKeys(t *testing.T) { Want []types.StateEntry }{{ Input: []types.StateEntry{ - {types.StateKeyTuple{1, 1}, 1}, - {types.StateKeyTuple{1, 1}, 2}, - {types.StateKeyTuple{2, 2}, 3}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 2}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 2, EventStateKeyNID: 2}, EventNID: 3}, }, Want: []types.StateEntry{ - {types.StateKeyTuple{1, 1}, 1}, - {types.StateKeyTuple{1, 1}, 2}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 2}, }, }, { Input: []types.StateEntry{ - {types.StateKeyTuple{1, 1}, 1}, - {types.StateKeyTuple{1, 2}, 2}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 1}, EventNID: 1}, + {StateKeyTuple: types.StateKeyTuple{EventTypeNID: 1, EventStateKeyNID: 2}, EventNID: 2}, }, Want: nil, }}