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

fix: remove unnecessary condition #766

Merged
merged 2 commits into from
Mar 14, 2024
Merged

Conversation

ulbqb
Copy link
Member

@ulbqb ulbqb commented Mar 11, 2024

Description

This PR removes unnecessary condition.

Issue

Regarding the connection side, the NewSignerListener supports the tcp and unix protocols.

func NewSignerListener(logger log.Logger, listenAddr string, remoteAddresses []string) (*SignerListenerEndpoint, error) {
var listener net.Listener
protocol, address := tmnet.ProtocolAndAddress(listenAddr)
ln, err := net.Listen(protocol, address)
if err != nil {
return nil, err
}
switch protocol {
case "unix":
listener = NewUnixListener(ln)
case "tcp":
// TODO: persist this key so external signer can actually authenticate us
listener = NewTCPListener(ln, ed25519.GenPrivKey())
default:
return nil, fmt.Errorf(
"wrong listen address: expected either 'tcp' or 'unix' protocols, got %s",
protocol,
)
}
pve := NewSignerListenerEndpoint(logger.With("module", "privval"), listener, SignerListenerEndpointAllowAddress(protocol, remoteAddresses))
return pve, nil
}

Therefore, in the context of the if statement, there should not be any instances where the protocol field is empty, indicated by len(protocol) == 0.

func SignerListenerEndpointAllowAddress(protocol string, allowedAddresses []string) SignerListenerEndpointOption {
return func(sl *SignerListenerEndpoint) {
if protocol == "tcp" || len(protocol) == 0 {
sl.connFilter = internal.NewIpFilter(allowedAddresses, sl.Logger)
return
}
sl.connFilter = internal.NewNullObject()
}
}

Copy link

codecov bot commented Mar 11, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 66.56%. Comparing base (2aa7d4c) to head (5144c7b).
Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #766      +/-   ##
==========================================
+ Coverage   66.54%   66.56%   +0.02%     
==========================================
  Files         285      285              
  Lines       37919    37918       -1     
==========================================
+ Hits        25232    25239       +7     
+ Misses      10883    10880       -3     
+ Partials     1804     1799       -5     
Files Coverage Δ
privval/signer_listener_endpoint.go 88.81% <100.00%> (+2.09%) ⬆️

... and 15 files with indirect coverage changes

@ulbqb ulbqb requested a review from 170210 March 11, 2024 08:29
@ulbqb ulbqb self-assigned this Mar 11, 2024
@ulbqb ulbqb added the C: enhancement Classification: New feature or its request, or improvement in maintainability of code label Mar 11, 2024
170210
170210 previously approved these changes Mar 12, 2024
Co-authored-by: murogari <55307968+Mdaiki0730@users.noreply.github.com>
@ulbqb ulbqb requested a review from 170210 March 13, 2024 10:37
@ulbqb ulbqb merged commit ae67c39 into Finschia:main Mar 14, 2024
23 checks passed
@ulbqb ulbqb deleted the fix/kms_allow_endpoint branch March 14, 2024 02:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: enhancement Classification: New feature or its request, or improvement in maintainability of code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants