From 657868e27ce72cade2af7c892b0e141ae0ed2a88 Mon Sep 17 00:00:00 2001 From: Chris Schinnerl Date: Mon, 8 Jul 2024 08:41:04 +0200 Subject: [PATCH] syncer: resolve domain before checking if peer is banned --- syncer/syncer.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/syncer/syncer.go b/syncer/syncer.go index e52c463..52a1080 100644 --- a/syncer/syncer.go +++ b/syncer/syncer.go @@ -360,10 +360,18 @@ func (s *Syncer) allowConnect(peer string, inbound bool) error { if s.l == nil { return errors.New("syncer is shutting down") } - if banned, err := s.pm.Banned(peer); err != nil { - return err - } else if banned { - return ErrPeerBanned + addrs, err := (&net.Resolver{}).LookupIPAddr(s.shutdownCtx, peer) + if err != nil { + return fmt.Errorf("failed to resolve peer address: %w", err) + } else if len(addrs) == 0 { + return fmt.Errorf("peer didn't resolve to any addresses") + } + for _, addr := range addrs { + if banned, err := s.pm.Banned(addr.String()); err != nil { + return err + } else if banned { + return ErrPeerBanned + } } var in, out int for _, p := range s.peers {