Skip to content

Commit

Permalink
Revert "p2p: move ping handling into pingLoop goroutine (ethereum#27887
Browse files Browse the repository at this point in the history
…)"

This reverts commit 951c49d.
  • Loading branch information
devopsbo3 authored Nov 10, 2023
1 parent 4ef5c21 commit 8586cf8
Showing 1 changed file with 2 additions and 13 deletions.
15 changes: 2 additions & 13 deletions p2p/peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ type Peer struct {
wg sync.WaitGroup
protoErr chan error
closed chan struct{}
pingRecv chan struct{}
disc chan DiscReason

// events receives message send / receive events if set
Expand Down Expand Up @@ -234,7 +233,6 @@ func newPeer(log log.Logger, conn *conn, protocols []Protocol) *Peer {
disc: make(chan DiscReason),
protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop
closed: make(chan struct{}),
pingRecv: make(chan struct{}, 16),
log: log.New("id", conn.node.ID(), "conn", conn.flags),
}
return p
Expand Down Expand Up @@ -295,11 +293,9 @@ loop:
}

func (p *Peer) pingLoop() {
defer p.wg.Done()

ping := time.NewTimer(pingInterval)
defer p.wg.Done()
defer ping.Stop()

for {
select {
case <-ping.C:
Expand All @@ -308,10 +304,6 @@ func (p *Peer) pingLoop() {
return
}
ping.Reset(pingInterval)

case <-p.pingRecv:
SendItems(p.rw, pongMsg)

case <-p.closed:
return
}
Expand All @@ -338,10 +330,7 @@ func (p *Peer) handle(msg Msg) error {
switch {
case msg.Code == pingMsg:
msg.Discard()
select {
case p.pingRecv <- struct{}{}:
case <-p.closed:
}
go SendItems(p.rw, pongMsg)
case msg.Code == discMsg:
// This is the last message. We don't need to discard or
// check errors because, the connection will be closed after it.
Expand Down

0 comments on commit 8586cf8

Please sign in to comment.