Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
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
925ac425
Commit
925ac425
authored
7 years ago
by
Steven Allen
Browse files
Options
Download
Email Patches
Plain Diff
Reset on error in ping.
parent
7cdd4bc9
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
p2p/protocol/ping/ping.go
+18
-8
p2p/protocol/ping/ping.go
with
18 additions
and
8 deletions
+18
-8
p2p/protocol/ping/ping.go
View file @
925ac425
...
...
@@ -33,33 +33,42 @@ func NewPingService(h host.Host) *PingService {
}
func
(
p
*
PingService
)
PingHandler
(
s
inet
.
Stream
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
buf
:=
make
([]
byte
,
PingSize
)
errCh
:=
make
(
chan
error
,
1
)
defer
close
(
errCh
)
timer
:=
time
.
NewTimer
(
pingTimeout
)
defer
timer
.
Stop
()
go
func
()
{
select
{
case
<-
timer
.
C
:
case
<-
ctx
.
Done
()
:
log
.
Debug
(
"ping timeout"
)
s
.
Reset
()
case
err
,
ok
:=
<-
errCh
:
if
ok
{
log
.
Debug
(
err
)
if
err
==
io
.
EOF
{
s
.
Close
()
}
else
{
s
.
Reset
()
}
}
else
{
log
.
Error
(
"ping loop failed without error"
)
}
}
s
.
Close
()
}()
for
{
_
,
err
:=
io
.
ReadFull
(
s
,
buf
)
if
err
!=
nil
{
log
.
Debug
(
err
)
errCh
<-
err
return
}
_
,
err
=
s
.
Write
(
buf
)
if
err
!=
nil
{
log
.
Debug
(
err
)
errCh
<-
err
return
}
...
...
@@ -84,6 +93,7 @@ func (ps *PingService) Ping(ctx context.Context, p peer.ID) (<-chan time.Duratio
default
:
t
,
err
:=
ping
(
s
)
if
err
!=
nil
{
s
.
Reset
()
log
.
Debugf
(
"ping error: %s"
,
err
)
return
}
...
...
This diff is collapsed.
Click to expand it.
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
Menu
Projects
Groups
Snippets
Help