*(home): do not set whois-info for manually created clients

 Closes: Do not set WhoisInfo for manually created clients
This commit is contained in:
Andrey Meshkov 2019-12-23 20:02:06 +03:00
parent cdd55139fa
commit 3a077717ae
3 changed files with 7 additions and 8 deletions

View File

@ -176,7 +176,7 @@ func (clients *clientsContainer) Exists(ip string, source clientSource) bool {
clients.lock.Lock() clients.lock.Lock()
defer clients.lock.Unlock() defer clients.lock.Unlock()
_, ok := clients.idIndex[ip] _, ok := clients.findByIP(ip)
if ok { if ok {
return true return true
} }
@ -484,10 +484,9 @@ func (clients *clientsContainer) SetWhoisInfo(ip string, info [][]string) {
clients.lock.Lock() clients.lock.Lock()
defer clients.lock.Unlock() defer clients.lock.Unlock()
c, ok := clients.idIndex[ip] _, ok := clients.findByIP(ip)
if ok { if ok {
c.WhoisInfo = info log.Debug("Clients: client for %s is already created, ignore WHOIS info", ip)
log.Debug("Clients: set WHOIS info for client %s: %v", c.Name, c.WhoisInfo)
return return
} }

View File

@ -167,14 +167,14 @@ func TestClientsWhois(t *testing.T) {
clients.SetWhoisInfo("1.1.1.1", whois) clients.SetWhoisInfo("1.1.1.1", whois)
assert.True(t, clients.ipHost["1.1.1.1"].WhoisInfo[0][1] == "orgname-val") 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{ c = Client{
IDs: []string{"1.1.1.2"}, IDs: []string{"1.1.1.2"},
Name: "client1", Name: "client1",
} }
_, _ = clients.Add(c) _, _ = clients.Add(c)
clients.SetWhoisInfo("1.1.1.2", whois) 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") _ = clients.Del("client1")
} }

View File

@ -16,6 +16,7 @@ const (
defaultServer = "whois.arin.net" defaultServer = "whois.arin.net"
defaultPort = "43" defaultPort = "43"
maxValueLength = 250 maxValueLength = 250
whoisTTL = 1 * 60 * 60 // 1 hour
) )
// Whois - module context // Whois - module context
@ -205,8 +206,7 @@ func (w *Whois) Begin(ip string) {
// TTL expired // TTL expired
} }
expire = make([]byte, 8) expire = make([]byte, 8)
const ttl = 1 * 60 * 60 binary.BigEndian.PutUint64(expire, now+whoisTTL)
binary.BigEndian.PutUint64(expire, now+ttl)
_ = w.ipAddrs.Set([]byte(ip), expire) _ = w.ipAddrs.Set([]byte(ip), expire)
log.Debug("Whois: adding %s", ip) log.Debug("Whois: adding %s", ip)