mirror of
https://github.com/fluencelabs/tendermint
synced 2025-05-19 01:51:19 +00:00
Filter out empty addresses in persistent_peers/seeds lists (#2323)
Fixes #2320
This commit is contained in:
parent
d27cd972d2
commit
d0bb1ab2b0
@ -23,6 +23,7 @@ BREAKING CHANGES:
|
|||||||
- [state] Implement BFT time
|
- [state] Implement BFT time
|
||||||
- [p2p] update secret connection to use a little endian encoded nonce
|
- [p2p] update secret connection to use a little endian encoded nonce
|
||||||
- [libs/clist] Panics if list extends beyond MaxLength
|
- [libs/clist] Panics if list extends beyond MaxLength
|
||||||
|
- [common] SplitAndTrim was deleted
|
||||||
|
|
||||||
FEATURES:
|
FEATURES:
|
||||||
- [types] allow genesis file to have 0 validators ([#2015](https://github.com/tendermint/tendermint/issues/2015))
|
- [types] allow genesis file to have 0 validators ([#2015](https://github.com/tendermint/tendermint/issues/2015))
|
||||||
|
@ -31,25 +31,6 @@ func TestIsHex(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSplitAndTrim(t *testing.T) {
|
|
||||||
testCases := []struct {
|
|
||||||
s string
|
|
||||||
sep string
|
|
||||||
cutset string
|
|
||||||
expected []string
|
|
||||||
}{
|
|
||||||
{"a,b,c", ",", " ", []string{"a", "b", "c"}},
|
|
||||||
{" a , b , c ", ",", " ", []string{"a", "b", "c"}},
|
|
||||||
{" a, b, c ", ",", " ", []string{"a", "b", "c"}},
|
|
||||||
{" , ", ",", " ", []string{"", ""}},
|
|
||||||
{" ", ",", " ", []string{""}},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tc := range testCases {
|
|
||||||
assert.Equal(t, tc.expected, SplitAndTrim(tc.s, tc.sep, tc.cutset), "%s", tc.s)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIsASCIIText(t *testing.T) {
|
func TestIsASCIIText(t *testing.T) {
|
||||||
notASCIIText := []string{
|
notASCIIText := []string{
|
||||||
"", "\xC2", "\xC2\xA2", "\xFF", "\x80", "\xF0", "\n", "\t",
|
"", "\xC2", "\xC2\xA2", "\xFF", "\x80", "\xF0", "\n", "\t",
|
||||||
|
33
node/node.go
33
node/node.go
@ -40,6 +40,7 @@ import (
|
|||||||
"github.com/tendermint/tendermint/version"
|
"github.com/tendermint/tendermint/version"
|
||||||
|
|
||||||
_ "net/http/pprof"
|
_ "net/http/pprof"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
@ -323,7 +324,7 @@ func NewNode(config *cfg.Config,
|
|||||||
// TODO persistent peers ? so we can have their DNS addrs saved
|
// TODO persistent peers ? so we can have their DNS addrs saved
|
||||||
pexReactor := pex.NewPEXReactor(addrBook,
|
pexReactor := pex.NewPEXReactor(addrBook,
|
||||||
&pex.PEXReactorConfig{
|
&pex.PEXReactorConfig{
|
||||||
Seeds: cmn.SplitAndTrim(config.P2P.Seeds, ",", " "),
|
Seeds: splitAndTrimEmpty(config.P2P.Seeds, ",", " "),
|
||||||
SeedMode: config.P2P.SeedMode,
|
SeedMode: config.P2P.SeedMode,
|
||||||
})
|
})
|
||||||
pexReactor.SetLogger(p2pLogger)
|
pexReactor.SetLogger(p2pLogger)
|
||||||
@ -375,7 +376,7 @@ func NewNode(config *cfg.Config,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if config.TxIndex.IndexTags != "" {
|
if config.TxIndex.IndexTags != "" {
|
||||||
txIndexer = kv.NewTxIndex(store, kv.IndexTags(cmn.SplitAndTrim(config.TxIndex.IndexTags, ",", " ")))
|
txIndexer = kv.NewTxIndex(store, kv.IndexTags(splitAndTrimEmpty(config.TxIndex.IndexTags, ",", " ")))
|
||||||
} else if config.TxIndex.IndexAllTags {
|
} else if config.TxIndex.IndexAllTags {
|
||||||
txIndexer = kv.NewTxIndex(store, kv.IndexAllTags())
|
txIndexer = kv.NewTxIndex(store, kv.IndexAllTags())
|
||||||
} else {
|
} else {
|
||||||
@ -444,7 +445,7 @@ func (n *Node) OnStart() error {
|
|||||||
n.addrBook.AddOurAddress(nodeInfo.NetAddress())
|
n.addrBook.AddOurAddress(nodeInfo.NetAddress())
|
||||||
|
|
||||||
// Add private IDs to addrbook to block those peers being added
|
// Add private IDs to addrbook to block those peers being added
|
||||||
n.addrBook.AddPrivateIDs(cmn.SplitAndTrim(n.config.P2P.PrivatePeerIDs, ",", " "))
|
n.addrBook.AddPrivateIDs(splitAndTrimEmpty(n.config.P2P.PrivatePeerIDs, ",", " "))
|
||||||
|
|
||||||
// Start the RPC server before the P2P server
|
// Start the RPC server before the P2P server
|
||||||
// so we can eg. receive txs for the first block
|
// so we can eg. receive txs for the first block
|
||||||
@ -469,7 +470,7 @@ func (n *Node) OnStart() error {
|
|||||||
|
|
||||||
// Always connect to persistent peers
|
// Always connect to persistent peers
|
||||||
if n.config.P2P.PersistentPeers != "" {
|
if n.config.P2P.PersistentPeers != "" {
|
||||||
err = n.sw.DialPeersAsync(n.addrBook, cmn.SplitAndTrim(n.config.P2P.PersistentPeers, ",", " "), true)
|
err = n.sw.DialPeersAsync(n.addrBook, splitAndTrimEmpty(n.config.P2P.PersistentPeers, ",", " "), true)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -551,7 +552,7 @@ func (n *Node) ConfigureRPC() {
|
|||||||
|
|
||||||
func (n *Node) startRPC() ([]net.Listener, error) {
|
func (n *Node) startRPC() ([]net.Listener, error) {
|
||||||
n.ConfigureRPC()
|
n.ConfigureRPC()
|
||||||
listenAddrs := cmn.SplitAndTrim(n.config.RPC.ListenAddress, ",", " ")
|
listenAddrs := splitAndTrimEmpty(n.config.RPC.ListenAddress, ",", " ")
|
||||||
coreCodec := amino.NewCodec()
|
coreCodec := amino.NewCodec()
|
||||||
ctypes.RegisterAmino(coreCodec)
|
ctypes.RegisterAmino(coreCodec)
|
||||||
|
|
||||||
@ -749,3 +750,25 @@ func saveGenesisDoc(db dbm.DB, genDoc *types.GenesisDoc) {
|
|||||||
}
|
}
|
||||||
db.SetSync(genesisDocKey, bytes)
|
db.SetSync(genesisDocKey, bytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// splitAndTrimEmpty slices s into all subslices separated by sep and returns a
|
||||||
|
// slice of the string s with all leading and trailing Unicode code points
|
||||||
|
// contained in cutset removed. If sep is empty, SplitAndTrim splits after each
|
||||||
|
// UTF-8 sequence. First part is equivalent to strings.SplitN with a count of
|
||||||
|
// -1. also filter out empty strings, only return non-empty strings.
|
||||||
|
func splitAndTrimEmpty(s, sep, cutset string) []string {
|
||||||
|
if s == "" {
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
spl := strings.Split(s, sep)
|
||||||
|
nonEmptyStrings := make([]string, 0, len(spl))
|
||||||
|
for i := 0; i < len(spl); i++ {
|
||||||
|
element := strings.Trim(spl[i], cutset)
|
||||||
|
if element != "" {
|
||||||
|
nonEmptyStrings = append(nonEmptyStrings, element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nonEmptyStrings
|
||||||
|
}
|
||||||
|
@ -56,3 +56,22 @@ func TestNodeStartStop(t *testing.T) {
|
|||||||
t.Fatal("timed out waiting for shutdown")
|
t.Fatal("timed out waiting for shutdown")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSplitAndTrimEmpty(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
s string
|
||||||
|
sep string
|
||||||
|
cutset string
|
||||||
|
expected []string
|
||||||
|
}{
|
||||||
|
{"a,b,c", ",", " ", []string{"a", "b", "c"}},
|
||||||
|
{" a , b , c ", ",", " ", []string{"a", "b", "c"}},
|
||||||
|
{" a, b, c ", ",", " ", []string{"a", "b", "c"}},
|
||||||
|
{" a, ", ",", " ", []string{"a"}},
|
||||||
|
{" ", ",", " ", []string{}},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
assert.Equal(t, tc.expected, splitAndTrimEmpty(tc.s, tc.sep, tc.cutset), "%s", tc.s)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user