|
|
@ -3,6 +3,7 @@ package core |
|
|
|
import ( |
|
|
|
"errors" |
|
|
|
"fmt" |
|
|
|
"strings" |
|
|
|
|
|
|
|
"github.com/tendermint/tendermint/p2p" |
|
|
|
ctypes "github.com/tendermint/tendermint/rpc/core/types" |
|
|
@ -51,19 +52,42 @@ func UnsafeDialSeeds(ctx *rpctypes.Context, seeds []string) (*ctypes.ResultDialS |
|
|
|
|
|
|
|
// UnsafeDialPeers dials the given peers (comma-separated id@IP:PORT),
|
|
|
|
// optionally making them persistent.
|
|
|
|
func UnsafeDialPeers(ctx *rpctypes.Context, peers []string, persistent bool) (*ctypes.ResultDialPeers, error) { |
|
|
|
func UnsafeDialPeers(ctx *rpctypes.Context, peers []string, persistent, unconditional, private bool) ( |
|
|
|
*ctypes.ResultDialPeers, error) { |
|
|
|
if len(peers) == 0 { |
|
|
|
return &ctypes.ResultDialPeers{}, errors.New("no peers provided") |
|
|
|
} |
|
|
|
env.Logger.Info("DialPeers", "peers", peers, "persistent", persistent) |
|
|
|
|
|
|
|
ids, err := getIDs(peers) |
|
|
|
if err != nil { |
|
|
|
return &ctypes.ResultDialPeers{}, err |
|
|
|
} |
|
|
|
|
|
|
|
env.Logger.Info("DialPeers", "peers", peers, "persistent", |
|
|
|
persistent, "unconditional", unconditional, "private", private) |
|
|
|
|
|
|
|
if persistent { |
|
|
|
if err := env.P2PPeers.AddPersistentPeers(peers); err != nil { |
|
|
|
return &ctypes.ResultDialPeers{}, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if private { |
|
|
|
if err := env.P2PPeers.AddPrivatePeerIDs(ids); err != nil { |
|
|
|
return &ctypes.ResultDialPeers{}, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if unconditional { |
|
|
|
if err := env.P2PPeers.AddUnconditionalPeerIDs(ids); err != nil { |
|
|
|
return &ctypes.ResultDialPeers{}, err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if err := env.P2PPeers.DialPeersAsync(peers); err != nil { |
|
|
|
return &ctypes.ResultDialPeers{}, err |
|
|
|
} |
|
|
|
|
|
|
|
return &ctypes.ResultDialPeers{Log: "Dialing peers in progress. See /net_info for details"}, nil |
|
|
|
} |
|
|
|
|
|
|
@ -72,3 +96,18 @@ func UnsafeDialPeers(ctx *rpctypes.Context, peers []string, persistent bool) (*c |
|
|
|
func Genesis(ctx *rpctypes.Context) (*ctypes.ResultGenesis, error) { |
|
|
|
return &ctypes.ResultGenesis{Genesis: env.GenDoc}, nil |
|
|
|
} |
|
|
|
|
|
|
|
func getIDs(peers []string) ([]string, error) { |
|
|
|
ids := make([]string, 0, len(peers)) |
|
|
|
|
|
|
|
for _, peer := range peers { |
|
|
|
|
|
|
|
spl := strings.Split(peer, "@") |
|
|
|
if len(spl) != 2 { |
|
|
|
return nil, p2p.ErrNetAddressNoID{Addr: peer} |
|
|
|
} |
|
|
|
ids = append(ids, spl[0]) |
|
|
|
|
|
|
|
} |
|
|
|
return ids, nil |
|
|
|
} |