p2p/simulations/examples: use atomic.Int64 (#27861)

pull/27887/head
ucwong 1 year ago committed by GitHub
parent eeebb07c73
commit 6d2bcb911a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      p2p/simulations/examples/ping-pong.go

@ -91,7 +91,7 @@ func main() {
type pingPongService struct {
id enode.ID
log log.Logger
received int64
received atomic.Int64
}
func newPingPongService(id enode.ID) *pingPongService {
@ -125,7 +125,7 @@ func (p *pingPongService) Info() interface{} {
return struct {
Received int64 `json:"received"`
}{
atomic.LoadInt64(&p.received),
p.received.Load(),
}
}
@ -162,7 +162,7 @@ func (p *pingPongService) Run(peer *p2p.Peer, rw p2p.MsgReadWriter) error {
return
}
log.Info("received message", "msg.code", msg.Code, "msg.payload", string(payload))
atomic.AddInt64(&p.received, 1)
p.received.Add(1)
if msg.Code == pingMsgCode {
log.Info("sending pong")
go p2p.Send(rw, pongMsgCode, "PONG")

Loading…
Cancel
Save