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