提交 6c3173d1 作者: Juan Batiz-Benet

Merge pull request #734 from jbenet/cmd-fixes

cmd fixes -- fix id + swarm bugs
...@@ -2,7 +2,7 @@ language: go ...@@ -2,7 +2,7 @@ language: go
go: go:
- 1.3 - 1.3
- release - 1.4
- tip - tip
script: script:
......
...@@ -14,8 +14,10 @@ import ( ...@@ -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: ...@@ -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) { ...@@ -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,6 +12,7 @@ import ( ...@@ -12,6 +12,7 @@ import (
iaddr "github.com/jbenet/go-ipfs/util/ipfsaddr" iaddr "github.com/jbenet/go-ipfs/util/ipfsaddr"
context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context" context "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
ma "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multiaddr"
) )
type stringList struct { type stringList struct {
...@@ -172,17 +173,17 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3 ...@@ -172,17 +173,17 @@ ipfs swarm connect /ip4/104.131.131.82/tcp/4001/ipfs/QmaCpDMGvV2BGHeYERUEnRQAwe3
return return
} }
peers, err := peersWithAddresses(n.Peerstore, addrs) pis, err := peersWithAddresses(addrs)
if err != nil { if err != nil {
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
} }
output := make([]string, len(peers)) output := make([]string, len(pis))
for i, p := range peers { for i, pi := range pis {
output[i] = "connect " + p.Pretty() output[i] = "connect " + pi.ID.Pretty()
err := n.PeerHost.Connect(ctx, peer.PeerInfo{ID: p}) err := n.PeerHost.Connect(ctx, pi)
if err != nil { if err != nil {
output[i] += " failure: " + err.Error() output[i] += " failure: " + err.Error()
} else { } else {
...@@ -294,15 +295,17 @@ func parseAddresses(addrs []string) (iaddrs []iaddr.IPFSAddr, err error) { ...@@ -294,15 +295,17 @@ func parseAddresses(addrs []string) (iaddrs []iaddr.IPFSAddr, err error) {
// peersWithAddresses is a function that takes in a slice of string peer addresses // peersWithAddresses is a function that takes in a slice of string peer addresses
// (multiaddr + peerid) and returns a slice of properly constructed peers // (multiaddr + peerid) and returns a slice of properly constructed peers
func peersWithAddresses(ps peer.Peerstore, addrs []string) (pids []peer.ID, err error) { func peersWithAddresses(addrs []string) (pis []peer.PeerInfo, err error) {
iaddrs, err := parseAddresses(addrs) iaddrs, err := parseAddresses(addrs)
if err != nil { if err != nil {
return nil, err return nil, err
} }
for _, iaddr := range iaddrs { for _, iaddr := range iaddrs {
pids = append(pids, iaddr.ID()) pis = append(pis, peer.PeerInfo{
ps.AddAddr(iaddr.ID(), iaddr.Multiaddr(), peer.TempAddrTTL) ID: iaddr.ID(),
Addrs: []ma.Multiaddr{iaddr.Transport()},
})
} }
return pids, nil return pis, nil
} }
...@@ -67,8 +67,9 @@ type IpfsNode struct { ...@@ -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 { ...@@ -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. ...@@ -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 { ...@@ -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) { ...@@ -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
} }
......
...@@ -11,14 +11,13 @@ import ( ...@@ -11,14 +11,13 @@ import (
) )
func TestNotifications(t *testing.T) { func TestNotifications(t *testing.T) {
t.Parallel()
mn, err := FullMeshLinked(context.Background(), 5) mn, err := FullMeshLinked(context.Background(), 5)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
timeout := 5 * time.Second timeout := 10 * time.Second
// signup notifs // signup notifs
nets := mn.Nets() nets := mn.Nets()
......
...@@ -301,7 +301,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) { ...@@ -301,7 +301,7 @@ func (s *Swarm) dial(ctx context.Context, p peer.ID) (*Conn, error) {
ila, _ := s.InterfaceListenAddresses() ila, _ := s.InterfaceListenAddresses()
remoteAddrs = addrutil.Subtract(remoteAddrs, ila) remoteAddrs = addrutil.Subtract(remoteAddrs, ila)
remoteAddrs = addrutil.Subtract(remoteAddrs, s.peers.Addrs(s.local)) remoteAddrs = addrutil.Subtract(remoteAddrs, s.peers.Addrs(s.local))
log.Debugf("%s swarm dialing %s -- remote:%s local:%s", s.local, p, remoteAddrs, s.ListenAddresses()) log.Debugf("%s swarm dialing %s -- local:%s remote:%s", s.local, p, s.ListenAddresses(), remoteAddrs)
if len(remoteAddrs) == 0 { if len(remoteAddrs) == 0 {
err := errors.New("peer has no addresses") err := errors.New("peer has no addresses")
logdial["error"] = err logdial["error"] = err
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论