Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
c3ad3b14
Commit
c3ad3b14
authored
Aug 31, 2018
by
Marten Seemann
Browse files
use NewStream to handle ping protocol selection
parent
85a86c83
Changes
1
Hide whitespace changes
Inline
Side-by-side
p2p/protocol/ping/ping.go
View file @
c3ad3b14
...
...
@@ -12,7 +12,6 @@ import (
host
"github.com/libp2p/go-libp2p-host"
inet
"github.com/libp2p/go-libp2p-net"
peer
"github.com/libp2p/go-libp2p-peer"
multistream
"github.com/multiformats/go-multistream"
)
var
log
=
logging
.
Logger
(
"ping"
)
...
...
@@ -61,13 +60,13 @@ func (ps *PingService) PingHandler(s inet.Stream) {
// It first attempts to use ping/2.0.0, and falls back to ping/1.0.0
// if the peer doesn't support it yet.
func
(
ps
*
PingService
)
Ping
(
ctx
context
.
Context
,
p
peer
.
ID
)
(
<-
chan
time
.
Duration
,
error
)
{
s
,
err
:=
ps
.
Host
.
NewStream
(
ctx
,
p
,
ID
)
if
err
==
multistream
.
ErrNotSupported
{
return
ps
.
PingLegacy
(
ctx
,
p
)
}
s
,
err
:=
ps
.
Host
.
NewStream
(
ctx
,
p
,
ID
,
IDLegacy
)
if
err
!=
nil
{
return
nil
,
err
}
if
s
.
Protocol
()
==
IDLegacy
{
return
ps
.
PingLegacy
(
ctx
,
p
)
}
out
:=
make
(
chan
time
.
Duration
)
go
func
()
{
...
...
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