Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: Ignore invalid tags #4517

Merged
merged 24 commits into from
Feb 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
0346b11
don't queue messages with unrecognized tags
cce Aug 31, 2022
0b0f37c
Merge remote-tracking branch 'upstream/master' into ignore-invalid-tags
cce Sep 8, 2022
0e2fe4c
update and add debug logging for bad tags
cce Sep 8, 2022
1b5595b
switch to setting telemetry field
cce Sep 8, 2022
9df1d0c
skip dropping message
cce Sep 8, 2022
06f5c56
add allowCustomTags
cce Sep 8, 2022
bfb3ca1
Merge remote-tracking branch 'upstream/master' into ignore-invalid-tags
cce Nov 9, 2022
ce2af33
turn OutOfProtocol into a counter
cce Nov 9, 2022
5e04cb8
Merge remote-tracking branch 'upstream/master' into ignore-invalid-tags
cce Jan 10, 2023
b7719f7
merge count test
cce Jan 10, 2023
0e702e4
update metric name
cce Jan 10, 2023
18ace9d
update OutOfProtocol to Unknown
cce Jan 10, 2023
ccd5f37
remove drop check behind dedupSafeTag
cce Jan 26, 2023
0c6f169
add test for wsPeer.readLoop to make sure the switch statement checks…
cce Jan 26, 2023
936e568
fix lint
cce Jan 26, 2023
5f0cd15
add protocol.TagList completeness check test
cce Jan 27, 2023
c91c1a4
remove UniCatchupReqTag
cce Jan 27, 2023
ceba110
add license to tags_test.go
cce Jan 27, 2023
12dbc02
add partitiontest for linter
cce Jan 27, 2023
a7dd7a7
add strconv.Unquote to TestTagList
cce Jan 27, 2023
0346817
add TestWebsocketNetworkBasicInvalidTags
cce Jan 27, 2023
e390c9a
update TestTagList
cce Jan 27, 2023
4fbc0f6
add TestHashIDPrefix and a few more comments
cce Jan 28, 2023
4a780fd
Update network/wsNetwork_test.go
algorandskiy Feb 1, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add protocol.TagList completeness check test
  • Loading branch information
cce committed Jan 27, 2023
commit 5f0cd15f5751d5b1034b60c2d2d6020596232e98
16 changes: 6 additions & 10 deletions network/wsPeer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,22 +257,18 @@ func getProtocolTags(t *testing.T) []string {
fset := token.NewFileSet()
f, _ := parser.ParseFile(fset, file, nil, parser.ParseComments)

// look for const declarations in protocol/tags.go
var declaredTags []string
for _, d := range f.Decls {
genDecl, ok := d.(*ast.GenDecl)
if !ok {
continue
}
if genDecl.Tok != token.CONST {
if !ok || genDecl.Tok != token.CONST {
continue
}
for _, spec := range genDecl.Specs {
valueSpec, ok := spec.(*ast.ValueSpec)
if !ok {
continue
}
for _, n := range valueSpec.Names {
declaredTags = append(declaredTags, n.Name)
if valueSpec, ok := spec.(*ast.ValueSpec); ok {
for _, n := range valueSpec.Names {
declaredTags = append(declaredTags, n.Name)
}
}
}
}
Expand Down
1 change: 0 additions & 1 deletion protocol/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ const (
)

// TagList is a list of all currently used protocol tags.
// TODO: generate this and/or have a test that it is complete.
var TagList = []Tag{
AgreementVoteTag,
MsgOfInterestTag,
Expand Down
53 changes: 53 additions & 0 deletions protocol/tags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package protocol

import (
"go/ast"
"go/parser"
"go/token"
"testing"

"github.com/stretchr/testify/require"
)

// TestTagList checks that the TagList global variable contains
// all the constant Tag variables declared in tags.go.
func TestTagList(t *testing.T) {
t.Parallel()

fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "tags.go", nil, 0)
require.NoError(t, err)

var constTags []Tag
for _, d := range f.Decls {
gen, ok := d.(*ast.GenDecl)
if !ok || gen.Tok != token.CONST {
continue
}

for _, spec := range gen.Specs {
v, ok := spec.(*ast.ValueSpec)
if !ok {
continue
}
for _, expr := range v.Values {
val, ok := expr.(*ast.BasicLit)
if !ok {
continue
}
constTags = append(constTags, Tag(val.Value))
}
}
}
require.NotEmpty(t, TagList)
require.Len(t, TagList, len(constTags), "TagList is not complete")
tagMap := make(map[Tag]bool)
for _, tag := range TagList {
tagMap[tag] = true
}
for _, tag := range constTags {
if !tagMap[tag] {
t.Errorf("Tag %s is not in TagList", tag)
}
cce marked this conversation as resolved.
Show resolved Hide resolved
}
}