net cli: Support miner addresses in net connect
This commit is contained in:
parent
0a620514b7
commit
eb3ca82fa0
51
cli/net.go
51
cli/net.go
@ -8,12 +8,17 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/libp2p/go-libp2p-core/peer"
|
|
||||||
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
|
||||||
|
|
||||||
"github.com/dustin/go-humanize"
|
"github.com/dustin/go-humanize"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
|
"github.com/libp2p/go-libp2p-core/peer"
|
||||||
|
protocol "github.com/libp2p/go-libp2p-core/protocol"
|
||||||
|
"github.com/multiformats/go-multiaddr"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/go-address"
|
||||||
|
|
||||||
|
"github.com/filecoin-project/lotus/chain/types"
|
||||||
"github.com/filecoin-project/lotus/lib/addrutil"
|
"github.com/filecoin-project/lotus/lib/addrutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -141,7 +146,7 @@ var NetListen = &cli.Command{
|
|||||||
var netConnect = &cli.Command{
|
var netConnect = &cli.Command{
|
||||||
Name: "connect",
|
Name: "connect",
|
||||||
Usage: "Connect to a peer",
|
Usage: "Connect to a peer",
|
||||||
ArgsUsage: "[peerMultiaddr]",
|
ArgsUsage: "[peerMultiaddr|minerActorAddress]",
|
||||||
Action: func(cctx *cli.Context) error {
|
Action: func(cctx *cli.Context) error {
|
||||||
api, closer, err := GetAPI(cctx)
|
api, closer, err := GetAPI(cctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -152,7 +157,43 @@ var netConnect = &cli.Command{
|
|||||||
|
|
||||||
pis, err := addrutil.ParseAddresses(ctx, cctx.Args().Slice())
|
pis, err := addrutil.ParseAddresses(ctx, cctx.Args().Slice())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
a, perr := address.NewFromString(cctx.Args().First())
|
||||||
|
if perr != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
na, fc, err := GetFullNodeAPI(cctx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer fc()
|
||||||
|
|
||||||
|
mi, err := na.StateMinerInfo(ctx, a, types.EmptyTSK)
|
||||||
|
if err != nil {
|
||||||
|
return xerrors.Errorf("getting miner info: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if mi.PeerId == nil {
|
||||||
|
return xerrors.Errorf("no PeerID for miner")
|
||||||
|
}
|
||||||
|
multiaddrs := make([]multiaddr.Multiaddr, 0, len(mi.Multiaddrs))
|
||||||
|
for i, a := range mi.Multiaddrs {
|
||||||
|
maddr, err := multiaddr.NewMultiaddrBytes(a)
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("parsing multiaddr %d (%x): %s", i, a, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
multiaddrs = append(multiaddrs, maddr)
|
||||||
|
}
|
||||||
|
|
||||||
|
pi := peer.AddrInfo{
|
||||||
|
ID: *mi.PeerId,
|
||||||
|
Addrs: multiaddrs,
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%s -> %s\n", a, pi)
|
||||||
|
|
||||||
|
pis = append(pis, pi)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, pi := range pis {
|
for _, pi := range pis {
|
||||||
|
Loading…
Reference in New Issue
Block a user