cli: net reachability command

This commit is contained in:
Łukasz Magiera
2020-08-13 13:18:14 +02:00
parent f212ca60c8
commit 3f2a62b5e2
4 changed files with 58 additions and 0 deletions
+19
View File
@@ -2,6 +2,7 @@ package common
import (
"context"
basichost "github.com/libp2p/go-libp2p/p2p/host/basic"
"sort"
"strings"
@@ -28,6 +29,7 @@ type CommonAPI struct {
fx.In
APISecret *dtypes.APIAlg
RawHost lp2p.RawHost
Host host.Host
Router lp2p.BaseIpfsRouting
Sk *dtypes.ScoreKeeper
@@ -113,6 +115,23 @@ func (a *CommonAPI) NetFindPeer(ctx context.Context, p peer.ID) (peer.AddrInfo,
return a.Router.FindPeer(ctx, p)
}
func (a *CommonAPI) NetAutoNatStatus(ctx context.Context) (i api.NatInfo, err error) {
autonat := a.RawHost.(*basichost.BasicHost).AutoNat
var maddr ma.Multiaddr
if autonat.Status() == network.ReachabilityPublic {
maddr, err = autonat.PublicAddr()
if err != nil {
return api.NatInfo{}, err
}
}
return api.NatInfo{
Reachability: autonat.Status(),
PublicAddr: maddr,
}, nil
}
func (a *CommonAPI) ID(context.Context) (peer.ID, error) {
return a.Host.ID(), nil
}