mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-03 15:27:57 +08:00
account for p2p-circuit address intricacies
License: MIT Signed-off-by: vyzo <vyzo@hackzen.org>
This commit is contained in:
parent
ba5940e617
commit
4900935bd8
@ -7,6 +7,7 @@ import (
|
||||
"io"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
cmds "github.com/ipfs/go-ipfs/commands"
|
||||
repo "github.com/ipfs/go-ipfs/repo"
|
||||
@ -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)
|
||||
}
|
||||
|
||||
8
thirdparty/ipfsaddr/ipfsaddr.go
vendored
8
thirdparty/ipfsaddr/ipfsaddr.go
vendored
@ -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"
|
||||
)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user