mirror of
https://github.com/ipfs/kubo.git
synced 2025-09-10 14:34:24 +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"
|
b58 "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-base58"
|
||||||
|
|
||||||
cmds "github.com/jbenet/go-ipfs/commands"
|
cmds "github.com/jbenet/go-ipfs/commands"
|
||||||
|
core "github.com/jbenet/go-ipfs/core"
|
||||||
ic "github.com/jbenet/go-ipfs/p2p/crypto"
|
ic "github.com/jbenet/go-ipfs/p2p/crypto"
|
||||||
"github.com/jbenet/go-ipfs/p2p/peer"
|
"github.com/jbenet/go-ipfs/p2p/peer"
|
||||||
|
identify "github.com/jbenet/go-ipfs/p2p/protocol/identify"
|
||||||
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
kb "github.com/jbenet/go-ipfs/routing/kbucket"
|
||||||
u "github.com/jbenet/go-ipfs/util"
|
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 {
|
if len(req.Arguments()) == 0 {
|
||||||
output, err := printPeer(node.Peerstore, node.Identity)
|
output, err := printSelf(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
res.SetError(err, cmds.ErrNormal)
|
res.SetError(err, cmds.ErrNormal)
|
||||||
return
|
return
|
||||||
@ -168,3 +170,32 @@ func printPeer(ps peer.Peerstore, p peer.ID) (interface{}, error) {
|
|||||||
|
|
||||||
return info, nil
|
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
|
||||||
|
}
|
||||||
|
12
core/core.go
12
core/core.go
@ -67,8 +67,9 @@ type IpfsNode struct {
|
|||||||
Repo repo.Repo
|
Repo repo.Repo
|
||||||
|
|
||||||
// Local node
|
// Local node
|
||||||
Pinning pin.Pinner // the pinning manager
|
Pinning pin.Pinner // the pinning manager
|
||||||
Mounts Mounts // current mount state, if any.
|
Mounts Mounts // current mount state, if any.
|
||||||
|
PrivateKey ic.PrivKey // the local node's private Key
|
||||||
|
|
||||||
// Services
|
// Services
|
||||||
Peerstore peer.Peerstore // storage for other Peer instances
|
Peerstore peer.Peerstore // storage for other Peer instances
|
||||||
@ -78,7 +79,6 @@ type IpfsNode struct {
|
|||||||
Resolver *path.Resolver // the path resolution system
|
Resolver *path.Resolver // the path resolution system
|
||||||
|
|
||||||
// Online
|
// Online
|
||||||
PrivateKey ic.PrivKey // the local node's private Key
|
|
||||||
PeerHost p2phost.Host // the network host (server+client)
|
PeerHost p2phost.Host // the network host (server+client)
|
||||||
Bootstrapper io.Closer // the periodic bootstrapper
|
Bootstrapper io.Closer // the periodic bootstrapper
|
||||||
Routing routing.IpfsRouting // the routing system. recommend ipfs-dht
|
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
|
// load private key
|
||||||
if err := n.loadPrivateKey(); err != nil {
|
if err := n.LoadPrivateKey(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,7 +368,7 @@ func (n *IpfsNode) loadID() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *IpfsNode) loadPrivateKey() error {
|
func (n *IpfsNode) LoadPrivateKey() error {
|
||||||
if n.Identity == "" || n.Peerstore == nil {
|
if n.Identity == "" || n.Peerstore == nil {
|
||||||
return debugerror.New("loaded private key out of order.")
|
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.
|
// uses it to instantiate a routing system in offline mode.
|
||||||
// This is primarily used for offline ipns modifications.
|
// This is primarily used for offline ipns modifications.
|
||||||
func (n *IpfsNode) SetupOfflineRouting() error {
|
func (n *IpfsNode) SetupOfflineRouting() error {
|
||||||
err := n.loadPrivateKey()
|
err := n.LoadPrivateKey()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user