@@ -29,12 +29,13 @@ import (
2929 "time"
3030
3131 lru "github.com/hashicorp/golang-lru/v2"
32+ "github.com/ledgerwatch/log/v3"
33+
3234 "github.com/ledgerwatch/erigon/common/debug"
3335 "github.com/ledgerwatch/erigon/crypto"
3436 "github.com/ledgerwatch/erigon/p2p/discover/v4wire"
3537 "github.com/ledgerwatch/erigon/p2p/enode"
3638 "github.com/ledgerwatch/erigon/p2p/netutil"
37- "github.com/ledgerwatch/log/v3"
3839)
3940
4041// Errors
@@ -610,74 +611,30 @@ func (t *UDPv4) loop() {
610611 }()
611612
612613 case r := <- t .gotreply :
613-
614- type matchCandidate struct {
615- el * list.Element
616- errc chan error
617- }
618-
619- var matchCandidates []matchCandidate
620-
621- mutex .Lock ()
622- for el := plist .Front (); el != nil ; el = el .Next () {
623- p := el .Value .(* replyMatcher )
624- if p .from == r .from && p .ptype == r .data .Kind () && p .ip .Equal (r .ip ) {
625- candidate := matchCandidate {el , p .errc }
626- p .errc = make (chan error , 1 )
627- matchCandidates = append (matchCandidates , candidate )
628- }
629- }
630- mutex .Unlock ()
631-
632- if len (matchCandidates ) == 0 {
633- // if there are no matched candidates try again matching against
634- // ip & port to handle node key changes
614+ func () {
635615 mutex .Lock ()
636- for el := plist .Front (); el != nil ; el = el .Next () {
637- p := el .Value .(* replyMatcher )
638- if p .ptype == r .data .Kind () && p .ip .Equal (r .ip ) && p .port == r .port {
639- candidate := matchCandidate {el , p .errc }
640- p .errc = make (chan error , 1 )
641- matchCandidates = append (matchCandidates , candidate )
642- }
643- }
644- mutex .Unlock ()
645-
646- if len (matchCandidates ) == 0 {
647- r .matched <- false
648- }
649- }
616+ defer mutex .Unlock ()
650617
651- go func (r reply ) {
652618 var matched bool // whether any replyMatcher considered the reply acceptable.
653- for _ , candidate := range matchCandidates {
654- p := candidate .el .Value .(* replyMatcher )
655- ok , requestDone := p .callback (r .data )
656- matched = matched || ok
657- p .reply = r .data
658-
659- // Remove the matcher if callback indicates that all replies have been received.
660- if requestDone {
661- mutex .Lock ()
662- plist .Remove (candidate .el )
663- mutex .Unlock ()
664- candidate .errc <- nil
665- listUpdate <- candidate .el
666- } else {
667- select {
668- case err := <- p .errc :
669- candidate .errc <- err
670- default :
671- p .errc = candidate .errc
619+ for el := plist .Front (); el != nil ; el = el .Next () {
620+ p := el .Value .(* replyMatcher )
621+ if (p .ptype == r .data .Kind ()) && p .ip .Equal (r .ip ) && (p .port == r .port ) {
622+ ok , requestDone := p .callback (r .data )
623+ matched = matched || ok
624+ p .reply = r .data
625+ // Remove the matcher if callback indicates that all replies have been received.
626+ if requestDone {
627+ p .errc <- nil
628+ plist .Remove (el )
629+ listUpdate <- el
672630 }
631+ // Reset the continuous timeout counter (time drift detection)
632+ contTimeouts = 0
673633 }
674634 }
675-
676635 r .matched <- matched
677- }(r )
636+ }()
678637
679- // Reset the continuous timeout counter (time drift detection)
680- contTimeouts = 0
681638 case key := <- t .gotkey :
682639 go func () {
683640 if key , err := v4wire .DecodePubkey (crypto .S256 (), key ); err == nil {
0 commit comments