Skip to content

Commit

Permalink
fix ping multiaddr parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
whyrusleeping committed Feb 1, 2015
1 parent 0ef4bcc commit eefa56a
Showing 1 changed file with 6 additions and 28 deletions.
34 changes: 6 additions & 28 deletions core/commands/ping.go
Expand Up @@ -12,6 +12,7 @@ import (
core "github.com/jbenet/go-ipfs/core"
peer "github.com/jbenet/go-ipfs/p2p/peer"
u "github.com/jbenet/go-ipfs/util"
ipfsaddr "github.com/jbenet/go-ipfs/util/ipfsaddr"

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"
Expand Down Expand Up @@ -170,38 +171,15 @@ func pingPeer(ctx context.Context, n *core.IpfsNode, pid peer.ID, numPings int)
}

func ParsePeerParam(text string) (ma.Multiaddr, peer.ID, error) {
// to be replaced with just multiaddr parsing, once ptp is a multiaddr protocol
idx := strings.LastIndex(text, "/")
if idx == -1 {
pid, err := peer.IDB58Decode(text)
if strings.Contains(text, "/") {
pa, err := ipfsaddr.ParseString(text)
if err != nil {
return nil, "", err
}

return nil, pid, nil
return pa.Multiaddr(), pa.ID(), nil
}

addrS := text[:idx]
peeridS := text[idx+1:]

var maddr ma.Multiaddr
var pid peer.ID

// make sure addrS parses as a multiaddr.
if len(addrS) > 0 {
var err error
maddr, err = ma.NewMultiaddr(addrS)
if err != nil {
return nil, "", err
}
}

// make sure idS parses as a peer.ID
var err error
pid, err = peer.IDB58Decode(peeridS)
if err != nil {
return nil, "", err
}

return maddr, pid, nil
pid, err := peer.IDB58Decode(text)
return nil, pid, err
}

0 comments on commit eefa56a

Please sign in to comment.