mirror of
https://github.com/tendermint/tendermint.git
synced 2026-07-08 00:56:39 +00:00
Fixes #4051 Function `parseRemoteAddr` is forcing protocol HTTP and protocol HTTPs to tcp. This causes the bug in the issue #4051. I find that the tcp is only needed where `net.Dial`. So I moved the switch to makeHTTPDialer. This is a backport to the v0.32 branch. Co-authored-by: yk <tankhoon@gmail.com> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
This commit is contained in:
committed by
Jack Zampolin
parent
d494952c82
commit
aad59f2a9a
@@ -20,4 +20,5 @@ program](https://hackerone.com/tendermint).
|
||||
### IMPROVEMENTS:
|
||||
|
||||
### BUG FIXES:
|
||||
- [rpc/lib] [\#4051](https://github.com/tendermint/tendermint/pull/4131) Fix RPC client, which was previously resolving https protocol to http (@yenkhoon)
|
||||
- [cs] \#4069 Don't panic when block meta is not found in store (@gregzaitsev)
|
||||
|
||||
@@ -82,12 +82,6 @@ func parseRemoteAddr(remoteAddr string) (network string, s string, err error) {
|
||||
return "", "", fmt.Errorf("invalid addr: %s", remoteAddr)
|
||||
}
|
||||
|
||||
// accept http(s) as an alias for tcp
|
||||
switch protocol {
|
||||
case protoHTTP, protoHTTPS:
|
||||
protocol = protoTCP
|
||||
}
|
||||
|
||||
return protocol, address, nil
|
||||
}
|
||||
|
||||
@@ -103,6 +97,12 @@ func makeHTTPDialer(remoteAddr string) func(string, string) (net.Conn, error) {
|
||||
return makeErrorDialer(err)
|
||||
}
|
||||
|
||||
// accept http(s) as an alias for tcp
|
||||
switch protocol {
|
||||
case protoHTTP, protoHTTPS:
|
||||
protocol = protoTCP
|
||||
}
|
||||
|
||||
return func(proto, addr string) (net.Conn, error) {
|
||||
return net.Dial(protocol, address)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package rpcclient
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestHTTPClientMakeHTTPDialer(t *testing.T) {
|
||||
remote := []string{"https://foo-bar.com:80", "http://foo-bar.net:80"}
|
||||
|
||||
for _, f := range remote {
|
||||
protocol, address, err := parseRemoteAddr(f)
|
||||
require.NoError(t, err)
|
||||
dialFn := makeHTTPDialer(f)
|
||||
|
||||
addr, err := dialFn(protocol, address)
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, addr)
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user