docstring_tokens
stringlengths
18
16.9k
code_tokens
stringlengths
75
1.81M
html_url
stringlengths
74
116
file_name
stringlengths
3
311
keep keep keep keep replace replace keep keep keep keep keep
<mask> n.MAC = mac <mask> } <mask> <mask> host := fields[0] <mask> if err := netutil.ValidateDomainName(host); err != nil { <mask> log.Debug("parsing arp output: %s", err) <mask> } else { <mask> n.Name = host <mask> } <mask> <mask> ns = append(ns, n) </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 log.Debug("parsing arp output: %s", verr) </s> add log.Debug("arpdb: parsing arp output: host: %s", verr) </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) </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 log.Debug("parsing arp output: %s", err) </s> add log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { log.Debug("parsing arp output: %s", err) </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_bsd.go
keep add keep keep keep keep keep keep
<mask> import ( <mask> "net" <mask> ) <mask> <mask> const arpAOutput = ` <mask> invalid.mac (1.2.3.4) at 12:34:56:78:910 on el0 ifscope [ethernet] <mask> invalid.ip (1.2.3.4.5) at ab:cd:ef:ab:cd:12 on ek0 ifscope [ethernet] <mask> invalid.fmt 1 at 12:cd:ef:ab:cd:ef on er0 ifscope [ethernet] </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> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_bsd_test.go
keep keep keep replace keep keep keep replace keep keep
<mask> <mask> var wantNeighs = []Neighbor{{ <mask> Name: "hostname.one", <mask> IP: net.IPv4(192, 168, 1, 2), <mask> MAC: net.HardwareAddr{0xAB, 0xCD, 0xEF, 0xAB, 0xCD, 0xEF}, <mask> }, { <mask> Name: "hostname.two", <mask> IP: net.ParseIP("::ffff:ffff"), <mask> MAC: net.HardwareAddr{0xEF, 0xCD, 0xAB, 0xEF, 0xCD, 0xAB}, <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.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_bsd_test.go
keep keep keep keep replace keep keep
<mask> IP: net.ParseIP("::ffff:ffff"), <mask> MAC: net.HardwareAddr{0xEF, 0xCD, 0xAB, 0xEF, 0xCD, 0xAB}, <mask> }, { <mask> Name: "", <mask> IP: net.ParseIP("::1234"), <mask> MAC: net.HardwareAddr{0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF}, <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.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_bsd_test.go
keep add keep keep keep keep keep keep
<mask> "io/fs" <mask> "net" <mask> "strings" <mask> "sync" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" <mask> "github.com/AdguardTeam/golibs/log" <mask> "github.com/AdguardTeam/golibs/netutil" </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> add "net/netip" </s> remove "net" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> continue <mask> } <mask> <mask> n := Neighbor{} <mask> if n.IP = net.ParseIP(fields[0]); n.IP == nil || n.IP.IsUnspecified() { <mask> continue <mask> } else if n.MAC, err = net.ParseMAC(fields[3]); err != nil { <mask> continue <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 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 := net.ParseIP(fields[0]); ip == nil { </s> add ip, err := netip.ParseAddr(fields[0]) if err != nil { </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) </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> n := Neighbor{} <mask> <mask> if ip := net.ParseIP(fields[0]); ip == nil || n.IP.IsUnspecified() { <mask> continue <mask> } else { <mask> n.IP = ip <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 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) </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> n.IP = ip <mask> } <mask> <mask> hwStr := fields[3] <mask> if mac, err := net.ParseMAC(hwStr); err != nil { <mask> log.Debug("parsing arp output: %s", err) <mask> <mask> continue <mask> } else { <mask> n.MAC = mac <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 log.Debug("parsing arp output: %s", err) </s> add log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </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) </s> remove if mac, err := net.ParseMAC(fields[1]); err != nil { </s> add mac, err := net.ParseMAC(fields[1]) if err != nil { </s> remove if err := netutil.ValidateDomainName(host); err != nil { log.Debug("parsing arp output: %s", err) </s> add err = netutil.ValidateDomainName(host) if err != nil { log.Debug("arpdb: parsing arp output: host: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> n := Neighbor{} <mask> <mask> if ipStr := fields[1]; len(ipStr) < 2 { <mask> continue <mask> } else if ip := net.ParseIP(ipStr[1 : len(ipStr)-1]); ip == nil { <mask> continue <mask> } else { <mask> n.IP = ip <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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> hwStr := fields[3] <mask> if mac, err := net.ParseMAC(hwStr); err != nil { <mask> log.Debug("parsing arp output: %s", err) <mask> <mask> continue <mask> } else { <mask> n.MAC = mac <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 mac, err := net.ParseMAC(hwStr); err != nil { log.Debug("parsing arp output: %s", err) </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </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) </s> remove if err := netutil.ValidateDomainName(host); err != nil { log.Debug("parsing arp output: %s", err) </s> add err = netutil.ValidateDomainName(host) if err != nil { log.Debug("arpdb: parsing arp output: host: %s", err) </s> remove if mac, err := net.ParseMAC(fields[1]); err != nil { </s> add mac, err := net.ParseMAC(fields[1]) if err != nil {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> host := fields[0] <mask> if verr := netutil.ValidateDomainName(host); verr != nil { <mask> log.Debug("parsing arp output: %s", verr) <mask> } else { <mask> n.Name = host <mask> } <mask> <mask> ns = append(ns, n) </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 err := netutil.ValidateDomainName(host); err != nil { log.Debug("parsing arp output: %s", err) </s> add err = netutil.ValidateDomainName(host) if err != nil { log.Debug("arpdb: parsing arp output: host: %s", err) </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) </s> remove log.Debug("parsing arp output: %s", err) </s> add log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { log.Debug("parsing arp output: %s", err) </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> n := Neighbor{} <mask> <mask> if ip := net.ParseIP(fields[0]); ip == nil { <mask> continue <mask> } else { <mask> n.IP = ip <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 ip := net.ParseIP(fields[0]); ip == nil { </s> add ip, err := netip.ParseAddr(fields[0]) if err != nil { </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 || 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 } 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() {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> } else { <mask> n.IP = ip <mask> } <mask> <mask> if mac, err := net.ParseMAC(fields[4]); err != nil { <mask> log.Debug("parsing arp output: %s", err) <mask> <mask> continue <mask> } else { <mask> n.MAC = mac <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 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) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { log.Debug("parsing arp output: %s", err) </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove log.Debug("parsing arp output: %s", err) </s> add log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(fields[1]); err != nil { </s> add mac, err := net.ParseMAC(fields[1]) if err != nil { </s> remove if err := netutil.ValidateDomainName(host); err != nil { log.Debug("parsing arp output: %s", err) </s> add err = netutil.ValidateDomainName(host) if err != nil { log.Debug("arpdb: parsing arp output: host: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux.go
keep keep add keep keep keep keep
<mask> <mask> import ( <mask> "net" <mask> "sync" <mask> "testing" <mask> "testing/fstest" <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> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux_test.go
keep keep keep replace keep keep replace keep
<mask> ::ffff:ffff dev enp0s3 lladdr ef:cd:ab:ef:cd:ab router STALE` <mask> <mask> var wantNeighs = []Neighbor{{ <mask> IP: net.IPv4(192, 168, 1, 2), <mask> MAC: net.HardwareAddr{0xAB, 0xCD, 0xEF, 0xAB, 0xCD, 0xEF}, <mask> }, { <mask> IP: net.ParseIP("::ffff:ffff"), <mask> MAC: net.HardwareAddr{0xEF, 0xCD, 0xAB, 0xEF, 0xCD, 0xAB}, </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.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_linux_test.go
keep keep add keep keep keep keep keep
<mask> import ( <mask> "bufio" <mask> "net" <mask> "strings" <mask> "sync" <mask> <mask> "github.com/AdguardTeam/golibs/log" <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> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> remove "net" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_openbsd.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> n := Neighbor{} <mask> <mask> if ip := net.ParseIP(fields[0]); ip == nil { <mask> continue <mask> } else { <mask> n.IP = ip <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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_openbsd.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> } else { <mask> n.IP = ip <mask> } <mask> <mask> if mac, err := net.ParseMAC(fields[1]); err != nil { <mask> log.Debug("parsing arp output: %s", err) <mask> <mask> continue <mask> } else { <mask> n.MAC = mac <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 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(hwStr); err != nil { log.Debug("parsing arp output: %s", err) </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(fields[1]); err != nil { </s> add mac, err := net.ParseMAC(fields[1]) if err != nil { </s> remove log.Debug("parsing arp output: %s", err) </s> add log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if err := netutil.ValidateDomainName(host); err != nil { log.Debug("parsing arp output: %s", err) </s> add err = netutil.ValidateDomainName(host) if err != nil { log.Debug("arpdb: parsing arp output: host: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_openbsd.go
keep keep add keep keep keep keep keep keep
<mask> <mask> import ( <mask> "net" <mask> ) <mask> <mask> const arpAOutput = ` <mask> Host Ethernet Address Netif Expire Flags <mask> 1.2.3.4.5 aa:bb:cc:dd:ee:ff em0 permanent <mask> 1.2.3.4 12:34:56:78:910 em0 permanent </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> add "net/netip" </s> add "net/netip" </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"), </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_openbsd_test.go
keep keep keep replace keep keep replace
<mask> ` <mask> <mask> var wantNeighs = []Neighbor{{ <mask> IP: net.IPv4(192, 168, 1, 2), <mask> MAC: net.HardwareAddr{0xAB, 0xCD, 0xEF, 0xAB, 0xCD, 0xEF}, <mask> }, { <mask> IP: net.ParseIP("::ffff:ffff"), </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.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_openbsd_test.go
keep keep keep add keep keep keep keep keep keep
<mask> package aghnet <mask> <mask> import ( <mask> "net" <mask> "sync" <mask> "testing" <mask> <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/testutil" <mask> "github.com/stretchr/testify/assert" </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> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "github.com/AdguardTeam/golibs/netutil" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> return arp.OnNeighbors() <mask> } <mask> <mask> func TestARPDBS(t *testing.T) { <mask> knownIP := net.IP{1, 2, 3, 4} <mask> knownMAC := net.HardwareAddr{0xAB, 0xCD, 0xEF, 0xAB, 0xCD, 0xEF} <mask> <mask> succRefrCount, failRefrCount := 0, 0 <mask> clnp := func() { <mask> succRefrCount, failRefrCount = 0, 0 </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, ClientSourceHostsFile)) </s> add assert.True(t, clients.exists(ip, ClientSourceHostsFile)) </s> remove ip := net.IP{127, 0, 0, 1} </s> add ip := netutil.IPv4Localhost() </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove ip := net.IP{127, 0, 0, 1} </s> add ip := netutil.IPv4Localhost()
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_test.go
keep keep keep add keep keep keep keep
<mask> <mask> import ( <mask> "bufio" <mask> "net" <mask> "strings" <mask> "sync" <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> add "net/netip" </s> add "net/netip" </s> remove "net" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_windows.go
keep keep keep keep replace keep keep keep keep keep
<mask> } <mask> <mask> n := Neighbor{} <mask> <mask> if ip := net.ParseIP(fields[0]); ip == nil { <mask> continue <mask> } else { <mask> n.IP = ip <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 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) </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 } 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() {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_windows.go
keep keep keep keep replace keep keep keep keep keep
<mask> } else { <mask> n.IP = ip <mask> } <mask> <mask> if mac, err := net.ParseMAC(fields[1]); err != nil { <mask> continue <mask> } else { <mask> n.MAC = mac <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 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) </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(hwStr); err != nil { </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if mac, err := net.ParseMAC(hwStr); err != nil { log.Debug("parsing arp output: %s", err) </s> add mac, err := net.ParseMAC(hwStr) if err != nil { log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove log.Debug("parsing arp output: %s", err) </s> add log.Debug("arpdb: parsing arp output: mac: %s", err) </s> remove if ip := net.ParseIP(fields[0]); ip == nil { </s> add ip, err := netip.ParseAddr(fields[0]) if err != nil {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_windows.go
keep add keep keep keep keep
<mask> import ( <mask> "net" <mask> ) <mask> <mask> const arpAOutput = ` <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> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_windows_test.go
keep keep replace keep keep replace
<mask> <mask> var wantNeighs = []Neighbor{{ <mask> IP: net.IPv4(192, 168, 1, 2), <mask> MAC: net.HardwareAddr{0xAB, 0xCD, 0xEF, 0xAB, 0xCD, 0xEF}, <mask> }, { <mask> IP: net.ParseIP("::ffff:ffff"), </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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/arpdb_windows_test.go
keep keep keep keep replace keep keep keep keep keep
<mask> "bufio" <mask> "fmt" <mask> "io" <mask> "io/fs" <mask> "net" <mask> "path" <mask> "strings" <mask> "sync" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghos" </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> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep add keep keep keep keep
<mask> "github.com/AdguardTeam/urlfilter/rules" <mask> "github.com/miekg/dns" <mask> ) <mask> <mask> // DefaultHostsPaths returns the slice of paths default for the operating system <mask> // to files and directories which are containing the hosts database. The result </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 </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) { </s> remove // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. last *netutil.IPMap </s> add last HostsRecords </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 table: netutil.NewIPMap(hc.last.Len()), </s> add table: make(HostsRecords, len(hc.last)), </s> remove func (hp *hostsParser) addRecord(ip net.IP, hosts []string) { </s> add func (hp *hostsParser) addRecord(ip netip.Addr, hosts []string) {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> "github.com/AdguardTeam/urlfilter/rules" <mask> "github.com/miekg/dns" <mask> ) <mask> <mask> //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap]. <mask> <mask> // DefaultHostsPaths returns the slice of paths default for the operating system <mask> // to files and directories which are containing the hosts database. The result <mask> // is intended to be used within fs.FS so the initial slash is omitted. <mask> func DefaultHostsPaths() (paths []string) { <mask> return defaultHostsPaths() </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> add "golang.org/x/exp/maps" </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) { </s> remove // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. last *netutil.IPMap </s> add last HostsRecords </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) addRecord(ip net.IP, hosts []string) { </s> add func (hp *hostsParser) addRecord(ip netip.Addr, hosts []string) { </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) {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> // done is the channel to sign closing the container. <mask> done chan struct{} <mask> <mask> // updates is the channel for receiving updated hosts. <mask> // <mask> // TODO(e.burkov): Use map[netip.Addr]struct{} instead. <mask> updates chan *netutil.IPMap <mask> <mask> // last is the set of hosts that was cached within last detected change. <mask> // <mask> // TODO(e.burkov): Use map[netip.Addr]struct{} instead. <mask> last *netutil.IPMap </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 // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. last *netutil.IPMap </s> add last HostsRecords </s> remove table *netutil.IPMap </s> add table HostsRecords </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) { </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap]. </s> add </s> remove rc, ok := clients.FindRuntimeClient(ip) </s> add rc, ok := clients.findRuntimeClient(ip) </s> remove ip := net.IP{127, 0, 0, 1} </s> add ip := netutil.IPv4Localhost()
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> // TODO(e.burkov): Use map[netip.Addr]struct{} instead. <mask> updates chan *netutil.IPMap <mask> <mask> // last is the set of hosts that was cached within last detected change. <mask> // <mask> // TODO(e.burkov): Use map[netip.Addr]struct{} instead. <mask> last *netutil.IPMap <mask> <mask> // fsys is the working file system to read hosts files from. <mask> fsys fs.FS <mask> <mask> // w tracks the changes in specified files and directories. </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 // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. updates chan *netutil.IPMap </s> add updates chan HostsRecords </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap]. </s> add </s> add "golang.org/x/exp/maps" </s> remove rc, ok := clients.FindRuntimeClient(ip) </s> add rc, ok := clients.findRuntimeClient(ip) </s> remove table *netutil.IPMap </s> add table HostsRecords </s> remove table: netutil.NewIPMap(hc.last.Len()), </s> add table: make(HostsRecords, len(hc.last)),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<mask> stateLock: &sync.RWMutex{}, <mask> }, <mask> listID: listID, <mask> done: make(chan struct{}, 1), <mask> updates: make(chan *netutil.IPMap, 1), <mask> fsys: fsys, <mask> w: w, <mask> patterns: patterns, <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 rc, ok = clients.FindRuntimeClient(ip) </s> add rc, ok = clients.findRuntimeClient(ip) </s> remove wantIP: nil, </s> add wantIP: netip.Addr{}, </s> remove wantIP: nil, </s> add wantIP: netip.Addr{}, </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"), </s> remove wantIP: nil, </s> add wantIP: netip.Addr{}, </s> remove IP: net.ParseIP("::1234"), </s> add IP: netip.MustParseAddr("::1234"),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace replace keep keep keep keep keep
<mask> <mask> return nil <mask> } <mask> <mask> // Upd returns the channel into which the updates are sent. The receivable <mask> // map's values are guaranteed to be of type of *HostsRecord. <mask> func (hc *HostsContainer) Upd() (updates <-chan *netutil.IPMap) { <mask> return hc.updates <mask> } <mask> <mask> // pathsToPatterns converts paths into patterns compatible with fs.Glob. <mask> func pathsToPatterns(fsys fs.FS, paths []string) (patterns []string, err error) { </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 </s> add "golang.org/x/exp/maps" </s> remove table *netutil.IPMap </s> add table HostsRecords </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 // 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 table: netutil.NewIPMap(hc.last.Len()), </s> add table: make(HostsRecords, len(hc.last)),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<mask> translations map[string]string <mask> <mask> // table stores only the unique IP-hostname pairs. It's also sent to the <mask> // updates channel afterwards. <mask> table *netutil.IPMap <mask> } <mask> <mask> // newHostsParser creates a new *hostsParser with buffers of size taken from the <mask> // previous parse. <mask> func (hc *HostsContainer) newHostsParser() (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 // 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) { </s> remove table: netutil.NewIPMap(hc.last.Len()), </s> add table: make(HostsRecords, len(hc.last)), </s> remove // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. updates chan *netutil.IPMap </s> add updates chan HostsRecords </s> remove return true }) </s> add } </s> remove // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. last *netutil.IPMap </s> add last HostsRecords </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())
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<mask> func (hc *HostsContainer) newHostsParser() (hp *hostsParser) { <mask> return &hostsParser{ <mask> rulesBuilder: &strings.Builder{}, <mask> translations: map[string]string{}, <mask> table: netutil.NewIPMap(hc.last.Len()), <mask> } <mask> } <mask> <mask> // parseFile is a aghos.FileWalker for parsing the files with hosts syntax. It <mask> // never signs to stop walking and never returns any additional patterns. </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 table *netutil.IPMap </s> add table HostsRecords </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) { </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap]. </s> add </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 // 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> add "golang.org/x/exp/maps"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<mask> func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) { <mask> s := bufio.NewScanner(r) <mask> for s.Scan() { <mask> ip, hosts := hp.parseLine(s.Text()) <mask> if ip == nil || len(hosts) == 0 { <mask> continue <mask> } <mask> <mask> hp.addRecord(ip, hosts) <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 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 = 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 ip := net.ParseIP(fields[0]); ip == nil { </s> add ip, err := netip.ParseAddr(fields[0]) if err != nil { </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 { 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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep replace keep keep replace keep keep keep keep
<mask> <mask> // parseLine parses the line having the hosts syntax ignoring invalid ones. <mask> func (hp *hostsParser) parseLine(line string) (ip net.IP, hosts []string) { <mask> fields := strings.Fields(line) <mask> if len(fields) < 2 { <mask> return nil, nil <mask> } <mask> <mask> if ip = net.ParseIP(fields[0]); ip == nil { <mask> return nil, nil </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 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 // 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) 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) {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace keep keep keep keep keep
<mask> if len(fields) < 2 { <mask> return nil, nil <mask> } <mask> <mask> if ip = net.ParseIP(fields[0]); ip == nil { <mask> return nil, nil <mask> } <mask> <mask> for _, f := range fields[1:] { <mask> hashIdx := strings.IndexByte(f, '#') <mask> if hashIdx == 0 { </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 nil, nil </s> add return netip.Addr{}, nil </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 if ip == nil || len(hosts) == 0 { </s> add if ip == (netip.Addr{}) || len(hosts) == 0 { </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<mask> // <mask> // See https://github.com/AdguardTeam/AdGuardHome/issues/3946. <mask> // <mask> // TODO(e.burkov): Investigate if hosts may contain DNS-SD domains. <mask> err := netutil.ValidateDomainName(f) <mask> if err != nil { <mask> log.Error("%s: host %q is invalid, ignoring", hostsContainerPref, f) <mask> <mask> continue <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 err := netutil.ValidateDomainName(host); err != nil { log.Debug("parsing arp output: %s", err) </s> add err = netutil.ValidateDomainName(host) if err != nil { log.Debug("arpdb: parsing arp output: host: %s", err) </s> remove // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. updates chan *netutil.IPMap </s> add updates chan HostsRecords </s> remove // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. last *netutil.IPMap </s> add last HostsRecords </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 // 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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep replace
<mask> <mask> return ip, hosts <mask> } <mask> <mask> // HostsRecord represents a single hosts file record. <mask> type HostsRecord struct { <mask> Aliases *stringutil.Set <mask> Canonical string <mask> } <mask> <mask> // Equal returns true if all fields of rec are equal to field in other or they <mask> // both are nil. <mask> func (rec *HostsRecord) Equal(other *HostsRecord) (ok bool) { <mask> if rec == nil { <mask> return other == nil <mask> } <mask> <mask> return rec.Canonical == other.Canonical && rec.Aliases.Equal(other.Aliases) <mask> } <mask> <mask> // addRecord puts the record for the IP address to the rules builder if needed. <mask> // The first host is considered to be the canonical name for the IP address. <mask> // hosts must have at least one name. <mask> func (hp *hostsParser) addRecord(ip net.IP, hosts []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 var rec *HostsRecord v, ok := hp.table.Get(ip) </s> add rec, ok := hp.table[ip] </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 return nil, nil </s> add return netip.Addr{}, nil </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) { </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap]. </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace keep keep keep keep keep
<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 { </s> remove return nil, nil </s> add return netip.Addr{}, nil
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace replace replace replace replace replace replace keep keep keep keep keep
<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() { </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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<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 </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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace replace keep keep keep keep keep
<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) { </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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<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()) </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap]. </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
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 replace keep keep keep keep
<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 <mask> select { </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 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] </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) {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<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 </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep keep keep keep replace keep keep keep keep keep
<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) </s> remove if err := netutil.ValidateDomainName(host); err != nil { log.Debug("parsing arp output: %s", err) </s> add err = netutil.ValidateDomainName(host) if err != nil { log.Debug("arpdb: parsing arp output: host: %s", err)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer.go
keep add keep keep keep keep
<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" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep add keep keep keep keep
<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> add "net/netip" </s> add "net/netip" </s> add "golang.org/x/exp/maps" </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap]. </s> add </s> add "net/netip" </s> add "net/netip"
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace keep keep keep keep keep
<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 </s> remove // // TODO(e.burkov): Use map[netip.Addr]struct{} instead. updates chan *netutil.IPMap </s> add updates chan HostsRecords
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep replace keep replace keep keep keep keep
<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) <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 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) </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP)) </s> add assert.True(t, clients.exists(ip, ClientSourceDHCP))
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace replace replace replace keep keep keep keep keep keep keep keep replace keep keep
<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> <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.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 var rec *HostsRecord v, ok := hp.table.Get(ip) </s> add rec, ok := hp.table[ip] </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 {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace keep keep keep keep keep
<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) </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace keep keep keep keep keep
<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() </s> remove IP net.IP </s> add IP netip.Addr
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace keep keep keep keep keep
<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() </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) {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace keep keep keep keep keep
<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"), </s> remove IP: net.IPv4(192, 168, 1, 2), </s> add IP: netip.MustParseAddr("192.168.1.2"),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace keep keep keep keep keep
<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 </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) {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace keep keep keep keep
<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() </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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/aghnet/hostscontainer_test.go
keep keep keep keep replace replace keep keep keep keep keep
<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) { </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
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace keep keep keep keep keep
<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"), </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 {
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace replace keep keep keep keep keep
<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 </s> remove rc, ok = clients.FindRuntimeClient(ip) </s> add rc, ok = clients.findRuntimeClient(ip)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace replace keep keep keep keep keep
<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] </s> remove rc, ok := clients.FindRuntimeClient(ip) </s> add rc, ok := clients.findRuntimeClient(ip)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace keep keep keep keep keep
<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) { </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())
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace replace replace keep keep keep keep keep
<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 </s> remove rc, ok = clients.FindRuntimeClient(ip) </s> add rc, ok = clients.findRuntimeClient(ip)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace replace replace replace replace replace replace replace replace keep keep keep keep keep
<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) </s> remove return true }) </s> add }
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace replace replace keep keep keep keep keep
<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) { </s> remove return true }) </s> add }
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep replace replace replace replace replace replace replace replace keep keep replace replace replace keep keep
<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> }) <mask> <mask> log.Debug("clients: added %d client aliases from system hosts file", n) </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 // 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 // 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 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 var rec *HostsRecord v, ok := hp.table.Get(ip) </s> add rec, ok := hp.table[ip]
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace keep keep keep keep keep
<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() { </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients.go
keep keep keep keep replace replace replace keep keep keep keep keep
<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)) </s> remove assert.True(t, tc.wantIP.Equal(got)) </s> add assert.Equal(t, tc.wantIP, got)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace replace keep keep keep keep keep
<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"), </s> remove IP: net.ParseIP("::ffff:ffff"), </s> add IP: netip.MustParseAddr("::ffff:ffff"),
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace keep keep keep keep keep
<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) </s> remove v, ok := upd.Get(ip) </s> add rec, ok := upd[ip]
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace keep keep keep keep keep
<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)) </s> remove knownIP := net.IP{1, 2, 3, 4} </s> add knownIP := netip.MustParseAddr("1.2.3.4")
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace keep keep keep keep keep
<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)) </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))
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace keep keep keep keep keep
<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) </s> remove clients.SetWHOISInfo(ip.AsSlice(), whois) </s> add clients.setWHOISInfo(ip.AsSlice(), whois)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace keep keep keep keep keep
<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)) </s> remove assert.Truef(t, rec.Equal(want), "%+v != %+v", rec, want) </s> add assert.Truef(t, rec.equal(want), "%+v != %+v", rec, want)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace keep keep keep keep keep
<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)) </s> remove assert.Equal(t, 1, upd.Len()) </s> add assert.Len(t, upd, 1)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace keep keep keep keep keep
<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)) </s> remove assert.True(t, cc.Exists(tc.cliIP, ClientSourceRDNS)) </s> add assert.True(t, cc.exists(tc.cliIP, ClientSourceRDNS))
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clients_test.go
keep keep keep keep replace keep keep keep keep keep
<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 </s> remove //lint:file-ignore SA1019 TODO(a.garipov): Replace [*netutil.IPMap]. </s> add
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/clientshttp.go
keep keep keep keep replace keep keep keep keep keep
<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() { </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())
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/rdns.go
keep keep keep keep replace keep keep keep
<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 </s> remove assert.True(t, clients.Exists(ip, ClientSourceDHCP)) </s> add assert.True(t, clients.exists(ip, ClientSourceDHCP))
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/rdns_test.go
keep keep keep keep replace keep keep
<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) </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04c8e3b2886bb02866ace61f796733c82b3e9aca
internal/home/whois.go
keep keep add keep keep keep keep
<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 </s> add if !isRunning() { return nil } </s> add 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 } </s> add if config.auth == nil { return fmt.Errorf("Couldn't initialize Auth module") }
https://github.com/AdguardTeam/AdGuardHome/commit/04de9d0f7bb1e59c2738538431ee90b1429fca0d
dnsforward/dnsforward.go
keep add keep keep keep keep keep keep
<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 </s> add if !isRunning() { return nil } </s> add 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") } } </s> add if config.auth == nil { return fmt.Errorf("Couldn't initialize Auth module") }
https://github.com/AdguardTeam/AdGuardHome/commit/04de9d0f7bb1e59c2738538431ee90b1429fca0d
dnsforward/dnsforward_test.go
keep keep keep add keep keep keep keep
<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 </s> add 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") } } </s> add 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 } </s> add if !isRunning() { return nil }
https://github.com/AdguardTeam/AdGuardHome/commit/04de9d0f7bb1e59c2738538431ee90b1429fca0d
home/dns.go
keep add keep keep keep keep keep
<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 </s> add 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") } } </s> add 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 } </s> add if config.auth == nil { return fmt.Errorf("Couldn't initialize Auth module") }
https://github.com/AdguardTeam/AdGuardHome/commit/04de9d0f7bb1e59c2738538431ee90b1429fca0d
home/dns.go
keep keep keep keep replace keep keep keep keep keep
<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) </s> remove func (s *statsCtx) initUnit(u *unit, id int) { </s> add func (s *statsCtx) initUnit(u *unit, id uint32) {
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
dnsforward/dnsforward.go
keep keep keep keep replace keep keep keep keep keep
<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 </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
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
home/config.go
keep keep keep keep replace keep keep keep keep keep
<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 { </s> remove func newUnitID() int { return int(time.Now().Unix() / (60 * 60)) </s> add func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60))
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
home/control_stats.go
keep keep keep keep replace keep keep
<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++ { </s> remove for i := firstDayID - firstID; i != len(units); i++ { </s> add for i := firstDayID - firstID; int(i) != len(units); i++ {
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
home/control_stats.go
keep keep keep keep replace keep keep keep keep keep
<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) { </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id int) *unitDB { </s> add func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB {
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
home/dns.go
keep keep keep keep replace keep keep keep keep keep
<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)) </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
stats/stats.go
keep keep keep keep replace keep keep keep keep keep
<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 </s> remove func newUnitID() int { return int(time.Now().Unix() / (60 * 60)) </s> add func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60))
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
stats/stats.go
keep keep keep keep replace keep
<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"` </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)
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
stats/stats.go
keep keep keep keep replace keep keep keep keep keep
<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 </s> remove var sum uint </s> add var sum uint64
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
stats/stats_test.go
keep replace replace keep replace replace keep
<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> </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_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)) </s> remove m = d["top_blocked_domains"].([]map[string]uint) </s> add m = d["top_blocked_domains"].([]map[string]uint64)
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
stats/stats_test.go
keep keep keep keep replace replace keep keep keep keep keep
<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) </s> remove m = d["top_clients"].([]map[string]uint) </s> add m = d["top_clients"].([]map[string]uint64)
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
stats/stats_test.go
keep keep keep keep replace replace keep keep keep keep keep
<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) </s> remove m = d["top_clients"].([]map[string]uint) </s> add m = d["top_clients"].([]map[string]uint64)
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
stats/stats_test.go
keep keep keep keep replace keep keep keep keep keep keep keep keep replace
<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> <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 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_clients"].([]map[string]uint) </s> add m = d["top_clients"].([]map[string]uint64)
https://github.com/AdguardTeam/AdGuardHome/commit/04e2566e9e968f299e134e812ca88d24073de9ff
stats/stats_test.go