Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
0f4f91c2
Commit
0f4f91c2
authored
Jan 10, 2015
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
restore ability to ping by ID alone
parent
1561291d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
12 deletions
+40
-12
core/commands/ping.go
core/commands/ping.go
+40
-12
No files found.
core/commands/ping.go
View file @
0f4f91c2
...
...
@@ -4,10 +4,10 @@ import (
"bytes"
"fmt"
"io"
"strings"
"time"
cmds
"github.com/jbenet/go-ipfs/commands"
config
"github.com/jbenet/go-ipfs/config"
core
"github.com/jbenet/go-ipfs/core"
peer
"github.com/jbenet/go-ipfs/p2p/peer"
u
"github.com/jbenet/go-ipfs/util"
...
...
@@ -82,21 +82,12 @@ Send pings to a peer using the routing system to discover its address
return
nil
,
errNotOnline
}
bsp
,
err
:=
config
.
ParseBootstrapPeer
(
req
.
Arguments
()[
0
])
addr
,
peerID
,
err
:=
ParsePeerParam
(
req
.
Arguments
()[
0
])
if
err
!=
nil
{
return
nil
,
err
}
peerID
,
err
:=
peer
.
IDB58Decode
(
bsp
.
PeerID
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
bsp
.
Address
)
>
0
{
addr
,
err
:=
ma
.
NewMultiaddr
(
bsp
.
Address
)
if
err
!=
nil
{
return
nil
,
err
}
if
addr
!=
nil
{
n
.
Peerstore
.
AddAddress
(
peerID
,
addr
)
}
...
...
@@ -161,3 +152,40 @@ func pingPeer(n *core.IpfsNode, pid peer.ID, numPings int, outChan chan interfac
Text
:
fmt
.
Sprintf
(
"Average latency: %.2fms"
,
averagems
),
}
}
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
err
!=
nil
{
return
nil
,
""
,
err
}
return
nil
,
pid
,
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment