From 127d6d057674fa0869877ec7949854cda941cfd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Tue, 18 Aug 2020 03:12:50 +0200 Subject: [PATCH 1/2] cli: Fix net reachability --- api/api_common.go | 6 ++---- cli/net.go | 4 ++-- node/impl/common/common.go | 5 +++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/api/api_common.go b/api/api_common.go index 0c20d0ad9..69b2df17a 100644 --- a/api/api_common.go +++ b/api/api_common.go @@ -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 } diff --git a/cli/net.go b/cli/net.go index 7a2474bf4..fb902e39c 100644 --- a/cli/net.go +++ b/cli/net.go @@ -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 }, diff --git a/node/impl/common/common.go b/node/impl/common/common.go index 73abea8fb..d149486b1 100644 --- a/node/impl/common/common.go +++ b/node/impl/common/common.go @@ -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{ From 4ef5a58b36718174bbccea7b20c22bb4cd8c8787 Mon Sep 17 00:00:00 2001 From: Aayush Rajasekaran Date: Mon, 17 Aug 2020 21:18:11 -0400 Subject: [PATCH 2/2] strip peerid when setting on-chain addrs --- cmd/lotus-storage-miner/actor.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/cmd/lotus-storage-miner/actor.go b/cmd/lotus-storage-miner/actor.go index 70df1446a..bd5caf0f0 100644 --- a/cmd/lotus-storage-miner/actor.go +++ b/cmd/lotus-storage-miner/actor.go @@ -59,7 +59,14 @@ var actorSetAddrsCmd = &cli.Command{ return fmt.Errorf("failed to parse %q as a multiaddr: %w", a, err) } - addrs = append(addrs, maddr.Bytes()) + maddrNop2p, strip := ma.SplitFunc(maddr, func(c ma.Component) bool { + return c.Protocol().Code == ma.P_P2P + }) + + if strip != nil { + fmt.Println("Stripping peerid ", strip, " from ", maddr) + } + addrs = append(addrs, maddrNop2p.Bytes()) } maddr, err := nodeAPI.ActorAddress(ctx)