* clients: remove an auto-client if a client with the same IP was added manually

This commit is contained in:
Simon Zolin 2019-09-23 21:25:17 +03:00
parent 95eeccde8f
commit fcf37da312
1 changed files with 12 additions and 0 deletions

View File

@ -206,6 +206,12 @@ func (clients *clientsContainer) Add(c Client) (bool, error) {
} }
} }
ch, ok := clients.ipHost[c.IP]
if ok {
c.WhoisInfo = ch.WhoisInfo
delete(clients.ipHost, c.IP)
}
clients.list[c.Name] = &c clients.list[c.Name] = &c
if len(c.IP) != 0 { if len(c.IP) != 0 {
clients.ipIndex[c.IP] = &c clients.ipIndex[c.IP] = &c
@ -312,6 +318,12 @@ func (clients *clientsContainer) AddHost(ip, host string, source clientSource) (
clients.lock.Lock() clients.lock.Lock()
defer clients.lock.Unlock() defer clients.lock.Unlock()
// check index
_, ok := clients.ipIndex[ip]
if ok {
return false, nil
}
// check index // check index
c, ok := clients.ipHost[ip] c, ok := clients.ipHost[ip]
if ok && c.Source > source { if ok && c.Source > source {