Skip to content

Commit

Permalink
account for p2p-circuit address intricacies
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: vyzo <vyzo@hackzen.org>
  • Loading branch information
vyzo committed Jul 26, 2017
1 parent 159fa52 commit 722a44a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion core/commands/swarm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"path"
"sort"
"strings"

cmds "github.com/ipfs/go-ipfs/commands"
repo "github.com/ipfs/go-ipfs/repo"
Expand Down Expand Up @@ -128,7 +129,11 @@ var swarmPeersCmd = &cmds.Command{

buf := new(bytes.Buffer)
for _, info := range ci.Peers {
fmt.Fprintf(buf, "%s/ipfs/%s", info.Addr, info.Peer)
if strings.Contains(info.Addr, "/p2p-circuit/") {
fmt.Fprintf(buf, "%s", info.Addr)
} else {
fmt.Fprintf(buf, "%s/ipfs/%s", info.Addr, info.Peer)
}
if info.Latency != "" {
fmt.Fprintf(buf, " %s", info.Latency)
}
Expand Down
8 changes: 8 additions & 0 deletions thirdparty/ipfsaddr/ipfsaddr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

path "github.com/ipfs/go-ipfs/path"
logging "gx/ipfs/QmSpJByNKFX1sCsHBEp3R73FL4NF6FnQTEGyNAXHm2GS52/go-log"
circuit "gx/ipfs/QmVEPsD9h95ToAC7NJpYopFcXyjVJm35xV4tw43J5JdCnL/go-libp2p-circuit"
peer "gx/ipfs/QmXYjuNuxVzXKJCfWasQk1RqkhVLDM9jtUKhqc2WPQmFSB/go-libp2p-peer"
)

Expand Down Expand Up @@ -106,6 +107,13 @@ func ParseMultiaddr(m ma.Multiaddr) (a IPFSAddr, err error) {

func Transport(iaddr IPFSAddr) (maddr ma.Multiaddr) {
maddr = iaddr.Multiaddr()

// /ipfs/QmId is part of the transport address for p2p-circuit
_, err := maddr.ValueForProtocol(circuit.P_CIRCUIT)
if err == nil {
return maddr
}

split := ma.Split(maddr)
maddr = ma.Join(split[:len(split)-1]...)
return
Expand Down

0 comments on commit 722a44a

Please sign in to comment.