mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 09:52:20 +08:00
cmds/id: show self addrs
This commit is contained in:
@ -14,8 +14,10 @@ import (
|
||||
b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
|
||||
|
||||
cmds "github.com/jbenet/go-ipfs/commands"
|
||||
core "github.com/jbenet/go-ipfs/core"
|
||||
ic "github.com/jbenet/go-ipfs/p2p/crypto"
|
||||
"github.com/jbenet/go-ipfs/p2p/peer"
|
||||
identify "github.com/jbenet/go-ipfs/p2p/protocol/identify"
|
||||
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
||||
u "github.com/jbenet/go-ipfs/util"
|
||||
)
|
||||
@ -63,7 +65,7 @@ ipfs id supports the format option for output with the following keys:
|
||||
}
|
||||
|
||||
if len(req.Arguments()) == 0 {
|
||||
output, err := printPeer(node.Peerstore, node.Identity)
|
||||
output, err := printSelf(node)
|
||||
if err != nil {
|
||||
res.SetError(err, cmds.ErrNormal)
|
||||
return
|
||||
@ -168,3 +170,32 @@ func printPeer(ps peer.Peerstore, p peer.ID) (interface{}, error) {
|
||||
|
||||
return info, nil
|
||||
}
|
||||
|
||||
// printing self is special cased as we get values differently.
|
||||
func printSelf(node *core.IpfsNode) (interface{}, error) {
|
||||
info := new(IdOutput)
|
||||
info.ID = node.Identity.Pretty()
|
||||
|
||||
if node.PrivateKey == nil {
|
||||
if err := node.LoadPrivateKey(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
pk := node.PrivateKey.GetPublic()
|
||||
pkb, err := ic.MarshalPublicKey(pk)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
info.PublicKey = base64.StdEncoding.EncodeToString(pkb)
|
||||
|
||||
if node.PeerHost != nil {
|
||||
for _, a := range node.PeerHost.Addrs() {
|
||||
s := a.String() + "/ipfs/" + info.ID
|
||||
info.Addresses = append(info.Addresses, s)
|
||||
}
|
||||
}
|
||||
info.ProtocolVersion = identify.IpfsVersion
|
||||
info.AgentVersion = identify.ClientVersion
|
||||
return info, nil
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ type IpfsNode struct {
|
||||
// Local node
|
||||
Pinning pin.Pinner // the pinning manager
|
||||
Mounts Mounts // current mount state, if any.
|
||||
PrivateKey ic.PrivKey // the local node's private Key
|
||||
|
||||
// Services
|
||||
Peerstore peer.Peerstore // storage for other Peer instances
|
||||
@ -78,7 +79,6 @@ type IpfsNode struct {
|
||||
Resolver *path.Resolver // the path resolution system
|
||||
|
||||
// Online
|
||||
PrivateKey ic.PrivKey // the local node's private Key
|
||||
PeerHost p2phost.Host // the network host (server+client)
|
||||
Bootstrapper io.Closer // the periodic bootstrapper
|
||||
Routing routing.IpfsRouting // the routing system. recommend ipfs-dht
|
||||
@ -222,7 +222,7 @@ func (n *IpfsNode) startOnlineServices(ctx context.Context, maybeRouter routing.
|
||||
}
|
||||
|
||||
// load private key
|
||||
if err := n.loadPrivateKey(); err != nil {
|
||||
if err := n.LoadPrivateKey(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -368,7 +368,7 @@ func (n *IpfsNode) loadID() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (n *IpfsNode) loadPrivateKey() error {
|
||||
func (n *IpfsNode) LoadPrivateKey() error {
|
||||
if n.Identity == "" || n.Peerstore == nil {
|
||||
return debugerror.New("loaded private key out of order.")
|
||||
}
|
||||
@ -400,7 +400,7 @@ func (n *IpfsNode) loadBootstrapPeers() ([]peer.PeerInfo, error) {
|
||||
// uses it to instantiate a routing system in offline mode.
|
||||
// This is primarily used for offline ipns modifications.
|
||||
func (n *IpfsNode) SetupOfflineRouting() error {
|
||||
err := n.loadPrivateKey()
|
||||
err := n.LoadPrivateKey()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
Reference in New Issue
Block a user