Skip to content

Commit

Permalink
handle misbehaving peers in identify push
Browse files Browse the repository at this point in the history
  • Loading branch information
vyzo committed Apr 19, 2019
1 parent cb712e6 commit 5503cd7
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions p2p/protocol/identify/id.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,11 +161,7 @@ func (ids *IDService) pushHandler(s inet.Stream) {
func (ids *IDService) Push() {
var wg sync.WaitGroup

// we could make this context timeout-less since we are only opening a new
// stream over an existing connection. This would avoid the need for the
// supervisory goroutine below, but timeout-less contexts in network operations
// make me nervous.
ctx, cancel := context.WithTimeout(ids.ctx, 15*time.Second)
ctx, cancel := context.WithTimeout(ids.ctx, 30*time.Second)
ctx = inet.WithNoDial(ctx, "identify push")

for _, p := range ids.Host.Network().Peers() {
Expand All @@ -179,7 +175,18 @@ func (ids *IDService) Push() {
return
}

ids.requestHandler(s)
rch := make(chan struct{}, 1)
go func() {
ids.requestHandler(s)
rch <- struct{}{}
}()

select {
case <-rch:
case <-ctx.Done():
// this is taking too long, abort!
s.Reset()
}
}(p)
}

Expand Down

0 comments on commit 5503cd7

Please sign in to comment.