From ca585bde1c27777917b9454fe1d9c3d736de143d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Fri, 19 May 2023 01:42:02 +0300 Subject: excluding votes for non-participants --- internal/config.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'internal/config.go') diff --git a/internal/config.go b/internal/config.go index 93549e2..17ec25b 100644 --- a/internal/config.go +++ b/internal/config.go @@ -38,11 +38,19 @@ func newConfig(configFile string) (config, error) { } func (c config) isParticipant(remoteAddr string) bool { - return c.isParticipantWithLookup(remoteAddr, net.LookupIP) + remoteAddr = stripPort(remoteAddr) + + for _, participant := range c.Participants { + if remoteAddr == stripPort(participant) { + return true + } + } + + return false } func (c config) isParticipantWithLookup(remoteAddr string, lookupIP func(string) ([]net.IP, error)) bool { - remoteIP := stripPort(remoteAddr) + remoteAddr = stripPort(remoteAddr) for _, participant := range c.Participants { ips, err := lookupIP(stripPort(participant)) @@ -52,7 +60,7 @@ func (c config) isParticipantWithLookup(remoteAddr string, lookupIP func(string) } for _, ip := range ips { - if remoteIP == ip.String() { + if remoteAddr == ip.String() { return true } } -- cgit v1.2.3