Skip to content

Commit

Permalink
fix: rename to protocolsAllowed for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
2color committed Sep 25, 2024
1 parent 9811e83 commit 51f200a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions routing/http/server/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func applyFilters(provider *types.PeerRecord, filterAddrs, filterProtocols []str
return provider
}

if !applyProtocolFilter(provider.Protocols, filterProtocols) {
if !protocolsAllowed(provider.Protocols, filterProtocols) {
// If the provider doesn't match any of the passed protocols, the provider is omitted from the response.
return nil
}
Expand Down Expand Up @@ -177,7 +177,8 @@ func containsProtocol(protos []multiaddr.Protocol, proto multiaddr.Protocol) boo
return false
}

func applyProtocolFilter(peerProtocols []string, filterProtocols []string) bool {
// protocolsAllowed returns true if the peerProtocols are allowed by the filter protocols.
func protocolsAllowed(peerProtocols []string, filterProtocols []string) bool {
if len(filterProtocols) == 0 {
// If no filter is passed, do not filter
return true
Expand Down
4 changes: 2 additions & 2 deletions routing/http/server/filters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ func TestApplyAddrFilter(t *testing.T) {
}
}

func TestApplyProtocolFilter(t *testing.T) {
func TestProtocolsAllowed(t *testing.T) {
testCases := []struct {
name string
peerProtocols []string
Expand Down Expand Up @@ -174,7 +174,7 @@ func TestApplyProtocolFilter(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
result := applyProtocolFilter(tc.peerProtocols, tc.filterProtocols)
result := protocolsAllowed(tc.peerProtocols, tc.filterProtocols)
assert.Equal(t, tc.expected, result, "Unexpected result for test case: %s", tc.name)
})
}
Expand Down

0 comments on commit 51f200a

Please sign in to comment.