mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
Revert "p2p: move ping handling into pingLoop goroutine (#27887)"
This reverts commit 951c49dcf0.
This commit is contained in:
parent
4ef5c21090
commit
8586cf807d
1 changed files with 2 additions and 13 deletions
15
p2p/peer.go
15
p2p/peer.go
|
|
@ -112,7 +112,6 @@ type Peer struct {
|
||||||
wg sync.WaitGroup
|
wg sync.WaitGroup
|
||||||
protoErr chan error
|
protoErr chan error
|
||||||
closed chan struct{}
|
closed chan struct{}
|
||||||
pingRecv chan struct{}
|
|
||||||
disc chan DiscReason
|
disc chan DiscReason
|
||||||
|
|
||||||
// events receives message send / receive events if set
|
// events receives message send / receive events if set
|
||||||
|
|
@ -234,7 +233,6 @@ func newPeer(log log.Logger, conn *conn, protocols []Protocol) *Peer {
|
||||||
disc: make(chan DiscReason),
|
disc: make(chan DiscReason),
|
||||||
protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop
|
protoErr: make(chan error, len(protomap)+1), // protocols + pingLoop
|
||||||
closed: make(chan struct{}),
|
closed: make(chan struct{}),
|
||||||
pingRecv: make(chan struct{}, 16),
|
|
||||||
log: log.New("id", conn.node.ID(), "conn", conn.flags),
|
log: log.New("id", conn.node.ID(), "conn", conn.flags),
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
|
|
@ -295,11 +293,9 @@ loop:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Peer) pingLoop() {
|
func (p *Peer) pingLoop() {
|
||||||
defer p.wg.Done()
|
|
||||||
|
|
||||||
ping := time.NewTimer(pingInterval)
|
ping := time.NewTimer(pingInterval)
|
||||||
|
defer p.wg.Done()
|
||||||
defer ping.Stop()
|
defer ping.Stop()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ping.C:
|
case <-ping.C:
|
||||||
|
|
@ -308,10 +304,6 @@ func (p *Peer) pingLoop() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ping.Reset(pingInterval)
|
ping.Reset(pingInterval)
|
||||||
|
|
||||||
case <-p.pingRecv:
|
|
||||||
SendItems(p.rw, pongMsg)
|
|
||||||
|
|
||||||
case <-p.closed:
|
case <-p.closed:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -338,10 +330,7 @@ func (p *Peer) handle(msg Msg) error {
|
||||||
switch {
|
switch {
|
||||||
case msg.Code == pingMsg:
|
case msg.Code == pingMsg:
|
||||||
msg.Discard()
|
msg.Discard()
|
||||||
select {
|
go SendItems(p.rw, pongMsg)
|
||||||
case p.pingRecv <- struct{}{}:
|
|
||||||
case <-p.closed:
|
|
||||||
}
|
|
||||||
case msg.Code == discMsg:
|
case msg.Code == discMsg:
|
||||||
// This is the last message. We don't need to discard or
|
// This is the last message. We don't need to discard or
|
||||||
// check errors because, the connection will be closed after it.
|
// check errors because, the connection will be closed after it.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue