code_before
stringlengths
16
1.81M
edits
stringlengths
4
328k
next_edit
stringlengths
0
76.5k
code_after
stringlengths
3
49.9M
label_window
sequencelengths
4
1.81k
instruction
stringlengths
20
51.9k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
</s> remove golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= </s> add golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= </s> remove golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= </s> add golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= </s> remove golang.org/x/sys v0.4.0 gopkg.in/natefinch/lumberjack.v2 v2.0.0 </s> add golang.org/x/sys v0.5.0 gopkg.in/natefinch/lumberjack.v2 v2.2.1 </s> remove golang.org/x/sys v0.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect </s> add golang.org/x/sys v0.5.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect </s> remove golang.org/x/exp v0.0.0-20230131160201-f062dba9d201 </s> add golang.org/x/exp v0.0.0-20230206171751-46f607a40771
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request 1729: upd-go Merge in DNS/adguard-home from upd-go to master Squashed commit of the following: commit 0e13d6863a3d463289823a27414b427cb76be88c Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:20:14 2023 +0300 scripts: try increasing test timeout commit 8e7d230e40de8f49a2b74a6d32a7fc78a361edab Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:00:17 2023 +0300 all: upd quic-go; imp atomic values commit fae2b75b6990f2bd77e5c019a35a72322bac85f7 Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 17:36:33 2023 +0300 all: upd go, deps; imp atomic values
https://github.com/AdguardTeam/AdGuardHome/commit/137d280032c8f2f0331f16b00cba83682369a43f
internal/tools/go.sum
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201007032633-0806396f153e/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
</s> remove golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= </s> add golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= </s> remove golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= </s> add golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= </s> remove golang.org/x/vuln v0.0.0-20230130175424-dd534eeddf33 h1:je2aB5nnlseeGvJy5clg6EyC3jjbbCNsRDroC3qQJsA= golang.org/x/vuln v0.0.0-20230130175424-dd534eeddf33/go.mod h1:cBP4HMKv0X+x96j8IJWCKk0eqpakBmmHjKGSSC0NaYE= </s> add golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1 h1:HRexnHfiDA2hkPNMDgf3vxabRMeC+XeS8tCKP9olVbs= golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1/go.mod h1:cBP4HMKv0X+x96j8IJWCKk0eqpakBmmHjKGSSC0NaYE= </s> remove github.com/securego/gosec/v2 v2.14.0 </s> add github.com/securego/gosec/v2 v2.15.0
golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20201007032633-0806396f153e/go.mod h1:z6u4i615ZeAfBE4XtMziQW1fSVJXACjjbWkB/mvPzlU= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request 1729: upd-go Merge in DNS/adguard-home from upd-go to master Squashed commit of the following: commit 0e13d6863a3d463289823a27414b427cb76be88c Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:20:14 2023 +0300 scripts: try increasing test timeout commit 8e7d230e40de8f49a2b74a6d32a7fc78a361edab Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:00:17 2023 +0300 all: upd quic-go; imp atomic values commit fae2b75b6990f2bd77e5c019a35a72322bac85f7 Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 17:36:33 2023 +0300 all: upd go, deps; imp atomic values
https://github.com/AdguardTeam/AdGuardHome/commit/137d280032c8f2f0331f16b00cba83682369a43f
internal/tools/go.sum
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.5.1-0.20230117180257-8aba49bb5ea2 h1:v0FhRDmSCNH/0EurAT6T8KRY4aNuUhz6/WwBMxG+gvQ= golang.org/x/tools v0.5.1-0.20230117180257-8aba49bb5ea2/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/vuln v0.0.0-20230130175424-dd534eeddf33 h1:je2aB5nnlseeGvJy5clg6EyC3jjbbCNsRDroC3qQJsA= golang.org/x/vuln v0.0.0-20230130175424-dd534eeddf33/go.mod h1:cBP4HMKv0X+x96j8IJWCKk0eqpakBmmHjKGSSC0NaYE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
</s> remove gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= </s> add </s> remove golang.org/x/text v0.3.8 h1:nAL+RVCQ9uMn3vJZbV+MRnydTJFPf8qqY42YiA6MrqY= </s> add golang.org/x/text v0.6.0 h1:3XmdazWV+ubf7QgHSTWeykHOci5oeekaGJBLkrkaw4k= </s> remove golang.org/x/vuln v0.0.0-20230130175424-dd534eeddf33 honnef.co/go/tools v0.3.3 </s> add golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1 honnef.co/go/tools v0.4.0 </s> remove github.com/securego/gosec/v2 v2.14.0 </s> add github.com/securego/gosec/v2 v2.15.0 </s> remove gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= </s> add gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1 h1:HRexnHfiDA2hkPNMDgf3vxabRMeC+XeS8tCKP9olVbs= golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1/go.mod h1:cBP4HMKv0X+x96j8IJWCKk0eqpakBmmHjKGSSC0NaYE=
golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E= golang.org/x/tools v0.5.1-0.20230117180257-8aba49bb5ea2 h1:v0FhRDmSCNH/0EurAT6T8KRY4aNuUhz6/WwBMxG+gvQ= golang.org/x/tools v0.5.1-0.20230117180257-8aba49bb5ea2/go.mod h1:N+Kgy78s5I24c24dU8OfWNEotWjutIs8SnJvn5IDq+k= golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1 h1:HRexnHfiDA2hkPNMDgf3vxabRMeC+XeS8tCKP9olVbs= golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1/go.mod h1:cBP4HMKv0X+x96j8IJWCKk0eqpakBmmHjKGSSC0NaYE= golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1 h1:HRexnHfiDA2hkPNMDgf3vxabRMeC+XeS8tCKP9olVbs= golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1/go.mod h1:cBP4HMKv0X+x96j8IJWCKk0eqpakBmmHjKGSSC0NaYE= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request 1729: upd-go Merge in DNS/adguard-home from upd-go to master Squashed commit of the following: commit 0e13d6863a3d463289823a27414b427cb76be88c Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:20:14 2023 +0300 scripts: try increasing test timeout commit 8e7d230e40de8f49a2b74a6d32a7fc78a361edab Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:00:17 2023 +0300 all: upd quic-go; imp atomic values commit fae2b75b6990f2bd77e5c019a35a72322bac85f7 Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 17:36:33 2023 +0300 all: upd go, deps; imp atomic values
https://github.com/AdguardTeam/AdGuardHome/commit/137d280032c8f2f0331f16b00cba83682369a43f
internal/tools/go.sum
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA= honnef.co/go/tools v0.3.3/go.mod h1:jzwdWgg7Jdq75wlfblQxO4neNaFFSvgc1tD5Wv8U0Yw=
</s> remove honnef.co/go/tools v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA= honnef.co/go/tools v0.3.3/go.mod h1:jzwdWgg7Jdq75wlfblQxO4neNaFFSvgc1tD5Wv8U0Yw= </s> add honnef.co/go/tools v0.4.0 h1:lyXVV1c8wUBJRKqI8JgIpT8TW1VDagfYYaxbKa/HoL8= honnef.co/go/tools v0.4.0/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA= </s> remove golang.org/x/vuln v0.0.0-20230130175424-dd534eeddf33 h1:je2aB5nnlseeGvJy5clg6EyC3jjbbCNsRDroC3qQJsA= golang.org/x/vuln v0.0.0-20230130175424-dd534eeddf33/go.mod h1:cBP4HMKv0X+x96j8IJWCKk0eqpakBmmHjKGSSC0NaYE= </s> add golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1 h1:HRexnHfiDA2hkPNMDgf3vxabRMeC+XeS8tCKP9olVbs= golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1/go.mod h1:cBP4HMKv0X+x96j8IJWCKk0eqpakBmmHjKGSSC0NaYE= </s> remove gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= </s> add </s> remove gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= </s> add gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc= </s> remove golang.org/x/sys v0.4.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect </s> add golang.org/x/sys v0.5.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA= honnef.co/go/tools v0.3.3/go.mod h1:jzwdWgg7Jdq75wlfblQxO4neNaFFSvgc1tD5Wv8U0Yw=
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request 1729: upd-go Merge in DNS/adguard-home from upd-go to master Squashed commit of the following: commit 0e13d6863a3d463289823a27414b427cb76be88c Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:20:14 2023 +0300 scripts: try increasing test timeout commit 8e7d230e40de8f49a2b74a6d32a7fc78a361edab Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:00:17 2023 +0300 all: upd quic-go; imp atomic values commit fae2b75b6990f2bd77e5c019a35a72322bac85f7 Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 17:36:33 2023 +0300 all: upd go, deps; imp atomic values
https://github.com/AdguardTeam/AdGuardHome/commit/137d280032c8f2f0331f16b00cba83682369a43f
internal/tools/go.sum
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA= honnef.co/go/tools v0.3.3/go.mod h1:jzwdWgg7Jdq75wlfblQxO4neNaFFSvgc1tD5Wv8U0Yw= mvdan.cc/gofumpt v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM= mvdan.cc/gofumpt v0.4.0/go.mod h1:PljLOHDeZqgS8opHRKLzp2It2VBuSdteAgqUfzMTxlQ= mvdan.cc/unparam v0.0.0-20230125043941-70a0ce6e7b95 h1:n/xhncJPSt0YzfOhnyn41XxUdrWQNgmLBG72FE27Fqw= mvdan.cc/unparam v0.0.0-20230125043941-70a0ce6e7b95/go.mod h1:2vU506e8nGWodqcci641NLi4im2twWSq4Lod756epHQ=
</s> remove gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= </s> add </s> remove gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= </s> add </s> remove golang.org/x/vuln v0.0.0-20230130175424-dd534eeddf33 honnef.co/go/tools v0.3.3 </s> add golang.org/x/vuln v0.0.0-20230201222900-4c848edceff1 honnef.co/go/tools v0.4.0 </s> remove github.com/securego/gosec/v2 v2.14.0 </s> add github.com/securego/gosec/v2 v2.15.0 </s> remove gopkg.in/natefinch/lumberjack.v2 v2.0.0 h1:1Lc07Kr7qY4U2YPouBjpCLxpiyxIVoxqXgkXLknAOE8= gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k= </s> add gopkg.in/natefinch/lumberjack.v2 v2.2.1 h1:bBRl1b0OH9s/DuPhuXpNl+VtCaJXFZ5/uEFST95x9zc= gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYskCTPBJVb9jqSc=
honnef.co/go/tools v0.4.0 h1:lyXVV1c8wUBJRKqI8JgIpT8TW1VDagfYYaxbKa/HoL8= honnef.co/go/tools v0.4.0/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.4.0 h1:lyXVV1c8wUBJRKqI8JgIpT8TW1VDagfYYaxbKa/HoL8= honnef.co/go/tools v0.4.0/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA= honnef.co/go/tools v0.4.0 h1:lyXVV1c8wUBJRKqI8JgIpT8TW1VDagfYYaxbKa/HoL8= honnef.co/go/tools v0.4.0/go.mod h1:36ZgoUOrqOk1GxwHhyryEkq8FQWkUO2xGuSMhUCcdvA= mvdan.cc/gofumpt v0.4.0 h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM= mvdan.cc/gofumpt v0.4.0/go.mod h1:PljLOHDeZqgS8opHRKLzp2It2VBuSdteAgqUfzMTxlQ= mvdan.cc/unparam v0.0.0-20230125043941-70a0ce6e7b95 h1:n/xhncJPSt0YzfOhnyn41XxUdrWQNgmLBG72FE27Fqw= mvdan.cc/unparam v0.0.0-20230125043941-70a0ce6e7b95/go.mod h1:2vU506e8nGWodqcci641NLi4im2twWSq4Lod756epHQ=
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep" ]
Pull request 1729: upd-go Merge in DNS/adguard-home from upd-go to master Squashed commit of the following: commit 0e13d6863a3d463289823a27414b427cb76be88c Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:20:14 2023 +0300 scripts: try increasing test timeout commit 8e7d230e40de8f49a2b74a6d32a7fc78a361edab Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 20:00:17 2023 +0300 all: upd quic-go; imp atomic values commit fae2b75b6990f2bd77e5c019a35a72322bac85f7 Author: Ainar Garipov <[email protected]> Date: Tue Feb 7 17:36:33 2023 +0300 all: upd go, deps; imp atomic values
https://github.com/AdguardTeam/AdGuardHome/commit/137d280032c8f2f0331f16b00cba83682369a43f
internal/tools/go.sum
- 'filtering' 'operationId': 'filteringRefresh' 'summary': > Reload filtering rules from URLs. This might be needed if new URL was just added and you dont want to wait for automatic refresh to kick in. This API request is ratelimited, so you can call it freely as often as you like, it wont create unnecessary burden on servers that host the URL. This should work as intended, a `force` parameter is offered as last-resort attempt to make filter lists fresh. If you ever find yourself using `force` to make something work that otherwise wont, this
</s> remove # Add the "netrwork-observe" plug to be able to bind to ports below 1024 </s> add # Add the "network-observe" plug to be able to bind to ports below 1024 </s> remove # Add the "netrwork-bind" plug to bind to interfaces. </s> add # Add the "network-bind" plug to bind to interfaces.
just added and you don't want to wait for automatic refresh to kick in.
- 'filtering' 'operationId': 'filteringRefresh' 'summary': > Reload filtering rules from URLs. This might be needed if new URL was just added and you don't want to wait for automatic refresh to kick in. This API request is ratelimited, so you can call it freely as often as you like, it wont create unnecessary burden on servers that host the URL. This should work as intended, a `force` parameter is offered as last-resort attempt to make filter lists fresh. If you ever find yourself using `force` to make something work that otherwise wont, this
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: all: fix some typos Merge in DNS/adguard-home from fix-docs to master Squashed commit of the following: commit 1a78c8fccabb90e97008cebe1f2cf5bd1dce9c24 Author: Ainar Garipov <[email protected]> Date: Tue Aug 31 17:02:52 2021 +0300 all: fix some typos
https://github.com/AdguardTeam/AdGuardHome/commit/138718e6eca965a98002a6afd5194de813db76c0
openapi/openapi.yaml
'apps': 'adguard-home': 'command': 'AdGuardHome --no-check-update -w $SNAP_DATA' 'plugs': # Add the "netrwork-bind" plug to bind to interfaces. - 'network-bind' # Add the "netrwork-observe" plug to be able to bind to ports below 1024 # (cap_net_bind_service) and also to bind to a particular interface using # SO_BINDTODEVICE (cap_net_raw). - 'network-observe'
</s> remove # Add the "netrwork-observe" plug to be able to bind to ports below 1024 </s> add # Add the "network-observe" plug to be able to bind to ports below 1024 </s> remove just added and you dont want to wait for automatic refresh to kick in. </s> add just added and you don't want to wait for automatic refresh to kick in.
# Add the "network-bind" plug to bind to interfaces.
'apps': 'adguard-home': 'command': 'AdGuardHome --no-check-update -w $SNAP_DATA' 'plugs': # Add the "network-bind" plug to bind to interfaces. - 'network-bind' # Add the "netrwork-observe" plug to be able to bind to ports below 1024 # (cap_net_bind_service) and also to bind to a particular interface using # SO_BINDTODEVICE (cap_net_raw). - 'network-observe'
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: all: fix some typos Merge in DNS/adguard-home from fix-docs to master Squashed commit of the following: commit 1a78c8fccabb90e97008cebe1f2cf5bd1dce9c24 Author: Ainar Garipov <[email protected]> Date: Tue Aug 31 17:02:52 2021 +0300 all: fix some typos
https://github.com/AdguardTeam/AdGuardHome/commit/138718e6eca965a98002a6afd5194de813db76c0
scripts/snap/snap.tmpl.yaml
'command': 'AdGuardHome --no-check-update -w $SNAP_DATA' 'plugs': # Add the "netrwork-bind" plug to bind to interfaces. - 'network-bind' # Add the "netrwork-observe" plug to be able to bind to ports below 1024 # (cap_net_bind_service) and also to bind to a particular interface using # SO_BINDTODEVICE (cap_net_raw). - 'network-observe' 'daemon': 'simple' 'restart-condition': 'always'
</s> remove # Add the "netrwork-bind" plug to bind to interfaces. </s> add # Add the "network-bind" plug to bind to interfaces. </s> remove just added and you dont want to wait for automatic refresh to kick in. </s> add just added and you don't want to wait for automatic refresh to kick in.
# Add the "network-observe" plug to be able to bind to ports below 1024
'command': 'AdGuardHome --no-check-update -w $SNAP_DATA' 'plugs': # Add the "netrwork-bind" plug to bind to interfaces. - 'network-bind' # Add the "network-observe" plug to be able to bind to ports below 1024 # (cap_net_bind_service) and also to bind to a particular interface using # SO_BINDTODEVICE (cap_net_raw). - 'network-observe' 'daemon': 'simple' 'restart-condition': 'always'
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: all: fix some typos Merge in DNS/adguard-home from fix-docs to master Squashed commit of the following: commit 1a78c8fccabb90e97008cebe1f2cf5bd1dce9c24 Author: Ainar Garipov <[email protected]> Date: Tue Aug 31 17:02:52 2021 +0300 all: fix some typos
https://github.com/AdguardTeam/AdGuardHome/commit/138718e6eca965a98002a6afd5194de813db76c0
scripts/snap/snap.tmpl.yaml
"strings" ) // manyError is an error containing several wrapped errors. It is created to be // a simpler version of the API provided by github.com/joomcode/errorx. type manyError struct { message string underlying []error }
</s> remove // ErrSeekNotFound is returned from the Seek method // if we failed to find the desired record var ErrSeekNotFound = errors.New("Seek not found the record") </s> add // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log" </s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove return nil </s> add return err
// Error is the constant error type. type Error string // Error implements the error interface for Error. func (err Error) Error() (msg string) { return string(err) }
"strings" ) // Error is the constant error type. type Error string // Error implements the error interface for Error. func (err Error) Error() (msg string) { return string(err) } // manyError is an error containing several wrapped errors. It is created to be // a simpler version of the API provided by github.com/joomcode/errorx. type manyError struct { message string underlying []error }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/agherr/agherr.go
package querylog import ( "errors" "io" "os" "sync" "time"
</s> remove if len(entries) == totalLimit { // change the "oldest" value here. // we cannot use the "oldest" we got from "searchFiles" anymore // because after adding in-memory records and removing extra records // the situation has changed </s> add if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer.
package querylog import ( "io" "os" "sync" "time"
[ "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_file.go
"sync" "time" "github.com/AdguardTeam/golibs/log" ) // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record.
</s> remove // ErrSeekNotFound is returned from the Seek method // if we failed to find the desired record var ErrSeekNotFound = errors.New("Seek not found the record") </s> add // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log" </s> remove "errors" </s> add
"github.com/AdguardTeam/AdGuardHome/internal/agherr"
"sync" "time" "github.com/AdguardTeam/AdGuardHome/internal/agherr" "github.com/AdguardTeam/golibs/log" ) // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record.
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_file.go
"github.com/AdguardTeam/golibs/log" ) // ErrSeekNotFound is returned from the Seek method // if we failed to find the desired record var ErrSeekNotFound = errors.New("Seek not found the record") // TODO: Find a way to grow buffer instead of relying on this value when reading strings const maxEntrySize = 16 * 1024 // buffer should be enough for at least this number of entries
</s> remove return nil </s> add return err
// ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log"
"github.com/AdguardTeam/golibs/log" ) // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log" // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log" // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log" // TODO: Find a way to grow buffer instead of relying on this value when reading strings const maxEntrySize = 16 * 1024 // buffer should be enough for at least this number of entries
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_file.go
} // NewQLogFile initializes a new instance of the QLogFile func NewQLogFile(path string) (*QLogFile, error) { f, err := os.OpenFile(path, os.O_RDONLY, 0644) if err != nil { return nil, err } return &QLogFile{
</s> remove return nil </s> add return err </s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove var startLine = int64(0) </s> add startLine := int64(0)
f, err := os.OpenFile(path, os.O_RDONLY, 0o644)
} // NewQLogFile initializes a new instance of the QLogFile func NewQLogFile(path string) (*QLogFile, error) { f, err := os.OpenFile(path, os.O_RDONLY, 0o644) f, err := os.OpenFile(path, os.O_RDONLY, 0o644) if err != nil { return nil, err } return &QLogFile{
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_file.go
// the scope is too narrow and we won't find anything anymore log.Error("querylog: didn't find timestamp:%v", timestamp) return 0, depth, ErrSeekNotFound } // Save the last found idx lastProbeLineIdx = lineIdx
</s> remove // ErrSeekNotFound is returned from the Seek method // if we failed to find the desired record var ErrSeekNotFound = errors.New("Seek not found the record") </s> add // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log" </s> remove return nil </s> add return err </s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove if len(entries) == totalLimit { // change the "oldest" value here. // we cannot use the "oldest" we got from "searchFiles" anymore // because after adding in-memory records and removing extra records // the situation has changed </s> add if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer.
} else if lineIdx == end && lineEndIdx == end { return 0, depth, ErrEndOfLog
// the scope is too narrow and we won't find anything anymore log.Error("querylog: didn't find timestamp:%v", timestamp) return 0, depth, ErrSeekNotFound } else if lineIdx == end && lineEndIdx == end { return 0, depth, ErrEndOfLog } // Save the last found idx lastProbeLineIdx = lineIdx
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_file.go
} // Look for the end of the prev line // This is where we'll read from var startLine = int64(0) for i := relativePos - 1; i >= 0; i-- { if q.buffer[i] == '\n' { startLine = i + 1 break }
</s> remove var startLine = int64(0) </s> add startLine := int64(0) </s> remove var endLine = int64(bufferLen) </s> add endLine := int64(bufferLen) </s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove return nil </s> add return err
startLine := int64(0)
} // Look for the end of the prev line // This is where we'll read from startLine := int64(0) for i := relativePos - 1; i >= 0; i-- { if q.buffer[i] == '\n' { startLine = i + 1 break }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_file.go
} // Now start looking for the new line character starting // from the relativePos and going left var startLine = int64(0) for i := relativePos - 1; i >= 0; i-- { if buffer[i] == '\n' { startLine = i + 1 break }
</s> remove var startLine = int64(0) </s> add startLine := int64(0) </s> remove var endLine = int64(bufferLen) </s> add endLine := int64(bufferLen) </s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove return nil </s> add return err </s> remove if len(entries) == totalLimit { // change the "oldest" value here. // we cannot use the "oldest" we got from "searchFiles" anymore // because after adding in-memory records and removing extra records // the situation has changed </s> add if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer.
startLine := int64(0)
} // Now start looking for the new line character starting // from the relativePos and going left startLine := int64(0) for i := relativePos - 1; i >= 0; i-- { if buffer[i] == '\n' { startLine = i + 1 break }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_file.go
break } } // Looking for the end of line now var endLine = int64(bufferLen) lineEndIdx := endLine + seekPosition for i := relativePos; i < int64(bufferLen); i++ { if buffer[i] == '\n' { endLine = i lineEndIdx = endLine + seekPosition + 1
</s> remove var startLine = int64(0) </s> add startLine := int64(0) </s> remove var startLine = int64(0) </s> add startLine := int64(0) </s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove return nil </s> add return err
endLine := int64(bufferLen)
break } } // Looking for the end of line now endLine := int64(bufferLen) lineEndIdx := endLine + seekPosition for i := relativePos; i < int64(bufferLen); i++ { if buffer[i] == '\n' { endLine = i lineEndIdx = endLine + seekPosition + 1
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_file.go
package querylog import ( "io" "github.com/AdguardTeam/AdGuardHome/internal/agherr" ) // QLogReader allows reading from multiple query log files in the reverse order.
</s> remove "errors" </s> add </s> remove // ErrSeekNotFound is returned from the Seek method // if we failed to find the desired record var ErrSeekNotFound = errors.New("Seek not found the record") </s> add // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log" </s> remove if len(entries) == totalLimit { // change the "oldest" value here. // we cannot use the "oldest" we got from "searchFiles" anymore // because after adding in-memory records and removing extra records // the situation has changed </s> add if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer.
"errors"
package querylog import ( "errors" "io" "github.com/AdguardTeam/AdGuardHome/internal/agherr" ) // QLogReader allows reading from multiple query log files in the reverse order.
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_reader.go
func (r *QLogReader) Seek(timestamp int64) error { for i := len(r.qFiles) - 1; i >= 0; i-- { q := r.qFiles[i] _, _, err := q.Seek(timestamp) if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile r.currentFile = i return nil } }
</s> remove return nil </s> add return err </s> remove var startLine = int64(0) </s> add startLine := int64(0) </s> remove var startLine = int64(0) </s> add startLine := int64(0) </s> remove f, err := os.OpenFile(path, os.O_RDONLY, 0644) </s> add f, err := os.OpenFile(path, os.O_RDONLY, 0o644)
if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile.
func (r *QLogReader) Seek(timestamp int64) error { for i := len(r.qFiles) - 1; i >= 0; i-- { q := r.qFiles[i] _, _, err := q.Seek(timestamp) if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. r.currentFile = i return nil } }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_reader.go
if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile r.currentFile = i return nil } } return ErrSeekNotFound }
</s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove f, err := os.OpenFile(path, os.O_RDONLY, 0644) </s> add f, err := os.OpenFile(path, os.O_RDONLY, 0o644) </s> remove if len(entries) == totalLimit { // change the "oldest" value here. // we cannot use the "oldest" we got from "searchFiles" anymore // because after adding in-memory records and removing extra records // the situation has changed </s> add if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer.
return err
if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile r.currentFile = i return err } } return ErrSeekNotFound }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/qlog_reader.go
import ( "io" "time" "github.com/AdguardTeam/AdGuardHome/internal/util" "github.com/AdguardTeam/golibs/log" )
</s> remove "errors" </s> add </s> remove // ErrSeekNotFound is returned from the Seek method // if we failed to find the desired record var ErrSeekNotFound = errors.New("Seek not found the record") </s> add // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log"
"errors"
import ( "errors" "io" "time" "github.com/AdguardTeam/AdGuardHome/internal/util" "github.com/AdguardTeam/golibs/log" )
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/querylog_search.go
entries = make([]*logEntry, 0) oldest = time.Time{} } } if len(entries) == totalLimit { // change the "oldest" value here. // we cannot use the "oldest" we got from "searchFiles" anymore // because after adding in-memory records and removing extra records // the situation has changed oldest = entries[len(entries)-1].Time } log.Debug("QueryLog: prepared data (%d/%d) older than %s in %s", len(entries), total, params.olderThan, time.Since(now))
</s> remove return nil </s> add return err </s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove var startLine = int64(0) </s> add startLine := int64(0)
if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer.
entries = make([]*logEntry, 0) oldest = time.Time{} } } if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer. if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer. if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer. if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer. if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer. oldest = entries[len(entries)-1].Time } log.Debug("QueryLog: prepared data (%d/%d) older than %s in %s", len(entries), total, params.olderThan, time.Since(now))
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/querylog_search.go
// The one that was specified in the "oldest" param is not needed, // we need only the one next to it _, err = r.ReadNext() } } if err != nil {
</s> remove if err == nil { // Our search is finished, we found the element we were looking for // Update currentFile only, position is already set properly in the QLogFile </s> add if err == nil || errors.Is(err, ErrEndOfLog) { // Our search is finished, and we either found the // element we were looking for or reached the end of the // log. Update currentFile only, position is already // set properly in QLogFile. </s> remove return nil </s> add return err </s> remove f, err := os.OpenFile(path, os.O_RDONLY, 0644) </s> add f, err := os.OpenFile(path, os.O_RDONLY, 0o644) </s> remove if len(entries) == totalLimit { // change the "oldest" value here. // we cannot use the "oldest" we got from "searchFiles" anymore // because after adding in-memory records and removing extra records // the situation has changed </s> add if len(entries) > 0 && len(entries) <= totalLimit { // Update oldest after merging in the memory buffer. </s> remove // ErrSeekNotFound is returned from the Seek method // if we failed to find the desired record var ErrSeekNotFound = errors.New("Seek not found the record") </s> add // ErrSeekNotFound is returned from Seek if when it fails to find the requested // record. const ErrSeekNotFound agherr.Error = "seek: record not found" // ErrEndOfLog is returned from Seek when the end of the current log is reached. const ErrEndOfLog agherr.Error = "seek: end of log"
} else if errors.Is(err, ErrEndOfLog) { // We've reached the end of the log. return entries, time.Time{}, 0
// The one that was specified in the "oldest" param is not needed, // we need only the one next to it _, err = r.ReadNext() } else if errors.Is(err, ErrEndOfLog) { // We've reached the end of the log. return entries, time.Time{}, 0 } } if err != nil {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
Pull request: * querylog: fix end of log handling Merge in DNS/adguard-home from 2229-query-log to master Closes #2229. Squashed commit of the following: commit 32508a3f3b1e098869e1649a2774f1f17d14d41f Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 16:51:25 2020 +0300 * querylog: add test commit 774159cc313a0284a8bb8327489671e5d7a3e4eb Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:26:26 2020 +0300 * querylog: better errors commit 27b13a4dcaff9e8f9b08aec81c0c03f62ebd3fa5 Author: Ainar Garipov <[email protected]> Date: Tue Nov 10 15:18:51 2020 +0300 * querylog: fix end of log handling
https://github.com/AdguardTeam/AdGuardHome/commit/13f708b483470b2002df1f2ceb35ef95ff400e86
internal/querylog/querylog_search.go
return rm.engine.MatchRequest(req) } // Translate returns the source hosts-syntax rule for the generated dnsrewrite // rule or an empty string if the last doesn't exist. func (rm *requestMatcher) Translate(rule string) (hostRule string) { rm.stateLock.RLock() defer rm.stateLock.RUnlock() return rm.translator[rule]
</s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) { </s> remove // writeMainHostRule writes the actual rule for the qtype and the PTR for the </s> add // writeMainRule writes the actual rule for the qtype and the PTR for the </s> remove // writeAliasHostRule writes the CNAME rule for the alias-host pair into // internal builders. func (hp *hostsParser) writeAliasHostRule(alias, host string) { </s> add // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) { </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
// rule or an empty string if the last doesn't exist. The returned rules are in // a processed format like: // // ip host1 host2 ... //
return rm.engine.MatchRequest(req) } // Translate returns the source hosts-syntax rule for the generated dnsrewrite // rule or an empty string if the last doesn't exist. The returned rules are in // a processed format like: // // ip host1 host2 ... // func (rm *requestMatcher) Translate(rule string) (hostRule string) { rm.stateLock.RLock() defer rm.stateLock.RUnlock() return rm.translator[rule]
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
if !errors.Is(err, fs.ErrNotExist) { return nil, fmt.Errorf("adding path: %w", err) } log.Debug("%s: file %q expected to exist but doesn't", hostsContainerPref, p) } } go hc.handleEvents()
</s> remove log.Debug("%s: no updates detected", hostsContainerPref) </s> add log.Debug("%s: no changes detected", hostsContainerPref) </s> remove hc.resetEng(rulesStrg, hp.translations) </s> add hc.resetEng(rulesStrg, hp.translations()) </s> remove // Since the hostAlias couldn't be returned from add before the // hostMain the mainHost shouldn't appear empty. hp.writeAliasHostRule(host, mainHost) </s> add hp.writeAliasRule(host, mainHost) </s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add </s> remove // writeAliasHostRule writes the CNAME rule for the alias-host pair into // internal builders. func (hp *hostsParser) writeAliasHostRule(alias, host string) { </s> add // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) {
log.Debug("%s: %s is expected to exist but doesn't", hostsContainerPref, p)
if !errors.Is(err, fs.ErrNotExist) { return nil, fmt.Errorf("adding path: %w", err) } log.Debug("%s: %s is expected to exist but doesn't", hostsContainerPref, p) } } go hc.handleEvents()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
return nil } // Upd returns the channel into which the updates are sent. The receivable // map's values are guaranteed to be of type of *stringutil.Set. func (hc *HostsContainer) Upd() (updates <-chan *netutil.IPMap) { return hc.updates } // pathsToPatterns converts paths into patterns compatible with fs.Glob.
</s> remove // handleEvents concurrently handles the events. It closes the update channel // of HostsContainer when finishes. Used to be called within a goroutine. </s> add // handleEvents concurrently handles the file system events. It closes the // update channel of HostsContainer when finishes. It's used to be called // within a separate goroutine. </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove // rule or an empty string if the last doesn't exist. </s> add // rule or an empty string if the last doesn't exist. The returned rules are in // a processed format like: // // ip host1 host2 ... // </s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) {
// map's values are guaranteed to be of type of *aghnet.Hosts.
return nil } // Upd returns the channel into which the updates are sent. The receivable // map's values are guaranteed to be of type of *aghnet.Hosts. func (hc *HostsContainer) Upd() (updates <-chan *netutil.IPMap) { return hc.updates } // pathsToPatterns converts paths into patterns compatible with fs.Glob.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
return patterns, nil } // handleEvents concurrently handles the events. It closes the update channel // of HostsContainer when finishes. Used to be called within a goroutine. func (hc *HostsContainer) handleEvents() { defer log.OnPanic(fmt.Sprintf("%s: handling events", hostsContainerPref)) defer close(hc.updates)
</s> remove // map's values are guaranteed to be of type of *stringutil.Set. </s> add // map's values are guaranteed to be of type of *aghnet.Hosts. </s> remove log.Debug("%s: no updates detected", hostsContainerPref) </s> add log.Debug("%s: no changes detected", hostsContainerPref) </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove // rule or an empty string if the last doesn't exist. </s> add // rule or an empty string if the last doesn't exist. The returned rules are in // a processed format like: // // ip host1 host2 ... //
// handleEvents concurrently handles the file system events. It closes the // update channel of HostsContainer when finishes. It's used to be called // within a separate goroutine.
return patterns, nil } // handleEvents concurrently handles the file system events. It closes the // update channel of HostsContainer when finishes. It's used to be called // within a separate goroutine. // handleEvents concurrently handles the file system events. It closes the // update channel of HostsContainer when finishes. It's used to be called // within a separate goroutine. func (hc *HostsContainer) handleEvents() { defer log.OnPanic(fmt.Sprintf("%s: handling events", hostsContainerPref)) defer close(hc.updates)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
} // hostsParser is a helper type to parse rules from the operating system's hosts // file. It exists for only a single refreshing session. type hostsParser struct { // rulesBuilder builds the resulting rules list content. rulesBuilder *strings.Builder
</s> remove // rulesBuilder builds the resulting rulesBuilder list content. </s> add // rulesBuilder builds the resulting rules list content. </s> remove // translations maps generated $dnsrewrite rules to the hosts-translations // rules. translations map[string]string </s> add // rules stores the rules for main hosts to generate translations. rules []ipRules </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove hosts.Add(host) return hostAlias </s> add // This is a duplicate. Go on.
// ipRules is the pair of generated A/AAAA and PTR rules with related IP. type ipRules struct { // rule is the A/AAAA $dnsrewrite rule. rule string // rulePtr is the PTR $dnsrewrite rule. rulePtr string // ip is the IP address related to the rules. ip net.IP }
} // ipRules is the pair of generated A/AAAA and PTR rules with related IP. type ipRules struct { // rule is the A/AAAA $dnsrewrite rule. rule string // rulePtr is the PTR $dnsrewrite rule. rulePtr string // ip is the IP address related to the rules. ip net.IP } // hostsParser is a helper type to parse rules from the operating system's hosts // file. It exists for only a single refreshing session. type hostsParser struct { // rulesBuilder builds the resulting rules list content. rulesBuilder *strings.Builder
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// hostsParser is a helper type to parse rules from the operating system's hosts // file. It exists for only a single refreshing session. type hostsParser struct { // rulesBuilder builds the resulting rulesBuilder list content. rulesBuilder *strings.Builder // translations maps generated $dnsrewrite rules to the hosts-translations // rules. translations map[string]string
</s> remove // translations maps generated $dnsrewrite rules to the hosts-translations // rules. translations map[string]string </s> add // rules stores the rules for main hosts to generate translations. rules []ipRules </s> remove // cnameSet prevents duplicating cname rules. </s> add // cnameSet prevents duplicating cname rules, e.g. same hostname for // different IP versions. </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) }
// rulesBuilder builds the resulting rules list content.
// hostsParser is a helper type to parse rules from the operating system's hosts // file. It exists for only a single refreshing session. type hostsParser struct { // rulesBuilder builds the resulting rules list content. rulesBuilder *strings.Builder // translations maps generated $dnsrewrite rules to the hosts-translations // rules. translations map[string]string
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
type hostsParser struct { // rulesBuilder builds the resulting rulesBuilder list content. rulesBuilder *strings.Builder // translations maps generated $dnsrewrite rules to the hosts-translations // rules. translations map[string]string // cnameSet prevents duplicating cname rules. cnameSet *stringutil.Set // table stores only the unique IP-hostname pairs. It's also sent to the
</s> remove // cnameSet prevents duplicating cname rules. </s> add // cnameSet prevents duplicating cname rules, e.g. same hostname for // different IP versions. </s> remove // rulesBuilder builds the resulting rulesBuilder list content. </s> add // rulesBuilder builds the resulting rules list content. </s> remove // appropriate hosts set isn't equal to the checked one, i.e. the maps // have at least one discrepancy. ok = !hasIP || !v.(*stringutil.Set).Equal(val.(*stringutil.Set)) </s> add // appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) } </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) }
// rules stores the rules for main hosts to generate translations. rules []ipRules
type hostsParser struct { // rulesBuilder builds the resulting rulesBuilder list content. rulesBuilder *strings.Builder // rules stores the rules for main hosts to generate translations. rules []ipRules // rules stores the rules for main hosts to generate translations. rules []ipRules // rules stores the rules for main hosts to generate translations. rules []ipRules // cnameSet prevents duplicating cname rules. cnameSet *stringutil.Set // table stores only the unique IP-hostname pairs. It's also sent to the
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// translations maps generated $dnsrewrite rules to the hosts-translations // rules. translations map[string]string // cnameSet prevents duplicating cname rules. cnameSet *stringutil.Set // table stores only the unique IP-hostname pairs. It's also sent to the // updates channel afterwards. table *netutil.IPMap
</s> remove // translations maps generated $dnsrewrite rules to the hosts-translations // rules. translations map[string]string </s> add // rules stores the rules for main hosts to generate translations. rules []ipRules </s> remove // rulesBuilder builds the resulting rulesBuilder list content. </s> add // rulesBuilder builds the resulting rules list content. </s> remove // handleEvents concurrently handles the events. It closes the update channel // of HostsContainer when finishes. Used to be called within a goroutine. </s> add // handleEvents concurrently handles the file system events. It closes the // update channel of HostsContainer when finishes. It's used to be called // within a separate goroutine.
// cnameSet prevents duplicating cname rules, e.g. same hostname for // different IP versions.
// translations maps generated $dnsrewrite rules to the hosts-translations // rules. translations map[string]string // cnameSet prevents duplicating cname rules, e.g. same hostname for // different IP versions. cnameSet *stringutil.Set // table stores only the unique IP-hostname pairs. It's also sent to the // updates channel afterwards. table *netutil.IPMap
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// updates channel afterwards. table *netutil.IPMap } func (hc *HostsContainer) newHostsParser() (hp *hostsParser) { lastLen := hc.last.Len() return &hostsParser{ rulesBuilder: &strings.Builder{},
</s> remove // For A/AAAA and PTRs. translations: make(map[string]string, hc.last.Len()*2), </s> add rules: make([]ipRules, 0, lastLen), </s> remove // cnameSet prevents duplicating cname rules. </s> add // cnameSet prevents duplicating cname rules, e.g. same hostname for // different IP versions. </s> remove // map's values are guaranteed to be of type of *stringutil.Set. </s> add // map's values are guaranteed to be of type of *aghnet.Hosts. </s> remove // handleEvents concurrently handles the events. It closes the update channel // of HostsContainer when finishes. Used to be called within a goroutine. </s> add // handleEvents concurrently handles the file system events. It closes the // update channel of HostsContainer when finishes. It's used to be called // within a separate goroutine.
// newHostsParser creates a new *hostsParser with buffers of size taken from the // previous parse.
// updates channel afterwards. table *netutil.IPMap } // newHostsParser creates a new *hostsParser with buffers of size taken from the // previous parse. func (hc *HostsContainer) newHostsParser() (hp *hostsParser) { lastLen := hc.last.Len() return &hostsParser{ rulesBuilder: &strings.Builder{},
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// previous parse. func (hc *HostsContainer) newHostsParser() (hp *hostsParser) { return &hostsParser{ rulesBuilder: &strings.Builder{}, rules: make([]ipRules, 0, lastLen), cnameSet: stringutil.NewSet(), table: netutil.NewIPMap(lastLen), }
</s> remove // For A/AAAA and PTRs. translations: make(map[string]string, hc.last.Len()*2), </s> add rules: make([]ipRules, 0, lastLen), </s> remove table: netutil.NewIPMap(hc.last.Len()), </s> add table: netutil.NewIPMap(lastLen), </s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) { </s> remove // map's values are guaranteed to be of type of *stringutil.Set. </s> add // map's values are guaranteed to be of type of *aghnet.Hosts.
lastLen := hc.last.Len()
// previous parse. func (hc *HostsContainer) newHostsParser() (hp *hostsParser) { lastLen := hc.last.Len() return &hostsParser{ rulesBuilder: &strings.Builder{}, rules: make([]ipRules, 0, lastLen), cnameSet: stringutil.NewSet(), table: netutil.NewIPMap(lastLen), }
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
func (hc *HostsContainer) newHostsParser() (hp *hostsParser) { return &hostsParser{ rulesBuilder: &strings.Builder{}, // For A/AAAA and PTRs. translations: make(map[string]string, hc.last.Len()*2), cnameSet: stringutil.NewSet(), table: netutil.NewIPMap(hc.last.Len()), } }
</s> remove table: netutil.NewIPMap(hc.last.Len()), </s> add table: netutil.NewIPMap(lastLen), </s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) {
rules: make([]ipRules, 0, lastLen),
func (hc *HostsContainer) newHostsParser() (hp *hostsParser) { return &hostsParser{ rulesBuilder: &strings.Builder{}, rules: make([]ipRules, 0, lastLen), rules: make([]ipRules, 0, lastLen), cnameSet: stringutil.NewSet(), table: netutil.NewIPMap(hc.last.Len()), } }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
rulesBuilder: &strings.Builder{}, // For A/AAAA and PTRs. translations: make(map[string]string, hc.last.Len()*2), cnameSet: stringutil.NewSet(), table: netutil.NewIPMap(hc.last.Len()), } } // parseFile is a aghos.FileWalker for parsing the files with hosts syntax. It // never signs to stop walking and never returns any additional patterns.
</s> remove // For A/AAAA and PTRs. translations: make(map[string]string, hc.last.Len()*2), </s> add rules: make([]ipRules, 0, lastLen), </s> remove func (hp *hostsParser) parseFile( r io.Reader, ) (patterns []string, cont bool, err error) { </s> add func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) { </s> remove hosts.Add(host) return hostAlias </s> add // This is a duplicate. Go on.
table: netutil.NewIPMap(lastLen),
rulesBuilder: &strings.Builder{}, // For A/AAAA and PTRs. translations: make(map[string]string, hc.last.Len()*2), cnameSet: stringutil.NewSet(), table: netutil.NewIPMap(lastLen), } } // parseFile is a aghos.FileWalker for parsing the files with hosts syntax. It // never signs to stop walking and never returns any additional patterns.
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// parseFile is a aghos.FileWalker for parsing the files with hosts syntax. It // never signs to stop walking and never returns any additional patterns. // // See man hosts(5). func (hp *hostsParser) parseFile( r io.Reader, ) (patterns []string, cont bool, err error) { s := bufio.NewScanner(r) for s.Scan() { ip, hosts := hp.parseLine(s.Text()) if ip == nil || len(hosts) == 0 { continue
</s> remove table: netutil.NewIPMap(hc.last.Len()), </s> add table: netutil.NewIPMap(lastLen), </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) { </s> remove switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain </s> add switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main </s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) {
func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) {
// parseFile is a aghos.FileWalker for parsing the files with hosts syntax. It // never signs to stop walking and never returns any additional patterns. // // See man hosts(5). func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) { func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) { func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) { s := bufio.NewScanner(r) for s.Scan() { ip, hosts := hp.parseLine(s.Text()) if ip == nil || len(hosts) == 0 { continue
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
return ip, hosts } // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) // add tries to add the ip-host pair. It returns: // // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip.
</s> remove // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. </s> add // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added. </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) { </s> remove hosts.Add(host) return hostAlias </s> add // This is a duplicate. Go on. </s> remove switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain </s> add switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main </s> remove // Since the hostAlias couldn't be returned from add before the // hostMain the mainHost shouldn't appear empty. hp.writeAliasHostRule(host, mainHost) </s> add hp.writeAliasRule(host, mainHost)
// Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) }
return ip, hosts } // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } // add tries to add the ip-host pair. It returns: // // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
) // add tries to add the ip-host pair. It returns: // // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. // func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { v, ok := hp.table.Get(ip) switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host):
</s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) { </s> remove switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain </s> add switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove // Since the hostAlias couldn't be returned from add before the // hostMain the mainHost shouldn't appear empty. hp.writeAliasHostRule(host, mainHost) </s> add hp.writeAliasRule(host, mainHost)
// main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added.
) // add tries to add the ip-host pair. It returns: // // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added. // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added. // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added. // func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { v, ok := hp.table.Get(ip) switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host):
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. // func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { v, ok := hp.table.Get(ip) switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil:
</s> remove // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. </s> add // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added. </s> remove switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain </s> add switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove // Put the rule in a processed format like: // // ip host1 host2 ... // hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string </s> add
func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
// hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. // func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) { v, ok := hp.table.Get(ip) switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil:
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// 0 if the ip-host pair has already been added. // func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { v, ok := hp.table.Get(ip) switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain default: hosts.Add(host) return hostAlias }
</s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) { </s> remove // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. </s> add // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added. </s> remove hosts.Add(host) return hostAlias </s> add // This is a duplicate. Go on. </s> remove case hostMain: mainHost = host added, addedPtr := hp.writeMainHostRule(host, ip) hp.translations[added], hp.translations[addedPtr] = hostsLine, hostsLine case hostAlias: </s> add case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. </s> remove names, ok := v.(*stringutil.Set) </s> add hosts, ok := v.(*aghnet.Hosts)
switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main
// 0 if the ip-host pair has already been added. // func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { v, ok := hp.table.Get(ip) switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main default: hosts.Add(host) return hostAlias }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
hp.table.Set(ip, hosts) return hostMain default: hosts.Add(host) return hostAlias } } // addPair puts the pair of ip and host to the rules builder if needed. For // each ip the first member of hosts will become the main one.
</s> remove // Put the rule in a processed format like: // // ip host1 host2 ... // hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string </s> add </s> remove switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain </s> add switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) }
// This is a duplicate. Go on.
hp.table.Set(ip, hosts) return hostMain default: // This is a duplicate. Go on. // This is a duplicate. Go on. // This is a duplicate. Go on. } } // addPair puts the pair of ip and host to the rules builder if needed. For // each ip the first member of hosts will become the main one.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
default: // This is a duplicate. Go on. } } // addPair puts the pair of ip and host to the rules builder if needed. For // each ip the first member of hosts will become the main one. func (hp *hostsParser) addPairs(ip net.IP, hosts []string) { for _, host := range hosts {
</s> remove hosts.Add(host) return hostAlias </s> add // This is a duplicate. Go on. </s> remove // Put the rule in a processed format like: // // ip host1 host2 ... // hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string </s> add </s> remove switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain </s> add switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) { </s> remove // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. </s> add // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added.
return ""
default: // This is a duplicate. Go on. } return "" } // addPair puts the pair of ip and host to the rules builder if needed. For // each ip the first member of hosts will become the main one. func (hp *hostsParser) addPairs(ip net.IP, hosts []string) { for _, host := range hosts {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// addPair puts the pair of ip and host to the rules builder if needed. For // each ip the first member of hosts will become the main one. func (hp *hostsParser) addPairs(ip net.IP, hosts []string) { // Put the rule in a processed format like: // // ip host1 host2 ... // hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string for _, host := range hosts { switch hp.add(ip, host) { case 0: continue case hostMain:
</s> remove switch hp.add(ip, host) { case 0: </s> add switch mainHost := hp.add(ip, host); mainHost { case "": // This host is a duplicate. </s> remove hosts.Add(host) return hostAlias </s> add // This is a duplicate. Go on. </s> remove case hostMain: mainHost = host added, addedPtr := hp.writeMainHostRule(host, ip) hp.translations[added], hp.translations[addedPtr] = hostsLine, hostsLine case hostAlias: </s> add case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. </s> remove // rule or an empty string if the last doesn't exist. </s> add // rule or an empty string if the last doesn't exist. The returned rules are in // a processed format like: // // ip host1 host2 ... //
// addPair puts the pair of ip and host to the rules builder if needed. For // each ip the first member of hosts will become the main one. func (hp *hostsParser) addPairs(ip net.IP, hosts []string) { for _, host := range hosts { switch hp.add(ip, host) { case 0: continue case hostMain:
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
// hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string for _, host := range hosts { switch hp.add(ip, host) { case 0: continue case hostMain: mainHost = host added, addedPtr := hp.writeMainHostRule(host, ip) hp.translations[added], hp.translations[addedPtr] = hostsLine, hostsLine
</s> remove case hostMain: mainHost = host added, addedPtr := hp.writeMainHostRule(host, ip) hp.translations[added], hp.translations[addedPtr] = hostsLine, hostsLine case hostAlias: </s> add case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. </s> remove // Put the rule in a processed format like: // // ip host1 host2 ... // hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string </s> add </s> remove switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain </s> add switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) { </s> remove // Since the hostAlias couldn't be returned from add before the // hostMain the mainHost shouldn't appear empty. hp.writeAliasHostRule(host, mainHost) </s> add hp.writeAliasRule(host, mainHost)
switch mainHost := hp.add(ip, host); mainHost { case "": // This host is a duplicate.
// hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string for _, host := range hosts { switch mainHost := hp.add(ip, host); mainHost { case "": // This host is a duplicate. switch mainHost := hp.add(ip, host); mainHost { case "": // This host is a duplicate. continue case hostMain: mainHost = host added, addedPtr := hp.writeMainHostRule(host, ip) hp.translations[added], hp.translations[addedPtr] = hostsLine, hostsLine
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
for _, host := range hosts { switch hp.add(ip, host) { case 0: continue case hostMain: mainHost = host added, addedPtr := hp.writeMainHostRule(host, ip) hp.translations[added], hp.translations[addedPtr] = hostsLine, hostsLine case hostAlias: pair := fmt.Sprint(host, " ", mainHost) if hp.cnameSet.Has(pair) { continue } // Since the hostAlias couldn't be returned from add before the
</s> remove switch hp.add(ip, host) { case 0: </s> add switch mainHost := hp.add(ip, host); mainHost { case "": // This host is a duplicate. </s> remove // Since the hostAlias couldn't be returned from add before the // hostMain the mainHost shouldn't appear empty. hp.writeAliasHostRule(host, mainHost) </s> add hp.writeAliasRule(host, mainHost) </s> remove // Put the rule in a processed format like: // // ip host1 host2 ... // hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string </s> add </s> remove switch hosts, _ := v.(*stringutil.Set); { case ok && hosts.Has(host): return 0 case hosts == nil: hosts = stringutil.NewSet(host) hp.table.Set(ip, hosts) return hostMain </s> add switch h, _ := v.(*Hosts); { case !ok: // This is the first host for the ip. hp.table.Set(ip, &Hosts{Main: host}) return host case h.Main == host: // This is a duplicate. Go on. case h.Aliases == nil: // This is the first alias. h.Aliases = stringutil.NewSet(host) return h.Main case !h.Aliases.Has(host): // This is a new alias. h.Aliases.Add(host) return h.Main </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias.
for _, host := range hosts { switch hp.add(ip, host) { case 0: continue case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. pair := fmt.Sprint(host, " ", mainHost) if hp.cnameSet.Has(pair) { continue } // Since the hostAlias couldn't be returned from add before the
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
pair := fmt.Sprint(host, " ", mainHost) if hp.cnameSet.Has(pair) { continue } // Since the hostAlias couldn't be returned from add before the // hostMain the mainHost shouldn't appear empty. hp.writeAliasHostRule(host, mainHost) hp.cnameSet.Add(pair) } log.Debug("%s: added ip-host pair %q-%q", hostsContainerPref, ip, host) }
</s> remove case hostMain: mainHost = host added, addedPtr := hp.writeMainHostRule(host, ip) hp.translations[added], hp.translations[addedPtr] = hostsLine, hostsLine case hostAlias: </s> add case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias. </s> remove // writeAliasHostRule writes the CNAME rule for the alias-host pair into // internal builders. func (hp *hostsParser) writeAliasHostRule(alias, host string) { </s> add // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) { </s> remove // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. </s> add // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added. </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
hp.writeAliasRule(host, mainHost)
pair := fmt.Sprint(host, " ", mainHost) if hp.cnameSet.Has(pair) { continue } hp.writeAliasRule(host, mainHost) hp.writeAliasRule(host, mainHost) hp.writeAliasRule(host, mainHost) hp.cnameSet.Add(pair) } log.Debug("%s: added ip-host pair %q-%q", hostsContainerPref, ip, host) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
log.Debug("%s: added ip-host pair %q-%q", hostsContainerPref, ip, host) } } // writeAliasHostRule writes the CNAME rule for the alias-host pair into // internal builders. func (hp *hostsParser) writeAliasHostRule(alias, host string) { const ( nl = "\n" sc = ";" rwSuccess = rules.MaskSeparator + "$dnsrewrite=NOERROR" + sc + "CNAME" + sc
</s> remove // writeMainHostRule writes the actual rule for the qtype and the PTR for the </s> add // writeMainRule writes the actual rule for the qtype and the PTR for the </s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) { </s> remove // Since the hostAlias couldn't be returned from add before the // hostMain the mainHost shouldn't appear empty. hp.writeAliasHostRule(host, mainHost) </s> add hp.writeAliasRule(host, mainHost) </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) { </s> remove // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. </s> add // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added.
// writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) {
log.Debug("%s: added ip-host pair %q-%q", hostsContainerPref, ip, host) } } // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) { // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) { // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) { const ( nl = "\n" sc = ";" rwSuccess = rules.MaskSeparator + "$dnsrewrite=NOERROR" + sc + "CNAME" + sc
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
hp.rulesBuilder.Grow(constLen + len(host) + len(alias)) stringutil.WriteToBuilder(hp.rulesBuilder, rules.MaskPipe, alias, rwSuccess, host, nl) } // writeMainHostRule writes the actual rule for the qtype and the PTR for the // host-ip pair into internal builders. func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { arpa, err := netutil.IPToReversedAddr(ip) if err != nil { return
</s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) { </s> remove // writeAliasHostRule writes the CNAME rule for the alias-host pair into // internal builders. func (hp *hostsParser) writeAliasHostRule(alias, host string) { </s> add // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) { </s> remove func (hp *hostsParser) parseFile( r io.Reader, ) (patterns []string, cont bool, err error) { </s> add func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) { </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
// writeMainRule writes the actual rule for the qtype and the PTR for the
hp.rulesBuilder.Grow(constLen + len(host) + len(alias)) stringutil.WriteToBuilder(hp.rulesBuilder, rules.MaskPipe, alias, rwSuccess, host, nl) } // writeMainRule writes the actual rule for the qtype and the PTR for the // host-ip pair into internal builders. func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { arpa, err := netutil.IPToReversedAddr(ip) if err != nil { return
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
} // writeMainHostRule writes the actual rule for the qtype and the PTR for the // host-ip pair into internal builders. func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { arpa, err := netutil.IPToReversedAddr(ip) if err != nil { return }
</s> remove // writeMainHostRule writes the actual rule for the qtype and the PTR for the </s> add // writeMainRule writes the actual rule for the qtype and the PTR for the </s> remove // writeAliasHostRule writes the CNAME rule for the alias-host pair into // internal builders. func (hp *hostsParser) writeAliasHostRule(alias, host string) { </s> add // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) { </s> remove func (hp *hostsParser) parseFile( r io.Reader, ) (patterns []string, cont bool, err error) { </s> add func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) { </s> remove hc.resetEng(rulesStrg, hp.translations) </s> add hc.resetEng(rulesStrg, hp.translations())
func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) {
} // writeMainHostRule writes the actual rule for the qtype and the PTR for the // host-ip pair into internal builders. func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) { arpa, err := netutil.IPToReversedAddr(ip) if err != nil { return }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
if hp.table.Len() != target.Len() { return false } hp.table.Range(func(ip net.IP, val interface{}) (cont bool) { v, hasIP := target.Get(ip) // ok is set to true if the target doesn't contain ip or if the // appropriate hosts set isn't equal to the checked one, i.e. the maps // have at least one discrepancy. ok = !hasIP || !v.(*stringutil.Set).Equal(val.(*stringutil.Set))
</s> remove // appropriate hosts set isn't equal to the checked one, i.e. the maps // have at least one discrepancy. ok = !hasIP || !v.(*stringutil.Set).Equal(val.(*stringutil.Set)) </s> add // appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) } </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove names, ok := v.(*stringutil.Set) </s> add hosts, ok := v.(*aghnet.Hosts) </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
hp.table.Range(func(ip net.IP, b interface{}) (cont bool) {
if hp.table.Len() != target.Len() { return false } hp.table.Range(func(ip net.IP, b interface{}) (cont bool) { hp.table.Range(func(ip net.IP, b interface{}) (cont bool) { // ok is set to true if the target doesn't contain ip or if the // appropriate hosts set isn't equal to the checked one, i.e. the maps // have at least one discrepancy. ok = !hasIP || !v.(*stringutil.Set).Equal(val.(*stringutil.Set))
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
hp.table.Range(func(ip net.IP, val interface{}) (cont bool) { v, hasIP := target.Get(ip) // ok is set to true if the target doesn't contain ip or if the // appropriate hosts set isn't equal to the checked one, i.e. the maps // have at least one discrepancy. ok = !hasIP || !v.(*stringutil.Set).Equal(val.(*stringutil.Set)) // Continue only if maps has no discrepancies. return !ok })
</s> remove hp.table.Range(func(ip net.IP, val interface{}) (cont bool) { v, hasIP := target.Get(ip) </s> add hp.table.Range(func(ip net.IP, b interface{}) (cont bool) { </s> remove names, ok := v.(*stringutil.Set) </s> add hosts, ok := v.(*aghnet.Hosts) </s> remove // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. </s> add // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added. </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
// appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) }
hp.table.Range(func(ip net.IP, val interface{}) (cont bool) { v, hasIP := target.Get(ip) // ok is set to true if the target doesn't contain ip or if the // appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) } // appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) } // appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) } // Continue only if maps has no discrepancies. return !ok })
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
return fmt.Errorf("refreshing : %w", err) } if hp.equalSet(hc.last) { log.Debug("%s: no updates detected", hostsContainerPref) return nil } defer hp.sendUpd(hc.updates)
</s> remove hc.resetEng(rulesStrg, hp.translations) </s> add hc.resetEng(rulesStrg, hp.translations()) </s> remove log.Debug("%s: file %q expected to exist but doesn't", hostsContainerPref, p) </s> add log.Debug("%s: %s is expected to exist but doesn't", hostsContainerPref, p) </s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add </s> remove // map's values are guaranteed to be of type of *stringutil.Set. </s> add // map's values are guaranteed to be of type of *aghnet.Hosts. </s> remove // handleEvents concurrently handles the events. It closes the update channel // of HostsContainer when finishes. Used to be called within a goroutine. </s> add // handleEvents concurrently handles the file system events. It closes the // update channel of HostsContainer when finishes. It's used to be called // within a separate goroutine.
log.Debug("%s: no changes detected", hostsContainerPref)
return fmt.Errorf("refreshing : %w", err) } if hp.equalSet(hc.last) { log.Debug("%s: no changes detected", hostsContainerPref) return nil } defer hp.sendUpd(hc.updates)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
if rulesStrg, err = hp.newStrg(hc.listID); err != nil { return fmt.Errorf("initializing rules storage: %w", err) } hc.resetEng(rulesStrg, hp.translations) return nil }
</s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add </s> remove log.Debug("%s: no updates detected", hostsContainerPref) </s> add log.Debug("%s: no changes detected", hostsContainerPref) </s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) { </s> remove // writeMainHostRule writes the actual rule for the qtype and the PTR for the </s> add // writeMainRule writes the actual rule for the qtype and the PTR for the </s> remove log.Debug("%s: file %q expected to exist but doesn't", hostsContainerPref, p) </s> add log.Debug("%s: %s is expected to exist but doesn't", hostsContainerPref, p)
hc.resetEng(rulesStrg, hp.translations())
if rulesStrg, err = hp.newStrg(hc.listID); err != nil { return fmt.Errorf("initializing rules storage: %w", err) } hc.resetEng(rulesStrg, hp.translations()) return nil }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer.go
"strings" "sync/atomic" "testing" "testing/fstest" "github.com/AdguardTeam/AdGuardHome/internal/aghtest" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/stringutil" "github.com/AdguardTeam/urlfilter" "github.com/AdguardTeam/urlfilter/rules"
</s> remove names.Range(func(name string) (cont bool) { </s> add if clients.addHostLocked(ip, hosts.Main, ClientSourceHostsFile) { n++ } hosts.Aliases.Range(func(name string) (cont bool) { </s> remove func (hp *hostsParser) writeMainHostRule(host string, ip net.IP) (added, addedPtr string) { </s> add func (hp *hostsParser) writeMainRule(host string, ip net.IP) (added, addedPtr string) { </s> remove // Put the rule in a processed format like: // // ip host1 host2 ... // hostsLine := strings.Join(append([]string{ip.String()}, hosts...), " ") var mainHost string </s> add </s> remove switch hp.add(ip, host) { case 0: </s> add switch mainHost := hp.add(ip, host); mainHost { case "": // This host is a duplicate. </s> remove case hostMain: mainHost = host added, addedPtr := hp.writeMainHostRule(host, ip) hp.translations[added], hp.translations[addedPtr] = hostsLine, hostsLine case hostAlias: </s> add case host: // This host is main. added, addedPtr := hp.writeMainRule(host, ip) hp.rules = append(hp.rules, ipRules{ rule: added, rulePtr: addedPtr, ip: ip, }) default: // This host is an alias.
"time"
"strings" "sync/atomic" "testing" "testing/fstest" "time" "github.com/AdguardTeam/AdGuardHome/internal/aghtest" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/stringutil" "github.com/AdguardTeam/urlfilter" "github.com/AdguardTeam/urlfilter/rules"
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
assert.Nil(t, hc) }) } func TestHostsContainer_Refresh(t *testing.T) { knownIP := net.IP{127, 0, 0, 1} const knownHost = "localhost" const knownAlias = "hocallost" const dirname = "dir"
</s> remove const knownHost = "localhost" const knownAlias = "hocallost" </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String() </s> remove const ( hostname = "localhost" alias = "hocallost" ) knownIP := net.IP{127, 0, 0, 1} </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String() </s> remove const dirname = "dir" const filename1 = "file1" const filename2 = "file2" p1 := path.Join(dirname, filename1) p2 := path.Join(dirname, filename2) testFS := fstest.MapFS{ p1: &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownHost}, sp) + nl), }, } </s> add testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} </s> remove const ( dir0 = "dir" dir1 = "dir_1" fn1 = "file_1" fn2 = "file_2" fn3 = "file_3" fn4 = "file_4" ) fp1 := path.Join(dir0, fn1) fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) </s> add </s> remove t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) </s> add return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1)
func TestHostsContainer_refresh(t *testing.T) { // TODO(e.burkov): Test the case with no actual updates.
assert.Nil(t, hc) }) } func TestHostsContainer_refresh(t *testing.T) { // TODO(e.burkov): Test the case with no actual updates. func TestHostsContainer_refresh(t *testing.T) { // TODO(e.burkov): Test the case with no actual updates. const knownHost = "localhost" const knownAlias = "hocallost" const dirname = "dir"
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
func TestHostsContainer_Refresh(t *testing.T) { knownIP := net.IP{127, 0, 0, 1} const knownHost = "localhost" const knownAlias = "hocallost" const dirname = "dir" const filename1 = "file1" const filename2 = "file2"
</s> remove func TestHostsContainer_Refresh(t *testing.T) { knownIP := net.IP{127, 0, 0, 1} </s> add func TestHostsContainer_refresh(t *testing.T) { // TODO(e.burkov): Test the case with no actual updates. </s> remove const dirname = "dir" const filename1 = "file1" const filename2 = "file2" p1 := path.Join(dirname, filename1) p2 := path.Join(dirname, filename2) testFS := fstest.MapFS{ p1: &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownHost}, sp) + nl), }, } </s> add testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} </s> remove const ( hostname = "localhost" alias = "hocallost" ) knownIP := net.IP{127, 0, 0, 1} </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String() </s> remove const ( dir0 = "dir" dir1 = "dir_1" fn1 = "file_1" fn2 = "file_2" fn3 = "file_3" fn4 = "file_4" ) fp1 := path.Join(dir0, fn1) fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) </s> add </s> remove // writeAliasHostRule writes the CNAME rule for the alias-host pair into // internal builders. func (hp *hostsParser) writeAliasHostRule(alias, host string) { </s> add // writeAliasRule writes the CNAME rule for the alias-host pair into internal // builders. func (hp *hostsParser) writeAliasRule(alias, host string) {
ip := net.IP{127, 0, 0, 1} ipStr := ip.String()
func TestHostsContainer_Refresh(t *testing.T) { knownIP := net.IP{127, 0, 0, 1} ip := net.IP{127, 0, 0, 1} ipStr := ip.String() ip := net.IP{127, 0, 0, 1} ipStr := ip.String() const dirname = "dir" const filename1 = "file1" const filename2 = "file2"
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
const knownHost = "localhost" const knownAlias = "hocallost" const dirname = "dir" const filename1 = "file1" const filename2 = "file2" p1 := path.Join(dirname, filename1) p2 := path.Join(dirname, filename2) testFS := fstest.MapFS{ p1: &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownHost}, sp) + nl), }, } // event is a convenient alias for an empty struct{} to emit test events. type event = struct{} eventsCh := make(chan event, 1)
</s> remove const knownHost = "localhost" const knownAlias = "hocallost" </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String() </s> remove func TestHostsContainer_Refresh(t *testing.T) { knownIP := net.IP{127, 0, 0, 1} </s> add func TestHostsContainer_refresh(t *testing.T) { // TODO(e.burkov): Test the case with no actual updates. </s> remove const ( hostname = "localhost" alias = "hocallost" ) knownIP := net.IP{127, 0, 0, 1} </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String() </s> remove const ( dir0 = "dir" dir1 = "dir_1" fn1 = "file_1" fn2 = "file_2" fn3 = "file_3" fn4 = "file_4" ) fp1 := path.Join(dir0, fn1) fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) </s> add </s> remove testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), } eventsCh <- event{} </s> add
testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}}
const knownHost = "localhost" const knownAlias = "hocallost" testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} // event is a convenient alias for an empty struct{} to emit test events. type event = struct{} eventsCh := make(chan event, 1)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
w := &aghtest.FSWatcher{ OnEvents: func() (e <-chan event) { return eventsCh }, OnAdd: func(name string) (err error) { assert.Equal(t, dirname, name) return nil }, OnClose: func() (err error) { panic("not implemented") }, }
</s> remove hc, err := NewHostsContainer(0, testFS, w, dirname) </s> add hc, err := NewHostsContainer(0, testFS, w, "dir") </s> remove t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) </s> add return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1) </s> remove eventsCh <- event{} </s> add t.Run("double_refresh", func(t *testing.T) { // Make a change once. testFS["dir/file1"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) </s> remove func (hp *hostsParser) parseFile( r io.Reader, ) (patterns []string, cont bool, err error) { </s> add func (hp *hostsParser) parseFile(r io.Reader) (patterns []string, cont bool, err error) {
assert.Equal(t, "dir", name)
w := &aghtest.FSWatcher{ OnEvents: func() (e <-chan event) { return eventsCh }, OnAdd: func(name string) (err error) { assert.Equal(t, "dir", name) return nil }, OnClose: func() (err error) { panic("not implemented") }, }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
}, OnClose: func() (err error) { panic("not implemented") }, } hc, err := NewHostsContainer(0, testFS, w, dirname) require.NoError(t, err) checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { upd, ok := <-hc.Upd() require.True(t, ok)
</s> remove checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { </s> add checkRefresh := func(t *testing.T, wantHosts Hosts) { </s> remove assert.Equal(t, dirname, name) </s> add assert.Equal(t, "dir", name) </s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add </s> remove v, ok := upd.Get(knownIP) </s> add v, ok := upd.Get(ip) </s> remove var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) </s> add var hosts *Hosts hosts, ok = v.(*Hosts)
hc, err := NewHostsContainer(0, testFS, w, "dir")
}, OnClose: func() (err error) { panic("not implemented") }, } hc, err := NewHostsContainer(0, testFS, w, "dir") require.NoError(t, err) checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { upd, ok := <-hc.Upd() require.True(t, ok)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
hc, err := NewHostsContainer(0, testFS, w, dirname) require.NoError(t, err) checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { upd, ok := <-hc.Upd() require.True(t, ok) require.NotNil(t, upd) assert.Equal(t, 1, upd.Len())
</s> remove hc, err := NewHostsContainer(0, testFS, w, dirname) </s> add hc, err := NewHostsContainer(0, testFS, w, "dir") </s> remove v, ok := upd.Get(knownIP) </s> add v, ok := upd.Get(ip) </s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add </s> remove var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) </s> add var hosts *Hosts hosts, ok = v.(*Hosts) </s> remove assert.True(t, hosts.Equal(wantHosts)) </s> add assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases))
checkRefresh := func(t *testing.T, wantHosts Hosts) {
hc, err := NewHostsContainer(0, testFS, w, dirname) require.NoError(t, err) checkRefresh := func(t *testing.T, wantHosts Hosts) { upd, ok := <-hc.Upd() require.True(t, ok) require.NotNil(t, upd) assert.Equal(t, 1, upd.Len())
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
require.NotNil(t, upd) assert.Equal(t, 1, upd.Len()) v, ok := upd.Get(knownIP) require.True(t, ok) var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) require.True(t, ok)
</s> remove var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) </s> add var hosts *Hosts hosts, ok = v.(*Hosts) </s> remove checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { </s> add checkRefresh := func(t *testing.T, wantHosts Hosts) { </s> remove assert.True(t, hosts.Equal(wantHosts)) </s> add assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases)) </s> remove hc, err := NewHostsContainer(0, testFS, w, dirname) </s> add hc, err := NewHostsContainer(0, testFS, w, "dir") </s> remove names, ok := v.(*stringutil.Set) </s> add hosts, ok := v.(*aghnet.Hosts)
v, ok := upd.Get(ip)
require.NotNil(t, upd) assert.Equal(t, 1, upd.Len()) v, ok := upd.Get(ip) require.True(t, ok) var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) require.True(t, ok)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
v, ok := upd.Get(knownIP) require.True(t, ok) var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) require.True(t, ok) assert.True(t, hosts.Equal(wantHosts)) }
</s> remove v, ok := upd.Get(knownIP) </s> add v, ok := upd.Get(ip) </s> remove assert.True(t, hosts.Equal(wantHosts)) </s> add assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases)) </s> remove hc, err := NewHostsContainer(0, testFS, w, dirname) </s> add hc, err := NewHostsContainer(0, testFS, w, "dir") </s> remove checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { </s> add checkRefresh := func(t *testing.T, wantHosts Hosts) { </s> remove names, ok := v.(*stringutil.Set) </s> add hosts, ok := v.(*aghnet.Hosts)
var hosts *Hosts hosts, ok = v.(*Hosts)
v, ok := upd.Get(knownIP) require.True(t, ok) var hosts *Hosts hosts, ok = v.(*Hosts) var hosts *Hosts hosts, ok = v.(*Hosts) require.True(t, ok) assert.True(t, hosts.Equal(wantHosts)) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) require.True(t, ok) assert.True(t, hosts.Equal(wantHosts)) } t.Run("initial_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost)) })
</s> remove var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) </s> add var hosts *Hosts hosts, ok = v.(*Hosts) </s> remove checkRefresh(t, stringutil.NewSet(knownHost)) </s> add checkRefresh(t, Hosts{Main: "hostname"}) </s> remove v, ok := upd.Get(knownIP) </s> add v, ok := upd.Get(ip) </s> remove testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), } eventsCh <- event{} </s> add </s> remove ip, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(ip)) </s> add got, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(got))
assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases))
var hosts *stringutil.Set hosts, ok = v.(*stringutil.Set) require.True(t, ok) assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases)) } t.Run("initial_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost)) })
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
assert.True(t, hosts.Equal(wantHosts)) } t.Run("initial_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost)) }) testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), }
</s> remove testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), } eventsCh <- event{} </s> add </s> remove assert.True(t, hosts.Equal(wantHosts)) </s> add assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases)) </s> remove const dirname = "dir" const filename1 = "file1" const filename2 = "file2" p1 := path.Join(dirname, filename1) p2 := path.Join(dirname, filename2) testFS := fstest.MapFS{ p1: &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownHost}, sp) + nl), }, } </s> add testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} </s> remove checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) </s> add testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} checkRefresh(t, Hosts{Main: "hostname", Aliases: stringutil.NewSet("alias")}) </s> remove eventsCh <- event{} </s> add t.Run("double_refresh", func(t *testing.T) { // Make a change once. testFS["dir/file1"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, })
checkRefresh(t, Hosts{Main: "hostname"})
assert.True(t, hosts.Equal(wantHosts)) } t.Run("initial_refresh", func(t *testing.T) { checkRefresh(t, Hosts{Main: "hostname"}) }) testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
t.Run("initial_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost)) }) testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), } eventsCh <- event{} t.Run("second_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) }) eventsCh <- event{}
</s> remove checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) </s> add testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} checkRefresh(t, Hosts{Main: "hostname", Aliases: stringutil.NewSet("alias")}) </s> remove checkRefresh(t, stringutil.NewSet(knownHost)) </s> add checkRefresh(t, Hosts{Main: "hostname"}) </s> remove eventsCh <- event{} </s> add t.Run("double_refresh", func(t *testing.T) { // Make a change once. testFS["dir/file1"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) </s> remove t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) </s> add return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1) </s> remove assert.True(t, hosts.Equal(wantHosts)) </s> add assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases))
t.Run("initial_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost)) }) t.Run("second_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) }) eventsCh <- event{}
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
} eventsCh <- event{} t.Run("second_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) }) eventsCh <- event{} t.Run("no_changes_refresh", func(t *testing.T) {
</s> remove testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), } eventsCh <- event{} </s> add </s> remove eventsCh <- event{} </s> add t.Run("double_refresh", func(t *testing.T) { // Make a change once. testFS["dir/file1"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) </s> remove t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) </s> add return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1) </s> remove checkRefresh(t, stringutil.NewSet(knownHost)) </s> add checkRefresh(t, Hosts{Main: "hostname"}) </s> remove assert.True(t, hosts.Equal(wantHosts)) </s> add assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases))
testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} checkRefresh(t, Hosts{Main: "hostname", Aliases: stringutil.NewSet("alias")})
} eventsCh <- event{} t.Run("second_refresh", func(t *testing.T) { testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} checkRefresh(t, Hosts{Main: "hostname", Aliases: stringutil.NewSet("alias")}) }) eventsCh <- event{} t.Run("no_changes_refresh", func(t *testing.T) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
t.Run("second_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) }) eventsCh <- event{} t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) }) }
</s> remove checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) </s> add testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} checkRefresh(t, Hosts{Main: "hostname", Aliases: stringutil.NewSet("alias")}) </s> remove testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), } eventsCh <- event{} </s> add </s> remove t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) </s> add return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1) </s> remove checkRefresh(t, stringutil.NewSet(knownHost)) </s> add checkRefresh(t, Hosts{Main: "hostname"}) </s> remove assert.True(t, hosts.Equal(wantHosts)) </s> add assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases))
t.Run("double_refresh", func(t *testing.T) { // Make a change once. testFS["dir/file1"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, })
t.Run("second_refresh", func(t *testing.T) { checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) }) t.Run("double_refresh", func(t *testing.T) { // Make a change once. testFS["dir/file1"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) }) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
}) eventsCh <- event{} t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) }) } func TestHostsContainer_PathsToPatterns(t *testing.T) { const (
</s> remove eventsCh <- event{} </s> add t.Run("double_refresh", func(t *testing.T) { // Make a change once. testFS["dir/file1"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) </s> remove checkRefresh(t, stringutil.NewSet(knownHost, knownAlias)) </s> add testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} checkRefresh(t, Hosts{Main: "hostname", Aliases: stringutil.NewSet("alias")}) </s> remove testFS[p2] = &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownAlias}, sp) + nl), } eventsCh <- event{} </s> add </s> remove const ( dir0 = "dir" dir1 = "dir_1" fn1 = "file_1" fn2 = "file_2" fn3 = "file_3" fn4 = "file_4" ) fp1 := path.Join(dir0, fn1) fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) </s> add </s> remove func TestHostsContainer_Refresh(t *testing.T) { knownIP := net.IP{127, 0, 0, 1} </s> add func TestHostsContainer_refresh(t *testing.T) { // TODO(e.burkov): Test the case with no actual updates.
return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1)
}) eventsCh <- event{} return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1) return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1) }) } func TestHostsContainer_PathsToPatterns(t *testing.T) { const (
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
}) } func TestHostsContainer_PathsToPatterns(t *testing.T) { const ( dir0 = "dir" dir1 = "dir_1" fn1 = "file_1" fn2 = "file_2" fn3 = "file_3" fn4 = "file_4" ) fp1 := path.Join(dir0, fn1) fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) gsfs := fstest.MapFS{ fp1: &fstest.MapFile{Data: []byte{1}}, fp2: &fstest.MapFile{Data: []byte{2}}, fp3: &fstest.MapFile{Data: []byte{3}}, }
</s> remove fp1: &fstest.MapFile{Data: []byte{1}}, fp2: &fstest.MapFile{Data: []byte{2}}, fp3: &fstest.MapFile{Data: []byte{3}}, </s> add "dir_0/file_1": &fstest.MapFile{Data: []byte{1}}, "dir_0/file_2": &fstest.MapFile{Data: []byte{2}}, "dir_0/dir_1/file_3": &fstest.MapFile{Data: []byte{3}}, </s> remove const dirname = "dir" const filename1 = "file1" const filename2 = "file2" p1 := path.Join(dirname, filename1) p2 := path.Join(dirname, filename2) testFS := fstest.MapFS{ p1: &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownHost}, sp) + nl), }, } </s> add testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}} </s> remove const ( hostname = "localhost" alias = "hocallost" ) knownIP := net.IP{127, 0, 0, 1} </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String() </s> remove func TestHostsContainer_Refresh(t *testing.T) { knownIP := net.IP{127, 0, 0, 1} </s> add func TestHostsContainer_refresh(t *testing.T) { // TODO(e.burkov): Test the case with no actual updates. </s> remove const knownHost = "localhost" const knownAlias = "hocallost" </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String()
}) } func TestHostsContainer_PathsToPatterns(t *testing.T) { gsfs := fstest.MapFS{ fp1: &fstest.MapFile{Data: []byte{1}}, fp2: &fstest.MapFile{Data: []byte{2}}, fp3: &fstest.MapFile{Data: []byte{3}}, }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) gsfs := fstest.MapFS{ fp1: &fstest.MapFile{Data: []byte{1}}, fp2: &fstest.MapFile{Data: []byte{2}}, fp3: &fstest.MapFile{Data: []byte{3}}, } testCases := []struct { name string wantErr error
</s> remove const ( dir0 = "dir" dir1 = "dir_1" fn1 = "file_1" fn2 = "file_2" fn3 = "file_3" fn4 = "file_4" ) fp1 := path.Join(dir0, fn1) fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) </s> add </s> remove name string wantErr error want []string paths []string </s> add name string paths []string want []string </s> remove const ( hostname = "localhost" alias = "hocallost" ) knownIP := net.IP{127, 0, 0, 1} </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String() </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, </s> remove const dirname = "dir" const filename1 = "file1" const filename2 = "file2" p1 := path.Join(dirname, filename1) p2 := path.Join(dirname, filename2) testFS := fstest.MapFS{ p1: &fstest.MapFile{ Data: []byte(strings.Join([]string{knownIP.String(), knownHost}, sp) + nl), }, } </s> add testFS := fstest.MapFS{"dir/file1": &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)}}
"dir_0/file_1": &fstest.MapFile{Data: []byte{1}}, "dir_0/file_2": &fstest.MapFile{Data: []byte{2}}, "dir_0/dir_1/file_3": &fstest.MapFile{Data: []byte{3}},
fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) gsfs := fstest.MapFS{ "dir_0/file_1": &fstest.MapFile{Data: []byte{1}}, "dir_0/file_2": &fstest.MapFile{Data: []byte{2}}, "dir_0/dir_1/file_3": &fstest.MapFile{Data: []byte{3}}, "dir_0/file_1": &fstest.MapFile{Data: []byte{1}}, "dir_0/file_2": &fstest.MapFile{Data: []byte{2}}, "dir_0/dir_1/file_3": &fstest.MapFile{Data: []byte{3}}, "dir_0/file_1": &fstest.MapFile{Data: []byte{1}}, "dir_0/file_2": &fstest.MapFile{Data: []byte{2}}, "dir_0/dir_1/file_3": &fstest.MapFile{Data: []byte{3}}, } testCases := []struct { name string wantErr error
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
fp3: &fstest.MapFile{Data: []byte{3}}, } testCases := []struct { name string wantErr error want []string paths []string }{{ name: "no_paths", wantErr: nil, want: nil, paths: nil,
</s> remove name: "no_paths", wantErr: nil, want: nil, paths: nil, </s> add name: "no_paths", paths: nil, want: nil, </s> remove fp1: &fstest.MapFile{Data: []byte{1}}, fp2: &fstest.MapFile{Data: []byte{2}}, fp3: &fstest.MapFile{Data: []byte{3}}, </s> add "dir_0/file_1": &fstest.MapFile{Data: []byte{1}}, "dir_0/file_2": &fstest.MapFile{Data: []byte{2}}, "dir_0/dir_1/file_3": &fstest.MapFile{Data: []byte{3}}, </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, </s> remove name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1}, </s> add name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, </s> remove name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, </s> add name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"},
name string paths []string want []string
fp3: &fstest.MapFile{Data: []byte{3}}, } testCases := []struct { name string paths []string want []string name string paths []string want []string name string paths []string want []string name string paths []string want []string }{{ name: "no_paths", wantErr: nil, want: nil, paths: nil,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantErr error want []string paths []string }{{ name: "no_paths", wantErr: nil, want: nil, paths: nil, }, { name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1},
</s> remove name string wantErr error want []string paths []string </s> add name string paths []string want []string </s> remove name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1}, </s> add name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, </s> remove name: "several_files", wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2}, </s> add name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, </s> remove name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, </s> add name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, </s> remove name: "whole_dir", wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0}, </s> add name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"},
name: "no_paths", paths: nil, want: nil,
wantErr error want []string paths []string }{{ name: "no_paths", paths: nil, want: nil, name: "no_paths", paths: nil, want: nil, name: "no_paths", paths: nil, want: nil, name: "no_paths", paths: nil, want: nil, }, { name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1},
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantErr: nil, want: nil, paths: nil, }, { name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1}, }, { name: "several_files", wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2},
</s> remove name: "several_files", wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2}, </s> add name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, </s> remove name: "whole_dir", wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0}, </s> add name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"}, </s> remove name: "no_paths", wantErr: nil, want: nil, paths: nil, </s> add name: "no_paths", paths: nil, want: nil, </s> remove name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, </s> add name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil,
name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"},
wantErr: nil, want: nil, paths: nil, }, { name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, }, { name: "several_files", wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2},
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantErr: nil, want: []string{fp1}, paths: []string{fp1}, }, { name: "several_files", wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2}, }, { name: "whole_dir", wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0},
</s> remove name: "whole_dir", wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0}, </s> add name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"}, </s> remove name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1}, </s> add name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, </s> remove name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, </s> add name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, </s> remove name: "no_paths", wantErr: nil, want: nil, paths: nil, </s> add name: "no_paths", paths: nil, want: nil, </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil,
name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"},
wantErr: nil, want: []string{fp1}, paths: []string{fp1}, }, { name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, }, { name: "whole_dir", wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0},
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2}, }, { name: "whole_dir", wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0}, }, { name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)},
</s> remove name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, </s> add name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, </s> remove name: "several_files", wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2}, </s> add name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, </s> remove name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1}, </s> add name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, </s> remove name: "no_paths", wantErr: nil, want: nil, paths: nil, </s> add name: "no_paths", paths: nil, want: nil,
name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"},
wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2}, }, { name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"}, name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"}, name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"}, name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"}, }, { name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)},
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0}, }, { name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, }, { name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")},
</s> remove name: "whole_dir", wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0}, </s> add name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"}, </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, </s> remove name: "several_files", wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2}, </s> add name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, </s> remove name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1}, </s> add name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, </s> remove name: "no_paths", wantErr: nil, want: nil, paths: nil, </s> add name: "no_paths", paths: nil, want: nil,
name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"},
wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0}, }, { name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, }, { name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")},
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, }, { name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { patterns, err := pathsToPatterns(gsfs, tc.paths)
</s> remove name: "file_and_dir", wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, </s> add name: "file_and_dir", paths: []string{"dir_0/file_1", "dir_0/dir_1"}, want: []string{"dir_0/file_1", "dir_0/dir_1/*"}, </s> remove name: "whole_dir", wantErr: nil, want: []string{path.Join(dir0, "*")}, paths: []string{dir0}, </s> add name: "whole_dir", paths: []string{"dir_0"}, want: []string{"dir_0/*"}, </s> remove name: "several_files", wantErr: nil, want: []string{fp1, fp2}, paths: []string{fp1, fp2}, </s> add name: "several_files", paths: []string{"dir_0/file_1", "dir_0/file_2"}, want: []string{"dir_0/file_1", "dir_0/file_2"}, </s> remove name: "single_file", wantErr: nil, want: []string{fp1}, paths: []string{fp1}, </s> add name: "single_file", paths: []string{"dir_0/file_1"}, want: []string{"dir_0/file_1"}, </s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add
name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil,
wantErr: nil, want: []string{fp1, path.Join(dir0, dir1, "*")}, paths: []string{fp1, path.Join(dir0, dir1)}, }, { name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, }} for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { patterns, err := pathsToPatterns(gsfs, tc.paths)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { patterns, err := pathsToPatterns(gsfs, tc.paths) if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } require.NoError(t, err) assert.Equal(t, tc.want, patterns) }) }
</s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, </s> remove ip, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(ip)) </s> add got, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(got)) </s> remove hc.resetEng(rulesStrg, hp.translations) </s> add hc.resetEng(rulesStrg, hp.translations()) </s> remove checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { </s> add checkRefresh := func(t *testing.T, wantHosts Hosts) { </s> remove hc, err := NewHostsContainer(0, testFS, w, dirname) </s> add hc, err := NewHostsContainer(0, testFS, w, "dir")
for _, tc := range testCases { t.Run(tc.name, func(t *testing.T) { patterns, err := pathsToPatterns(gsfs, tc.paths) require.NoError(t, err) assert.Equal(t, tc.want, patterns) }) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
testdata := os.DirFS("./testdata") nRewrites := func(t *testing.T, res *urlfilter.DNSResult, n int) (rws []*rules.DNSRewrite) { t.Helper() rewrites := res.DNSRewrites() assert.Len(t, rewrites, n) for _, rewrite := range rewrites { require.Equal(t, listID, rewrite.FilterListID)
</s> remove assert.Len(t, rewrites, n) </s> add require.Len(t, rewrites, n) </s> remove ip, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(ip)) </s> add got, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(got)) </s> remove checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { </s> add checkRefresh := func(t *testing.T, wantHosts Hosts) { </s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil,
testdata := os.DirFS("./testdata") nRewrites := func(t *testing.T, res *urlfilter.DNSResult, n int) (rws []*rules.DNSRewrite) { rewrites := res.DNSRewrites() assert.Len(t, rewrites, n) for _, rewrite := range rewrites { require.Equal(t, listID, rewrite.FilterListID)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
nRewrites := func(t *testing.T, res *urlfilter.DNSResult, n int) (rws []*rules.DNSRewrite) { t.Helper() rewrites := res.DNSRewrites() assert.Len(t, rewrites, n) for _, rewrite := range rewrites { require.Equal(t, listID, rewrite.FilterListID) rw := rewrite.DNSRewrite
</s> remove t.Helper() </s> add </s> remove ip, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(ip)) </s> add got, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(got)) </s> remove checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { </s> add checkRefresh := func(t *testing.T, wantHosts Hosts) { </s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil,
require.Len(t, rewrites, n)
nRewrites := func(t *testing.T, res *urlfilter.DNSResult, n int) (rws []*rules.DNSRewrite) { t.Helper() rewrites := res.DNSRewrites() require.Len(t, rewrites, n) for _, rewrite := range rewrites { require.Equal(t, listID, rewrite.FilterListID) rw := rewrite.DNSRewrite
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
testTail: func(t *testing.T, res *urlfilter.DNSResult) { assert.Equal(t, "hello", nRewrites(t, res, 1)[0].NewCNAME) }, }, { name: "hello_subdomain", req: urlfilter.DNSRequest{ Hostname: "say.hello", DNSType: dns.TypeA,
</s> remove eventsCh <- event{} </s> add t.Run("double_refresh", func(t *testing.T) { // Make a change once. testFS["dir/file1"] = &fstest.MapFile{Data: []byte(ipStr + ` alias` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) </s> remove t.Run("no_changes_refresh", func(t *testing.T) { assert.Empty(t, hc.Upd()) </s> add return !ok && res.DNSRewrites() == nil }, 5*time.Second, time.Second/2) // Make a change again. testFS["dir/file2"] = &fstest.MapFile{Data: []byte(ipStr + ` hostname` + nl)} eventsCh <- event{} // Require the changes are written. require.Eventually(t, func() bool { res, ok := hc.MatchRequest(urlfilter.DNSRequest{ Hostname: "hostname", DNSType: dns.TypeA, }) return !ok && res.DNSRewrites() != nil }, 5*time.Second, time.Second/2) assert.Len(t, hc.Upd(), 1) </s> remove checkRefresh := func(t *testing.T, wantHosts *stringutil.Set) { </s> add checkRefresh := func(t *testing.T, wantHosts Hosts) { </s> remove t.Helper() </s> add </s> remove assert.Len(t, rewrites, n) </s> add require.Len(t, rewrites, n)
}, { name: "other_line_alias", req: urlfilter.DNSRequest{ Hostname: "hello.world.again", DNSType: dns.TypeA, }, testTail: func(t *testing.T, res *urlfilter.DNSResult) { assert.Equal(t, "hello", nRewrites(t, res, 1)[0].NewCNAME) },
testTail: func(t *testing.T, res *urlfilter.DNSResult) { assert.Equal(t, "hello", nRewrites(t, res, 1)[0].NewCNAME) }, }, { name: "other_line_alias", req: urlfilter.DNSRequest{ Hostname: "hello.world.again", DNSType: dns.TypeA, }, testTail: func(t *testing.T, res *urlfilter.DNSResult) { assert.Equal(t, "hello", nRewrites(t, res, 1)[0].NewCNAME) }, }, { name: "hello_subdomain", req: urlfilter.DNSRequest{ Hostname: "say.hello", DNSType: dns.TypeA,
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
} } func TestUniqueRules_ParseLine(t *testing.T) { const ( hostname = "localhost" alias = "hocallost" ) knownIP := net.IP{127, 0, 0, 1} testCases := []struct { name string line string wantIP net.IP
</s> remove const knownHost = "localhost" const knownAlias = "hocallost" </s> add ip := net.IP{127, 0, 0, 1} ipStr := ip.String() </s> remove func TestHostsContainer_Refresh(t *testing.T) { knownIP := net.IP{127, 0, 0, 1} </s> add func TestHostsContainer_refresh(t *testing.T) { // TODO(e.burkov): Test the case with no actual updates. </s> remove name string wantErr error want []string paths []string </s> add name string paths []string want []string </s> remove fp1: &fstest.MapFile{Data: []byte{1}}, fp2: &fstest.MapFile{Data: []byte{2}}, fp3: &fstest.MapFile{Data: []byte{3}}, </s> add "dir_0/file_1": &fstest.MapFile{Data: []byte{1}}, "dir_0/file_2": &fstest.MapFile{Data: []byte{2}}, "dir_0/dir_1/file_3": &fstest.MapFile{Data: []byte{3}}, </s> remove const ( dir0 = "dir" dir1 = "dir_1" fn1 = "file_1" fn2 = "file_2" fn3 = "file_3" fn4 = "file_4" ) fp1 := path.Join(dir0, fn1) fp2 := path.Join(dir0, fn2) fp3 := path.Join(dir0, dir1, fn3) </s> add
ip := net.IP{127, 0, 0, 1} ipStr := ip.String()
} } func TestUniqueRules_ParseLine(t *testing.T) { ip := net.IP{127, 0, 0, 1} ipStr := ip.String() ip := net.IP{127, 0, 0, 1} ipStr := ip.String() ip := net.IP{127, 0, 0, 1} ipStr := ip.String() ip := net.IP{127, 0, 0, 1} ipStr := ip.String() ip := net.IP{127, 0, 0, 1} ipStr := ip.String() ip := net.IP{127, 0, 0, 1} ipStr := ip.String() testCases := []struct { name string line string wantIP net.IP
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantIP net.IP wantHosts []string }{{ name: "simple", line: strings.Join([]string{knownIP.String(), hostname}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, }, { name: "aliases", line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"},
</s> remove line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, </s> add line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"}, </s> remove line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, </s> remove line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp), wantIP: knownIP, </s> add line: ipStr + ` # hostname`, wantIP: ip, </s> remove line: knownIP.String(), </s> add line: ipStr, </s> remove line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), </s> add line: `# ` + ipStr + ` hostname`,
line: ipStr + ` hostname`, wantIP: ip, wantHosts: []string{"hostname"},
wantIP net.IP wantHosts []string }{{ name: "simple", line: ipStr + ` hostname`, wantIP: ip, wantHosts: []string{"hostname"}, line: ipStr + ` hostname`, wantIP: ip, wantHosts: []string{"hostname"}, line: ipStr + ` hostname`, wantIP: ip, wantHosts: []string{"hostname"}, }, { name: "aliases", line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"},
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantIP: knownIP, wantHosts: []string{"localhost"}, }, { name: "aliases", line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, }, { name: "invalid_line", line: knownIP.String(), wantIP: nil, wantHosts: nil,
</s> remove line: strings.Join([]string{knownIP.String(), hostname}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname`, wantIP: ip, wantHosts: []string{"hostname"}, </s> remove line: knownIP.String(), </s> add line: ipStr, </s> remove line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, </s> remove line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp), wantIP: knownIP, </s> add line: ipStr + ` # hostname`, wantIP: ip, </s> remove line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), </s> add line: `# ` + ipStr + ` hostname`,
line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"},
wantIP: knownIP, wantHosts: []string{"localhost"}, }, { name: "aliases", line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"}, line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"}, line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"}, }, { name: "invalid_line", line: knownIP.String(), wantIP: nil, wantHosts: nil,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, }, { name: "invalid_line", line: knownIP.String(), wantIP: nil, wantHosts: nil, }, { name: "invalid_line_hostname", line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp),
</s> remove line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, </s> add line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"}, </s> remove line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp), wantIP: knownIP, </s> add line: ipStr + ` # hostname`, wantIP: ip, </s> remove line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, </s> remove line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), </s> add line: `# ` + ipStr + ` hostname`, </s> remove line: strings.Join([]string{knownIP.String(), hostname}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname`, wantIP: ip, wantHosts: []string{"hostname"},
line: ipStr,
wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, }, { name: "invalid_line", line: ipStr, wantIP: nil, wantHosts: nil, }, { name: "invalid_line_hostname", line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp),
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantIP: nil, wantHosts: nil, }, { name: "invalid_line_hostname", line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp), wantIP: knownIP, wantHosts: nil, }, { name: "commented_aliases", line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP,
</s> remove line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, </s> remove line: knownIP.String(), </s> add line: ipStr, </s> remove line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), </s> add line: `# ` + ipStr + ` hostname`, </s> remove line: strings.Join([]string{knownIP.String(), hostname[:4] + "#" + hostname[4:]}, sp), wantIP: knownIP, wantHosts: []string{hostname[:4]}, </s> add line: ipStr + ` host#name`, wantIP: ip, wantHosts: []string{"host"}, </s> remove line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, </s> add line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"},
line: ipStr + ` # hostname`, wantIP: ip,
wantIP: nil, wantHosts: nil, }, { name: "invalid_line_hostname", line: ipStr + ` # hostname`, wantIP: ip, line: ipStr + ` # hostname`, wantIP: ip, wantHosts: nil, }, { name: "commented_aliases", line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP,
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantIP: knownIP, wantHosts: nil, }, { name: "commented_aliases", line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, }, { name: "whole_comment", line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), wantIP: nil, wantHosts: nil,
</s> remove line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp), wantIP: knownIP, </s> add line: ipStr + ` # hostname`, wantIP: ip, </s> remove line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), </s> add line: `# ` + ipStr + ` hostname`, </s> remove line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, </s> add line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"}, </s> remove line: knownIP.String(), </s> add line: ipStr, </s> remove line: strings.Join([]string{knownIP.String(), hostname}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname`, wantIP: ip, wantHosts: []string{"hostname"},
line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"},
wantIP: knownIP, wantHosts: nil, }, { name: "commented_aliases", line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, }, { name: "whole_comment", line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), wantIP: nil, wantHosts: nil,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantIP: knownIP, wantHosts: []string{"localhost"}, }, { name: "whole_comment", line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), wantIP: nil, wantHosts: nil, }, { name: "partial_comment", line: strings.Join([]string{knownIP.String(), hostname[:4] + "#" + hostname[4:]}, sp),
</s> remove line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, </s> remove line: strings.Join([]string{knownIP.String(), hostname[:4] + "#" + hostname[4:]}, sp), wantIP: knownIP, wantHosts: []string{hostname[:4]}, </s> add line: ipStr + ` host#name`, wantIP: ip, wantHosts: []string{"host"}, </s> remove line: knownIP.String(), </s> add line: ipStr, </s> remove line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp), wantIP: knownIP, </s> add line: ipStr + ` # hostname`, wantIP: ip, </s> remove line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, </s> add line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"},
line: `# ` + ipStr + ` hostname`,
wantIP: knownIP, wantHosts: []string{"localhost"}, }, { name: "whole_comment", line: `# ` + ipStr + ` hostname`, wantIP: nil, wantHosts: nil, }, { name: "partial_comment", line: strings.Join([]string{knownIP.String(), hostname[:4] + "#" + hostname[4:]}, sp),
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
wantIP: nil, wantHosts: nil, }, { name: "partial_comment", line: strings.Join([]string{knownIP.String(), hostname[:4] + "#" + hostname[4:]}, sp), wantIP: knownIP, wantHosts: []string{hostname[:4]}, }, { name: "empty", line: ``, wantIP: nil, wantHosts: nil,
</s> remove line: strings.Join([]string{"#", knownIP.String(), hostname}, sp), </s> add line: `# ` + ipStr + ` hostname`, </s> remove line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp), wantIP: knownIP, </s> add line: ipStr + ` # hostname`, wantIP: ip, </s> remove line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, </s> remove line: knownIP.String(), </s> add line: ipStr, </s> remove line: strings.Join([]string{knownIP.String(), hostname, alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost", "hocallost"}, </s> add line: ipStr + ` hostname alias`, wantIP: ip, wantHosts: []string{"hostname", "alias"},
line: ipStr + ` host#name`, wantIP: ip, wantHosts: []string{"host"},
wantIP: nil, wantHosts: nil, }, { name: "partial_comment", line: ipStr + ` host#name`, wantIP: ip, wantHosts: []string{"host"}, line: ipStr + ` host#name`, wantIP: ip, wantHosts: []string{"host"}, line: ipStr + ` host#name`, wantIP: ip, wantHosts: []string{"host"}, }, { name: "empty", line: ``, wantIP: nil, wantHosts: nil,
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
for _, tc := range testCases { hp := hostsParser{} t.Run(tc.name, func(t *testing.T) { ip, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(ip)) assert.Equal(t, tc.wantHosts, hosts) }) } }
</s> remove if tc.wantErr != nil { assert.ErrorIs(t, err, tc.wantErr) return } </s> add </s> remove name: "non-existing", wantErr: nil, want: nil, paths: []string{path.Join(dir0, "file_3")}, </s> add name: "non-existing", paths: []string{path.Join("dir_0", "file_3")}, want: nil, </s> remove assert.True(t, hosts.Equal(wantHosts)) </s> add assert.Equal(t, wantHosts.Main, hosts.Main) assert.True(t, hosts.Aliases.Equal(wantHosts.Aliases)) </s> remove checkRefresh(t, stringutil.NewSet(knownHost)) </s> add checkRefresh(t, Hosts{Main: "hostname"}) </s> remove t.Helper() </s> add
got, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(got))
for _, tc := range testCases { hp := hostsParser{} t.Run(tc.name, func(t *testing.T) { got, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(got)) got, hosts := hp.parseLine(tc.line) assert.True(t, tc.wantIP.Equal(got)) assert.Equal(t, tc.wantHosts, hosts) }) } }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/hostscontainer_test.go
1.0.0.3 * 1.0.0.4 *.com # Same for IPv6. ::1 simplehost :: hello hello.world ::2 a.whole lot.of aliases for.testing
</s> remove line: strings.Join([]string{knownIP.String(), "#" + hostname}, sp), wantIP: knownIP, </s> add line: ipStr + ` # hostname`, wantIP: ip, </s> remove line: strings.Join([]string{knownIP.String(), hostname, "#" + alias}, sp), wantIP: knownIP, wantHosts: []string{"localhost"}, </s> add line: ipStr + ` hostname # alias`, wantIP: ip, wantHosts: []string{"hostname"}, </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) } </s> remove // writeMainHostRule writes the actual rule for the qtype and the PTR for the </s> add // writeMainRule writes the actual rule for the qtype and the PTR for the </s> remove // hostAlias if the host is not the first one added for the ip. // hostMain if the host is the first one added for the ip. // 0 if the ip-host pair has already been added. </s> add // main host if the host is not the first one added for the ip. // host itself if the host is the first one added for the ip. // "" if the ip-host pair has already been added.
# See https://github.com/AdguardTeam/AdGuardHome/issues/4079. 1.0.0.0 hello.world.again # Duplicates of a main host and an alias. 1.0.0.1 simplehost 1.0.0.0 hello.world
1.0.0.3 * 1.0.0.4 *.com # See https://github.com/AdguardTeam/AdGuardHome/issues/4079. 1.0.0.0 hello.world.again # Duplicates of a main host and an alias. 1.0.0.1 simplehost 1.0.0.0 hello.world # Same for IPv6. ::1 simplehost :: hello hello.world ::2 a.whole lot.of aliases for.testing
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/aghnet/testdata/etc_hosts
clients.rmHostsBySrc(ClientSourceHostsFile) n := 0 hosts.Range(func(ip net.IP, v interface{}) (cont bool) { names, ok := v.(*stringutil.Set) if !ok { log.Error("dns: bad type %T in ipToRC for %s", v, ip) } names.Range(func(name string) (cont bool) {
</s> remove names.Range(func(name string) (cont bool) { </s> add if clients.addHostLocked(ip, hosts.Main, ClientSourceHostsFile) { n++ } hosts.Aliases.Range(func(name string) (cont bool) { </s> remove hp.table.Range(func(ip net.IP, val interface{}) (cont bool) { v, hasIP := target.Get(ip) </s> add hp.table.Range(func(ip net.IP, b interface{}) (cont bool) { </s> remove // appropriate hosts set isn't equal to the checked one, i.e. the maps // have at least one discrepancy. ok = !hasIP || !v.(*stringutil.Set).Equal(val.(*stringutil.Set)) </s> add // appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) } </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
hosts, ok := v.(*aghnet.Hosts)
clients.rmHostsBySrc(ClientSourceHostsFile) n := 0 hosts.Range(func(ip net.IP, v interface{}) (cont bool) { hosts, ok := v.(*aghnet.Hosts) if !ok { log.Error("dns: bad type %T in ipToRC for %s", v, ip) } names.Range(func(name string) (cont bool) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/home/clients.go
hosts.Range(func(ip net.IP, v interface{}) (cont bool) { hosts, ok := v.(*aghnet.Hosts) if !ok { log.Error("dns: bad type %T in ipToRC for %s", v, ip) } if clients.addHostLocked(ip, hosts.Main, ClientSourceHostsFile) { n++ } hosts.Aliases.Range(func(name string) (cont bool) {
</s> remove names.Range(func(name string) (cont bool) { </s> add if clients.addHostLocked(ip, hosts.Main, ClientSourceHostsFile) { n++ } hosts.Aliases.Range(func(name string) (cont bool) { </s> remove names, ok := v.(*stringutil.Set) </s> add hosts, ok := v.(*aghnet.Hosts) </s> remove hp.table.Range(func(ip net.IP, val interface{}) (cont bool) { v, hasIP := target.Get(ip) </s> add hp.table.Range(func(ip net.IP, b interface{}) (cont bool) { </s> remove // appropriate hosts set isn't equal to the checked one, i.e. the maps // have at least one discrepancy. ok = !hasIP || !v.(*stringutil.Set).Equal(val.(*stringutil.Set)) </s> add // appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) } </s> remove func (hp *hostsParser) add(ip net.IP, host string) (hostType int) { </s> add func (hp *hostsParser) add(ip net.IP, host string) (mainHost string) {
return true
hosts.Range(func(ip net.IP, v interface{}) (cont bool) { hosts, ok := v.(*aghnet.Hosts) if !ok { log.Error("dns: bad type %T in ipToRC for %s", v, ip) return true } if clients.addHostLocked(ip, hosts.Main, ClientSourceHostsFile) { n++ } hosts.Aliases.Range(func(name string) (cont bool) {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/home/clients.go
if !ok { log.Error("dns: bad type %T in ipToRC for %s", v, ip) } names.Range(func(name string) (cont bool) { if clients.addHostLocked(ip, name, ClientSourceHostsFile) { n++ } return true
</s> remove names, ok := v.(*stringutil.Set) </s> add hosts, ok := v.(*aghnet.Hosts) </s> remove hp.table.Range(func(ip net.IP, val interface{}) (cont bool) { v, hasIP := target.Get(ip) </s> add hp.table.Range(func(ip net.IP, b interface{}) (cont bool) { </s> remove // appropriate hosts set isn't equal to the checked one, i.e. the maps // have at least one discrepancy. ok = !hasIP || !v.(*stringutil.Set).Equal(val.(*stringutil.Set)) </s> add // appropriate hosts set isn't equal to the checked one, i.e. the main // hosts differ or the maps have at least one discrepancy. if a, hasIP := target.Get(ip); !hasIP { ok = true } else if hosts, aok := a.(*Hosts); aok { ok = !hosts.Equal(b.(*Hosts)) } </s> remove // Simple types of hosts in hosts database. Zero value isn't used to be able // quizzaciously emulate nil with 0. const ( _ = iota hostAlias hostMain ) </s> add // Hosts is used to contain the main host and all it's aliases. type Hosts struct { // Aliases contains all the aliases for Main. Aliases *stringutil.Set // Main is the host itself. Main string } // Equal returns true if h equals hh. func (h *Hosts) Equal(hh *Hosts) (ok bool) { if h == nil || hh == nil { return h == hh } return h.Main == hh.Main && h.Aliases.Equal(hh.Aliases) }
if clients.addHostLocked(ip, hosts.Main, ClientSourceHostsFile) { n++ } hosts.Aliases.Range(func(name string) (cont bool) {
if !ok { log.Error("dns: bad type %T in ipToRC for %s", v, ip) } if clients.addHostLocked(ip, hosts.Main, ClientSourceHostsFile) { n++ } hosts.Aliases.Range(func(name string) (cont bool) { if clients.addHostLocked(ip, name, ClientSourceHostsFile) { n++ } return true
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4079 fix hosts container aliases Merge in DNS/adguard-home from 4079-hosts-again to master Updates #4079. Squashed commit of the following: commit 6aa8cbf32e8e47ba46bf5fba7681a10b68b4bc01 Merge: 19dba371 34c95f99 Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:30 2022 +0500 Merge branch 'master' into 4079-hosts-again commit 19dba371cc30ab8b75b0116833f4ecf0ef0f182f Author: Eugene Burkov <[email protected]> Date: Wed Jan 12 14:05:20 2022 +0500 aghnet: imp docs commit 9f341eb8ee4ba8468240bc3eeeb4951a3f7f5e6d Author: Eugene Burkov <[email protected]> Date: Mon Jan 10 18:44:17 2022 +0500 aghnet: fix races commit fd66191c7637c8584711e5bb8186494327ce0f87 Author: Eugene Burkov <[email protected]> Date: Thu Jan 6 17:21:14 2022 +0500 aghnet: fix hosts container aliases
https://github.com/AdguardTeam/AdGuardHome/commit/1458600c37dba16003518685729c7212598fe8ad
internal/home/clients.go
} // Init checks the configuration and initializes the server func (s *Server) Init(config ServerConfig) error { err := s.setConfig(config) if err != nil { return err
</s> remove dhcpServer dhcpd.Server </s> add dhcpServer *dhcpd.Server </s> remove func (clients *clientsContainer) Init(objects []clientObject) { </s> add func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server) { </s> remove macFound := config.dhcpServer.FindMACbyIP(ipAddr) </s> add if clients.dhcpServer == nil { return Client{}, false } macFound := clients.dhcpServer.FindMACbyIP(ipAddr)
// Create - create object func Create(config ServerConfig) *Server { s := Server{} s.conf = config return &s }
} // Create - create object func Create(config ServerConfig) *Server { s := Server{} s.conf = config return &s } // Init checks the configuration and initializes the server func (s *Server) Init(config ServerConfig) error { err := s.setConfig(config) if err != nil { return err
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
* dhcp,clients: DHCP server module is passed to Clients module during initialization.
https://github.com/AdguardTeam/AdGuardHome/commit/149fcc0f2dccbe0018122f1efa5b8977cf6ff273
dhcpd/dhcpd.go
} func (s *Server) setConfig(config ServerConfig) error { s.conf = config s.conf.DBFilePath = filepath.Join(config.WorkDir, dbFilename)
</s> remove func (clients *clientsContainer) Init(objects []clientObject) { </s> add func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server) { </s> remove config.clients.Init(config.Clients) </s> add config.dhcpServer = dhcpd.Create(config.DHCP) config.clients.Init(config.Clients, config.dhcpServer)
// WriteDiskConfig - write configuration func (s *Server) WriteDiskConfig(c *ServerConfig) { *c = s.conf }
} // WriteDiskConfig - write configuration func (s *Server) WriteDiskConfig(c *ServerConfig) { *c = s.conf } func (s *Server) setConfig(config ServerConfig) error { s.conf = config s.conf.DBFilePath = filepath.Join(config.WorkDir, dbFilename)
[ "keep", "add", "keep", "keep", "keep", "keep" ]
* dhcp,clients: DHCP server module is passed to Clients module during initialization.
https://github.com/AdguardTeam/AdGuardHome/commit/149fcc0f2dccbe0018122f1efa5b8977cf6ff273
dhcpd/dhcpd.go
"strings" "sync" "time" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/utils" ) const (
</s> remove config.clients.Init(config.Clients) </s> add config.dhcpServer = dhcpd.Create(config.DHCP) config.clients.Init(config.Clients, config.dhcpServer) </s> remove dhcpServer dhcpd.Server </s> add dhcpServer *dhcpd.Server </s> remove clients.Init(nil) </s> add clients.Init(nil, nil)
"github.com/AdguardTeam/AdGuardHome/dhcpd"
"strings" "sync" "time" "github.com/AdguardTeam/AdGuardHome/dhcpd" "github.com/AdguardTeam/golibs/log" "github.com/AdguardTeam/golibs/utils" ) const (
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
* dhcp,clients: DHCP server module is passed to Clients module during initialization.
https://github.com/AdguardTeam/AdGuardHome/commit/149fcc0f2dccbe0018122f1efa5b8977cf6ff273
home/clients.go
idIndex map[string]*Client // IP -> client ipHost map[string]*ClientHost // IP -> Hostname lock sync.Mutex } // Init initializes clients container // Note: this function must be called only once func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server) {
</s> remove func (clients *clientsContainer) Init(objects []clientObject) { </s> add func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server) { </s> remove leases := config.dhcpServer.Leases() </s> add if clients.dhcpServer == nil { return } leases := clients.dhcpServer.Leases() </s> remove dhcpServer dhcpd.Server </s> add dhcpServer *dhcpd.Server </s> remove clients.Init(nil) </s> add clients.Init(nil, nil)
dhcpServer *dhcpd.Server
idIndex map[string]*Client // IP -> client ipHost map[string]*ClientHost // IP -> Hostname lock sync.Mutex dhcpServer *dhcpd.Server } // Init initializes clients container // Note: this function must be called only once func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server) {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
* dhcp,clients: DHCP server module is passed to Clients module during initialization.
https://github.com/AdguardTeam/AdGuardHome/commit/149fcc0f2dccbe0018122f1efa5b8977cf6ff273
home/clients.go
} // Init initializes clients container // Note: this function must be called only once func (clients *clientsContainer) Init(objects []clientObject) { if clients.list != nil { log.Fatal("clients.list != nil") } clients.list = make(map[string]*Client) clients.idIndex = make(map[string]*Client)
</s> remove leases := config.dhcpServer.Leases() </s> add if clients.dhcpServer == nil { return } leases := clients.dhcpServer.Leases() </s> remove macFound := config.dhcpServer.FindMACbyIP(ipAddr) </s> add if clients.dhcpServer == nil { return Client{}, false } macFound := clients.dhcpServer.FindMACbyIP(ipAddr)
func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server) {
} // Init initializes clients container // Note: this function must be called only once func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server) { if clients.list != nil { log.Fatal("clients.list != nil") } clients.list = make(map[string]*Client) clients.idIndex = make(map[string]*Client)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
* dhcp,clients: DHCP server module is passed to Clients module during initialization.
https://github.com/AdguardTeam/AdGuardHome/commit/149fcc0f2dccbe0018122f1efa5b8977cf6ff273
home/clients.go
clients.list = make(map[string]*Client) clients.idIndex = make(map[string]*Client) clients.ipHost = make(map[string]*ClientHost) clients.addFromConfig(objects) go clients.periodicUpdate() }
</s> remove func (clients *clientsContainer) Init(objects []clientObject) { </s> add func (clients *clientsContainer) Init(objects []clientObject, dhcpServer *dhcpd.Server) { </s> remove macFound := config.dhcpServer.FindMACbyIP(ipAddr) </s> add if clients.dhcpServer == nil { return Client{}, false } macFound := clients.dhcpServer.FindMACbyIP(ipAddr) </s> remove config.clients.Init(config.Clients) </s> add config.dhcpServer = dhcpd.Create(config.DHCP) config.clients.Init(config.Clients, config.dhcpServer)
clients.dhcpServer = dhcpServer
clients.list = make(map[string]*Client) clients.idIndex = make(map[string]*Client) clients.ipHost = make(map[string]*ClientHost) clients.dhcpServer = dhcpServer clients.addFromConfig(objects) go clients.periodicUpdate() }
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
* dhcp,clients: DHCP server module is passed to Clients module during initialization.
https://github.com/AdguardTeam/AdGuardHome/commit/149fcc0f2dccbe0018122f1efa5b8977cf6ff273
home/clients.go