Merge pull request #3130 from filecoin-project/fix/reachability-cli

cli: Fix net reachability
This commit is contained in:
Łukasz Magiera 2020-08-18 03:14:11 +02:00 committed by GitHub
commit 1bd90d0701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 8 deletions

View File

@ -4,11 +4,9 @@ import (
"context"
"fmt"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"
"github.com/filecoin-project/go-jsonrpc/auth"
"github.com/filecoin-project/lotus/build"
)
@ -70,5 +68,5 @@ func (v Version) String() string {
type NatInfo struct {
Reachability network.Reachability
PublicAddr ma.Multiaddr
PublicAddr string
}

View File

@ -222,8 +222,8 @@ var NetReachability = &cli.Command{
}
fmt.Println("AutoNAT status: ", i.Reachability.String())
if i.PublicAddr != nil {
fmt.Println("Public address: ", i.PublicAddr.String())
if i.PublicAddr != "" {
fmt.Println("Public address: ", i.PublicAddr)
}
return nil
},

View File

@ -118,12 +118,13 @@ func (a *CommonAPI) NetFindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo,
func (a *CommonAPI) NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err error) {
autonat := a.RawHost.(*basichost.BasicHost).AutoNat
var maddr ma.Multiaddr
var maddr string
if autonat.Status() == network.ReachabilityPublic {
maddr, err = autonat.PublicAddr()
pa, err := autonat.PublicAddr()
if err != nil {
return api.NatInfo{}, err
}
maddr = pa.String()
}
return api.NatInfo{