From 3a077717ae29207fdf2ebee15f42684892dca79a Mon Sep 17 00:00:00 2001 From: Andrey Meshkov Date: Mon, 23 Dec 2019 20:02:06 +0300 Subject: [PATCH] *(home): do not set whois-info for manually created clients MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✅ Closes: Do not set WhoisInfo for manually created clients --- home/clients.go | 7 +++---- home/clients_test.go | 4 ++-- home/whois.go | 4 ++-- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/home/clients.go b/home/clients.go index 8769ebc3..7b6c9a44 100644 --- a/home/clients.go +++ b/home/clients.go @@ -176,7 +176,7 @@ func (clients *clientsContainer) Exists(ip string, source clientSource) bool { clients.lock.Lock() defer clients.lock.Unlock() - _, ok := clients.idIndex[ip] + _, ok := clients.findByIP(ip) if ok { return true } @@ -484,10 +484,9 @@ func (clients *clientsContainer) SetWhoisInfo(ip string, info [][]string) { clients.lock.Lock() defer clients.lock.Unlock() - c, ok := clients.idIndex[ip] + _, ok := clients.findByIP(ip) if ok { - c.WhoisInfo = info - log.Debug("Clients: set WHOIS info for client %s: %v", c.Name, c.WhoisInfo) + log.Debug("Clients: client for %s is already created, ignore WHOIS info", ip) return } diff --git a/home/clients_test.go b/home/clients_test.go index 457b8aef..490035ed 100644 --- a/home/clients_test.go +++ b/home/clients_test.go @@ -167,14 +167,14 @@ func TestClientsWhois(t *testing.T) { clients.SetWhoisInfo("1.1.1.1", whois) assert.True(t, clients.ipHost["1.1.1.1"].WhoisInfo[0][1] == "orgname-val") - // set whois info on existing client + // Check that we cannot set whois info on existing client c = Client{ IDs: []string{"1.1.1.2"}, Name: "client1", } _, _ = clients.Add(c) clients.SetWhoisInfo("1.1.1.2", whois) - assert.True(t, clients.idIndex["1.1.1.2"].WhoisInfo[0][1] == "orgname-val") + assert.Nil(t, clients.idIndex["1.1.1.2"].WhoisInfo) _ = clients.Del("client1") } diff --git a/home/whois.go b/home/whois.go index 0db44dc6..25fe211a 100644 --- a/home/whois.go +++ b/home/whois.go @@ -16,6 +16,7 @@ const ( defaultServer = "whois.arin.net" defaultPort = "43" maxValueLength = 250 + whoisTTL = 1 * 60 * 60 // 1 hour ) // Whois - module context @@ -205,8 +206,7 @@ func (w *Whois) Begin(ip string) { // TTL expired } expire = make([]byte, 8) - const ttl = 1 * 60 * 60 - binary.BigEndian.PutUint64(expire, now+ttl) + binary.BigEndian.PutUint64(expire, now+whoisTTL) _ = w.ipAddrs.Set([]byte(ip), expire) log.Debug("Whois: adding %s", ip)