code_before
stringlengths 16
1.81M
| edits
stringlengths 4
328k
| next_edit
stringlengths 0
76.5k
| code_after
stringlengths 3
49.9M
| label_window
sequencelengths 4
1.81k
| instruction
stringlengths 20
51.9k
| html_url
stringlengths 74
116
| file_name
stringlengths 3
311
|
---|---|---|---|---|---|---|---|
// hosts must have at least one name.
func (hp *hostsParser) addRecord(ip net.IP, hosts []string) {
line := strings.Join(append([]string{ip.String()}, hosts...), " ")
var rec *HostsRecord
v, ok := hp.table.Get(ip)
if !ok {
rec = &HostsRecord{
Aliases: stringutil.NewSet(),
}
| </s> remove func (hp *hostsParser) addRecord(ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) addRecord(ip netip.Addr, hosts []string) { </s> remove // HostsRecord represents a single hosts file record.
type HostsRecord struct {
Aliases *stringutil.Set
Canonical string
}
// Equal returns true if all fields of rec are equal to field in other or they
// both are nil.
func (rec *HostsRecord) Equal(other *HostsRecord) (ok bool) {
if rec == nil {
return other == nil
}
return rec.Canonical == other.Canonical && rec.Aliases.Equal(other.Aliases)
}
</s> add </s> remove func (hp *hostsParser) parseLine(line string) (ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) parseLine(line string) (ip netip.Addr, hosts []string) { </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add </s> remove hosts.Range(func(ip net.IP, v any) (cont bool) {
rec, ok := v.(*aghnet.HostsRecord)
if !ok {
log.Error("clients: bad type %T in hosts for %s", v, ip)
return true
}
</s> add for ip, rec := range hosts { | rec, ok := hp.table[ip] | // hosts must have at least one name.
func (hp *hostsParser) addRecord(ip net.IP, hosts []string) {
line := strings.Join(append([]string{ip.String()}, hosts...), " ")
rec, ok := hp.table[ip]
rec, ok := hp.table[ip]
if !ok {
rec = &HostsRecord{
Aliases: stringutil.NewSet(),
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
}
rec.Canonical, hosts = hosts[0], hosts[1:]
hp.addRules(ip, rec.Canonical, line)
hp.table.Set(ip, rec)
} else {
rec, ok = v.(*HostsRecord)
if !ok {
log.Error("%s: adding pairs: unexpected type %T", hostsContainerPref, v)
return
}
}
for _, host := range hosts {
if rec.Canonical == host || rec.Aliases.Has(host) {
continue
| </s> remove hosts.Range(func(ip net.IP, v any) (cont bool) {
rec, ok := v.(*aghnet.HostsRecord)
if !ok {
log.Error("clients: bad type %T in hosts for %s", v, ip)
return true
}
</s> add for ip, rec := range hosts { </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add </s> remove err := netutil.ValidateDomainName(f)
</s> add err = netutil.ValidateDomainName(f) </s> remove if ip == nil || len(hosts) == 0 {
</s> add if ip == (netip.Addr{}) || len(hosts) == 0 { </s> remove if n.IP = net.ParseIP(fields[0]); n.IP == nil || n.IP.IsUnspecified() {
</s> add n.IP, err = netip.ParseAddr(fields[0])
if err != nil || n.IP.IsUnspecified() { | hp.table[ip] = rec | }
rec.Canonical, hosts = hosts[0], hosts[1:]
hp.addRules(ip, rec.Canonical, line)
hp.table[ip] = rec
hp.table[ip] = rec
hp.table[ip] = rec
hp.table[ip] = rec
hp.table[ip] = rec
hp.table[ip] = rec
hp.table[ip] = rec
hp.table[ip] = rec
}
for _, host := range hosts {
if rec.Canonical == host || rec.Aliases.Has(host) {
continue | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
}
}
// addRules adds rules and rule translations for the line.
func (hp *hostsParser) addRules(ip net.IP, host, line string) {
rule, rulePtr := hp.writeRules(host, ip)
hp.translations[rule], hp.translations[rulePtr] = line, line
log.Debug("%s: added ip-host pair %q-%q", hostsContainerPref, ip, host)
}
| </s> remove func (hp *hostsParser) writeRules(host string, ip net.IP) (rule, rulePtr string) {
arpa, err := netutil.IPToReversedAddr(ip)
</s> add func (hp *hostsParser) writeRules(host string, ip netip.Addr) (rule, rulePtr string) {
// TODO(a.garipov): Add a netip.Addr version to netutil.
arpa, err := netutil.IPToReversedAddr(ip.AsSlice()) </s> remove func (hp *hostsParser) parseLine(line string) (ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) parseLine(line string) (ip netip.Addr, hosts []string) { </s> remove return nil, nil
</s> add return netip.Addr{}, nil </s> remove func (hp *hostsParser) addRecord(ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) addRecord(ip netip.Addr, hosts []string) { </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add | func (hp *hostsParser) addRules(ip netip.Addr, host, line string) { | }
}
// addRules adds rules and rule translations for the line.
func (hp *hostsParser) addRules(ip netip.Addr, host, line string) {
rule, rulePtr := hp.writeRules(host, ip)
hp.translations[rule], hp.translations[rulePtr] = line, line
log.Debug("%s: added ip-host pair %q-%q", hostsContainerPref, ip, host)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
}
// writeRules writes the actual rule for the qtype and the PTR for the host-ip
// pair into internal builders.
func (hp *hostsParser) writeRules(host string, ip net.IP) (rule, rulePtr string) {
arpa, err := netutil.IPToReversedAddr(ip)
if err != nil {
return "", ""
}
const (
| </s> remove func (hp *hostsParser) addRules(ip net.IP, host, line string) {
</s> add func (hp *hostsParser) addRules(ip netip.Addr, host, line string) { </s> remove func (hp *hostsParser) parseLine(line string) (ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) parseLine(line string) (ip netip.Addr, hosts []string) { </s> remove return nil, nil
</s> add return netip.Addr{}, nil </s> remove func (hp *hostsParser) addRecord(ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) addRecord(ip netip.Addr, hosts []string) { </s> remove // Upd returns the channel into which the updates are sent. The receivable
// map's values are guaranteed to be of type of *HostsRecord.
func (hc *HostsContainer) Upd() (updates <-chan *netutil.IPMap) {
</s> add // Upd returns the channel into which the updates are sent.
func (hc *HostsContainer) Upd() (updates <-chan HostsRecords) { | func (hp *hostsParser) writeRules(host string, ip netip.Addr) (rule, rulePtr string) {
// TODO(a.garipov): Add a netip.Addr version to netutil.
arpa, err := netutil.IPToReversedAddr(ip.AsSlice()) | }
// writeRules writes the actual rule for the qtype and the PTR for the host-ip
// pair into internal builders.
func (hp *hostsParser) writeRules(host string, ip netip.Addr) (rule, rulePtr string) {
// TODO(a.garipov): Add a netip.Addr version to netutil.
arpa, err := netutil.IPToReversedAddr(ip.AsSlice())
func (hp *hostsParser) writeRules(host string, ip netip.Addr) (rule, rulePtr string) {
// TODO(a.garipov): Add a netip.Addr version to netutil.
arpa, err := netutil.IPToReversedAddr(ip.AsSlice())
if err != nil {
return "", ""
}
const ( | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
var qtype string
// The validation of the IP address has been performed earlier so it is
// guaranteed to be either an IPv4 or an IPv6.
if ip.To4() != nil {
qtype = "A"
} else {
qtype = "AAAA"
}
| </s> remove IP net.IP
</s> add IP netip.Addr </s> remove // HostsRecord represents a single hosts file record.
type HostsRecord struct {
Aliases *stringutil.Set
Canonical string
}
// Equal returns true if all fields of rec are equal to field in other or they
// both are nil.
func (rec *HostsRecord) Equal(other *HostsRecord) (ok bool) {
if rec == nil {
return other == nil
}
return rec.Canonical == other.Canonical && rec.Aliases.Equal(other.Aliases)
}
</s> add </s> remove rc, ok := clients.FindRuntimeClient(ip)
</s> add rc, ok := clients.findRuntimeClient(ip) </s> remove func (hp *hostsParser) addRecord(ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) addRecord(ip netip.Addr, hosts []string) { </s> remove func (hp *hostsParser) writeRules(host string, ip net.IP) (rule, rulePtr string) {
arpa, err := netutil.IPToReversedAddr(ip)
</s> add func (hp *hostsParser) writeRules(host string, ip netip.Addr) (rule, rulePtr string) {
// TODO(a.garipov): Add a netip.Addr version to netutil.
arpa, err := netutil.IPToReversedAddr(ip.AsSlice()) | if ip.Is4() { |
var qtype string
// The validation of the IP address has been performed earlier so it is
// guaranteed to be either an IPv4 or an IPv6.
if ip.Is4() {
qtype = "A"
} else {
qtype = "AAAA"
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
return rule, rulePtr
}
// equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
// sendUpd tries to send the parsed data to the ch.
func (hp *hostsParser) sendUpd(ch chan *netutil.IPMap) {
log.Debug("%s: sending upd", hostsContainerPref)
upd := hp.table
| </s> remove func (hp *hostsParser) sendUpd(ch chan *netutil.IPMap) {
</s> add func (hp *hostsParser) sendUpd(ch chan HostsRecords) { </s> remove hp.table.Set(ip, rec)
} else {
rec, ok = v.(*HostsRecord)
if !ok {
log.Error("%s: adding pairs: unexpected type %T", hostsContainerPref, v)
return
}
</s> add hp.table[ip] = rec </s> remove hosts.Range(func(ip net.IP, v any) (cont bool) {
rec, ok := v.(*aghnet.HostsRecord)
if !ok {
log.Error("clients: bad type %T in hosts for %s", v, ip)
return true
}
</s> add for ip, rec := range hosts { </s> remove var rec *HostsRecord
v, ok := hp.table.Get(ip)
</s> add rec, ok := hp.table[ip] </s> remove // addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip)
</s> add // addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip] |
return rule, rulePtr
}
// sendUpd tries to send the parsed data to the ch.
func (hp *hostsParser) sendUpd(ch chan *netutil.IPMap) {
log.Debug("%s: sending upd", hostsContainerPref)
upd := hp.table | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
|
return ok
}
// sendUpd tries to send the parsed data to the ch.
func (hp *hostsParser) sendUpd(ch chan *netutil.IPMap) {
log.Debug("%s: sending upd", hostsContainerPref)
upd := hp.table
select {
case ch <- upd:
| </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add </s> remove if r.isCached(ip) || r.clients.Exists(ip, ClientSourceRDNS) {
</s> add if r.isCached(ip) || r.clients.exists(ip, ClientSourceRDNS) { </s> remove func (hp *hostsParser) addRecord(ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) addRecord(ip netip.Addr, hosts []string) { </s> remove func (hp *hostsParser) writeRules(host string, ip net.IP) (rule, rulePtr string) {
arpa, err := netutil.IPToReversedAddr(ip)
</s> add func (hp *hostsParser) writeRules(host string, ip netip.Addr) (rule, rulePtr string) {
// TODO(a.garipov): Add a netip.Addr version to netutil.
arpa, err := netutil.IPToReversedAddr(ip.AsSlice()) </s> remove func (hp *hostsParser) addRules(ip net.IP, host, line string) {
</s> add func (hp *hostsParser) addRules(ip netip.Addr, host, line string) { | func (hp *hostsParser) sendUpd(ch chan HostsRecords) { | return ok
}
// sendUpd tries to send the parsed data to the ch.
func (hp *hostsParser) sendUpd(ch chan HostsRecords) {
log.Debug("%s: sending upd", hostsContainerPref)
upd := hp.table
select {
case ch <- upd: | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
if _, err = aghos.FileWalker(hp.parseFile).Walk(hc.fsys, hc.patterns...); err != nil {
return fmt.Errorf("refreshing : %w", err)
}
if hp.equalSet(hc.last) {
log.Debug("%s: no changes detected", hostsContainerPref)
return nil
}
defer hp.sendUpd(hc.updates)
| </s> remove hc.last = hp.table.ShallowClone()
</s> add hc.last = maps.Clone(hp.table) </s> remove if ip = net.ParseIP(fields[0]); ip == nil {
return nil, nil
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil {
return netip.Addr{}, nil </s> remove } else if ip := net.ParseIP(ipStr[1 : len(ipStr)-1]); ip == nil {
</s> add } else if ip, err := netip.ParseAddr(ipStr[1 : len(ipStr)-1]); err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
</s> remove } else if ip := net.ParseIP(ipStr[1 : len(ipStr)-1]); ip == nil {
</s> add } else if ip, err := netip.ParseAddr(ipStr[1 : len(ipStr)-1]); err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
</s> remove return clients.addHostLocked(ip, host, src), nil
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil | if maps.EqualFunc(hp.table, hc.last, (*HostsRecord).equal) { | if _, err = aghos.FileWalker(hp.parseFile).Walk(hc.fsys, hc.patterns...); err != nil {
return fmt.Errorf("refreshing : %w", err)
}
if maps.EqualFunc(hp.table, hc.last, (*HostsRecord).equal) {
log.Debug("%s: no changes detected", hostsContainerPref)
return nil
}
defer hp.sendUpd(hc.updates) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
return nil
}
defer hp.sendUpd(hc.updates)
hc.last = hp.table.ShallowClone()
var rulesStrg *filterlist.RuleStorage
if rulesStrg, err = hp.newStrg(hc.listID); err != nil {
return fmt.Errorf("initializing rules storage: %w", err)
}
| </s> remove if hp.equalSet(hc.last) {
</s> add if maps.EqualFunc(hp.table, hc.last, (*HostsRecord).equal) { </s> remove return clients.addHostLocked(ip, host, src), nil
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil </s> remove if ip = net.ParseIP(fields[0]); ip == nil {
return nil, nil
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil {
return netip.Addr{}, nil </s> remove if mac, err := net.ParseMAC(fields[4]); err != nil {
log.Debug("parsing arp output: %s", err)
</s> add mac, err := net.ParseMAC(fields[4])
if err != nil {
log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(fields[1]); err != nil {
log.Debug("parsing arp output: %s", err)
</s> add mac, err := net.ParseMAC(fields[1])
if err != nil {
log.Debug("arpdb: parsing arp output: mac: %s", err) | hc.last = maps.Clone(hp.table) | return nil
}
defer hp.sendUpd(hc.updates)
hc.last = maps.Clone(hp.table)
var rulesStrg *filterlist.RuleStorage
if rulesStrg, err = hp.newStrg(hc.listID); err != nil {
return fmt.Errorf("initializing rules storage: %w", err)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer.go |
"io/fs"
"net"
"path"
"strings"
"sync/atomic"
"testing"
| </s> remove "net"
</s> add "net/netip" | "net/netip" | "io/fs"
"net"
"net/netip"
"path"
"strings"
"sync/atomic"
"testing" | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/AdguardTeam/urlfilter"
"github.com/AdguardTeam/urlfilter/rules"
| </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap].
</s> add | "github.com/AdguardTeam/golibs/netutil" | "github.com/AdguardTeam/AdGuardHome/internal/aghtest"
"github.com/AdguardTeam/golibs/errors"
"github.com/AdguardTeam/golibs/netutil"
"github.com/AdguardTeam/golibs/stringutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/AdguardTeam/urlfilter"
"github.com/AdguardTeam/urlfilter/rules" | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
func TestHostsContainer_refresh(t *testing.T) {
// TODO(e.burkov): Test the case with no actual updates.
ip := net.IP{127, 0, 0, 1}
ipStr := ip.String()
testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}}
// event is a convenient alias for an empty struct{} to emit test events.
| </s> remove ip := net.IP{127, 0, 0, 1}
</s> add ip := netutil.IPv4Localhost() </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove knownIP := net.IP{1, 2, 3, 4}
</s> add knownIP := netip.MustParseAddr("1.2.3.4") </s> remove func (hp *hostsParser) writeRules(host string, ip net.IP) (rule, rulePtr string) {
arpa, err := netutil.IPToReversedAddr(ip)
</s> add func (hp *hostsParser) writeRules(host string, ip netip.Addr) (rule, rulePtr string) {
// TODO(a.garipov): Add a netip.Addr version to netutil.
arpa, err := netutil.IPToReversedAddr(ip.AsSlice()) </s> remove wantIP net.IP
</s> add wantIP netip.Addr | ip := netutil.IPv4Localhost() |
func TestHostsContainer_refresh(t *testing.T) {
// TODO(e.burkov): Test the case with no actual updates.
ip := netutil.IPv4Localhost()
ipStr := ip.String()
testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}}
// event is a convenient alias for an empty struct{} to emit test events. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
upd, ok := aghchan.MustReceive(hc.Upd(), 1*time.Second)
require.True(t, ok)
require.NotNil(t, upd)
assert.Equal(t, 1, upd.Len())
v, ok := upd.Get(ip)
require.True(t, ok)
require.IsType(t, (*HostsRecord)(nil), v)
| </s> remove v, ok := upd.Get(ip)
</s> add rec, ok := upd[ip] </s> remove
require.IsType(t, (*HostsRecord)(nil), v)
rec, _ := v.(*HostsRecord)
</s> add </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) </s> remove assert.False(t, clients.Exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile)) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) | assert.Len(t, upd, 1) | upd, ok := aghchan.MustReceive(hc.Upd(), 1*time.Second)
require.True(t, ok)
require.NotNil(t, upd)
assert.Len(t, upd, 1)
v, ok := upd.Get(ip)
require.True(t, ok)
require.IsType(t, (*HostsRecord)(nil), v) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
require.NotNil(t, upd)
assert.Equal(t, 1, upd.Len())
v, ok := upd.Get(ip)
require.True(t, ok)
require.IsType(t, (*HostsRecord)(nil), v)
rec, _ := v.(*HostsRecord)
| </s> remove
require.IsType(t, (*HostsRecord)(nil), v)
rec, _ := v.(*HostsRecord)
</s> add </s> remove assert.Equal(t, 1, upd.Len())
</s> add assert.Len(t, upd, 1) </s> remove assert.Truef(t, rec.Equal(want), "%+v != %+v", rec, want)
</s> add assert.Truef(t, rec.equal(want), "%+v != %+v", rec, want) </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) | rec, ok := upd[ip] | require.NotNil(t, upd)
assert.Equal(t, 1, upd.Len())
rec, ok := upd[ip]
require.True(t, ok)
require.IsType(t, (*HostsRecord)(nil), v)
rec, _ := v.(*HostsRecord) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
assert.Equal(t, 1, upd.Len())
v, ok := upd.Get(ip)
require.True(t, ok)
require.IsType(t, (*HostsRecord)(nil), v)
rec, _ := v.(*HostsRecord)
require.NotNil(t, rec)
assert.Truef(t, rec.Equal(want), "%+v != %+v", rec, want)
}
| </s> remove v, ok := upd.Get(ip)
</s> add rec, ok := upd[ip] </s> remove assert.Truef(t, rec.Equal(want), "%+v != %+v", rec, want)
</s> add assert.Truef(t, rec.equal(want), "%+v != %+v", rec, want) </s> remove assert.Equal(t, 1, upd.Len())
</s> add assert.Len(t, upd, 1) </s> remove hp.table.Set(ip, rec)
} else {
rec, ok = v.(*HostsRecord)
if !ok {
log.Error("%s: adding pairs: unexpected type %T", hostsContainerPref, v)
return
}
</s> add hp.table[ip] = rec </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) | assert.Equal(t, 1, upd.Len())
v, ok := upd.Get(ip)
require.True(t, ok)
require.NotNil(t, rec)
assert.Truef(t, rec.Equal(want), "%+v != %+v", rec, want)
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
|
rec, _ := v.(*HostsRecord)
require.NotNil(t, rec)
assert.Truef(t, rec.Equal(want), "%+v != %+v", rec, want)
}
t.Run("initial_refresh", func(t *testing.T) {
checkRefresh(t, &HostsRecord{
Aliases: stringutil.NewSet(),
| </s> remove
require.IsType(t, (*HostsRecord)(nil), v)
rec, _ := v.(*HostsRecord)
</s> add </s> remove v, ok := upd.Get(ip)
</s> add rec, ok := upd[ip] </s> remove var rec *HostsRecord
v, ok := hp.table.Get(ip)
</s> add rec, ok := hp.table[ip] </s> remove hp.table.Set(ip, rec)
} else {
rec, ok = v.(*HostsRecord)
if !ok {
log.Error("%s: adding pairs: unexpected type %T", hostsContainerPref, v)
return
}
</s> add hp.table[ip] = rec </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) | assert.Truef(t, rec.equal(want), "%+v != %+v", rec, want) |
rec, _ := v.(*HostsRecord)
require.NotNil(t, rec)
assert.Truef(t, rec.equal(want), "%+v != %+v", rec, want)
}
t.Run("initial_refresh", func(t *testing.T) {
checkRefresh(t, &HostsRecord{
Aliases: stringutil.NewSet(), | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
}
}
func TestUniqueRules_ParseLine(t *testing.T) {
ip := net.IP{127, 0, 0, 1}
ipStr := ip.String()
testCases := []struct {
name string
line string
| </s> remove wantIP net.IP
</s> add wantIP netip.Addr </s> remove ip := net.IP{127, 0, 0, 1}
</s> add ip := netutil.IPv4Localhost() </s> remove knownIP := net.IP{1, 2, 3, 4}
</s> add knownIP := netip.MustParseAddr("1.2.3.4") </s> remove assert.True(t, tc.wantIP.Equal(got))
</s> add assert.Equal(t, tc.wantIP, got) </s> remove } else if ip := net.ParseIP(ipStr[1 : len(ipStr)-1]); ip == nil {
</s> add } else if ip, err := netip.ParseAddr(ipStr[1 : len(ipStr)-1]); err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
| ip := netutil.IPv4Localhost() | }
}
func TestUniqueRules_ParseLine(t *testing.T) {
ip := netutil.IPv4Localhost()
ipStr := ip.String()
testCases := []struct {
name string
line string | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
testCases := []struct {
name string
line string
wantIP net.IP
wantHosts []string
}{{
name: "simple",
line: ipStr + ` hostname`,
wantIP: ip,
| </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove ip := net.IP{127, 0, 0, 1}
</s> add ip := netutil.IPv4Localhost() </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove ip := net.IP{127, 0, 0, 1}
</s> add ip := netutil.IPv4Localhost() | wantIP netip.Addr |
testCases := []struct {
name string
line string
wantIP netip.Addr
wantHosts []string
}{{
name: "simple",
line: ipStr + ` hostname`,
wantIP: ip, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
wantHosts: []string{"hostname", "alias"},
}, {
name: "invalid_line",
line: ipStr,
wantIP: nil,
wantHosts: nil,
}, {
name: "invalid_line_hostname",
line: ipStr + ` # hostname`,
wantIP: ip,
| </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove wantIP net.IP
</s> add wantIP netip.Addr </s> remove if ip = net.ParseIP(fields[0]); ip == nil {
return nil, nil
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil {
return netip.Addr{}, nil </s> remove ip := net.IP{127, 0, 0, 1}
</s> add ip := netutil.IPv4Localhost() | wantIP: netip.Addr{}, | wantHosts: []string{"hostname", "alias"},
}, {
name: "invalid_line",
line: ipStr,
wantIP: netip.Addr{},
wantHosts: nil,
}, {
name: "invalid_line_hostname",
line: ipStr + ` # hostname`,
wantIP: ip, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
wantHosts: []string{"hostname"},
}, {
name: "whole_comment",
line: `# ` + ipStr + ` hostname`,
wantIP: nil,
wantHosts: nil,
}, {
name: "partial_comment",
line: ipStr + ` host#name`,
wantIP: ip,
| </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove wantIP net.IP
</s> add wantIP netip.Addr </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove ip := net.IP{127, 0, 0, 1}
</s> add ip := netutil.IPv4Localhost() </s> remove IP: net.IPv4(192, 168, 1, 2),
</s> add IP: netip.MustParseAddr("192.168.1.2"), | wantIP: netip.Addr{}, | wantHosts: []string{"hostname"},
}, {
name: "whole_comment",
line: `# ` + ipStr + ` hostname`,
wantIP: netip.Addr{},
wantHosts: nil,
}, {
name: "partial_comment",
line: ipStr + ` host#name`,
wantIP: ip, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
wantHosts: []string{"host"},
}, {
name: "empty",
line: ``,
wantIP: nil,
wantHosts: nil,
}}
for _, tc := range testCases {
hp := hostsParser{}
| </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove assert.True(t, tc.wantIP.Equal(got))
</s> add assert.Equal(t, tc.wantIP, got) </s> remove wantIP net.IP
</s> add wantIP netip.Addr </s> remove if ip = net.ParseIP(fields[0]); ip == nil {
return nil, nil
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil {
return netip.Addr{}, nil | wantIP: netip.Addr{}, | wantHosts: []string{"host"},
}, {
name: "empty",
line: ``,
wantIP: netip.Addr{},
wantHosts: nil,
}}
for _, tc := range testCases {
hp := hostsParser{} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
for _, tc := range testCases {
hp := hostsParser{}
t.Run(tc.name, func(t *testing.T) {
got, hosts := hp.parseLine(tc.line)
assert.True(t, tc.wantIP.Equal(got))
assert.Equal(t, tc.wantHosts, hosts)
})
}
}
| </s> remove wantIP: nil,
</s> add wantIP: netip.Addr{}, </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove hosts.Range(func(ip net.IP, v any) (cont bool) {
rec, ok := v.(*aghnet.HostsRecord)
if !ok {
log.Error("clients: bad type %T in hosts for %s", v, ip)
return true
}
</s> add for ip, rec := range hosts { </s> remove ip := net.IP{127, 0, 0, 1}
</s> add ip := netutil.IPv4Localhost() | assert.Equal(t, tc.wantIP, got) | for _, tc := range testCases {
hp := hostsParser{}
t.Run(tc.name, func(t *testing.T) {
got, hosts := hp.parseLine(tc.line)
assert.Equal(t, tc.wantIP, got)
assert.Equal(t, tc.wantHosts, hosts)
})
}
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/aghnet/hostscontainer_test.go |
clients.updateFromDHCP(false)
}
}
// Exists checks if client with this IP address already exists.
func (clients *clientsContainer) Exists(ip net.IP, source clientSource) (ok bool) {
clients.lock.Lock()
defer clients.lock.Unlock()
_, ok = clients.findLocked(ip.String())
if ok {
| </s> remove // SetWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) SetWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) {
</s> add // setWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) setWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) { </s> remove return clients.addHostLocked(ip, host, src), nil
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil </s> remove // FindRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) FindRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
</s> add // findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) { </s> remove // addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip)
</s> add // addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip] </s> remove //
//lint:ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap].
func (clients *clientsContainer) addFromHostsFile(hosts *netutil.IPMap) {
</s> add func (clients *clientsContainer) addFromHostsFile(hosts aghnet.HostsRecords) { | // exists checks if client with this IP address already exists.
func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool) { | clients.updateFromDHCP(false)
}
}
// exists checks if client with this IP address already exists.
func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool) {
// exists checks if client with this IP address already exists.
func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool) {
clients.lock.Lock()
defer clients.lock.Unlock()
_, ok = clients.findLocked(ip.String())
if ok { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
}, true
}
var rc *RuntimeClient
rc, ok = clients.FindRuntimeClient(ip)
if ok {
return &querylog.Client{
Name: rc.Host,
WHOIS: toQueryLogWHOIS(rc.WHOISInfo),
}, false
| </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add </s> remove // FindRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) FindRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
</s> add // findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) { </s> remove // addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip)
</s> add // addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip] </s> remove // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
log.Error("clients: bad client ip %v: %s", ip, err)
return false
}
clients.ipToRC[ipAddr] = rc
</s> add clients.ipToRC[ip] = rc </s> remove IP: net.IPv4(192, 168, 1, 2),
</s> add IP: netip.MustParseAddr("192.168.1.2"), | rc, ok = clients.findRuntimeClient(ip) | }, true
}
var rc *RuntimeClient
rc, ok = clients.findRuntimeClient(ip)
if ok {
return &querylog.Client{
Name: rc.Host,
WHOIS: toQueryLogWHOIS(rc.WHOISInfo),
}, false | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
return rc, ok
}
// FindRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) FindRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
if ip == nil {
return nil, false
}
clients.lock.Lock()
| </s> remove // addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip)
</s> add // addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip] </s> remove // Exists checks if client with this IP address already exists.
func (clients *clientsContainer) Exists(ip net.IP, source clientSource) (ok bool) {
</s> add // exists checks if client with this IP address already exists.
func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool) { </s> remove // SetWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) SetWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) {
</s> add // setWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) setWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) { </s> remove return clients.addHostLocked(ip, host, src), nil
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add | // findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) { |
return rc, ok
}
// findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
// findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
if ip == nil {
return nil, false
}
clients.lock.Lock() | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
return nil
}
// SetWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) SetWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) {
clients.lock.Lock()
defer clients.lock.Unlock()
_, ok := clients.findLocked(ip.String())
if ok {
| </s> remove // Exists checks if client with this IP address already exists.
func (clients *clientsContainer) Exists(ip net.IP, source clientSource) (ok bool) {
</s> add // exists checks if client with this IP address already exists.
func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool) { </s> remove return clients.addHostLocked(ip, host, src), nil
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil </s> remove // FindRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) FindRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
</s> add // findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) { </s> remove //
//lint:ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap].
func (clients *clientsContainer) addFromHostsFile(hosts *netutil.IPMap) {
</s> add func (clients *clientsContainer) addFromHostsFile(hosts aghnet.HostsRecords) { </s> remove // addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip)
</s> add // addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip] | // setWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) setWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) { |
return nil
}
// setWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) setWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) {
// setWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) setWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) {
clients.lock.Lock()
defer clients.lock.Unlock()
_, ok := clients.findLocked(ip.String())
if ok { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
func (clients *clientsContainer) AddHost(ip net.IP, host string, src clientSource) (ok bool, err error) {
clients.lock.Lock()
defer clients.lock.Unlock()
return clients.addHostLocked(ip, host, src), nil
}
// addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip)
| </s> remove // addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip)
</s> add // addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip] </s> remove // Exists checks if client with this IP address already exists.
func (clients *clientsContainer) Exists(ip net.IP, source clientSource) (ok bool) {
</s> add // exists checks if client with this IP address already exists.
func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool) { </s> remove // SetWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) SetWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) {
</s> add // setWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) setWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) { </s> remove // FindRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) FindRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
</s> add // findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) { </s> remove //
//lint:ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap].
func (clients *clientsContainer) addFromHostsFile(hosts *netutil.IPMap) {
</s> add func (clients *clientsContainer) addFromHostsFile(hosts aghnet.HostsRecords) { | // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil | func (clients *clientsContainer) AddHost(ip net.IP, host string, src clientSource) (ok bool, err error) {
clients.lock.Lock()
defer clients.lock.Unlock()
// TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil
}
// addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
return clients.addHostLocked(ip, host, src), nil
}
// addHostLocked adds a new IP-hostname pairing. For internal use only.
func (clients *clientsContainer) addHostLocked(ip net.IP, host string, src clientSource) (ok bool) {
rc, ok := clients.findRuntimeClientLocked(ip)
if ok {
if rc.Source > src {
return false
}
| </s> remove return clients.addHostLocked(ip, host, src), nil
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil </s> remove // FindRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) FindRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
</s> add // findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) { </s> remove // Exists checks if client with this IP address already exists.
func (clients *clientsContainer) Exists(ip net.IP, source clientSource) (ok bool) {
</s> add // exists checks if client with this IP address already exists.
func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool) { </s> remove // SetWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) SetWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) {
</s> add // setWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) setWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) { </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add | // addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip] |
return clients.addHostLocked(ip, host, src), nil
}
// addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip]
// addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip]
// addHostLocked adds a new IP-hostname pairing. clients.lock is expected to be
// locked.
func (clients *clientsContainer) addHostLocked(
ip netip.Addr,
host string,
src clientSource,
) (ok bool) {
rc, ok := clients.ipToRC[ip]
if ok {
if rc.Source > src {
return false
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
Source: src,
WHOISInfo: &RuntimeClientWHOISInfo{},
}
// TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
log.Error("clients: bad client ip %v: %s", ip, err)
return false
}
clients.ipToRC[ipAddr] = rc
}
log.Debug("clients: added %s -> %q [%d]", ip, host, len(clients.ipToRC))
return true
| </s> remove ok := clients.addHostLocked(l.IP, l.Hostname, ClientSourceDHCP)
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(l.IP)
if err != nil {
log.Error("clients: bad client ip %v from dhcp: %s", l.IP, err)
continue
}
ok := clients.addHostLocked(ipAddr, l.Hostname, ClientSourceDHCP) </s> remove return clients.addHostLocked(ip, host, src), nil
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil </s> remove hosts.Range(func(ip net.IP, v any) (cont bool) {
rec, ok := v.(*aghnet.HostsRecord)
if !ok {
log.Error("clients: bad type %T in hosts for %s", v, ip)
return true
}
</s> add for ip, rec := range hosts { </s> remove if ip := net.ParseIP(fields[0]); ip == nil {
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
</s> remove if ip := net.ParseIP(fields[0]); ip == nil {
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
| clients.ipToRC[ip] = rc | Source: src,
WHOISInfo: &RuntimeClientWHOISInfo{},
}
clients.ipToRC[ip] = rc
clients.ipToRC[ip] = rc
clients.ipToRC[ip] = rc
clients.ipToRC[ip] = rc
clients.ipToRC[ip] = rc
clients.ipToRC[ip] = rc
clients.ipToRC[ip] = rc
clients.ipToRC[ip] = rc
clients.ipToRC[ip] = rc
}
log.Debug("clients: added %s -> %q [%d]", ip, host, len(clients.ipToRC))
return true | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
}
// addFromHostsFile fills the client-hostname pairing index from the system's
// hosts files.
//
//lint:ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap].
func (clients *clientsContainer) addFromHostsFile(hosts *netutil.IPMap) {
clients.lock.Lock()
defer clients.lock.Unlock()
clients.rmHostsBySrc(ClientSourceHostsFile)
| </s> remove // SetWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) SetWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) {
</s> add // setWHOISInfo sets the WHOIS information for a client.
func (clients *clientsContainer) setWHOISInfo(ip net.IP, wi *RuntimeClientWHOISInfo) { </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap].
</s> add </s> remove // Exists checks if client with this IP address already exists.
func (clients *clientsContainer) Exists(ip net.IP, source clientSource) (ok bool) {
</s> add // exists checks if client with this IP address already exists.
func (clients *clientsContainer) exists(ip net.IP, source clientSource) (ok bool) { </s> remove return clients.addHostLocked(ip, host, src), nil
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
return false, fmt.Errorf("adding host: %w", err)
}
return clients.addHostLocked(ipAddr, host, src), nil </s> remove // FindRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) FindRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
</s> add // findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) { | func (clients *clientsContainer) addFromHostsFile(hosts aghnet.HostsRecords) { | }
// addFromHostsFile fills the client-hostname pairing index from the system's
// hosts files.
func (clients *clientsContainer) addFromHostsFile(hosts aghnet.HostsRecords) {
func (clients *clientsContainer) addFromHostsFile(hosts aghnet.HostsRecords) {
func (clients *clientsContainer) addFromHostsFile(hosts aghnet.HostsRecords) {
clients.lock.Lock()
defer clients.lock.Unlock()
clients.rmHostsBySrc(ClientSourceHostsFile)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
clients.rmHostsBySrc(ClientSourceHostsFile)
n := 0
hosts.Range(func(ip net.IP, v any) (cont bool) {
rec, ok := v.(*aghnet.HostsRecord)
if !ok {
log.Error("clients: bad type %T in hosts for %s", v, ip)
return true
}
clients.addHostLocked(ip, rec.Canonical, ClientSourceHostsFile)
n++
return true
})
| </s> remove
return true
})
</s> add } </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add </s> remove hp.table.Set(ip, rec)
} else {
rec, ok = v.(*HostsRecord)
if !ok {
log.Error("%s: adding pairs: unexpected type %T", hostsContainerPref, v)
return
}
</s> add hp.table[ip] = rec </s> remove var rec *HostsRecord
v, ok := hp.table.Get(ip)
</s> add rec, ok := hp.table[ip] </s> remove ok := clients.addHostLocked(l.IP, l.Hostname, ClientSourceDHCP)
</s> add // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(l.IP)
if err != nil {
log.Error("clients: bad client ip %v from dhcp: %s", l.IP, err)
continue
}
ok := clients.addHostLocked(ipAddr, l.Hostname, ClientSourceDHCP) | for ip, rec := range hosts { |
clients.rmHostsBySrc(ClientSourceHostsFile)
n := 0
for ip, rec := range hosts {
for ip, rec := range hosts {
for ip, rec := range hosts {
for ip, rec := range hosts {
for ip, rec := range hosts {
for ip, rec := range hosts {
for ip, rec := range hosts {
for ip, rec := range hosts {
clients.addHostLocked(ip, rec.Canonical, ClientSourceHostsFile)
n++
return true
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
}
clients.addHostLocked(ip, rec.Canonical, ClientSourceHostsFile)
n++
return true
})
log.Debug("clients: added %d client aliases from system hosts file", n)
}
// addFromSystemARP adds the IP-hostname pairings from the output of the arp -a
| </s> remove hosts.Range(func(ip net.IP, v any) (cont bool) {
rec, ok := v.(*aghnet.HostsRecord)
if !ok {
log.Error("clients: bad type %T in hosts for %s", v, ip)
return true
}
</s> add for ip, rec := range hosts { </s> remove table *netutil.IPMap
</s> add table HostsRecords </s> remove //
//lint:ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap].
func (clients *clientsContainer) addFromHostsFile(hosts *netutil.IPMap) {
</s> add func (clients *clientsContainer) addFromHostsFile(hosts aghnet.HostsRecords) { </s> remove // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(ip)
if err != nil {
log.Error("clients: bad client ip %v: %s", ip, err)
return false
}
clients.ipToRC[ipAddr] = rc
</s> add clients.ipToRC[ip] = rc | } | }
clients.addHostLocked(ip, rec.Canonical, ClientSourceHostsFile)
n++
}
}
}
log.Debug("clients: added %d client aliases from system hosts file", n)
}
// addFromSystemARP adds the IP-hostname pairings from the output of the arp -a | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
if l.Hostname == "" {
continue
}
ok := clients.addHostLocked(l.IP, l.Hostname, ClientSourceDHCP)
if ok {
n++
}
}
| </s> remove hp.table.Set(ip, rec)
} else {
rec, ok = v.(*HostsRecord)
if !ok {
log.Error("%s: adding pairs: unexpected type %T", hostsContainerPref, v)
return
}
</s> add hp.table[ip] = rec </s> remove if ip := net.ParseIP(fields[0]); ip == nil {
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil { </s> remove } else if ip := net.ParseIP(ipStr[1 : len(ipStr)-1]); ip == nil {
</s> add } else if ip, err := netip.ParseAddr(ipStr[1 : len(ipStr)-1]); err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
</s> remove } else if ip := net.ParseIP(ipStr[1 : len(ipStr)-1]); ip == nil {
</s> add } else if ip, err := netip.ParseAddr(ipStr[1 : len(ipStr)-1]); err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
</s> remove if n.IP = net.ParseIP(fields[0]); n.IP == nil || n.IP.IsUnspecified() {
</s> add n.IP, err = netip.ParseAddr(fields[0])
if err != nil || n.IP.IsUnspecified() { | // TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(l.IP)
if err != nil {
log.Error("clients: bad client ip %v from dhcp: %s", l.IP, err)
continue
}
ok := clients.addHostLocked(ipAddr, l.Hostname, ClientSourceDHCP) | if l.Hostname == "" {
continue
}
// TODO(a.garipov): Remove once we switch to netip.Addr more fully.
ipAddr, err := netutil.IPToAddrNoMapped(l.IP)
if err != nil {
log.Error("clients: bad client ip %v from dhcp: %s", l.IP, err)
continue
}
ok := clients.addHostLocked(ipAddr, l.Hostname, ClientSourceDHCP)
if ok {
n++
}
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients.go |
require.True(t, ok)
assert.Equal(t, "client2", c.Name)
assert.False(t, clients.Exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
})
t.Run("add_fail_name", func(t *testing.T) {
ok, err := clients.Add(&Client{
IDs: []string{"1.2.3.5"},
| </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP))
</s> add assert.True(t, clients.exists(ip, ClientSourceDHCP)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceARP))
</s> add assert.True(t, clients.exists(ip, ClientSourceARP)) | assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile)) | require.True(t, ok)
assert.Equal(t, "client2", c.Name)
assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
})
t.Run("add_fail_name", func(t *testing.T) {
ok, err := clients.Add(&Client{
IDs: []string{"1.2.3.5"}, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
Name: "client1",
})
require.NoError(t, err)
assert.False(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
err = clients.Update("client1", &Client{
IDs: []string{"1.1.1.2"},
Name: "client1-renamed",
UseOwnSettings: true,
| </s> remove assert.False(t, clients.Exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile)) </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP))
</s> add assert.True(t, clients.exists(ip, ClientSourceDHCP)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove IP: net.IPv4(192, 168, 1, 2),
</s> add IP: netip.MustParseAddr("192.168.1.2"), | assert.False(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) | Name: "client1",
})
require.NoError(t, err)
assert.False(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
assert.False(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
err = clients.Update("client1", &Client{
IDs: []string{"1.1.1.2"},
Name: "client1-renamed",
UseOwnSettings: true, | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
t.Run("del_success", func(t *testing.T) {
ok := clients.Del("client1-renamed")
require.True(t, ok)
assert.False(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
})
t.Run("del_fail", func(t *testing.T) {
ok := clients.Del("client3")
assert.False(t, ok)
| </s> remove assert.False(t, clients.Exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile)) </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP))
</s> add assert.True(t, clients.exists(ip, ClientSourceDHCP)) </s> remove assert.Equal(t, 1, upd.Len())
</s> add assert.Len(t, upd, 1) | assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) | t.Run("del_success", func(t *testing.T) {
ok := clients.Del("client1-renamed")
require.True(t, ok)
assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
})
t.Run("del_fail", func(t *testing.T) {
ok := clients.Del("client3")
assert.False(t, ok) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
require.NoError(t, err)
assert.True(t, ok)
assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
})
t.Run("dhcp_replaces_arp", func(t *testing.T) {
ip := net.IP{1, 2, 3, 4}
| </s> remove assert.False(t, clients.Exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP))
</s> add assert.True(t, clients.exists(ip, ClientSourceDHCP)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceARP))
</s> add assert.True(t, clients.exists(ip, ClientSourceARP)) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) | assert.True(t, clients.exists(ip, ClientSourceHostsFile)) | require.NoError(t, err)
assert.True(t, ok)
assert.True(t, clients.exists(ip, ClientSourceHostsFile))
})
t.Run("dhcp_replaces_arp", func(t *testing.T) {
ip := net.IP{1, 2, 3, 4}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
ok, err := clients.AddHost(ip, "from_arp", ClientSourceARP)
require.NoError(t, err)
assert.True(t, ok)
assert.True(t, clients.Exists(ip, ClientSourceARP))
ok, err = clients.AddHost(ip, "from_dhcp", ClientSourceDHCP)
require.NoError(t, err)
assert.True(t, ok)
| </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP))
</s> add assert.True(t, clients.exists(ip, ClientSourceDHCP)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove assert.False(t, clients.Exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile)) | assert.True(t, clients.exists(ip, ClientSourceARP)) | ok, err := clients.AddHost(ip, "from_arp", ClientSourceARP)
require.NoError(t, err)
assert.True(t, ok)
assert.True(t, clients.exists(ip, ClientSourceARP))
ok, err = clients.AddHost(ip, "from_dhcp", ClientSourceDHCP)
require.NoError(t, err)
assert.True(t, ok) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
ok, err = clients.AddHost(ip, "from_dhcp", ClientSourceDHCP)
require.NoError(t, err)
assert.True(t, ok)
assert.True(t, clients.Exists(ip, ClientSourceDHCP))
})
t.Run("addhost_fail", func(t *testing.T) {
ok, err := clients.AddHost(net.IP{1, 1, 1, 1}, "host1", ClientSourceRDNS)
require.NoError(t, err)
| </s> remove assert.True(t, clients.Exists(ip, ClientSourceARP))
</s> add assert.True(t, clients.exists(ip, ClientSourceARP)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove assert.False(t, clients.Exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 2, 3, 4}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{2, 2, 2, 2}, ClientSourceHostsFile)) </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 1}, ClientSourceHostsFile))
assert.True(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) | assert.True(t, clients.exists(ip, ClientSourceDHCP)) | ok, err = clients.AddHost(ip, "from_dhcp", ClientSourceDHCP)
require.NoError(t, err)
assert.True(t, ok)
assert.True(t, clients.exists(ip, ClientSourceDHCP))
})
t.Run("addhost_fail", func(t *testing.T) {
ok, err := clients.AddHost(net.IP{1, 1, 1, 1}, "host1", ClientSourceRDNS)
require.NoError(t, err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
}
t.Run("new_client", func(t *testing.T) {
ip := netip.MustParseAddr("1.1.1.255")
clients.SetWHOISInfo(ip.AsSlice(), whois)
rc := clients.ipToRC[ip]
require.NotNil(t, rc)
assert.Equal(t, rc.WHOISInfo, whois)
})
| </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove assert.True(t, tc.wantIP.Equal(got))
</s> add assert.Equal(t, tc.wantIP, got) </s> remove assert.False(t, clients.Exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile))
</s> add assert.False(t, clients.exists(net.IP{1, 1, 1, 2}, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) | clients.setWHOISInfo(ip.AsSlice(), whois) | }
t.Run("new_client", func(t *testing.T) {
ip := netip.MustParseAddr("1.1.1.255")
clients.setWHOISInfo(ip.AsSlice(), whois)
rc := clients.ipToRC[ip]
require.NotNil(t, rc)
assert.Equal(t, rc.WHOISInfo, whois)
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
require.NoError(t, err)
assert.True(t, ok)
clients.SetWHOISInfo(ip.AsSlice(), whois)
rc := clients.ipToRC[ip]
require.NotNil(t, rc)
assert.Equal(t, rc.WHOISInfo, whois)
})
| </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP))
</s> add assert.True(t, clients.exists(ip, ClientSourceDHCP)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceARP))
</s> add assert.True(t, clients.exists(ip, ClientSourceARP)) | clients.setWHOISInfo(ip.AsSlice(), whois) | require.NoError(t, err)
assert.True(t, ok)
clients.setWHOISInfo(ip.AsSlice(), whois)
rc := clients.ipToRC[ip]
require.NotNil(t, rc)
assert.Equal(t, rc.WHOISInfo, whois)
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
})
require.NoError(t, err)
assert.True(t, ok)
clients.SetWHOISInfo(ip.AsSlice(), whois)
rc := clients.ipToRC[ip]
require.Nil(t, rc)
assert.True(t, clients.Del("client1"))
})
| </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP))
</s> add assert.True(t, clients.exists(ip, ClientSourceDHCP)) </s> remove assert.True(t, clients.Exists(ip, ClientSourceARP))
</s> add assert.True(t, clients.exists(ip, ClientSourceARP)) | clients.setWHOISInfo(ip.AsSlice(), whois) | })
require.NoError(t, err)
assert.True(t, ok)
clients.setWHOISInfo(ip.AsSlice(), whois)
rc := clients.ipToRC[ip]
require.Nil(t, rc)
assert.True(t, clients.Del("client1"))
}) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clients_test.go |
// findRuntime looks up the IP in runtime and temporary storages, like
// /etc/hosts tables, DHCP leases, or blocklists. cj is guaranteed to be
// non-nil.
func (clients *clientsContainer) findRuntime(ip net.IP, idStr string) (cj *clientJSON) {
rc, ok := clients.FindRuntimeClient(ip)
if !ok {
// It is still possible that the IP used to be in the runtime clients
// list, but then the server was reloaded. So, check the DNS server's
// blocked IP list.
//
| </s> remove func (hp *hostsParser) addRecord(ip net.IP, hosts []string) {
</s> add func (hp *hostsParser) addRecord(ip netip.Addr, hosts []string) { </s> remove // HostsRecord represents a single hosts file record.
type HostsRecord struct {
Aliases *stringutil.Set
Canonical string
}
// Equal returns true if all fields of rec are equal to field in other or they
// both are nil.
func (rec *HostsRecord) Equal(other *HostsRecord) (ok bool) {
if rec == nil {
return other == nil
}
return rec.Canonical == other.Canonical && rec.Aliases.Equal(other.Aliases)
}
</s> add </s> remove IP net.IP
</s> add IP netip.Addr </s> remove if ip.To4() != nil {
</s> add if ip.Is4() { </s> remove //
// TODO(e.burkov): Use map[netip.Addr]struct{} instead.
last *netutil.IPMap
</s> add last HostsRecords | rc, ok := clients.findRuntimeClient(ip) | // findRuntime looks up the IP in runtime and temporary storages, like
// /etc/hosts tables, DHCP leases, or blocklists. cj is guaranteed to be
// non-nil.
func (clients *clientsContainer) findRuntime(ip net.IP, idStr string) (cj *clientJSON) {
rc, ok := clients.findRuntimeClient(ip)
if !ok {
// It is still possible that the IP used to be in the runtime clients
// list, but then the server was reloaded. So, check the DNS server's
// blocked IP list.
// | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/clientshttp.go |
// resolved.
func (r *RDNS) Begin(ip net.IP) {
r.ensurePrivateCache()
if r.isCached(ip) || r.clients.Exists(ip, ClientSourceRDNS) {
return
}
select {
case r.ipCh <- ip:
| </s> remove func (hp *hostsParser) sendUpd(ch chan *netutil.IPMap) {
</s> add func (hp *hostsParser) sendUpd(ch chan HostsRecords) { </s> remove // FindRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) FindRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) {
</s> add // findRuntimeClient finds a runtime client by their IP.
func (clients *clientsContainer) findRuntimeClient(ip net.IP) (rc *RuntimeClient, ok bool) { </s> remove if ip := net.ParseIP(fields[0]); ip == nil || n.IP.IsUnspecified() {
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil || n.IP.IsUnspecified() {
log.Debug("arpdb: parsing arp output: ip: %s", err)
</s> remove if ip == nil || len(hosts) == 0 {
</s> add if ip == (netip.Addr{}) || len(hosts) == 0 { </s> remove if n.IP = net.ParseIP(fields[0]); n.IP == nil || n.IP.IsUnspecified() {
</s> add n.IP, err = netip.ParseAddr(fields[0])
if err != nil || n.IP.IsUnspecified() { | if r.isCached(ip) || r.clients.exists(ip, ClientSourceRDNS) { | // resolved.
func (r *RDNS) Begin(ip net.IP) {
r.ensurePrivateCache()
if r.isCached(ip) || r.clients.exists(ip, ClientSourceRDNS) {
return
}
select {
case r.ipCh <- ip: | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/rdns.go |
return
}
assert.True(t, cc.Exists(tc.cliIP, ClientSourceRDNS))
})
}
}
| </s> remove assert.True(t, tc.wantIP.Equal(got))
</s> add assert.Equal(t, tc.wantIP, got) </s> remove
return true
})
</s> add } </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois)
</s> add clients.setWHOISInfo(ip.AsSlice(), whois) </s> remove assert.True(t, clients.Exists(ip, ClientSourceHostsFile))
</s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove // equalSet returns true if the internal hosts table just parsed equals target.
// target's values must be of type *HostsRecord.
func (hp *hostsParser) equalSet(target *netutil.IPMap) (ok bool) {
if target == nil {
// hp.table shouldn't appear nil since it's initialized on each refresh.
return target == hp.table
}
if hp.table.Len() != target.Len() {
return false
}
hp.table.Range(func(ip net.IP, recVal any) (cont bool) {
var targetVal any
targetVal, ok = target.Get(ip)
if !ok {
return false
}
var rec *HostsRecord
rec, ok = recVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: unexpected type %T", hostsContainerPref, recVal)
return false
}
var targetRec *HostsRecord
targetRec, ok = targetVal.(*HostsRecord)
if !ok {
log.Error("%s: comparing: target: unexpected type %T", hostsContainerPref, targetVal)
return false
}
ok = rec.Equal(targetRec)
return ok
})
return ok
}
</s> add | assert.True(t, cc.exists(tc.cliIP, ClientSourceRDNS)) |
return
}
assert.True(t, cc.exists(tc.cliIP, ClientSourceRDNS))
})
}
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/rdns_test.go |
if info == nil {
continue
}
w.clients.SetWHOISInfo(ip, info)
}
}
| </s> remove if n.IP = net.ParseIP(fields[0]); n.IP == nil || n.IP.IsUnspecified() {
</s> add n.IP, err = netip.ParseAddr(fields[0])
if err != nil || n.IP.IsUnspecified() { </s> remove if ip := net.ParseIP(fields[0]); ip == nil {
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil { </s> remove } else if ip := net.ParseIP(ipStr[1 : len(ipStr)-1]); ip == nil {
</s> add } else if ip, err := netip.ParseAddr(ipStr[1 : len(ipStr)-1]); err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
</s> remove } else if ip := net.ParseIP(ipStr[1 : len(ipStr)-1]); ip == nil {
</s> add } else if ip, err := netip.ParseAddr(ipStr[1 : len(ipStr)-1]); err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
</s> remove if ip := net.ParseIP(fields[0]); ip == nil {
</s> add ip, err := netip.ParseAddr(fields[0])
if err != nil {
log.Debug("arpdb: parsing arp output: ip: %s", err)
| w.clients.setWHOISInfo(ip, info) | if info == nil {
continue
}
w.clients.setWHOISInfo(ip, info)
}
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep"
] | Pull request: 5035-netip-arp-hosts
Updates #5035.
Squashed commit of the following:
commit d1c4493ee4e28d05670c20532ebae1aa809d18da
Author: Ainar Garipov <[email protected]>
Date: Tue Oct 25 14:26:52 2022 +0300
aghnet: imp hosts rec equal
commit 0a7f40a64a819245fba20d3b481b0fc34e0c60e6
Author: Ainar Garipov <[email protected]>
Date: Mon Oct 24 18:10:09 2022 +0300
aghnet: move arp and hosts to netip.Addr | https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca | internal/home/whois.go |
func (s *Server) Prepare(config *ServerConfig) error {
if config != nil {
s.conf = *config
}
if len(s.conf.UpstreamDNS) == 0 {
s.conf.UpstreamDNS = defaultDNS
| </s> | if s.conf.BlockingMode == "custom_ip" {
s.conf.BlockingIPAddrv4 = net.ParseIP(s.conf.BlockingIPv4)
s.conf.BlockingIPAddrv6 = net.ParseIP(s.conf.BlockingIPv6)
if s.conf.BlockingIPAddrv4 == nil || s.conf.BlockingIPAddrv6 == nil {
return fmt.Errorf("DNS: invalid custom blocking IP address specified")
}
} | func (s *Server) Prepare(config *ServerConfig) error {
if config != nil {
s.conf = *config
if s.conf.BlockingMode == "custom_ip" {
s.conf.BlockingIPAddrv4 = net.ParseIP(s.conf.BlockingIPv4)
s.conf.BlockingIPAddrv6 = net.ParseIP(s.conf.BlockingIPv6)
if s.conf.BlockingIPAddrv4 == nil || s.conf.BlockingIPAddrv6 == nil {
return fmt.Errorf("DNS: invalid custom blocking IP address specified")
}
}
}
if len(s.conf.UpstreamDNS) == 0 {
s.conf.UpstreamDNS = defaultDNS | [
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Merge: - DNS: "custom_ip" blocking mode didn't work after app restart
Close #1262
Squashed commit of the following:
commit bacd683ef5b52e275323a3c07b370ca08702403e
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 17:00:49 2019 +0300
fix
commit 3d4f9626460de3e13a621f2b8e535e9e0939e2bb
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:54:23 2019 +0300
fix
commit bf924bf90e9b705883bec88f8d7af11c39c1f322
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:45:41 2019 +0300
add test
commit 43338ea3645a025d69dd838bc732344255960bed
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:07:51 2019 +0300
- DNS: "custom_ip" blocking mode didn't work after app restart
commit 220f32e713a95d2c67355c61e419dd09df9d42b2
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 15:46:01 2019 +0300
- first run: fix panic on stop in case initialization didn't complete
e.g. when Stats module can't be initialized because of incompatible file system | https://github.com/AdguardTeam/AdGuardHome/commit/04de9d0f7bb1e59c2738538431ee90b1429fca0d | dnsforward/dnsforward.go |
}
func assertGoogleAResponse(t *testing.T, reply *dns.Msg) {
assertResponse(t, reply, "8.8.8.8")
}
func assertResponse(t *testing.T, reply *dns.Msg, ip string) {
if len(reply.Answer) != 1 {
| </s> | func createTestMessageWithType(host string, qtype uint16) *dns.Msg {
req := dns.Msg{}
req.Id = dns.Id()
req.RecursionDesired = true
req.Question = []dns.Question{
{Name: host, Qtype: qtype, Qclass: dns.ClassINET},
}
return &req
}
| }
func createTestMessageWithType(host string, qtype uint16) *dns.Msg {
req := dns.Msg{}
req.Id = dns.Id()
req.RecursionDesired = true
req.Question = []dns.Question{
{Name: host, Qtype: qtype, Qclass: dns.ClassINET},
}
return &req
}
func assertGoogleAResponse(t *testing.T, reply *dns.Msg) {
assertResponse(t, reply, "8.8.8.8")
}
func assertResponse(t *testing.T, reply *dns.Msg, ip string) {
if len(reply.Answer) != 1 { | [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Merge: - DNS: "custom_ip" blocking mode didn't work after app restart
Close #1262
Squashed commit of the following:
commit bacd683ef5b52e275323a3c07b370ca08702403e
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 17:00:49 2019 +0300
fix
commit 3d4f9626460de3e13a621f2b8e535e9e0939e2bb
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:54:23 2019 +0300
fix
commit bf924bf90e9b705883bec88f8d7af11c39c1f322
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:45:41 2019 +0300
add test
commit 43338ea3645a025d69dd838bc732344255960bed
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:07:51 2019 +0300
- DNS: "custom_ip" blocking mode didn't work after app restart
commit 220f32e713a95d2c67355c61e419dd09df9d42b2
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 15:46:01 2019 +0300
- first run: fix panic on stop in case initialization didn't complete
e.g. when Stats module can't be initialized because of incompatible file system | https://github.com/AdguardTeam/AdGuardHome/commit/04de9d0f7bb1e59c2738538431ee90b1429fca0d | dnsforward/dnsforward_test.go |
}
sessFilename := filepath.Join(baseDir, "sessions.db")
config.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60)
config.Users = nil
Context.rdns = InitRDNS(Context.dnsServer, &Context.clients)
Context.whois = initWhois(&Context.clients)
| </s> | if config.auth == nil {
return fmt.Errorf("Couldn't initialize Auth module")
} | }
sessFilename := filepath.Join(baseDir, "sessions.db")
config.auth = InitAuth(sessFilename, config.Users, config.WebSessionTTLHours*60*60)
if config.auth == nil {
return fmt.Errorf("Couldn't initialize Auth module")
}
config.Users = nil
Context.rdns = InitRDNS(Context.dnsServer, &Context.clients)
Context.whois = initWhois(&Context.clients) | [
"keep",
"keep",
"keep",
"add",
"keep",
"keep",
"keep",
"keep"
] | Merge: - DNS: "custom_ip" blocking mode didn't work after app restart
Close #1262
Squashed commit of the following:
commit bacd683ef5b52e275323a3c07b370ca08702403e
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 17:00:49 2019 +0300
fix
commit 3d4f9626460de3e13a621f2b8e535e9e0939e2bb
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:54:23 2019 +0300
fix
commit bf924bf90e9b705883bec88f8d7af11c39c1f322
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:45:41 2019 +0300
add test
commit 43338ea3645a025d69dd838bc732344255960bed
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:07:51 2019 +0300
- DNS: "custom_ip" blocking mode didn't work after app restart
commit 220f32e713a95d2c67355c61e419dd09df9d42b2
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 15:46:01 2019 +0300
- first run: fix panic on stop in case initialization didn't complete
e.g. when Stats module can't be initialized because of incompatible file system | https://github.com/AdguardTeam/AdGuardHome/commit/04de9d0f7bb1e59c2738538431ee90b1429fca0d | home/dns.go |
func stopDNSServer() error {
err := Context.dnsServer.Stop()
if err != nil {
return errorx.Decorate(err, "Couldn't stop forwarding DNS server")
}
| </s> | if !isRunning() {
return nil
}
|
func stopDNSServer() error {
if !isRunning() {
return nil
}
err := Context.dnsServer.Stop()
if err != nil {
return errorx.Decorate(err, "Couldn't stop forwarding DNS server")
}
| [
"keep",
"add",
"keep",
"keep",
"keep",
"keep",
"keep"
] | Merge: - DNS: "custom_ip" blocking mode didn't work after app restart
Close #1262
Squashed commit of the following:
commit bacd683ef5b52e275323a3c07b370ca08702403e
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 17:00:49 2019 +0300
fix
commit 3d4f9626460de3e13a621f2b8e535e9e0939e2bb
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:54:23 2019 +0300
fix
commit bf924bf90e9b705883bec88f8d7af11c39c1f322
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:45:41 2019 +0300
add test
commit 43338ea3645a025d69dd838bc732344255960bed
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 16:07:51 2019 +0300
- DNS: "custom_ip" blocking mode didn't work after app restart
commit 220f32e713a95d2c67355c61e419dd09df9d42b2
Author: Simon Zolin <[email protected]>
Date: Mon Dec 16 15:46:01 2019 +0300
- first run: fix panic on stop in case initialization didn't complete
e.g. when Stats module can't be initialized because of incompatible file system | https://github.com/AdguardTeam/AdGuardHome/commit/04de9d0f7bb1e59c2738538431ee90b1429fca0d | home/dns.go |
e.Client = addr.IP
case *net.TCPAddr:
e.Client = addr.IP
}
e.Time = uint(elapsed / 1000)
switch res.Reason {
case dnsfilter.NotFilteredNotFound:
fallthrough
case dnsfilter.NotFilteredWhiteList:
| </s> remove a := []uint{}
</s> add a := []uint64{} </s> remove avgTime = float64(sum.TimeAvg/uint(timeN)) / 1000000
</s> add avgTime = float64(sum.TimeAvg/uint32(timeN)) / 1000000 </s> remove udb.TimeAvg = uint(u.timeSum / u.nTotal)
</s> add udb.TimeAvg = uint32(u.timeSum / u.nTotal) </s> remove udb.NTotal = uint(u.nTotal)
</s> add udb.NTotal = u.nTotal </s> remove udb.NResult = append(udb.NResult, uint(it))
</s> add udb.NResult = append(udb.NResult, it) | e.Time = uint32(elapsed / 1000) | e.Client = addr.IP
case *net.TCPAddr:
e.Client = addr.IP
}
e.Time = uint32(elapsed / 1000)
switch res.Reason {
case dnsfilter.NotFilteredNotFound:
fallthrough
case dnsfilter.NotFilteredWhiteList: | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | dnsforward/dnsforward.go |
BindHost string `yaml:"bind_host"`
Port int `yaml:"port"`
// time interval for statistics (in days)
StatsInterval uint `yaml:"statistics_interval"`
dnsforward.FilteringConfig `yaml:",inline"`
UpstreamDNS []string `yaml:"upstream_dns"`
}
| </s> remove limit int // maximum time we need to keep data for (in hours)
</s> add limit uint32 // maximum time we need to keep data for (in hours) </s> remove type unitIDCallback func() int
</s> add type unitIDCallback func() uint32 </s> remove Time uint // processing time (msec)
</s> add Time uint32 // processing time (msec) </s> remove func New(filename string, limit int, unitID unitIDCallback) (Stats, error) {
</s> add func New(filename string, limit uint32, unitID unitIDCallback) (Stats, error) { </s> remove Count uint
</s> add Count uint64 | StatsInterval uint32 `yaml:"statistics_interval"` | BindHost string `yaml:"bind_host"`
Port int `yaml:"port"`
// time interval for statistics (in days)
StatsInterval uint32 `yaml:"statistics_interval"`
dnsforward.FilteringConfig `yaml:",inline"`
UpstreamDNS []string `yaml:"upstream_dns"`
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | home/config.go |
"github.com/AdguardTeam/golibs/log"
)
type statsConfig struct {
Interval uint `json:"interval"`
}
// Get stats configuration
func handleStatsInfo(w http.ResponseWriter, r *http.Request) {
resp := statsConfig{}
| </s> remove Count uint
</s> add Count uint64 </s> remove Time uint // processing time (msec)
</s> add Time uint32 // processing time (msec) </s> remove NTotal uint
NResult []uint
</s> add NTotal uint64
NResult []uint64 </s> remove func unitName(id int) []byte {
return itob(id)
</s> add func unitName(id uint32) []byte {
return itob(uint64(id)) </s> remove func UIntArrayEquals(a []uint, b []uint) bool {
</s> add func UIntArrayEquals(a []uint64, b []uint64) bool { | Interval uint32 `json:"interval"` | "github.com/AdguardTeam/golibs/log"
)
type statsConfig struct {
Interval uint32 `json:"interval"`
}
// Get stats configuration
func handleStatsInfo(w http.ResponseWriter, r *http.Request) {
resp := statsConfig{} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | home/control_stats.go |
httpRegister(http.MethodPost, "/control/stats_config", handleStatsConfig)
httpRegister(http.MethodGet, "/control/stats_info", handleStatsInfo)
}
func checkStatsInterval(i uint) bool {
return i == 1 || i == 7 || i == 30 || i == 90
}
| </s> remove u.NResult = make([]uint, rLast)
</s> add u.NResult = make([]uint64, rLast) </s> remove func UIntArrayEquals(a []uint, b []uint) bool {
</s> add func UIntArrayEquals(a []uint64, b []uint64) bool { </s> remove for i := firstDayID - firstID; i != len(units); i++ {
</s> add for i := firstDayID - firstID; int(i) != len(units); i++ { </s> remove for i := firstDayID - firstID; i != len(units); i++ {
</s> add for i := firstDayID - firstID; int(i) != len(units); i++ { </s> remove for i := firstDayID - firstID; i != len(units); i++ {
</s> add for i := firstDayID - firstID; int(i) != len(units); i++ { | func checkStatsInterval(i uint32) bool { | httpRegister(http.MethodPost, "/control/stats_config", handleStatsConfig)
httpRegister(http.MethodGet, "/control/stats_info", handleStatsInfo)
}
func checkStatsInterval(i uint32) bool {
return i == 1 || i == 7 || i == 30 || i == 90
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | home/control_stats.go |
if err != nil {
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
}
config.stats, err = stats.New(filepath.Join(baseDir, "stats.db"), int(config.DNS.StatsInterval), nil)
if err != nil {
log.Fatal("Couldn't initialize statistics module")
}
config.dnsServer = dnsforward.NewServer(baseDir, config.stats)
| </s> remove func (s *statsCtx) deleteUnit(tx *bolt.Tx, id int) bool {
</s> add func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
</s> add func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> remove id := btoi(name)
</s> add id := uint32(btoi(name)) </s> remove u.NResult = make([]uint, rLast)
</s> add u.NResult = make([]uint64, rLast) </s> remove func createObject(filename string, limitDays int, unitID unitIDCallback) (*statsCtx, error) {
</s> add func createObject(filename string, limitDays uint32, unitID unitIDCallback) (*statsCtx, error) { | statsDBFilename := filepath.Join(baseDir, "stats.db")
config.stats, err = stats.New(statsDBFilename, config.DNS.StatsInterval, nil) | if err != nil {
log.Fatalf("Cannot create DNS data dir at %s: %s", baseDir, err)
}
statsDBFilename := filepath.Join(baseDir, "stats.db")
config.stats, err = stats.New(statsDBFilename, config.DNS.StatsInterval, nil)
if err != nil {
log.Fatal("Couldn't initialize statistics module")
}
config.dnsServer = dnsforward.NewServer(baseDir, config.stats)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | home/dns.go |
import (
"net"
)
type unitIDCallback func() int
// New - create object
// filename: DB file name
// limit: time limit (in days)
// unitID: user function to get the current unit ID. If nil, the current time hour is used.
| </s> remove func New(filename string, limit int, unitID unitIDCallback) (Stats, error) {
</s> add func New(filename string, limit uint32, unitID unitIDCallback) (Stats, error) { </s> remove limit int // maximum time we need to keep data for (in hours)
</s> add limit uint32 // maximum time we need to keep data for (in hours) </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove id int // unit ID. Default: absolute hour since Jan 1, 1970
</s> add id uint32 // unit ID. Default: absolute hour since Jan 1, 1970 </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) | type unitIDCallback func() uint32 | import (
"net"
)
type unitIDCallback func() uint32
// New - create object
// filename: DB file name
// limit: time limit (in days)
// unitID: user function to get the current unit ID. If nil, the current time hour is used. | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats.go |
// New - create object
// filename: DB file name
// limit: time limit (in days)
// unitID: user function to get the current unit ID. If nil, the current time hour is used.
func New(filename string, limit int, unitID unitIDCallback) (Stats, error) {
return createObject(filename, limit, unitID)
}
// Stats - main interface
type Stats interface {
| </s> remove type unitIDCallback func() int
</s> add type unitIDCallback func() uint32 </s> remove limit int // maximum time we need to keep data for (in hours)
</s> add limit uint32 // maximum time we need to keep data for (in hours) </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove func createObject(filename string, limitDays int, unitID unitIDCallback) (*statsCtx, error) {
</s> add func createObject(filename string, limitDays uint32, unitID unitIDCallback) (*statsCtx, error) { </s> remove TimeAvg uint // usec
</s> add TimeAvg uint32 // usec | func New(filename string, limit uint32, unitID unitIDCallback) (Stats, error) { | // New - create object
// filename: DB file name
// limit: time limit (in days)
// unitID: user function to get the current unit ID. If nil, the current time hour is used.
func New(filename string, limit uint32, unitID unitIDCallback) (Stats, error) {
return createObject(filename, limit, unitID)
}
// Stats - main interface
type Stats interface { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats.go |
type Entry struct {
Domain string
Client net.IP
Result Result
Time uint // processing time (msec)
}
| </s> remove Count uint
</s> add Count uint64 </s> remove id int // unit ID. Default: absolute hour since Jan 1, 1970
</s> add id uint32 // unit ID. Default: absolute hour since Jan 1, 1970 </s> remove domains map[string]int // number of requests per domain
blockedDomains map[string]int // number of blocked requests per domain
clients map[string]int // number of requests per client
</s> add domains map[string]uint64 // number of requests per domain
blockedDomains map[string]uint64 // number of blocked requests per domain
clients map[string]uint64 // number of requests per client </s> remove limit int // maximum time we need to keep data for (in hours)
</s> add limit uint32 // maximum time we need to keep data for (in hours) </s> remove Interval uint `json:"interval"`
</s> add Interval uint32 `json:"interval"` | Time uint32 // processing time (msec) | type Entry struct {
Domain string
Client net.IP
Result Result
Time uint32 // processing time (msec)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats.go |
"github.com/stretchr/testify/assert"
)
func UIntArrayEquals(a []uint, b []uint) bool {
if len(a) != len(b) {
return false
}
for i := range a {
| </s> remove func (s *statsCtx) deleteUnit(tx *bolt.Tx, id int) bool {
</s> add func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> remove if len(a) != s.limit/24 {
</s> add if len(a) != int(s.limit/24) { </s> remove func checkStatsInterval(i uint) bool {
</s> add func checkStatsInterval(i uint32) bool { </s> remove var sum uint
</s> add var sum uint64 </s> remove var sum uint
</s> add var sum uint64 | func UIntArrayEquals(a []uint64, b []uint64) bool { |
"github.com/stretchr/testify/assert"
)
func UIntArrayEquals(a []uint64, b []uint64) bool {
if len(a) != len(b) {
return false
}
for i := range a { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
e.Time = 123456
s.Update(e)
d := s.GetData(Hours)
a := []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
| </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint64), a)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint64), a)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a)) </s> remove m := d["top_queried_domains"].([]map[string]uint)
</s> add m := d["top_queried_domains"].([]map[string]uint64) </s> remove assert.True(t, d["num_dns_queries"].(uint) == uint(int(hour)*n))
</s> add assert.True(t, d["num_dns_queries"].(uint64) == uint64(int(hour)*n)) | a := []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint64), a)) | e.Time = 123456
s.Update(e)
d := s.GetData(Hours)
a := []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint64), a))
a := []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint64), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
d := s.GetData(Hours)
a := []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
| </s> remove a := []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint), a))
</s> add a := []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint64), a)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint64), a)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a)) </s> remove m := d["top_queried_domains"].([]map[string]uint)
</s> add m := d["top_queried_domains"].([]map[string]uint64) </s> remove assert.True(t, d["num_dns_queries"].(uint) == uint(int(hour)*n))
</s> add assert.True(t, d["num_dns_queries"].(uint64) == uint64(int(hour)*n)) | a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint64), a)) | d := s.GetData(Hours)
a := []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint), a))
a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint64), a))
a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint64), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
m := d["top_queried_domains"].([]map[string]uint)
| </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint64), a)) </s> remove a := []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint), a))
</s> add a := []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint64), a)) </s> remove m := d["top_queried_domains"].([]map[string]uint)
</s> add m := d["top_queried_domains"].([]map[string]uint64) </s> remove m = d["top_blocked_domains"].([]map[string]uint)
</s> add m = d["top_blocked_domains"].([]map[string]uint64) | a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint64), a)) |
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint64), a))
a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint64), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
m := d["top_queried_domains"].([]map[string]uint) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
m := d["top_queried_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
m = d["top_blocked_domains"].([]map[string]uint)
| </s> remove m := d["top_queried_domains"].([]map[string]uint)
</s> add m := d["top_queried_domains"].([]map[string]uint64) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint64), a)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint64), a)) </s> remove a := []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint), a))
</s> add a := []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint64), a)) </s> remove m = d["top_blocked_domains"].([]map[string]uint)
</s> add m = d["top_blocked_domains"].([]map[string]uint64) | a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a)) |
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a))
a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a))
m := d["top_queried_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
m = d["top_blocked_domains"].([]map[string]uint) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
m := d["top_queried_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
m = d["top_blocked_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
| </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_safebrowsing"].([]uint64), a)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1}
assert.True(t, UIntArrayEquals(d["blocked_filtering"].([]uint64), a)) </s> remove a := []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint), a))
</s> add a := []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}
assert.True(t, UIntArrayEquals(d["dns_queries"].([]uint64), a)) </s> remove m = d["top_blocked_domains"].([]map[string]uint)
</s> add m = d["top_blocked_domains"].([]map[string]uint64) | m := d["top_queried_domains"].([]map[string]uint64) |
a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
m := d["top_queried_domains"].([]map[string]uint64)
assert.True(t, m[0]["domain"] == 1)
m = d["top_blocked_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
m := d["top_queried_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
m = d["top_blocked_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
m = d["top_clients"].([]map[string]uint)
assert.True(t, m[0]["127.0.0.1"] == 2)
| </s> remove m = d["top_clients"].([]map[string]uint)
</s> add m = d["top_clients"].([]map[string]uint64) </s> remove m := d["top_queried_domains"].([]map[string]uint)
</s> add m := d["top_queried_domains"].([]map[string]uint64) </s> remove assert.True(t, d["num_dns_queries"].(uint) == 2)
assert.True(t, d["num_blocked_filtering"].(uint) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint) == 0)
assert.True(t, d["num_replaced_parental"].(uint) == 0)
</s> add assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a)) </s> remove assert.True(t, d["num_dns_queries"].(uint) == uint(int(hour)*n))
</s> add assert.True(t, d["num_dns_queries"].(uint64) == uint64(int(hour)*n)) | m = d["top_blocked_domains"].([]map[string]uint64) |
m := d["top_queried_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
m = d["top_blocked_domains"].([]map[string]uint64)
assert.True(t, m[0]["domain"] == 1)
m = d["top_clients"].([]map[string]uint)
assert.True(t, m[0]["127.0.0.1"] == 2)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
m = d["top_blocked_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
m = d["top_clients"].([]map[string]uint)
assert.True(t, m[0]["127.0.0.1"] == 2)
assert.True(t, d["num_dns_queries"].(uint) == 2)
assert.True(t, d["num_blocked_filtering"].(uint) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint) == 0)
| </s> remove assert.True(t, d["num_dns_queries"].(uint) == 2)
assert.True(t, d["num_blocked_filtering"].(uint) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint) == 0)
assert.True(t, d["num_replaced_parental"].(uint) == 0)
</s> add assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0) </s> remove m = d["top_blocked_domains"].([]map[string]uint)
</s> add m = d["top_blocked_domains"].([]map[string]uint64) </s> remove m := d["top_queried_domains"].([]map[string]uint)
</s> add m := d["top_queried_domains"].([]map[string]uint64) </s> remove assert.True(t, d["num_dns_queries"].(uint) == uint(int(hour)*n))
</s> add assert.True(t, d["num_dns_queries"].(uint64) == uint64(int(hour)*n)) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a)) | m = d["top_clients"].([]map[string]uint64) |
m = d["top_blocked_domains"].([]map[string]uint)
assert.True(t, m[0]["domain"] == 1)
m = d["top_clients"].([]map[string]uint64)
assert.True(t, m[0]["127.0.0.1"] == 2)
assert.True(t, d["num_dns_queries"].(uint) == 2)
assert.True(t, d["num_blocked_filtering"].(uint) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint) == 0) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
m = d["top_clients"].([]map[string]uint)
assert.True(t, m[0]["127.0.0.1"] == 2)
assert.True(t, d["num_dns_queries"].(uint) == 2)
assert.True(t, d["num_blocked_filtering"].(uint) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint) == 0)
assert.True(t, d["num_replaced_parental"].(uint) == 0)
assert.True(t, d["avg_processing_time"].(float64) == 0.123456)
s.Clear()
s.Close()
os.Remove("./stats.db")
| </s> remove m = d["top_clients"].([]map[string]uint)
</s> add m = d["top_clients"].([]map[string]uint64) </s> remove m = d["top_blocked_domains"].([]map[string]uint)
</s> add m = d["top_blocked_domains"].([]map[string]uint64) </s> remove assert.True(t, d["num_dns_queries"].(uint) == uint(int(hour)*n))
</s> add assert.True(t, d["num_dns_queries"].(uint64) == uint64(int(hour)*n)) </s> remove m := d["top_queried_domains"].([]map[string]uint)
</s> add m := d["top_queried_domains"].([]map[string]uint64) </s> remove a = []uint{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint), a))
</s> add a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
assert.True(t, UIntArrayEquals(d["replaced_parental"].([]uint64), a)) | assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0) |
m = d["top_clients"].([]map[string]uint)
assert.True(t, m[0]["127.0.0.1"] == 2)
assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0)
assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0)
assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0)
assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0)
assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0)
assert.True(t, d["avg_processing_time"].(float64) == 0.123456)
s.Clear()
s.Close()
os.Remove("./stats.db") | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
func TestLargeNumbers(t *testing.T) {
var hour int32
hour = 1
newID := func() int {
// use "atomic" to make Go race detector happy
return int(atomic.LoadInt32(&hour))
}
// log.SetLevel(log.DEBUG)
| </s> remove return int(atomic.LoadInt32(&hour))
</s> add return uint32(atomic.LoadInt32(&hour)) </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) </s> remove id int // unit ID. Default: absolute hour since Jan 1, 1970
</s> add id uint32 // unit ID. Default: absolute hour since Jan 1, 1970 </s> remove type unitIDCallback func() int
</s> add type unitIDCallback func() uint32 | newID := func() uint32 { |
func TestLargeNumbers(t *testing.T) {
var hour int32
hour = 1
newID := func() uint32 {
// use "atomic" to make Go race detector happy
return int(atomic.LoadInt32(&hour))
}
// log.SetLevel(log.DEBUG) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
var hour int32
hour = 1
newID := func() int {
// use "atomic" to make Go race detector happy
return int(atomic.LoadInt32(&hour))
}
// log.SetLevel(log.DEBUG)
fn := "./stats.db"
os.Remove(fn)
| </s> remove newID := func() int {
</s> add newID := func() uint32 { </s> remove type unitIDCallback func() int
</s> add type unitIDCallback func() uint32 </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove id int // unit ID. Default: absolute hour since Jan 1, 1970
</s> add id uint32 // unit ID. Default: absolute hour since Jan 1, 1970 </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) | return uint32(atomic.LoadInt32(&hour)) | var hour int32
hour = 1
newID := func() int {
// use "atomic" to make Go race detector happy
return uint32(atomic.LoadInt32(&hour))
}
// log.SetLevel(log.DEBUG)
fn := "./stats.db"
os.Remove(fn) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
}
}
d := s.GetData(Hours)
assert.True(t, d["num_dns_queries"].(uint) == uint(int(hour)*n))
s.Close()
os.Remove(fn)
}
| </s> remove assert.True(t, d["num_dns_queries"].(uint) == 2)
assert.True(t, d["num_blocked_filtering"].(uint) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint) == 0)
assert.True(t, d["num_replaced_parental"].(uint) == 0)
</s> add assert.True(t, d["num_dns_queries"].(uint64) == 2)
assert.True(t, d["num_blocked_filtering"].(uint64) == 1)
assert.True(t, d["num_replaced_safebrowsing"].(uint64) == 0)
assert.True(t, d["num_replaced_safesearch"].(uint64) == 0)
assert.True(t, d["num_replaced_parental"].(uint64) == 0) </s> remove m = d["top_clients"].([]map[string]uint)
</s> add m = d["top_clients"].([]map[string]uint64) </s> remove return int(atomic.LoadInt32(&hour))
</s> add return uint32(atomic.LoadInt32(&hour)) </s> remove a = []uint{}
</s> add a = []uint64{} </s> remove a = []uint{}
</s> add a = []uint64{} | assert.True(t, d["num_dns_queries"].(uint64) == uint64(int(hour)*n)) | }
}
d := s.GetData(Hours)
assert.True(t, d["num_dns_queries"].(uint64) == uint64(int(hour)*n))
s.Close()
os.Remove(fn)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_test.go |
)
// statsCtx - global context
type statsCtx struct {
limit int // maximum time we need to keep data for (in hours)
filename string // database file name
unitID unitIDCallback // user function which returns the current unit ID
db *bolt.DB
unit *unit // the current unit
| </s> remove type unitIDCallback func() int
</s> add type unitIDCallback func() uint32 </s> remove func New(filename string, limit int, unitID unitIDCallback) (Stats, error) {
</s> add func New(filename string, limit uint32, unitID unitIDCallback) (Stats, error) { </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove id int // unit ID. Default: absolute hour since Jan 1, 1970
</s> add id uint32 // unit ID. Default: absolute hour since Jan 1, 1970 | limit uint32 // maximum time we need to keep data for (in hours) | )
// statsCtx - global context
type statsCtx struct {
limit uint32 // maximum time we need to keep data for (in hours)
filename string // database file name
unitID unitIDCallback // user function which returns the current unit ID
db *bolt.DB
unit *unit // the current unit | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
}
// data for 1 time unit
type unit struct {
id int // unit ID. Default: absolute hour since Jan 1, 1970
nTotal int // total requests
nResult []int // number of requests per one result
timeSum int // sum of processing time of all requests (usec)
| </s> remove nTotal int // total requests
nResult []int // number of requests per one result
timeSum int // sum of processing time of all requests (usec)
</s> add nTotal uint64 // total requests
nResult []uint64 // number of requests per one result
timeSum uint64 // sum of processing time of all requests (usec) </s> remove domains map[string]int // number of requests per domain
blockedDomains map[string]int // number of blocked requests per domain
clients map[string]int // number of requests per client
</s> add domains map[string]uint64 // number of requests per domain
blockedDomains map[string]uint64 // number of blocked requests per domain
clients map[string]uint64 // number of requests per client </s> remove limit int // maximum time we need to keep data for (in hours)
</s> add limit uint32 // maximum time we need to keep data for (in hours) </s> remove type unitIDCallback func() int
</s> add type unitIDCallback func() uint32 </s> remove Time uint // processing time (msec)
</s> add Time uint32 // processing time (msec) | id uint32 // unit ID. Default: absolute hour since Jan 1, 1970 | }
// data for 1 time unit
type unit struct {
id uint32 // unit ID. Default: absolute hour since Jan 1, 1970
nTotal int // total requests
nResult []int // number of requests per one result
timeSum int // sum of processing time of all requests (usec)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
// data for 1 time unit
type unit struct {
id int // unit ID. Default: absolute hour since Jan 1, 1970
nTotal int // total requests
nResult []int // number of requests per one result
timeSum int // sum of processing time of all requests (usec)
// top:
domains map[string]int // number of requests per domain
blockedDomains map[string]int // number of blocked requests per domain
clients map[string]int // number of requests per client
| </s> remove domains map[string]int // number of requests per domain
blockedDomains map[string]int // number of blocked requests per domain
clients map[string]int // number of requests per client
</s> add domains map[string]uint64 // number of requests per domain
blockedDomains map[string]uint64 // number of blocked requests per domain
clients map[string]uint64 // number of requests per client </s> remove id int // unit ID. Default: absolute hour since Jan 1, 1970
</s> add id uint32 // unit ID. Default: absolute hour since Jan 1, 1970 </s> remove limit int // maximum time we need to keep data for (in hours)
</s> add limit uint32 // maximum time we need to keep data for (in hours) </s> remove type unitIDCallback func() int
</s> add type unitIDCallback func() uint32 </s> remove if len(units) != s.limit {
</s> add if len(units) != int(s.limit) { | nTotal uint64 // total requests
nResult []uint64 // number of requests per one result
timeSum uint64 // sum of processing time of all requests (usec) | // data for 1 time unit
type unit struct {
id int // unit ID. Default: absolute hour since Jan 1, 1970
nTotal uint64 // total requests
nResult []uint64 // number of requests per one result
timeSum uint64 // sum of processing time of all requests (usec)
nTotal uint64 // total requests
nResult []uint64 // number of requests per one result
timeSum uint64 // sum of processing time of all requests (usec)
nTotal uint64 // total requests
nResult []uint64 // number of requests per one result
timeSum uint64 // sum of processing time of all requests (usec)
// top:
domains map[string]int // number of requests per domain
blockedDomains map[string]int // number of blocked requests per domain
clients map[string]int // number of requests per client | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
nResult []int // number of requests per one result
timeSum int // sum of processing time of all requests (usec)
// top:
domains map[string]int // number of requests per domain
blockedDomains map[string]int // number of blocked requests per domain
clients map[string]int // number of requests per client
}
// name-count pair
type countPair struct {
Name string
| </s> remove nTotal int // total requests
nResult []int // number of requests per one result
timeSum int // sum of processing time of all requests (usec)
</s> add nTotal uint64 // total requests
nResult []uint64 // number of requests per one result
timeSum uint64 // sum of processing time of all requests (usec) </s> remove id int // unit ID. Default: absolute hour since Jan 1, 1970
</s> add id uint32 // unit ID. Default: absolute hour since Jan 1, 1970 </s> remove Count uint
</s> add Count uint64 </s> remove Time uint // processing time (msec)
</s> add Time uint32 // processing time (msec) </s> remove if len(units) != s.limit {
</s> add if len(units) != int(s.limit) { | domains map[string]uint64 // number of requests per domain
blockedDomains map[string]uint64 // number of blocked requests per domain
clients map[string]uint64 // number of requests per client | nResult []int // number of requests per one result
timeSum int // sum of processing time of all requests (usec)
// top:
domains map[string]uint64 // number of requests per domain
blockedDomains map[string]uint64 // number of blocked requests per domain
clients map[string]uint64 // number of requests per client
domains map[string]uint64 // number of requests per domain
blockedDomains map[string]uint64 // number of blocked requests per domain
clients map[string]uint64 // number of requests per client
domains map[string]uint64 // number of requests per domain
blockedDomains map[string]uint64 // number of blocked requests per domain
clients map[string]uint64 // number of requests per client
}
// name-count pair
type countPair struct {
Name string | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
// name-count pair
type countPair struct {
Name string
Count uint
}
// structure for storing data in file
type unitDB struct {
NTotal uint
| </s> remove NTotal uint
NResult []uint
</s> add NTotal uint64
NResult []uint64 </s> remove Time uint // processing time (msec)
</s> add Time uint32 // processing time (msec) </s> remove domains map[string]int // number of requests per domain
blockedDomains map[string]int // number of blocked requests per domain
clients map[string]int // number of requests per client
</s> add domains map[string]uint64 // number of requests per domain
blockedDomains map[string]uint64 // number of blocked requests per domain
clients map[string]uint64 // number of requests per client </s> remove Interval uint `json:"interval"`
</s> add Interval uint32 `json:"interval"` </s> remove limit int // maximum time we need to keep data for (in hours)
</s> add limit uint32 // maximum time we need to keep data for (in hours) | Count uint64 |
// name-count pair
type countPair struct {
Name string
Count uint64
}
// structure for storing data in file
type unitDB struct {
NTotal uint | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
}
// structure for storing data in file
type unitDB struct {
NTotal uint
NResult []uint
Domains []countPair
BlockedDomains []countPair
Clients []countPair
| </s> remove Count uint
</s> add Count uint64 </s> remove TimeAvg uint // usec
</s> add TimeAvg uint32 // usec </s> remove func convertMapToArray(m map[string]int, max int) []countPair {
</s> add func convertMapToArray(m map[string]uint64, max int) []countPair { </s> remove limit int // maximum time we need to keep data for (in hours)
</s> add limit uint32 // maximum time we need to keep data for (in hours) </s> remove Time uint // processing time (msec)
</s> add Time uint32 // processing time (msec) | NTotal uint64
NResult []uint64 | }
// structure for storing data in file
type unitDB struct {
NTotal uint64
NResult []uint64
NTotal uint64
NResult []uint64
Domains []countPair
BlockedDomains []countPair
Clients []countPair
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
Domains []countPair
BlockedDomains []countPair
Clients []countPair
TimeAvg uint // usec
}
func createObject(filename string, limitDays int, unitID unitIDCallback) (*statsCtx, error) {
s := statsCtx{}
s.limit = limitDays * 24
| </s> remove func createObject(filename string, limitDays int, unitID unitIDCallback) (*statsCtx, error) {
</s> add func createObject(filename string, limitDays uint32, unitID unitIDCallback) (*statsCtx, error) { </s> remove NTotal uint
NResult []uint
</s> add NTotal uint64
NResult []uint64 </s> remove func New(filename string, limit int, unitID unitIDCallback) (Stats, error) {
</s> add func New(filename string, limit uint32, unitID unitIDCallback) (Stats, error) { </s> remove func convertMapToArray(m map[string]int, max int) []countPair {
</s> add func convertMapToArray(m map[string]uint64, max int) []countPair { </s> remove s.limit = limit * 24
</s> add s.limit = uint32(limit) * 24 | TimeAvg uint32 // usec | Domains []countPair
BlockedDomains []countPair
Clients []countPair
TimeAvg uint32 // usec
}
func createObject(filename string, limitDays int, unitID unitIDCallback) (*statsCtx, error) {
s := statsCtx{}
s.limit = limitDays * 24 | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
TimeAvg uint // usec
}
func createObject(filename string, limitDays int, unitID unitIDCallback) (*statsCtx, error) {
s := statsCtx{}
s.limit = limitDays * 24
s.filename = filename
s.unitID = newUnitID
if unitID != nil {
| </s> remove TimeAvg uint // usec
</s> add TimeAvg uint32 // usec </s> remove func New(filename string, limit int, unitID unitIDCallback) (Stats, error) {
</s> add func New(filename string, limit uint32, unitID unitIDCallback) (Stats, error) { </s> remove s.limit = limit * 24
</s> add s.limit = uint32(limit) * 24 </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
</s> add func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> remove u.timeSum = int(udb.TimeAvg) * u.nTotal
</s> add u.timeSum = uint64(udb.TimeAvg) * u.nTotal | func createObject(filename string, limitDays uint32, unitID unitIDCallback) (*statsCtx, error) { |
TimeAvg uint // usec
}
func createObject(filename string, limitDays uint32, unitID unitIDCallback) (*statsCtx, error) {
s := statsCtx{}
s.limit = limitDays * 24
s.filename = filename
s.unitID = newUnitID
if unitID != nil { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
log.Tracef("Deleting old units...")
firstID := id - s.limit - 1
unitDel := 0
forEachBkt := func(name []byte, b *bolt.Bucket) error {
id := btoi(name)
if id < firstID {
err := tx.DeleteBucket(name)
if err != nil {
log.Debug("tx.DeleteBucket: %s", err)
}
| </s> remove func (s *statsCtx) deleteUnit(tx *bolt.Tx, id int) bool {
</s> add func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
</s> add func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> remove config.stats, err = stats.New(filepath.Join(baseDir, "stats.db"), int(config.DNS.StatsInterval), nil)
</s> add statsDBFilename := filepath.Join(baseDir, "stats.db")
config.stats, err = stats.New(statsDBFilename, config.DNS.StatsInterval, nil) </s> remove for i := firstDayID - firstID; i != len(units); i++ {
</s> add for i := firstDayID - firstID; int(i) != len(units); i++ { </s> remove for i := firstDayID - firstID; i != len(units); i++ {
</s> add for i := firstDayID - firstID; int(i) != len(units); i++ { | id := uint32(btoi(name)) | log.Tracef("Deleting old units...")
firstID := id - s.limit - 1
unitDel := 0
forEachBkt := func(name []byte, b *bolt.Bucket) error {
id := uint32(btoi(name))
if id < firstID {
err := tx.DeleteBucket(name)
if err != nil {
log.Debug("tx.DeleteBucket: %s", err)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
return u
}
// Get unit ID for the current hour
func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
}
// Initialize a unit
func (s *statsCtx) initUnit(u *unit, id int) {
u.id = id
| </s> remove func (s *statsCtx) initUnit(u *unit, id int) {
</s> add func (s *statsCtx) initUnit(u *unit, id uint32) { </s> remove u.nResult = make([]int, rLast)
u.domains = make(map[string]int)
u.blockedDomains = make(map[string]int)
u.clients = make(map[string]int)
</s> add u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64) </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove s.limit = limit * 24
</s> add s.limit = uint32(limit) * 24 </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id int) *unitDB {
</s> add func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { | func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) | return u
}
// Get unit ID for the current hour
func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60))
func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60))
}
// Initialize a unit
func (s *statsCtx) initUnit(u *unit, id int) {
u.id = id | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
return int(time.Now().Unix() / (60 * 60))
}
// Initialize a unit
func (s *statsCtx) initUnit(u *unit, id int) {
u.id = id
u.nResult = make([]int, rLast)
u.domains = make(map[string]int)
u.blockedDomains = make(map[string]int)
u.clients = make(map[string]int)
| </s> remove u.nResult = make([]int, rLast)
u.domains = make(map[string]int)
u.blockedDomains = make(map[string]int)
u.clients = make(map[string]int)
</s> add u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64) </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) </s> remove u.timeSum = int(udb.TimeAvg) * u.nTotal
</s> add u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> remove u.nTotal = int(udb.NTotal)
</s> add u.nTotal = udb.NTotal </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
</s> add func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { | func (s *statsCtx) initUnit(u *unit, id uint32) { | return int(time.Now().Unix() / (60 * 60))
}
// Initialize a unit
func (s *statsCtx) initUnit(u *unit, id uint32) {
u.id = id
u.nResult = make([]int, rLast)
u.domains = make(map[string]int)
u.blockedDomains = make(map[string]int)
u.clients = make(map[string]int) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
// Initialize a unit
func (s *statsCtx) initUnit(u *unit, id int) {
u.id = id
u.nResult = make([]int, rLast)
u.domains = make(map[string]int)
u.blockedDomains = make(map[string]int)
u.clients = make(map[string]int)
}
// Open a DB transaction
func (s *statsCtx) beginTxn(wr bool) *bolt.Tx {
db := s.db
| </s> remove func (s *statsCtx) initUnit(u *unit, id int) {
</s> add func (s *statsCtx) initUnit(u *unit, id uint32) { </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) </s> remove u.timeSum = int(udb.TimeAvg) * u.nTotal
</s> add u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
</s> add func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> remove s.limit = limit * 24
</s> add s.limit = uint32(limit) * 24 | u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64) |
// Initialize a unit
func (s *statsCtx) initUnit(u *unit, id int) {
u.id = id
u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64)
u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64)
u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64)
u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64)
}
// Open a DB transaction
func (s *statsCtx) beginTxn(wr bool) *bolt.Tx {
db := s.db | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
log.Tracef("tx.Commit")
}
// Get unit name
func unitName(id int) []byte {
return itob(id)
}
// Convert integer to 8-byte array (big endian)
func itob(v int) []byte {
b := make([]byte, 8)
| </s> remove func itob(v int) []byte {
</s> add func itob(v uint64) []byte { </s> remove binary.BigEndian.PutUint64(b, uint64(v))
</s> add binary.BigEndian.PutUint64(b, v) </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) </s> remove func convertMapToArray(m map[string]int, max int) []countPair {
</s> add func convertMapToArray(m map[string]uint64, max int) []countPair { | func unitName(id uint32) []byte {
return itob(uint64(id)) | log.Tracef("tx.Commit")
}
// Get unit name
func unitName(id uint32) []byte {
return itob(uint64(id))
func unitName(id uint32) []byte {
return itob(uint64(id))
}
// Convert integer to 8-byte array (big endian)
func itob(v int) []byte {
b := make([]byte, 8) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
return itob(id)
}
// Convert integer to 8-byte array (big endian)
func itob(v int) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, uint64(v))
return b
}
| </s> remove binary.BigEndian.PutUint64(b, uint64(v))
</s> add binary.BigEndian.PutUint64(b, v) </s> remove func unitName(id int) []byte {
return itob(id)
</s> add func unitName(id uint32) []byte {
return itob(uint64(id)) </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove func UIntArrayEquals(a []uint, b []uint) bool {
</s> add func UIntArrayEquals(a []uint64, b []uint64) bool { </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id int) *unitDB {
</s> add func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { | func itob(v uint64) []byte { | return itob(id)
}
// Convert integer to 8-byte array (big endian)
func itob(v uint64) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, uint64(v))
return b
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
// Convert integer to 8-byte array (big endian)
func itob(v int) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, uint64(v))
return b
}
// Convert 8-byte array (big endian) to integer
func btoi(b []byte) int {
| </s> remove func itob(v int) []byte {
</s> add func itob(v uint64) []byte { </s> remove func unitName(id int) []byte {
return itob(id)
</s> add func unitName(id uint32) []byte {
return itob(uint64(id)) </s> remove func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
</s> add func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) </s> remove func UIntArrayEquals(a []uint, b []uint) bool {
</s> add func UIntArrayEquals(a []uint64, b []uint64) bool { </s> remove newID := func() int {
</s> add newID := func() uint32 { | binary.BigEndian.PutUint64(b, v) |
// Convert integer to 8-byte array (big endian)
func itob(v int) []byte {
b := make([]byte, 8)
binary.BigEndian.PutUint64(b, v)
return b
}
// Convert 8-byte array (big endian) to integer
func btoi(b []byte) int { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
return b
}
// Convert 8-byte array (big endian) to integer
func btoi(b []byte) int {
return int(binary.BigEndian.Uint64(b))
}
// Flush the current unit to DB and delete an old unit when a new hour is started
func (s *statsCtx) periodicFlush() {
for {
| </s> remove binary.BigEndian.PutUint64(b, uint64(v))
</s> add binary.BigEndian.PutUint64(b, v) </s> remove func unitName(id int) []byte {
return itob(id)
</s> add func unitName(id uint32) []byte {
return itob(uint64(id)) </s> remove func itob(v int) []byte {
</s> add func itob(v uint64) []byte { </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) </s> remove func New(filename string, limit int, unitID unitIDCallback) (Stats, error) {
</s> add func New(filename string, limit uint32, unitID unitIDCallback) (Stats, error) { | func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b) | return b
}
// Convert 8-byte array (big endian) to integer
func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b)
func btoi(b []byte) uint64 {
return binary.BigEndian.Uint64(b)
}
// Flush the current unit to DB and delete an old unit when a new hour is started
func (s *statsCtx) periodicFlush() {
for { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
log.Tracef("periodicFlush() exited")
}
// Delete unit's data from file
func (s *statsCtx) deleteUnit(tx *bolt.Tx, id int) bool {
err := tx.DeleteBucket(unitName(id))
if err != nil {
log.Tracef("bolt DeleteBucket: %s", err)
return false
}
| </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
</s> add func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> remove config.stats, err = stats.New(filepath.Join(baseDir, "stats.db"), int(config.DNS.StatsInterval), nil)
</s> add statsDBFilename := filepath.Join(baseDir, "stats.db")
config.stats, err = stats.New(statsDBFilename, config.DNS.StatsInterval, nil) </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id int) *unitDB {
</s> add func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { </s> remove id := btoi(name)
</s> add id := uint32(btoi(name)) </s> remove func UIntArrayEquals(a []uint, b []uint) bool {
</s> add func UIntArrayEquals(a []uint64, b []uint64) bool { | func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { | log.Tracef("periodicFlush() exited")
}
// Delete unit's data from file
func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool {
err := tx.DeleteBucket(unitName(id))
if err != nil {
log.Tracef("bolt DeleteBucket: %s", err)
return false
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
log.Debug("Stats: deleted unit %d", id)
return true
}
func convertMapToArray(m map[string]int, max int) []countPair {
a := []countPair{}
for k, v := range m {
pair := countPair{}
pair.Name = k
pair.Count = uint(v)
| </s> remove pair.Count = uint(v)
</s> add pair.Count = v </s> remove s.limit = limit * 24
</s> add s.limit = uint32(limit) * 24 </s> remove ent := map[string]uint{}
</s> add ent := map[string]uint64{} </s> remove func convertTopArray(a []countPair) []map[string]uint {
m := []map[string]uint{}
</s> add func convertTopArray(a []countPair) []map[string]uint64 {
m := []map[string]uint64{} </s> remove func convertArrayToMap(a []countPair) map[string]int {
m := map[string]int{}
</s> add func convertArrayToMap(a []countPair) map[string]uint64 {
m := map[string]uint64{} | func convertMapToArray(m map[string]uint64, max int) []countPair { | log.Debug("Stats: deleted unit %d", id)
return true
}
func convertMapToArray(m map[string]uint64, max int) []countPair {
a := []countPair{}
for k, v := range m {
pair := countPair{}
pair.Name = k
pair.Count = uint(v) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
a := []countPair{}
for k, v := range m {
pair := countPair{}
pair.Name = k
pair.Count = uint(v)
a = append(a, pair)
}
less := func(i, j int) bool {
if a[i].Count >= a[j].Count {
return true
| </s> remove func convertMapToArray(m map[string]int, max int) []countPair {
</s> add func convertMapToArray(m map[string]uint64, max int) []countPair { </s> remove ent := map[string]uint{}
</s> add ent := map[string]uint64{} </s> remove func convertTopArray(a []countPair) []map[string]uint {
m := []map[string]uint{}
</s> add func convertTopArray(a []countPair) []map[string]uint64 {
m := []map[string]uint64{} </s> remove m[it.Name] = int(it.Count)
</s> add m[it.Name] = it.Count </s> remove func convertArrayToMap(a []countPair) map[string]int {
m := map[string]int{}
</s> add func convertArrayToMap(a []countPair) map[string]uint64 {
m := map[string]uint64{} | pair.Count = v | a := []countPair{}
for k, v := range m {
pair := countPair{}
pair.Name = k
pair.Count = v
a = append(a, pair)
}
less := func(i, j int) bool {
if a[i].Count >= a[j].Count {
return true | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
}
return a[:max]
}
func convertArrayToMap(a []countPair) map[string]int {
m := map[string]int{}
for _, it := range a {
m[it.Name] = int(it.Count)
}
return m
}
| </s> remove m[it.Name] = int(it.Count)
</s> add m[it.Name] = it.Count </s> remove m = map[string]int{}
</s> add m = map[string]uint64{} </s> remove m := map[string]int{}
</s> add m := map[string]uint64{} </s> remove m = map[string]int{}
</s> add m = map[string]uint64{} </s> remove m[it.Name] += int(it.Count)
</s> add m[it.Name] += it.Count | func convertArrayToMap(a []countPair) map[string]uint64 {
m := map[string]uint64{} | }
return a[:max]
}
func convertArrayToMap(a []countPair) map[string]uint64 {
m := map[string]uint64{}
func convertArrayToMap(a []countPair) map[string]uint64 {
m := map[string]uint64{}
for _, it := range a {
m[it.Name] = int(it.Count)
}
return m
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
func convertArrayToMap(a []countPair) map[string]int {
m := map[string]int{}
for _, it := range a {
m[it.Name] = int(it.Count)
}
return m
}
func serialize(u *unit) *unitDB {
| </s> remove func convertArrayToMap(a []countPair) map[string]int {
m := map[string]int{}
</s> add func convertArrayToMap(a []countPair) map[string]uint64 {
m := map[string]uint64{} </s> remove m := map[string]int{}
</s> add m := map[string]uint64{} </s> remove m = map[string]int{}
</s> add m = map[string]uint64{} </s> remove m = map[string]int{}
</s> add m = map[string]uint64{} </s> remove func convertTopArray(a []countPair) []map[string]uint {
m := []map[string]uint{}
</s> add func convertTopArray(a []countPair) []map[string]uint64 {
m := []map[string]uint64{} | m[it.Name] = it.Count |
func convertArrayToMap(a []countPair) map[string]int {
m := map[string]int{}
for _, it := range a {
m[it.Name] = it.Count
}
return m
}
func serialize(u *unit) *unitDB { | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
}
func serialize(u *unit) *unitDB {
udb := unitDB{}
udb.NTotal = uint(u.nTotal)
for _, it := range u.nResult {
udb.NResult = append(udb.NResult, uint(it))
}
if u.nTotal != 0 {
udb.TimeAvg = uint(u.timeSum / u.nTotal)
| </s> remove udb.NResult = append(udb.NResult, uint(it))
</s> add udb.NResult = append(udb.NResult, it) </s> remove udb.TimeAvg = uint(u.timeSum / u.nTotal)
</s> add udb.TimeAvg = uint32(u.timeSum / u.nTotal) </s> remove u.nTotal = int(udb.NTotal)
</s> add u.nTotal = udb.NTotal </s> remove m[it.Name] = int(it.Count)
</s> add m[it.Name] = it.Count </s> remove sum.NResult = make([]uint, rLast)
</s> add | udb.NTotal = u.nTotal | }
func serialize(u *unit) *unitDB {
udb := unitDB{}
udb.NTotal = u.nTotal
for _, it := range u.nResult {
udb.NResult = append(udb.NResult, uint(it))
}
if u.nTotal != 0 {
udb.TimeAvg = uint(u.timeSum / u.nTotal) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
func serialize(u *unit) *unitDB {
udb := unitDB{}
udb.NTotal = uint(u.nTotal)
for _, it := range u.nResult {
udb.NResult = append(udb.NResult, uint(it))
}
if u.nTotal != 0 {
udb.TimeAvg = uint(u.timeSum / u.nTotal)
}
udb.Domains = convertMapToArray(u.domains, maxDomains)
| </s> remove udb.NTotal = uint(u.nTotal)
</s> add udb.NTotal = u.nTotal </s> remove udb.TimeAvg = uint(u.timeSum / u.nTotal)
</s> add udb.TimeAvg = uint32(u.timeSum / u.nTotal) </s> remove u.nTotal = int(udb.NTotal)
</s> add u.nTotal = udb.NTotal </s> remove m[it.Name] = int(it.Count)
</s> add m[it.Name] = it.Count </s> remove m = map[string]int{}
</s> add m = map[string]uint64{} | udb.NResult = append(udb.NResult, it) | func serialize(u *unit) *unitDB {
udb := unitDB{}
udb.NTotal = uint(u.nTotal)
for _, it := range u.nResult {
udb.NResult = append(udb.NResult, it)
}
if u.nTotal != 0 {
udb.TimeAvg = uint(u.timeSum / u.nTotal)
}
udb.Domains = convertMapToArray(u.domains, maxDomains) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
for _, it := range u.nResult {
udb.NResult = append(udb.NResult, uint(it))
}
if u.nTotal != 0 {
udb.TimeAvg = uint(u.timeSum / u.nTotal)
}
udb.Domains = convertMapToArray(u.domains, maxDomains)
udb.BlockedDomains = convertMapToArray(u.blockedDomains, maxDomains)
udb.Clients = convertMapToArray(u.clients, maxClients)
return &udb
| </s> remove udb.NResult = append(udb.NResult, uint(it))
</s> add udb.NResult = append(udb.NResult, it) </s> remove udb.NTotal = uint(u.nTotal)
</s> add udb.NTotal = u.nTotal </s> remove u.nTotal = int(udb.NTotal)
</s> add u.nTotal = udb.NTotal </s> remove m = map[string]int{}
</s> add m = map[string]uint64{} </s> remove m = map[string]int{}
</s> add m = map[string]uint64{} | udb.TimeAvg = uint32(u.timeSum / u.nTotal) | for _, it := range u.nResult {
udb.NResult = append(udb.NResult, uint(it))
}
if u.nTotal != 0 {
udb.TimeAvg = uint32(u.timeSum / u.nTotal)
}
udb.Domains = convertMapToArray(u.domains, maxDomains)
udb.BlockedDomains = convertMapToArray(u.blockedDomains, maxDomains)
udb.Clients = convertMapToArray(u.clients, maxClients)
return &udb | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
return &udb
}
func deserialize(u *unit, udb *unitDB) {
u.nTotal = int(udb.NTotal)
for _, it := range udb.NResult {
u.nResult = append(u.nResult, int(it))
}
u.domains = convertArrayToMap(udb.Domains)
u.blockedDomains = convertArrayToMap(udb.BlockedDomains)
| </s> remove u.timeSum = int(udb.TimeAvg) * u.nTotal
</s> add u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> remove udb.NTotal = uint(u.nTotal)
</s> add udb.NTotal = u.nTotal </s> remove udb.NResult = append(udb.NResult, uint(it))
</s> add udb.NResult = append(udb.NResult, it) </s> remove udb.TimeAvg = uint(u.timeSum / u.nTotal)
</s> add udb.TimeAvg = uint32(u.timeSum / u.nTotal) </s> remove u.nResult = make([]int, rLast)
u.domains = make(map[string]int)
u.blockedDomains = make(map[string]int)
u.clients = make(map[string]int)
</s> add u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64) | u.nTotal = udb.NTotal | return &udb
}
func deserialize(u *unit, udb *unitDB) {
u.nTotal = udb.NTotal
for _, it := range udb.NResult {
u.nResult = append(u.nResult, int(it))
}
u.domains = convertArrayToMap(udb.Domains)
u.blockedDomains = convertArrayToMap(udb.BlockedDomains) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
}
u.domains = convertArrayToMap(udb.Domains)
u.blockedDomains = convertArrayToMap(udb.BlockedDomains)
u.clients = convertArrayToMap(udb.Clients)
u.timeSum = int(udb.TimeAvg) * u.nTotal
}
func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
log.Tracef("Flushing unit %d", id)
| </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
</s> add func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> remove u.nTotal = int(udb.NTotal)
</s> add u.nTotal = udb.NTotal </s> remove func (s *statsCtx) initUnit(u *unit, id int) {
</s> add func (s *statsCtx) initUnit(u *unit, id uint32) { </s> remove u.nResult = make([]int, rLast)
u.domains = make(map[string]int)
u.blockedDomains = make(map[string]int)
u.clients = make(map[string]int)
</s> add u.nResult = make([]uint64, rLast)
u.domains = make(map[string]uint64)
u.blockedDomains = make(map[string]uint64)
u.clients = make(map[string]uint64) </s> remove s.limit = limit * 24
</s> add s.limit = uint32(limit) * 24 | u.timeSum = uint64(udb.TimeAvg) * u.nTotal | }
u.domains = convertArrayToMap(udb.Domains)
u.blockedDomains = convertArrayToMap(udb.BlockedDomains)
u.clients = convertArrayToMap(udb.Clients)
u.timeSum = uint64(udb.TimeAvg) * u.nTotal
}
func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
log.Tracef("Flushing unit %d", id)
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
u.clients = convertArrayToMap(udb.Clients)
u.timeSum = int(udb.TimeAvg) * u.nTotal
}
func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
log.Tracef("Flushing unit %d", id)
bkt, err := tx.CreateBucketIfNotExists(unitName(id))
if err != nil {
log.Error("tx.CreateBucketIfNotExists: %s", err)
| </s> remove u.timeSum = int(udb.TimeAvg) * u.nTotal
</s> add u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> remove func (s *statsCtx) deleteUnit(tx *bolt.Tx, id int) bool {
</s> add func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> remove config.stats, err = stats.New(filepath.Join(baseDir, "stats.db"), int(config.DNS.StatsInterval), nil)
</s> add statsDBFilename := filepath.Join(baseDir, "stats.db")
config.stats, err = stats.New(statsDBFilename, config.DNS.StatsInterval, nil) </s> remove id := btoi(name)
</s> add id := uint32(btoi(name)) </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id int) *unitDB {
</s> add func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { | func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { | u.clients = convertArrayToMap(udb.Clients)
u.timeSum = int(udb.TimeAvg) * u.nTotal
}
func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool {
log.Tracef("Flushing unit %d", id)
bkt, err := tx.CreateBucketIfNotExists(unitName(id))
if err != nil {
log.Error("tx.CreateBucketIfNotExists: %s", err) | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
return true
}
func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id int) *unitDB {
bkt := tx.Bucket(unitName(id))
if bkt == nil {
return nil
}
| </s> remove func (s *statsCtx) deleteUnit(tx *bolt.Tx, id int) bool {
</s> add func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id int, udb *unitDB) bool {
</s> add func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> remove s.limit = limit * 24
</s> add s.limit = uint32(limit) * 24 </s> remove func (s *statsCtx) initUnit(u *unit, id int) {
</s> add func (s *statsCtx) initUnit(u *unit, id uint32) { </s> remove func newUnitID() int {
return int(time.Now().Unix() / (60 * 60))
</s> add func newUnitID() uint32 {
return uint32(time.Now().Unix() / (60 * 60)) | func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { |
return true
}
func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB {
bkt := tx.Bucket(unitName(id))
if bkt == nil {
return nil
}
| [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
return &udb
}
func convertTopArray(a []countPair) []map[string]uint {
m := []map[string]uint{}
for _, it := range a {
ent := map[string]uint{}
ent[it.Name] = it.Count
m = append(m, ent)
}
| </s> remove ent := map[string]uint{}
</s> add ent := map[string]uint64{} </s> remove m[it.Name] = int(it.Count)
</s> add m[it.Name] = it.Count </s> remove func convertArrayToMap(a []countPair) map[string]int {
m := map[string]int{}
</s> add func convertArrayToMap(a []countPair) map[string]uint64 {
m := map[string]uint64{} </s> remove m[it.Name] += int(it.Count)
</s> add m[it.Name] += it.Count </s> remove m[it.Name] += int(it.Count)
</s> add m[it.Name] += it.Count | func convertTopArray(a []countPair) []map[string]uint64 {
m := []map[string]uint64{} |
return &udb
}
func convertTopArray(a []countPair) []map[string]uint64 {
m := []map[string]uint64{}
func convertTopArray(a []countPair) []map[string]uint64 {
m := []map[string]uint64{}
for _, it := range a {
ent := map[string]uint{}
ent[it.Name] = it.Count
m = append(m, ent)
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
func convertTopArray(a []countPair) []map[string]uint {
m := []map[string]uint{}
for _, it := range a {
ent := map[string]uint{}
ent[it.Name] = it.Count
m = append(m, ent)
}
return m
}
| </s> remove func convertTopArray(a []countPair) []map[string]uint {
m := []map[string]uint{}
</s> add func convertTopArray(a []countPair) []map[string]uint64 {
m := []map[string]uint64{} </s> remove m[it.Name] = int(it.Count)
</s> add m[it.Name] = it.Count </s> remove func convertArrayToMap(a []countPair) map[string]int {
m := map[string]int{}
</s> add func convertArrayToMap(a []countPair) map[string]uint64 {
m := map[string]uint64{} </s> remove m[it.Name] += int(it.Count)
</s> add m[it.Name] += it.Count </s> remove m[it.Name] += int(it.Count)
</s> add m[it.Name] += it.Count | ent := map[string]uint64{} |
func convertTopArray(a []countPair) []map[string]uint {
m := []map[string]uint{}
for _, it := range a {
ent := map[string]uint64{}
ent[it.Name] = it.Count
m = append(m, ent)
}
return m
} | [
"keep",
"keep",
"keep",
"keep",
"replace",
"keep",
"keep",
"keep",
"keep",
"keep"
] | * stats: use uint32 or uint64 integer values, not int | https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff | stats/stats_unit.go |
Subsets and Splits