mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-08 14:21:14 +00:00
rpc: fix RPC client doesn't handle url's without ports (#6507)
This commit is contained in:
@@ -126,5 +126,6 @@ Friendly reminder: We have a [bug bounty program](https://hackerone.com/tendermi
|
||||
- [privval] \#5638 Increase read/write timeout to 5s and calculate ping interval based on it (@JoeKash)
|
||||
- [blockchain/v1] [\#5701](https://github.com/tendermint/tendermint/pull/5701) Handle peers without blocks (@melekes)
|
||||
- [blockchain/v1] \#5711 Fix deadlock (@melekes)
|
||||
- [evidence] \#6375 Fix bug with inconsistent LightClientAttackEvidence hashing (@cmwaters)
|
||||
- [evidence] \#6375 Fix bug with inconsistent LightClientAttackEvidence hashing (cmwaters)
|
||||
- [rpc] \#6507 fix RPC client doesn't handle url's without ports (@JayT106)
|
||||
- [statesync] \#6463 Adds Reverse Sync feature to fetch historical light blocks after state sync in order to verify any evidence (@cmwaters)
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
tmsync "github.com/tendermint/tendermint/internal/libs/sync"
|
||||
types "github.com/tendermint/tendermint/rpc/jsonrpc/types"
|
||||
@@ -370,6 +371,7 @@ func makeHTTPDialer(remoteAddr string) (func(string, string) (net.Conn, error),
|
||||
}
|
||||
|
||||
protocol := u.Scheme
|
||||
padding := u.Scheme
|
||||
|
||||
// accept http(s) as an alias for tcp
|
||||
switch protocol {
|
||||
@@ -378,7 +380,13 @@ func makeHTTPDialer(remoteAddr string) (func(string, string) (net.Conn, error),
|
||||
}
|
||||
|
||||
dialFn := func(proto, addr string) (net.Conn, error) {
|
||||
return net.Dial(protocol, u.GetDialAddress())
|
||||
var timeout = 10 * time.Second
|
||||
if !u.isUnixSocket && strings.LastIndex(u.Host, ":") == -1 {
|
||||
u.Host = fmt.Sprintf("%s:%s", u.Host, padding)
|
||||
return net.DialTimeout(protocol, u.GetDialAddress(), timeout)
|
||||
}
|
||||
|
||||
return net.DialTimeout(protocol, u.GetDialAddress(), timeout)
|
||||
}
|
||||
|
||||
return dialFn, nil
|
||||
|
||||
@@ -84,3 +84,31 @@ func Test_parsedURL(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestMakeHTTPDialerURL(t *testing.T) {
|
||||
remotes := []string{"https://foo-bar.com", "http://foo-bar.com"}
|
||||
|
||||
for _, remote := range remotes {
|
||||
u, err := newParsedURL(remote)
|
||||
require.NoError(t, err)
|
||||
dialFn, err := makeHTTPDialer(remote)
|
||||
require.Nil(t, err)
|
||||
|
||||
addr, err := dialFn(u.Scheme, u.GetHostWithPath())
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, addr)
|
||||
}
|
||||
|
||||
errorURLs := []string{"tcp://foo-bar.com", "ftp://foo-bar.com"}
|
||||
|
||||
for _, errorURL := range errorURLs {
|
||||
u, err := newParsedURL(errorURL)
|
||||
require.NoError(t, err)
|
||||
dialFn, err := makeHTTPDialer(errorURL)
|
||||
require.Nil(t, err)
|
||||
|
||||
addr, err := dialFn(u.Scheme, u.GetHostWithPath())
|
||||
require.Error(t, err)
|
||||
require.Nil(t, addr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user