diff --git a/CHANGELOG.md b/CHANGELOG.md index b935a381..fdf3aea5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,10 +28,12 @@ BUG FIXES: ## 0.16.0 (TBD) BREAKING CHANGES: -- rpc: `/unsafe_dial_seeds` renamed to `/unsafe_dial_persistent_peers` - [p2p] old `seeds` is now `persistent_peers` (persistent peers to which TM will always connect to) - [p2p] now `seeds` only used for getting addresses (if addrbook is empty; not persistent) +FEATURES: +- [p2p] added new `/dial_persistent_peers` **unsafe** endpoint + ## 0.15.0 (December 29, 2017) BREAKING CHANGES: diff --git a/docs/specification/rpc.rst b/docs/specification/rpc.rst index daafce11..e273ce84 100644 --- a/docs/specification/rpc.rst +++ b/docs/specification/rpc.rst @@ -111,6 +111,7 @@ An HTTP Get request to the root RPC endpoint (e.g. http://localhost:46657/broadcast_tx_commit?tx=_ http://localhost:46657/broadcast_tx_sync?tx=_ http://localhost:46657/commit?height=_ + http://localhost:46657/dial_seeds?seeds=_ http://localhost:46657/dial_persistent_peers?persistent_peers=_ http://localhost:46657/subscribe?event=_ http://localhost:46657/tx?hash=_&prove=_ diff --git a/rpc/client/localclient.go b/rpc/client/localclient.go index af91ac79..cc23b944 100644 --- a/rpc/client/localclient.go +++ b/rpc/client/localclient.go @@ -84,6 +84,10 @@ func (Local) DumpConsensusState() (*ctypes.ResultDumpConsensusState, error) { return core.DumpConsensusState() } +func (Local) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { + return core.UnsafeDialSeeds(seeds) +} + func (Local) DialPersistentPeers(persistent_peers []string) (*ctypes.ResultDialPersistentPeers, error) { return core.UnsafeDialPersistentPeers(persistent_peers) } diff --git a/rpc/client/mock/client.go b/rpc/client/mock/client.go index 469e80a6..913812d6 100644 --- a/rpc/client/mock/client.go +++ b/rpc/client/mock/client.go @@ -107,6 +107,10 @@ func (c Client) NetInfo() (*ctypes.ResultNetInfo, error) { return core.NetInfo() } +func (c Client) DialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { + return core.UnsafeDialSeeds(seeds) +} + func (c Client) DialPersistentPeers(persistent_peers []string) (*ctypes.ResultDialPersistentPeers, error) { return core.UnsafeDialPersistentPeers(persistent_peers) } diff --git a/rpc/core/doc.go b/rpc/core/doc.go index 030e5d61..a801cd0d 100644 --- a/rpc/core/doc.go +++ b/rpc/core/doc.go @@ -94,6 +94,7 @@ Endpoints that require arguments: /broadcast_tx_commit?tx=_ /broadcast_tx_sync?tx=_ /commit?height=_ +/dial_seeds?seeds=_ /dial_persistent_peers?persistent_peers=_ /subscribe?event=_ /tx?hash=_&prove=_ diff --git a/rpc/core/net.go b/rpc/core/net.go index c79c55de..b528e1e3 100644 --- a/rpc/core/net.go +++ b/rpc/core/net.go @@ -1,8 +1,7 @@ package core import ( - "fmt" - + "github.com/pkg/errors" ctypes "github.com/tendermint/tendermint/rpc/core/types" ) @@ -54,10 +53,22 @@ func NetInfo() (*ctypes.ResultNetInfo, error) { }, nil } -func UnsafeDialPersistentPeers(persistent_peers []string) (*ctypes.ResultDialPersistentPeers, error) { +func UnsafeDialSeeds(seeds []string) (*ctypes.ResultDialSeeds, error) { + if len(seeds) == 0 { + return &ctypes.ResultDialSeeds{}, errors.New("No seeds provided") + } + // starts go routines to dial each peer after random delays + logger.Info("DialSeeds", "addrBook", addrBook, "seeds", seeds) + err := p2pSwitch.DialPeersAsync(addrBook, seeds, false) + if err != nil { + return &ctypes.ResultDialSeeds{}, err + } + return &ctypes.ResultDialSeeds{"Dialing seeds in progress. See /net_info for details"}, nil +} +func UnsafeDialPersistentPeers(persistent_peers []string) (*ctypes.ResultDialPersistentPeers, error) { if len(persistent_peers) == 0 { - return &ctypes.ResultDialPersistentPeers{}, fmt.Errorf("No persistent peers provided") + return &ctypes.ResultDialPersistentPeers{}, errors.New("No persistent peers provided") } // starts go routines to dial each peer after random delays logger.Info("DialPersistentPeers", "addrBook", addrBook, "persistent_peers", persistent_peers) diff --git a/rpc/core/routes.go b/rpc/core/routes.go index 0bf7af62..d00165e6 100644 --- a/rpc/core/routes.go +++ b/rpc/core/routes.go @@ -38,6 +38,7 @@ var Routes = map[string]*rpc.RPCFunc{ func AddUnsafeRoutes() { // control API + Routes["dial_seeds"] = rpc.NewRPCFunc(UnsafeDialSeeds, "seeds") Routes["dial_persistent_peers"] = rpc.NewRPCFunc(UnsafeDialPersistentPeers, "persistent_peers") Routes["unsafe_flush_mempool"] = rpc.NewRPCFunc(UnsafeFlushMempool, "") diff --git a/rpc/core/types/responses.go b/rpc/core/types/responses.go index 59c2aeea..c26defb7 100644 --- a/rpc/core/types/responses.go +++ b/rpc/core/types/responses.go @@ -82,6 +82,10 @@ type ResultNetInfo struct { Peers []Peer `json:"peers"` } +type ResultDialSeeds struct { + Log string `json:"log"` +} + type ResultDialPersistentPeers struct { Log string `json:"log"` } diff --git a/test/p2p/pex/dial_manual_peers.sh b/test/p2p/pex/dial_persistent_peers.sh similarity index 100% rename from test/p2p/pex/dial_manual_peers.sh rename to test/p2p/pex/dial_persistent_peers.sh diff --git a/test/p2p/pex/test.sh b/test/p2p/pex/test.sh index 7cf6151d..06d40c3e 100644 --- a/test/p2p/pex/test.sh +++ b/test/p2p/pex/test.sh @@ -6,10 +6,10 @@ NETWORK_NAME=$2 N=$3 PROXY_APP=$4 -cd $GOPATH/src/github.com/tendermint/tendermint +cd "$GOPATH/src/github.com/tendermint/tendermint" echo "Test reconnecting from the address book" -bash test/p2p/pex/test_addrbook.sh $DOCKER_IMAGE $NETWORK_NAME $N $PROXY_APP +bash test/p2p/pex/test_addrbook.sh "$DOCKER_IMAGE" "$NETWORK_NAME" "$N" "$PROXY_APP" echo "Test connecting via /dial_persistent_peers" -bash test/p2p/pex/test_dial_persistent_peers.sh $DOCKER_IMAGE $NETWORK_NAME $N $PROXY_APP +bash test/p2p/pex/test_dial_persistent_peers.sh "$DOCKER_IMAGE" "$NETWORK_NAME" "$N" "$PROXY_APP" diff --git a/test/p2p/pex/test_dial_manual_peers.sh b/test/p2p/pex/test_dial_persistent_peers.sh similarity index 100% rename from test/p2p/pex/test_dial_manual_peers.sh rename to test/p2p/pex/test_dial_persistent_peers.sh