Pull in newest consul-template from master and all corresponding dependencies [VAULT-1392] (#10756)
* pull in newest consul template with bugfix and all dependencies * pull in newest consul template with bugfix and all dependencies * Rename readme.md to README.md * add changelog
This commit is contained in:
parent
588ce498d3
commit
fa5784d789
|
@ -0,0 +1,4 @@
|
||||||
|
```release-note:bug
|
||||||
|
consul-template: Update consul-template vendor version and associated dependencies to master,
|
||||||
|
pulling in https://github.com/hashicorp/consul-template/pull/1447
|
||||||
|
```
|
14
go.mod
14
go.mod
|
@ -51,9 +51,9 @@ require (
|
||||||
github.com/golang/protobuf v1.4.2
|
github.com/golang/protobuf v1.4.2
|
||||||
github.com/google/go-github v17.0.0+incompatible
|
github.com/google/go-github v17.0.0+incompatible
|
||||||
github.com/google/go-metrics-stackdriver v0.2.0
|
github.com/google/go-metrics-stackdriver v0.2.0
|
||||||
github.com/hashicorp/consul-template v0.25.1
|
github.com/hashicorp/consul-template v0.25.2-0.20210123001810-166043f8559d
|
||||||
github.com/hashicorp/consul/api v1.4.0
|
github.com/hashicorp/consul/api v1.4.0
|
||||||
github.com/hashicorp/errwrap v1.0.0
|
github.com/hashicorp/errwrap v1.1.0
|
||||||
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible
|
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.1
|
github.com/hashicorp/go-cleanhttp v0.5.1
|
||||||
github.com/hashicorp/go-discover v0.0.0-20200812215701-c4b85f6ed31f
|
github.com/hashicorp/go-discover v0.0.0-20200812215701-c4b85f6ed31f
|
||||||
|
@ -69,7 +69,7 @@ require (
|
||||||
github.com/hashicorp/go-sockaddr v1.0.2
|
github.com/hashicorp/go-sockaddr v1.0.2
|
||||||
github.com/hashicorp/go-syslog v1.0.0
|
github.com/hashicorp/go-syslog v1.0.0
|
||||||
github.com/hashicorp/go-uuid v1.0.2
|
github.com/hashicorp/go-uuid v1.0.2
|
||||||
github.com/hashicorp/golang-lru v0.5.3
|
github.com/hashicorp/golang-lru v0.5.4
|
||||||
github.com/hashicorp/hcl v1.0.1-vault
|
github.com/hashicorp/hcl v1.0.1-vault
|
||||||
github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d
|
github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d
|
||||||
github.com/hashicorp/raft v1.1.3-0.20201002073007-f367681f9c48
|
github.com/hashicorp/raft v1.1.3-0.20201002073007-f367681f9c48
|
||||||
|
@ -107,7 +107,7 @@ require (
|
||||||
github.com/kr/pretty v0.2.1
|
github.com/kr/pretty v0.2.1
|
||||||
github.com/kr/text v0.2.0
|
github.com/kr/text v0.2.0
|
||||||
github.com/lib/pq v1.8.0
|
github.com/lib/pq v1.8.0
|
||||||
github.com/mattn/go-colorable v0.1.6
|
github.com/mattn/go-colorable v0.1.7
|
||||||
github.com/mholt/archiver v3.1.1+incompatible
|
github.com/mholt/archiver v3.1.1+incompatible
|
||||||
github.com/michaelklishin/rabbit-hole v0.0.0-20191008194146-93d9988f0cd5
|
github.com/michaelklishin/rabbit-hole v0.0.0-20191008194146-93d9988f0cd5
|
||||||
github.com/mitchellh/cli v1.1.1
|
github.com/mitchellh/cli v1.1.1
|
||||||
|
@ -129,7 +129,7 @@ require (
|
||||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||||
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
|
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/posener/complete v1.2.1
|
github.com/posener/complete v1.2.3
|
||||||
github.com/pquerna/otp v1.2.1-0.20191009055518-468c2dd2b58d
|
github.com/pquerna/otp v1.2.1-0.20191009055518-468c2dd2b58d
|
||||||
github.com/prometheus/client_golang v1.7.1
|
github.com/prometheus/client_golang v1.7.1
|
||||||
github.com/prometheus/common v0.11.1
|
github.com/prometheus/common v0.11.1
|
||||||
|
@ -151,9 +151,9 @@ require (
|
||||||
go.mongodb.org/mongo-driver v1.4.2
|
go.mongodb.org/mongo-driver v1.4.2
|
||||||
go.uber.org/atomic v1.6.0
|
go.uber.org/atomic v1.6.0
|
||||||
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
|
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344
|
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c
|
||||||
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
|
||||||
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f
|
||||||
golang.org/x/tools v0.0.0-20200521155704-91d71f6c2f04
|
golang.org/x/tools v0.0.0-20200521155704-91d71f6c2f04
|
||||||
google.golang.org/api v0.29.0
|
google.golang.org/api v0.29.0
|
||||||
google.golang.org/grpc v1.29.1
|
google.golang.org/grpc v1.29.1
|
||||||
|
|
34
go.sum
34
go.sum
|
@ -442,6 +442,8 @@ github.com/golang/snappy v0.0.0-20170215233205-553a64147049/go.mod h1:/XxbfmMg8l
|
||||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
|
||||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
|
github.com/golang/snappy v0.0.2 h1:aeE13tS0IiQgFjYdoL8qN3K1N2bXXtI6Vi51/y7BpMw=
|
||||||
|
github.com/golang/snappy v0.0.2/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||||
github.com/google/flatbuffers v1.11.0 h1:O7CEyB8Cb3/DmtxODGtLHcEvpr81Jm5qLg/hsHnxA2A=
|
github.com/google/flatbuffers v1.11.0 h1:O7CEyB8Cb3/DmtxODGtLHcEvpr81Jm5qLg/hsHnxA2A=
|
||||||
|
@ -509,14 +511,19 @@ github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed h1:5upAirOpQc
|
||||||
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
|
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
|
||||||
github.com/hashicorp/consul-template v0.25.1 h1:+D2s8eyRqWyX7GPNxeUi8tsyh8pRn3J6k8giEchPfKQ=
|
github.com/hashicorp/consul-template v0.25.1 h1:+D2s8eyRqWyX7GPNxeUi8tsyh8pRn3J6k8giEchPfKQ=
|
||||||
github.com/hashicorp/consul-template v0.25.1/go.mod h1:/vUsrJvDuuQHcxEw0zik+YXTS7ZKWZjQeaQhshBmfH0=
|
github.com/hashicorp/consul-template v0.25.1/go.mod h1:/vUsrJvDuuQHcxEw0zik+YXTS7ZKWZjQeaQhshBmfH0=
|
||||||
|
github.com/hashicorp/consul-template v0.25.2-0.20210123001810-166043f8559d h1:DSrhJ8Nqyr3oleIu0rCjRV4j6f4CJSPUp5DljXKKu4w=
|
||||||
|
github.com/hashicorp/consul-template v0.25.2-0.20210123001810-166043f8559d/go.mod h1:kNLSN13aPJz/P0we1XNU+ZDsjkbzX+iHJ+dJOqFZck0=
|
||||||
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
|
||||||
github.com/hashicorp/consul/api v1.4.0 h1:jfESivXnO5uLdH650JU/6AnjRoHrLhULq0FnC3Kp9EY=
|
github.com/hashicorp/consul/api v1.4.0 h1:jfESivXnO5uLdH650JU/6AnjRoHrLhULq0FnC3Kp9EY=
|
||||||
github.com/hashicorp/consul/api v1.4.0/go.mod h1:xc8u05kyMa3Wjr9eEAsIAo3dg8+LywT5E/Cl7cNS5nU=
|
github.com/hashicorp/consul/api v1.4.0/go.mod h1:xc8u05kyMa3Wjr9eEAsIAo3dg8+LywT5E/Cl7cNS5nU=
|
||||||
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||||
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
github.com/hashicorp/consul/sdk v0.3.0/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||||
github.com/hashicorp/consul/sdk v0.4.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM=
|
github.com/hashicorp/consul/sdk v0.4.0/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM=
|
||||||
|
github.com/hashicorp/consul/sdk v0.4.1-0.20200910203702-bb2b5dd871ca/go.mod h1:fY08Y9z5SvJqevyZNy6WWPXiG3KwBPAvlcdx16zZ0fM=
|
||||||
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
|
||||||
|
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible h1:EDTAuh27kAIhxuyK8ef3iHQARA+8NQaXyTeDEiG3Q6o=
|
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible h1:EDTAuh27kAIhxuyK8ef3iHQARA+8NQaXyTeDEiG3Q6o=
|
||||||
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible/go.mod h1:+IrDq36jUYG0q6TsDY9uO2p77C8f8S5y+RbYHr2UI+U=
|
github.com/hashicorp/go-bindata v3.0.8-0.20180209072458-bf7910af8997+incompatible/go.mod h1:+IrDq36jUYG0q6TsDY9uO2p77C8f8S5y+RbYHr2UI+U=
|
||||||
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||||
|
@ -538,6 +545,8 @@ github.com/hashicorp/go-hclog v0.14.1/go.mod h1:whpDNt7SSdeAju8AWKIWsul05p54N/39
|
||||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||||
github.com/hashicorp/go-immutable-radix v1.1.0 h1:vN9wG1D6KG6YHRTWr8512cxGOVgTMEfgEdSj/hr8MPc=
|
github.com/hashicorp/go-immutable-radix v1.1.0 h1:vN9wG1D6KG6YHRTWr8512cxGOVgTMEfgEdSj/hr8MPc=
|
||||||
github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
github.com/hashicorp/go-immutable-radix v1.1.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||||
|
github.com/hashicorp/go-immutable-radix v1.3.0 h1:8exGP7ego3OmkfksihtSouGMZ+hQrhxx+FVELeXpVPE=
|
||||||
|
github.com/hashicorp/go-immutable-radix v1.3.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||||
github.com/hashicorp/go-kms-wrapping v0.5.16 h1:7qvB7JYLFART/bt1wafobMU5dDeyseE3ZBKB6UiyxWs=
|
github.com/hashicorp/go-kms-wrapping v0.5.16 h1:7qvB7JYLFART/bt1wafobMU5dDeyseE3ZBKB6UiyxWs=
|
||||||
github.com/hashicorp/go-kms-wrapping v0.5.16/go.mod h1:lxD7e9q7ZyCtDEP+tnMevsEvw3M0gmZnneAgv8BaO1Q=
|
github.com/hashicorp/go-kms-wrapping v0.5.16/go.mod h1:lxD7e9q7ZyCtDEP+tnMevsEvw3M0gmZnneAgv8BaO1Q=
|
||||||
github.com/hashicorp/go-kms-wrapping/entropy v0.1.0 h1:xuTi5ZwjimfpvpL09jDE71smCBRpnF5xfo871BSX4gs=
|
github.com/hashicorp/go-kms-wrapping/entropy v0.1.0 h1:xuTi5ZwjimfpvpL09jDE71smCBRpnF5xfo871BSX4gs=
|
||||||
|
@ -580,6 +589,8 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ
|
||||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||||
github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk=
|
github.com/hashicorp/golang-lru v0.5.3 h1:YPkqC67at8FYaadspW/6uE0COsBxS2656RLEr8Bppgk=
|
||||||
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
|
||||||
|
github.com/hashicorp/golang-lru v0.5.4/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
github.com/hashicorp/hcl v1.0.1-vault h1:UiJeEzCWAYdVaJr8Xo4lBkTozlW1+1yxVUnpbS1xVEk=
|
github.com/hashicorp/hcl v1.0.1-vault h1:UiJeEzCWAYdVaJr8Xo4lBkTozlW1+1yxVUnpbS1xVEk=
|
||||||
github.com/hashicorp/hcl v1.0.1-vault/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
github.com/hashicorp/hcl v1.0.1-vault/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||||
|
@ -590,6 +601,7 @@ github.com/hashicorp/mdns v1.0.1 h1:XFSOubp8KWB+Jd2PDyaX5xUd5bhSP/+pTDZVDMzZJM8=
|
||||||
github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY=
|
github.com/hashicorp/mdns v1.0.1/go.mod h1:4gW7WsVCke5TE7EPeYliwHlRUyBtfCwuFwuMg2DmyNY=
|
||||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||||
github.com/hashicorp/memberlist v0.1.4/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
github.com/hashicorp/memberlist v0.1.4/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||||
|
github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
|
||||||
github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d h1:BXqsASWhyiAiEVm6FcltF0dg8XvoookQwmpHn8lstu8=
|
github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d h1:BXqsASWhyiAiEVm6FcltF0dg8XvoookQwmpHn8lstu8=
|
||||||
github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d/go.mod h1:WKCL+tLVhN1D+APwH3JiTRZoxcdwRk86bWu1LVCUPaE=
|
github.com/hashicorp/nomad/api v0.0.0-20191220223628-edc62acd919d/go.mod h1:WKCL+tLVhN1D+APwH3JiTRZoxcdwRk86bWu1LVCUPaE=
|
||||||
github.com/hashicorp/raft v1.0.1/go.mod h1:DVSAWItjLjTOkVbSpWQ0j0kUADIvDaCtBxIcbNAQLkI=
|
github.com/hashicorp/raft v1.0.1/go.mod h1:DVSAWItjLjTOkVbSpWQ0j0kUADIvDaCtBxIcbNAQLkI=
|
||||||
|
@ -602,6 +614,8 @@ github.com/hashicorp/raft-snapshot v1.0.3/go.mod h1:5sL9eUn72lH5DzsFIJ9jaysITbHk
|
||||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||||
github.com/hashicorp/serf v0.8.3 h1:MWYcmct5EtKz0efYooPcL0yNkem+7kWxqXDi/UIh+8k=
|
github.com/hashicorp/serf v0.8.3 h1:MWYcmct5EtKz0efYooPcL0yNkem+7kWxqXDi/UIh+8k=
|
||||||
github.com/hashicorp/serf v0.8.3/go.mod h1:UpNcs7fFbpKIyZaUuSW6EPiH+eZC7OuyFD+wc1oal+k=
|
github.com/hashicorp/serf v0.8.3/go.mod h1:UpNcs7fFbpKIyZaUuSW6EPiH+eZC7OuyFD+wc1oal+k=
|
||||||
|
github.com/hashicorp/serf v0.9.4 h1:xrZ4ZR0wT5Dz8oQHHdfOzr0ei1jMToWlFFz3hh/DI7I=
|
||||||
|
github.com/hashicorp/serf v0.9.4/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
|
||||||
github.com/hashicorp/vault-plugin-auth-alicloud v0.7.0 h1:qCTaVIb+FUWatLXszACH47Q/yTMrbedHt0CMGX9X41w=
|
github.com/hashicorp/vault-plugin-auth-alicloud v0.7.0 h1:qCTaVIb+FUWatLXszACH47Q/yTMrbedHt0CMGX9X41w=
|
||||||
github.com/hashicorp/vault-plugin-auth-alicloud v0.7.0/go.mod h1:lyfBMcULXKJfVu8dNo1w9bUikV5oem5HKmJoWwXupnY=
|
github.com/hashicorp/vault-plugin-auth-alicloud v0.7.0/go.mod h1:lyfBMcULXKJfVu8dNo1w9bUikV5oem5HKmJoWwXupnY=
|
||||||
github.com/hashicorp/vault-plugin-auth-azure v0.6.0 h1:LWUAYV+Td30+AnwjlBiYDk3j4XMDKOyk+OZyBSXU8tk=
|
github.com/hashicorp/vault-plugin-auth-azure v0.6.0 h1:LWUAYV+Td30+AnwjlBiYDk3j4XMDKOyk+OZyBSXU8tk=
|
||||||
|
@ -766,6 +780,8 @@ github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaO
|
||||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||||
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
github.com/mattn/go-colorable v0.1.6 h1:6Su7aK7lXmJ/U79bYtBjLNaha4Fs1Rg9plHpcH+vvnE=
|
||||||
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
|
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
|
||||||
|
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||||
github.com/mattn/go-ieproxy v0.0.1 h1:qiyop7gCflfhwCzGyeT0gro3sF9AIg9HU98JORTkqfI=
|
github.com/mattn/go-ieproxy v0.0.1 h1:qiyop7gCflfhwCzGyeT0gro3sF9AIg9HU98JORTkqfI=
|
||||||
github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E=
|
github.com/mattn/go-ieproxy v0.0.1/go.mod h1:pYabZ6IHcRpFh7vIaLfK7rdcWgFEb3SFJ6/gNWuh88E=
|
||||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||||
|
@ -779,6 +795,8 @@ github.com/mattn/go-runewidth v0.0.2/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzp
|
||||||
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
|
||||||
github.com/mattn/go-shellwords v1.0.5 h1:JhhFTIOslh5ZsPrpa3Wdg8bF0WI3b44EMblmU9wIsXc=
|
github.com/mattn/go-shellwords v1.0.5 h1:JhhFTIOslh5ZsPrpa3Wdg8bF0WI3b44EMblmU9wIsXc=
|
||||||
github.com/mattn/go-shellwords v1.0.5/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
|
github.com/mattn/go-shellwords v1.0.5/go.mod h1:3xCvwCdWdlDJUrvuMn7Wuy9eWs4pE8vqg+NOMyg4B2o=
|
||||||
|
github.com/mattn/go-shellwords v1.0.10 h1:Y7Xqm8piKOO3v10Thp7Z36h4FYFjt5xB//6XvOrs2Gw=
|
||||||
|
github.com/mattn/go-shellwords v1.0.10/go.mod h1:EZzvwXDESEeg03EKmM+RmDnNOPKG4lLtQsUlTZDWQ8Y=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||||
github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU=
|
github.com/mholt/archiver v3.1.1+incompatible h1:1dCVxuqs0dJseYEhi5pl7MYPH9zDa1wBi7mF09cbNkU=
|
||||||
|
@ -788,7 +806,10 @@ github.com/michaelklishin/rabbit-hole v0.0.0-20191008194146-93d9988f0cd5/go.mod
|
||||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
github.com/miekg/dns v1.1.15 h1:CSSIDtllwGLMoA6zjdKnaE6Tx6eVUxQ29LUgGetiDCI=
|
github.com/miekg/dns v1.1.15 h1:CSSIDtllwGLMoA6zjdKnaE6Tx6eVUxQ29LUgGetiDCI=
|
||||||
github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||||
|
github.com/miekg/dns v1.1.26 h1:gPxPSwALAeHJSjarOs00QjVdV9QoBvc1D2ujQUr5BzU=
|
||||||
|
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
||||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||||
|
github.com/mitchellh/cli v1.1.0/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
|
||||||
github.com/mitchellh/cli v1.1.1 h1:J64v/xD7Clql+JVKSvkYojLOXu1ibnY9ZjGLwSt/89w=
|
github.com/mitchellh/cli v1.1.1 h1:J64v/xD7Clql+JVKSvkYojLOXu1ibnY9ZjGLwSt/89w=
|
||||||
github.com/mitchellh/cli v1.1.1/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
|
github.com/mitchellh/cli v1.1.1/go.mod h1:xcISNoH86gajksDmfB23e/pu+B+GeFRMYmoHXxx3xhI=
|
||||||
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
|
github.com/mitchellh/copystructure v1.0.0 h1:Laisrj+bAB6b/yJwB5Bt3ITZhGJdqmxquMKeZ+mmkFQ=
|
||||||
|
@ -938,6 +959,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
|
||||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||||
github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI=
|
github.com/posener/complete v1.2.1 h1:LrvDIY//XNo65Lq84G/akBuMGlawHvGBABv8f/ZN6DI=
|
||||||
github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E=
|
github.com/posener/complete v1.2.1/go.mod h1:6gapUrK/U1TAN7ciCoNRIdVC5sbdBTUh1DKN0g6uH7E=
|
||||||
|
github.com/posener/complete v1.2.3 h1:NP0eAhjcjImqslEwo/1hq7gpajME0fTLTezBKDqfXqo=
|
||||||
|
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
|
||||||
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU=
|
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35 h1:J9b7z+QKAmPf4YLrFg6oQUotqHQeUNWwkvo7jZp1GLU=
|
||||||
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
|
github.com/pquerna/cachecontrol v0.0.0-20180517163645-1555304b9b35/go.mod h1:prYjPmNq4d1NPVmpShWobRqXY3q7Vp+80DqgxxUrUIA=
|
||||||
github.com/pquerna/otp v1.2.1-0.20191009055518-468c2dd2b58d h1:PinQItctnaL2LtkaSM678+ZLLy5TajwOeXzWvYC7tII=
|
github.com/pquerna/otp v1.2.1-0.20191009055518-468c2dd2b58d h1:PinQItctnaL2LtkaSM678+ZLLy5TajwOeXzWvYC7tII=
|
||||||
|
@ -1147,6 +1170,7 @@ golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8U
|
||||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||||
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20191206172530-e9b2fee46413/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
|
@ -1215,6 +1239,7 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL
|
||||||
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190724013045-ca1201d0de80/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20191003171128-d98b1b443823/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20191003171128-d98b1b443823/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
golang.org/x/net v0.0.0-20191112182307-2180aed22343/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
@ -1229,6 +1254,8 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/
|
||||||
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200602114024-627f9648deb9/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
|
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c h1:dk0ukUIHmGHqASjP0iue2261isepFCC6XRCSd1nHgDw=
|
||||||
|
golang.org/x/net v0.0.0-20201002202402-0a1ea396d57c/go.mod h1:iQL9McJNjoIa5mjH6nYTCTZXUN6RP+XW3eib7Ya3XcI=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190130055435-99b60b757ec1/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190130055435-99b60b757ec1/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
|
@ -1281,6 +1308,8 @@ golang.org/x/sys v0.0.0-20190712062909-fae7ac547cb7/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190726091711-fc99dfbffb4e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191001151750-bb3f8db39f24/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191008105621-543471e840be/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191022100944-742c48ecaeb7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
@ -1308,6 +1337,8 @@ golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||||
golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200828194041-157a740278f4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a h1:i47hUS795cOydZI4AwJQCKXOr4BvxzvikwDoDtHhP2Y=
|
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a h1:i47hUS795cOydZI4AwJQCKXOr4BvxzvikwDoDtHhP2Y=
|
||||||
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200831180312-196b9ba8737a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
||||||
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
@ -1322,6 +1353,8 @@ golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxb
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
|
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1 h1:NusfzzA6yGQ+ua51ck7E3omNUX/JuqbFSaRGqU8CcLI=
|
||||||
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20200416051211-89c76fbcd5d1/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
|
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
|
||||||
|
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
@ -1347,6 +1380,7 @@ golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgw
|
||||||
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||||
golang.org/x/tools v0.0.0-20190718200317-82a3ea8a504c/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
golang.org/x/tools v0.0.0-20190718200317-82a3ea8a504c/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
||||||
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
golang.org/x/tools v0.0.0-20191029041327-9cc4af7d6b2c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
|
|
@ -8,8 +8,10 @@
|
||||||
|
|
||||||
# Please keep the list sorted.
|
# Please keep the list sorted.
|
||||||
|
|
||||||
|
Amazon.com, Inc
|
||||||
Damian Gryski <dgryski@gmail.com>
|
Damian Gryski <dgryski@gmail.com>
|
||||||
Google Inc.
|
Google Inc.
|
||||||
Jan Mercl <0xjnml@gmail.com>
|
Jan Mercl <0xjnml@gmail.com>
|
||||||
|
Klaus Post <klauspost@gmail.com>
|
||||||
Rodolfo Carvalho <rhcarvalho@gmail.com>
|
Rodolfo Carvalho <rhcarvalho@gmail.com>
|
||||||
Sebastien Binet <seb.binet@gmail.com>
|
Sebastien Binet <seb.binet@gmail.com>
|
||||||
|
|
|
@ -28,7 +28,9 @@
|
||||||
|
|
||||||
Damian Gryski <dgryski@gmail.com>
|
Damian Gryski <dgryski@gmail.com>
|
||||||
Jan Mercl <0xjnml@gmail.com>
|
Jan Mercl <0xjnml@gmail.com>
|
||||||
|
Jonathan Swinney <jswinney@amazon.com>
|
||||||
Kai Backman <kaib@golang.org>
|
Kai Backman <kaib@golang.org>
|
||||||
|
Klaus Post <klauspost@gmail.com>
|
||||||
Marc-Antoine Ruel <maruel@chromium.org>
|
Marc-Antoine Ruel <maruel@chromium.org>
|
||||||
Nigel Tao <nigeltao@golang.org>
|
Nigel Tao <nigeltao@golang.org>
|
||||||
Rob Pike <r@golang.org>
|
Rob Pike <r@golang.org>
|
||||||
|
|
|
@ -52,6 +52,8 @@ const (
|
||||||
// Otherwise, a newly allocated slice will be returned.
|
// Otherwise, a newly allocated slice will be returned.
|
||||||
//
|
//
|
||||||
// The dst and src must not overlap. It is valid to pass a nil dst.
|
// The dst and src must not overlap. It is valid to pass a nil dst.
|
||||||
|
//
|
||||||
|
// Decode handles the Snappy block format, not the Snappy stream format.
|
||||||
func Decode(dst, src []byte) ([]byte, error) {
|
func Decode(dst, src []byte) ([]byte, error) {
|
||||||
dLen, s, err := decodedLen(src)
|
dLen, s, err := decodedLen(src)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -83,6 +85,8 @@ func NewReader(r io.Reader) *Reader {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reader is an io.Reader that can read Snappy-compressed bytes.
|
// Reader is an io.Reader that can read Snappy-compressed bytes.
|
||||||
|
//
|
||||||
|
// Reader handles the Snappy stream format, not the Snappy block format.
|
||||||
type Reader struct {
|
type Reader struct {
|
||||||
r io.Reader
|
r io.Reader
|
||||||
err error
|
err error
|
||||||
|
|
|
@ -0,0 +1,503 @@
|
||||||
|
// Copyright 2020 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build !appengine
|
||||||
|
// +build gc
|
||||||
|
// +build !noasm
|
||||||
|
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// The asm code generally follows the pure Go code in decode_other.go, except
|
||||||
|
// where marked with a "!!!".
|
||||||
|
|
||||||
|
// func decode(dst, src []byte) int
|
||||||
|
//
|
||||||
|
// All local variables fit into registers. The non-zero stack size is only to
|
||||||
|
// spill registers and push args when issuing a CALL. The register allocation:
|
||||||
|
// - R2 scratch
|
||||||
|
// - R3 scratch
|
||||||
|
// - R4 length or x
|
||||||
|
// - R5 offset
|
||||||
|
// - R6 &src[s]
|
||||||
|
// - R7 &dst[d]
|
||||||
|
// + R8 dst_base
|
||||||
|
// + R9 dst_len
|
||||||
|
// + R10 dst_base + dst_len
|
||||||
|
// + R11 src_base
|
||||||
|
// + R12 src_len
|
||||||
|
// + R13 src_base + src_len
|
||||||
|
// - R14 used by doCopy
|
||||||
|
// - R15 used by doCopy
|
||||||
|
//
|
||||||
|
// The registers R8-R13 (marked with a "+") are set at the start of the
|
||||||
|
// function, and after a CALL returns, and are not otherwise modified.
|
||||||
|
//
|
||||||
|
// The d variable is implicitly R7 - R8, and len(dst)-d is R10 - R7.
|
||||||
|
// The s variable is implicitly R6 - R11, and len(src)-s is R13 - R6.
|
||||||
|
TEXT ·decode(SB), NOSPLIT, $56-56
|
||||||
|
// Initialize R6, R7 and R8-R13.
|
||||||
|
MOVD dst_base+0(FP), R8
|
||||||
|
MOVD dst_len+8(FP), R9
|
||||||
|
MOVD R8, R7
|
||||||
|
MOVD R8, R10
|
||||||
|
ADD R9, R10, R10
|
||||||
|
MOVD src_base+24(FP), R11
|
||||||
|
MOVD src_len+32(FP), R12
|
||||||
|
MOVD R11, R6
|
||||||
|
MOVD R11, R13
|
||||||
|
ADD R12, R13, R13
|
||||||
|
|
||||||
|
loop:
|
||||||
|
// for s < len(src)
|
||||||
|
CMP R13, R6
|
||||||
|
BEQ end
|
||||||
|
|
||||||
|
// R4 = uint32(src[s])
|
||||||
|
//
|
||||||
|
// switch src[s] & 0x03
|
||||||
|
MOVBU (R6), R4
|
||||||
|
MOVW R4, R3
|
||||||
|
ANDW $3, R3
|
||||||
|
MOVW $1, R1
|
||||||
|
CMPW R1, R3
|
||||||
|
BGE tagCopy
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
// The code below handles literal tags.
|
||||||
|
|
||||||
|
// case tagLiteral:
|
||||||
|
// x := uint32(src[s] >> 2)
|
||||||
|
// switch
|
||||||
|
MOVW $60, R1
|
||||||
|
ADD R4>>2, ZR, R4
|
||||||
|
CMPW R4, R1
|
||||||
|
BLS tagLit60Plus
|
||||||
|
|
||||||
|
// case x < 60:
|
||||||
|
// s++
|
||||||
|
ADD $1, R6, R6
|
||||||
|
|
||||||
|
doLit:
|
||||||
|
// This is the end of the inner "switch", when we have a literal tag.
|
||||||
|
//
|
||||||
|
// We assume that R4 == x and x fits in a uint32, where x is the variable
|
||||||
|
// used in the pure Go decode_other.go code.
|
||||||
|
|
||||||
|
// length = int(x) + 1
|
||||||
|
//
|
||||||
|
// Unlike the pure Go code, we don't need to check if length <= 0 because
|
||||||
|
// R4 can hold 64 bits, so the increment cannot overflow.
|
||||||
|
ADD $1, R4, R4
|
||||||
|
|
||||||
|
// Prepare to check if copying length bytes will run past the end of dst or
|
||||||
|
// src.
|
||||||
|
//
|
||||||
|
// R2 = len(dst) - d
|
||||||
|
// R3 = len(src) - s
|
||||||
|
MOVD R10, R2
|
||||||
|
SUB R7, R2, R2
|
||||||
|
MOVD R13, R3
|
||||||
|
SUB R6, R3, R3
|
||||||
|
|
||||||
|
// !!! Try a faster technique for short (16 or fewer bytes) copies.
|
||||||
|
//
|
||||||
|
// if length > 16 || len(dst)-d < 16 || len(src)-s < 16 {
|
||||||
|
// goto callMemmove // Fall back on calling runtime·memmove.
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// The C++ snappy code calls this TryFastAppend. It also checks len(src)-s
|
||||||
|
// against 21 instead of 16, because it cannot assume that all of its input
|
||||||
|
// is contiguous in memory and so it needs to leave enough source bytes to
|
||||||
|
// read the next tag without refilling buffers, but Go's Decode assumes
|
||||||
|
// contiguousness (the src argument is a []byte).
|
||||||
|
MOVD $16, R1
|
||||||
|
CMP R1, R4
|
||||||
|
BGT callMemmove
|
||||||
|
CMP R1, R2
|
||||||
|
BLT callMemmove
|
||||||
|
CMP R1, R3
|
||||||
|
BLT callMemmove
|
||||||
|
|
||||||
|
// !!! Implement the copy from src to dst as a 16-byte load and store.
|
||||||
|
// (Decode's documentation says that dst and src must not overlap.)
|
||||||
|
//
|
||||||
|
// This always copies 16 bytes, instead of only length bytes, but that's
|
||||||
|
// OK. If the input is a valid Snappy encoding then subsequent iterations
|
||||||
|
// will fix up the overrun. Otherwise, Decode returns a nil []byte (and a
|
||||||
|
// non-nil error), so the overrun will be ignored.
|
||||||
|
//
|
||||||
|
// Note that on arm64, it is legal and cheap to issue unaligned 8-byte or
|
||||||
|
// 16-byte loads and stores. This technique probably wouldn't be as
|
||||||
|
// effective on architectures that are fussier about alignment.
|
||||||
|
|
||||||
|
VLD1 0(R6), [V0.B16]
|
||||||
|
VST1 [V0.B16], 0(R7)
|
||||||
|
|
||||||
|
// d += length
|
||||||
|
// s += length
|
||||||
|
ADD R4, R7, R7
|
||||||
|
ADD R4, R6, R6
|
||||||
|
B loop
|
||||||
|
|
||||||
|
callMemmove:
|
||||||
|
// if length > len(dst)-d || length > len(src)-s { etc }
|
||||||
|
CMP R2, R4
|
||||||
|
BGT errCorrupt
|
||||||
|
CMP R3, R4
|
||||||
|
BGT errCorrupt
|
||||||
|
|
||||||
|
// copy(dst[d:], src[s:s+length])
|
||||||
|
//
|
||||||
|
// This means calling runtime·memmove(&dst[d], &src[s], length), so we push
|
||||||
|
// R7, R6 and R4 as arguments. Coincidentally, we also need to spill those
|
||||||
|
// three registers to the stack, to save local variables across the CALL.
|
||||||
|
MOVD R7, 8(RSP)
|
||||||
|
MOVD R6, 16(RSP)
|
||||||
|
MOVD R4, 24(RSP)
|
||||||
|
MOVD R7, 32(RSP)
|
||||||
|
MOVD R6, 40(RSP)
|
||||||
|
MOVD R4, 48(RSP)
|
||||||
|
CALL runtime·memmove(SB)
|
||||||
|
|
||||||
|
// Restore local variables: unspill registers from the stack and
|
||||||
|
// re-calculate R8-R13.
|
||||||
|
MOVD 32(RSP), R7
|
||||||
|
MOVD 40(RSP), R6
|
||||||
|
MOVD 48(RSP), R4
|
||||||
|
MOVD dst_base+0(FP), R8
|
||||||
|
MOVD dst_len+8(FP), R9
|
||||||
|
MOVD R8, R10
|
||||||
|
ADD R9, R10, R10
|
||||||
|
MOVD src_base+24(FP), R11
|
||||||
|
MOVD src_len+32(FP), R12
|
||||||
|
MOVD R11, R13
|
||||||
|
ADD R12, R13, R13
|
||||||
|
|
||||||
|
// d += length
|
||||||
|
// s += length
|
||||||
|
ADD R4, R7, R7
|
||||||
|
ADD R4, R6, R6
|
||||||
|
B loop
|
||||||
|
|
||||||
|
tagLit60Plus:
|
||||||
|
// !!! This fragment does the
|
||||||
|
//
|
||||||
|
// s += x - 58; if uint(s) > uint(len(src)) { etc }
|
||||||
|
//
|
||||||
|
// checks. In the asm version, we code it once instead of once per switch case.
|
||||||
|
ADD R4, R6, R6
|
||||||
|
SUB $58, R6, R6
|
||||||
|
MOVD R6, R3
|
||||||
|
SUB R11, R3, R3
|
||||||
|
CMP R12, R3
|
||||||
|
BGT errCorrupt
|
||||||
|
|
||||||
|
// case x == 60:
|
||||||
|
MOVW $61, R1
|
||||||
|
CMPW R1, R4
|
||||||
|
BEQ tagLit61
|
||||||
|
BGT tagLit62Plus
|
||||||
|
|
||||||
|
// x = uint32(src[s-1])
|
||||||
|
MOVBU -1(R6), R4
|
||||||
|
B doLit
|
||||||
|
|
||||||
|
tagLit61:
|
||||||
|
// case x == 61:
|
||||||
|
// x = uint32(src[s-2]) | uint32(src[s-1])<<8
|
||||||
|
MOVHU -2(R6), R4
|
||||||
|
B doLit
|
||||||
|
|
||||||
|
tagLit62Plus:
|
||||||
|
MOVW $62, R1
|
||||||
|
CMPW R1, R4
|
||||||
|
BHI tagLit63
|
||||||
|
|
||||||
|
// case x == 62:
|
||||||
|
// x = uint32(src[s-3]) | uint32(src[s-2])<<8 | uint32(src[s-1])<<16
|
||||||
|
MOVHU -3(R6), R4
|
||||||
|
MOVBU -1(R6), R3
|
||||||
|
ORR R3<<16, R4
|
||||||
|
B doLit
|
||||||
|
|
||||||
|
tagLit63:
|
||||||
|
// case x == 63:
|
||||||
|
// x = uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24
|
||||||
|
MOVWU -4(R6), R4
|
||||||
|
B doLit
|
||||||
|
|
||||||
|
// The code above handles literal tags.
|
||||||
|
// ----------------------------------------
|
||||||
|
// The code below handles copy tags.
|
||||||
|
|
||||||
|
tagCopy4:
|
||||||
|
// case tagCopy4:
|
||||||
|
// s += 5
|
||||||
|
ADD $5, R6, R6
|
||||||
|
|
||||||
|
// if uint(s) > uint(len(src)) { etc }
|
||||||
|
MOVD R6, R3
|
||||||
|
SUB R11, R3, R3
|
||||||
|
CMP R12, R3
|
||||||
|
BGT errCorrupt
|
||||||
|
|
||||||
|
// length = 1 + int(src[s-5])>>2
|
||||||
|
MOVD $1, R1
|
||||||
|
ADD R4>>2, R1, R4
|
||||||
|
|
||||||
|
// offset = int(uint32(src[s-4]) | uint32(src[s-3])<<8 | uint32(src[s-2])<<16 | uint32(src[s-1])<<24)
|
||||||
|
MOVWU -4(R6), R5
|
||||||
|
B doCopy
|
||||||
|
|
||||||
|
tagCopy2:
|
||||||
|
// case tagCopy2:
|
||||||
|
// s += 3
|
||||||
|
ADD $3, R6, R6
|
||||||
|
|
||||||
|
// if uint(s) > uint(len(src)) { etc }
|
||||||
|
MOVD R6, R3
|
||||||
|
SUB R11, R3, R3
|
||||||
|
CMP R12, R3
|
||||||
|
BGT errCorrupt
|
||||||
|
|
||||||
|
// length = 1 + int(src[s-3])>>2
|
||||||
|
MOVD $1, R1
|
||||||
|
ADD R4>>2, R1, R4
|
||||||
|
|
||||||
|
// offset = int(uint32(src[s-2]) | uint32(src[s-1])<<8)
|
||||||
|
MOVHU -2(R6), R5
|
||||||
|
B doCopy
|
||||||
|
|
||||||
|
tagCopy:
|
||||||
|
// We have a copy tag. We assume that:
|
||||||
|
// - R3 == src[s] & 0x03
|
||||||
|
// - R4 == src[s]
|
||||||
|
MOVD $2, R1
|
||||||
|
CMP R1, R3
|
||||||
|
BEQ tagCopy2
|
||||||
|
BGT tagCopy4
|
||||||
|
|
||||||
|
// case tagCopy1:
|
||||||
|
// s += 2
|
||||||
|
ADD $2, R6, R6
|
||||||
|
|
||||||
|
// if uint(s) > uint(len(src)) { etc }
|
||||||
|
MOVD R6, R3
|
||||||
|
SUB R11, R3, R3
|
||||||
|
CMP R12, R3
|
||||||
|
BGT errCorrupt
|
||||||
|
|
||||||
|
// offset = int(uint32(src[s-2])&0xe0<<3 | uint32(src[s-1]))
|
||||||
|
MOVD R4, R5
|
||||||
|
AND $0xe0, R5
|
||||||
|
MOVBU -1(R6), R3
|
||||||
|
ORR R5<<3, R3, R5
|
||||||
|
|
||||||
|
// length = 4 + int(src[s-2])>>2&0x7
|
||||||
|
MOVD $7, R1
|
||||||
|
AND R4>>2, R1, R4
|
||||||
|
ADD $4, R4, R4
|
||||||
|
|
||||||
|
doCopy:
|
||||||
|
// This is the end of the outer "switch", when we have a copy tag.
|
||||||
|
//
|
||||||
|
// We assume that:
|
||||||
|
// - R4 == length && R4 > 0
|
||||||
|
// - R5 == offset
|
||||||
|
|
||||||
|
// if offset <= 0 { etc }
|
||||||
|
MOVD $0, R1
|
||||||
|
CMP R1, R5
|
||||||
|
BLE errCorrupt
|
||||||
|
|
||||||
|
// if d < offset { etc }
|
||||||
|
MOVD R7, R3
|
||||||
|
SUB R8, R3, R3
|
||||||
|
CMP R5, R3
|
||||||
|
BLT errCorrupt
|
||||||
|
|
||||||
|
// if length > len(dst)-d { etc }
|
||||||
|
MOVD R10, R3
|
||||||
|
SUB R7, R3, R3
|
||||||
|
CMP R3, R4
|
||||||
|
BGT errCorrupt
|
||||||
|
|
||||||
|
// forwardCopy(dst[d:d+length], dst[d-offset:]); d += length
|
||||||
|
//
|
||||||
|
// Set:
|
||||||
|
// - R14 = len(dst)-d
|
||||||
|
// - R15 = &dst[d-offset]
|
||||||
|
MOVD R10, R14
|
||||||
|
SUB R7, R14, R14
|
||||||
|
MOVD R7, R15
|
||||||
|
SUB R5, R15, R15
|
||||||
|
|
||||||
|
// !!! Try a faster technique for short (16 or fewer bytes) forward copies.
|
||||||
|
//
|
||||||
|
// First, try using two 8-byte load/stores, similar to the doLit technique
|
||||||
|
// above. Even if dst[d:d+length] and dst[d-offset:] can overlap, this is
|
||||||
|
// still OK if offset >= 8. Note that this has to be two 8-byte load/stores
|
||||||
|
// and not one 16-byte load/store, and the first store has to be before the
|
||||||
|
// second load, due to the overlap if offset is in the range [8, 16).
|
||||||
|
//
|
||||||
|
// if length > 16 || offset < 8 || len(dst)-d < 16 {
|
||||||
|
// goto slowForwardCopy
|
||||||
|
// }
|
||||||
|
// copy 16 bytes
|
||||||
|
// d += length
|
||||||
|
MOVD $16, R1
|
||||||
|
MOVD $8, R0
|
||||||
|
CMP R1, R4
|
||||||
|
BGT slowForwardCopy
|
||||||
|
CMP R0, R5
|
||||||
|
BLT slowForwardCopy
|
||||||
|
CMP R1, R14
|
||||||
|
BLT slowForwardCopy
|
||||||
|
MOVD 0(R15), R2
|
||||||
|
MOVD R2, 0(R7)
|
||||||
|
MOVD 8(R15), R3
|
||||||
|
MOVD R3, 8(R7)
|
||||||
|
ADD R4, R7, R7
|
||||||
|
B loop
|
||||||
|
|
||||||
|
slowForwardCopy:
|
||||||
|
// !!! If the forward copy is longer than 16 bytes, or if offset < 8, we
|
||||||
|
// can still try 8-byte load stores, provided we can overrun up to 10 extra
|
||||||
|
// bytes. As above, the overrun will be fixed up by subsequent iterations
|
||||||
|
// of the outermost loop.
|
||||||
|
//
|
||||||
|
// The C++ snappy code calls this technique IncrementalCopyFastPath. Its
|
||||||
|
// commentary says:
|
||||||
|
//
|
||||||
|
// ----
|
||||||
|
//
|
||||||
|
// The main part of this loop is a simple copy of eight bytes at a time
|
||||||
|
// until we've copied (at least) the requested amount of bytes. However,
|
||||||
|
// if d and d-offset are less than eight bytes apart (indicating a
|
||||||
|
// repeating pattern of length < 8), we first need to expand the pattern in
|
||||||
|
// order to get the correct results. For instance, if the buffer looks like
|
||||||
|
// this, with the eight-byte <d-offset> and <d> patterns marked as
|
||||||
|
// intervals:
|
||||||
|
//
|
||||||
|
// abxxxxxxxxxxxx
|
||||||
|
// [------] d-offset
|
||||||
|
// [------] d
|
||||||
|
//
|
||||||
|
// a single eight-byte copy from <d-offset> to <d> will repeat the pattern
|
||||||
|
// once, after which we can move <d> two bytes without moving <d-offset>:
|
||||||
|
//
|
||||||
|
// ababxxxxxxxxxx
|
||||||
|
// [------] d-offset
|
||||||
|
// [------] d
|
||||||
|
//
|
||||||
|
// and repeat the exercise until the two no longer overlap.
|
||||||
|
//
|
||||||
|
// This allows us to do very well in the special case of one single byte
|
||||||
|
// repeated many times, without taking a big hit for more general cases.
|
||||||
|
//
|
||||||
|
// The worst case of extra writing past the end of the match occurs when
|
||||||
|
// offset == 1 and length == 1; the last copy will read from byte positions
|
||||||
|
// [0..7] and write to [4..11], whereas it was only supposed to write to
|
||||||
|
// position 1. Thus, ten excess bytes.
|
||||||
|
//
|
||||||
|
// ----
|
||||||
|
//
|
||||||
|
// That "10 byte overrun" worst case is confirmed by Go's
|
||||||
|
// TestSlowForwardCopyOverrun, which also tests the fixUpSlowForwardCopy
|
||||||
|
// and finishSlowForwardCopy algorithm.
|
||||||
|
//
|
||||||
|
// if length > len(dst)-d-10 {
|
||||||
|
// goto verySlowForwardCopy
|
||||||
|
// }
|
||||||
|
SUB $10, R14, R14
|
||||||
|
CMP R14, R4
|
||||||
|
BGT verySlowForwardCopy
|
||||||
|
|
||||||
|
makeOffsetAtLeast8:
|
||||||
|
// !!! As above, expand the pattern so that offset >= 8 and we can use
|
||||||
|
// 8-byte load/stores.
|
||||||
|
//
|
||||||
|
// for offset < 8 {
|
||||||
|
// copy 8 bytes from dst[d-offset:] to dst[d:]
|
||||||
|
// length -= offset
|
||||||
|
// d += offset
|
||||||
|
// offset += offset
|
||||||
|
// // The two previous lines together means that d-offset, and therefore
|
||||||
|
// // R15, is unchanged.
|
||||||
|
// }
|
||||||
|
MOVD $8, R1
|
||||||
|
CMP R1, R5
|
||||||
|
BGE fixUpSlowForwardCopy
|
||||||
|
MOVD (R15), R3
|
||||||
|
MOVD R3, (R7)
|
||||||
|
SUB R5, R4, R4
|
||||||
|
ADD R5, R7, R7
|
||||||
|
ADD R5, R5, R5
|
||||||
|
B makeOffsetAtLeast8
|
||||||
|
|
||||||
|
fixUpSlowForwardCopy:
|
||||||
|
// !!! Add length (which might be negative now) to d (implied by R7 being
|
||||||
|
// &dst[d]) so that d ends up at the right place when we jump back to the
|
||||||
|
// top of the loop. Before we do that, though, we save R7 to R2 so that, if
|
||||||
|
// length is positive, copying the remaining length bytes will write to the
|
||||||
|
// right place.
|
||||||
|
MOVD R7, R2
|
||||||
|
ADD R4, R7, R7
|
||||||
|
|
||||||
|
finishSlowForwardCopy:
|
||||||
|
// !!! Repeat 8-byte load/stores until length <= 0. Ending with a negative
|
||||||
|
// length means that we overrun, but as above, that will be fixed up by
|
||||||
|
// subsequent iterations of the outermost loop.
|
||||||
|
MOVD $0, R1
|
||||||
|
CMP R1, R4
|
||||||
|
BLE loop
|
||||||
|
MOVD (R15), R3
|
||||||
|
MOVD R3, (R2)
|
||||||
|
ADD $8, R15, R15
|
||||||
|
ADD $8, R2, R2
|
||||||
|
SUB $8, R4, R4
|
||||||
|
B finishSlowForwardCopy
|
||||||
|
|
||||||
|
verySlowForwardCopy:
|
||||||
|
// verySlowForwardCopy is a simple implementation of forward copy. In C
|
||||||
|
// parlance, this is a do/while loop instead of a while loop, since we know
|
||||||
|
// that length > 0. In Go syntax:
|
||||||
|
//
|
||||||
|
// for {
|
||||||
|
// dst[d] = dst[d - offset]
|
||||||
|
// d++
|
||||||
|
// length--
|
||||||
|
// if length == 0 {
|
||||||
|
// break
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
MOVB (R15), R3
|
||||||
|
MOVB R3, (R7)
|
||||||
|
ADD $1, R15, R15
|
||||||
|
ADD $1, R7, R7
|
||||||
|
SUB $1, R4, R4
|
||||||
|
MOVD $0, R1
|
||||||
|
CMP R1, R4
|
||||||
|
BNE verySlowForwardCopy
|
||||||
|
B loop
|
||||||
|
|
||||||
|
// The code above handles copy tags.
|
||||||
|
// ----------------------------------------
|
||||||
|
|
||||||
|
end:
|
||||||
|
// This is the end of the "for s < len(src)".
|
||||||
|
//
|
||||||
|
// if d != len(dst) { etc }
|
||||||
|
CMP R10, R7
|
||||||
|
BNE errCorrupt
|
||||||
|
|
||||||
|
// return 0
|
||||||
|
MOVD $0, ret+48(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
errCorrupt:
|
||||||
|
// return decodeErrCodeCorrupt
|
||||||
|
MOVD $1, R2
|
||||||
|
MOVD R2, ret+48(FP)
|
||||||
|
RET
|
|
@ -5,6 +5,7 @@
|
||||||
// +build !appengine
|
// +build !appengine
|
||||||
// +build gc
|
// +build gc
|
||||||
// +build !noasm
|
// +build !noasm
|
||||||
|
// +build amd64 arm64
|
||||||
|
|
||||||
package snappy
|
package snappy
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build !amd64 appengine !gc noasm
|
// +build !amd64,!arm64 appengine !gc noasm
|
||||||
|
|
||||||
package snappy
|
package snappy
|
||||||
|
|
||||||
|
@ -85,14 +85,28 @@ func decode(dst, src []byte) int {
|
||||||
if offset <= 0 || d < offset || length > len(dst)-d {
|
if offset <= 0 || d < offset || length > len(dst)-d {
|
||||||
return decodeErrCodeCorrupt
|
return decodeErrCodeCorrupt
|
||||||
}
|
}
|
||||||
// Copy from an earlier sub-slice of dst to a later sub-slice. Unlike
|
// Copy from an earlier sub-slice of dst to a later sub-slice.
|
||||||
// the built-in copy function, this byte-by-byte copy always runs
|
// If no overlap, use the built-in copy:
|
||||||
|
if offset >= length {
|
||||||
|
copy(dst[d:d+length], dst[d-offset:])
|
||||||
|
d += length
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlike the built-in copy function, this byte-by-byte copy always runs
|
||||||
// forwards, even if the slices overlap. Conceptually, this is:
|
// forwards, even if the slices overlap. Conceptually, this is:
|
||||||
//
|
//
|
||||||
// d += forwardCopy(dst[d:d+length], dst[d-offset:])
|
// d += forwardCopy(dst[d:d+length], dst[d-offset:])
|
||||||
for end := d + length; d != end; d++ {
|
//
|
||||||
dst[d] = dst[d-offset]
|
// We align the slices into a and b and show the compiler they are the same size.
|
||||||
|
// This allows the loop to run without bounds checks.
|
||||||
|
a := dst[d : d+length]
|
||||||
|
b := dst[d-offset:]
|
||||||
|
b = b[:len(a)]
|
||||||
|
for i := range a {
|
||||||
|
a[i] = b[i]
|
||||||
}
|
}
|
||||||
|
d += length
|
||||||
}
|
}
|
||||||
if d != len(dst) {
|
if d != len(dst) {
|
||||||
return decodeErrCodeCorrupt
|
return decodeErrCodeCorrupt
|
||||||
|
|
|
@ -15,6 +15,8 @@ import (
|
||||||
// Otherwise, a newly allocated slice will be returned.
|
// Otherwise, a newly allocated slice will be returned.
|
||||||
//
|
//
|
||||||
// The dst and src must not overlap. It is valid to pass a nil dst.
|
// The dst and src must not overlap. It is valid to pass a nil dst.
|
||||||
|
//
|
||||||
|
// Encode handles the Snappy block format, not the Snappy stream format.
|
||||||
func Encode(dst, src []byte) []byte {
|
func Encode(dst, src []byte) []byte {
|
||||||
if n := MaxEncodedLen(len(src)); n < 0 {
|
if n := MaxEncodedLen(len(src)); n < 0 {
|
||||||
panic(ErrTooLarge)
|
panic(ErrTooLarge)
|
||||||
|
@ -139,6 +141,8 @@ func NewBufferedWriter(w io.Writer) *Writer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Writer is an io.Writer that can write Snappy-compressed bytes.
|
// Writer is an io.Writer that can write Snappy-compressed bytes.
|
||||||
|
//
|
||||||
|
// Writer handles the Snappy stream format, not the Snappy block format.
|
||||||
type Writer struct {
|
type Writer struct {
|
||||||
w io.Writer
|
w io.Writer
|
||||||
err error
|
err error
|
||||||
|
|
|
@ -0,0 +1,729 @@
|
||||||
|
// Copyright 2020 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build !appengine
|
||||||
|
// +build gc
|
||||||
|
// +build !noasm
|
||||||
|
|
||||||
|
#include "textflag.h"
|
||||||
|
|
||||||
|
// The asm code generally follows the pure Go code in encode_other.go, except
|
||||||
|
// where marked with a "!!!".
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// func emitLiteral(dst, lit []byte) int
|
||||||
|
//
|
||||||
|
// All local variables fit into registers. The register allocation:
|
||||||
|
// - R3 len(lit)
|
||||||
|
// - R4 n
|
||||||
|
// - R6 return value
|
||||||
|
// - R8 &dst[i]
|
||||||
|
// - R10 &lit[0]
|
||||||
|
//
|
||||||
|
// The 32 bytes of stack space is to call runtime·memmove.
|
||||||
|
//
|
||||||
|
// The unusual register allocation of local variables, such as R10 for the
|
||||||
|
// source pointer, matches the allocation used at the call site in encodeBlock,
|
||||||
|
// which makes it easier to manually inline this function.
|
||||||
|
TEXT ·emitLiteral(SB), NOSPLIT, $32-56
|
||||||
|
MOVD dst_base+0(FP), R8
|
||||||
|
MOVD lit_base+24(FP), R10
|
||||||
|
MOVD lit_len+32(FP), R3
|
||||||
|
MOVD R3, R6
|
||||||
|
MOVW R3, R4
|
||||||
|
SUBW $1, R4, R4
|
||||||
|
|
||||||
|
MOVW $60, R2
|
||||||
|
CMPW R2, R4
|
||||||
|
BLT oneByte
|
||||||
|
MOVW $256, R2
|
||||||
|
CMPW R2, R4
|
||||||
|
BLT twoBytes
|
||||||
|
|
||||||
|
threeBytes:
|
||||||
|
MOVD $0xf4, R2
|
||||||
|
MOVB R2, 0(R8)
|
||||||
|
MOVW R4, 1(R8)
|
||||||
|
ADD $3, R8, R8
|
||||||
|
ADD $3, R6, R6
|
||||||
|
B memmove
|
||||||
|
|
||||||
|
twoBytes:
|
||||||
|
MOVD $0xf0, R2
|
||||||
|
MOVB R2, 0(R8)
|
||||||
|
MOVB R4, 1(R8)
|
||||||
|
ADD $2, R8, R8
|
||||||
|
ADD $2, R6, R6
|
||||||
|
B memmove
|
||||||
|
|
||||||
|
oneByte:
|
||||||
|
LSLW $2, R4, R4
|
||||||
|
MOVB R4, 0(R8)
|
||||||
|
ADD $1, R8, R8
|
||||||
|
ADD $1, R6, R6
|
||||||
|
|
||||||
|
memmove:
|
||||||
|
MOVD R6, ret+48(FP)
|
||||||
|
|
||||||
|
// copy(dst[i:], lit)
|
||||||
|
//
|
||||||
|
// This means calling runtime·memmove(&dst[i], &lit[0], len(lit)), so we push
|
||||||
|
// R8, R10 and R3 as arguments.
|
||||||
|
MOVD R8, 8(RSP)
|
||||||
|
MOVD R10, 16(RSP)
|
||||||
|
MOVD R3, 24(RSP)
|
||||||
|
CALL runtime·memmove(SB)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// func emitCopy(dst []byte, offset, length int) int
|
||||||
|
//
|
||||||
|
// All local variables fit into registers. The register allocation:
|
||||||
|
// - R3 length
|
||||||
|
// - R7 &dst[0]
|
||||||
|
// - R8 &dst[i]
|
||||||
|
// - R11 offset
|
||||||
|
//
|
||||||
|
// The unusual register allocation of local variables, such as R11 for the
|
||||||
|
// offset, matches the allocation used at the call site in encodeBlock, which
|
||||||
|
// makes it easier to manually inline this function.
|
||||||
|
TEXT ·emitCopy(SB), NOSPLIT, $0-48
|
||||||
|
MOVD dst_base+0(FP), R8
|
||||||
|
MOVD R8, R7
|
||||||
|
MOVD offset+24(FP), R11
|
||||||
|
MOVD length+32(FP), R3
|
||||||
|
|
||||||
|
loop0:
|
||||||
|
// for length >= 68 { etc }
|
||||||
|
MOVW $68, R2
|
||||||
|
CMPW R2, R3
|
||||||
|
BLT step1
|
||||||
|
|
||||||
|
// Emit a length 64 copy, encoded as 3 bytes.
|
||||||
|
MOVD $0xfe, R2
|
||||||
|
MOVB R2, 0(R8)
|
||||||
|
MOVW R11, 1(R8)
|
||||||
|
ADD $3, R8, R8
|
||||||
|
SUB $64, R3, R3
|
||||||
|
B loop0
|
||||||
|
|
||||||
|
step1:
|
||||||
|
// if length > 64 { etc }
|
||||||
|
MOVD $64, R2
|
||||||
|
CMP R2, R3
|
||||||
|
BLE step2
|
||||||
|
|
||||||
|
// Emit a length 60 copy, encoded as 3 bytes.
|
||||||
|
MOVD $0xee, R2
|
||||||
|
MOVB R2, 0(R8)
|
||||||
|
MOVW R11, 1(R8)
|
||||||
|
ADD $3, R8, R8
|
||||||
|
SUB $60, R3, R3
|
||||||
|
|
||||||
|
step2:
|
||||||
|
// if length >= 12 || offset >= 2048 { goto step3 }
|
||||||
|
MOVD $12, R2
|
||||||
|
CMP R2, R3
|
||||||
|
BGE step3
|
||||||
|
MOVW $2048, R2
|
||||||
|
CMPW R2, R11
|
||||||
|
BGE step3
|
||||||
|
|
||||||
|
// Emit the remaining copy, encoded as 2 bytes.
|
||||||
|
MOVB R11, 1(R8)
|
||||||
|
LSRW $3, R11, R11
|
||||||
|
AND $0xe0, R11, R11
|
||||||
|
SUB $4, R3, R3
|
||||||
|
LSLW $2, R3
|
||||||
|
AND $0xff, R3, R3
|
||||||
|
ORRW R3, R11, R11
|
||||||
|
ORRW $1, R11, R11
|
||||||
|
MOVB R11, 0(R8)
|
||||||
|
ADD $2, R8, R8
|
||||||
|
|
||||||
|
// Return the number of bytes written.
|
||||||
|
SUB R7, R8, R8
|
||||||
|
MOVD R8, ret+40(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
step3:
|
||||||
|
// Emit the remaining copy, encoded as 3 bytes.
|
||||||
|
SUB $1, R3, R3
|
||||||
|
AND $0xff, R3, R3
|
||||||
|
LSLW $2, R3, R3
|
||||||
|
ORRW $2, R3, R3
|
||||||
|
MOVB R3, 0(R8)
|
||||||
|
MOVW R11, 1(R8)
|
||||||
|
ADD $3, R8, R8
|
||||||
|
|
||||||
|
// Return the number of bytes written.
|
||||||
|
SUB R7, R8, R8
|
||||||
|
MOVD R8, ret+40(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// func extendMatch(src []byte, i, j int) int
|
||||||
|
//
|
||||||
|
// All local variables fit into registers. The register allocation:
|
||||||
|
// - R6 &src[0]
|
||||||
|
// - R7 &src[j]
|
||||||
|
// - R13 &src[len(src) - 8]
|
||||||
|
// - R14 &src[len(src)]
|
||||||
|
// - R15 &src[i]
|
||||||
|
//
|
||||||
|
// The unusual register allocation of local variables, such as R15 for a source
|
||||||
|
// pointer, matches the allocation used at the call site in encodeBlock, which
|
||||||
|
// makes it easier to manually inline this function.
|
||||||
|
TEXT ·extendMatch(SB), NOSPLIT, $0-48
|
||||||
|
MOVD src_base+0(FP), R6
|
||||||
|
MOVD src_len+8(FP), R14
|
||||||
|
MOVD i+24(FP), R15
|
||||||
|
MOVD j+32(FP), R7
|
||||||
|
ADD R6, R14, R14
|
||||||
|
ADD R6, R15, R15
|
||||||
|
ADD R6, R7, R7
|
||||||
|
MOVD R14, R13
|
||||||
|
SUB $8, R13, R13
|
||||||
|
|
||||||
|
cmp8:
|
||||||
|
// As long as we are 8 or more bytes before the end of src, we can load and
|
||||||
|
// compare 8 bytes at a time. If those 8 bytes are equal, repeat.
|
||||||
|
CMP R13, R7
|
||||||
|
BHI cmp1
|
||||||
|
MOVD (R15), R3
|
||||||
|
MOVD (R7), R4
|
||||||
|
CMP R4, R3
|
||||||
|
BNE bsf
|
||||||
|
ADD $8, R15, R15
|
||||||
|
ADD $8, R7, R7
|
||||||
|
B cmp8
|
||||||
|
|
||||||
|
bsf:
|
||||||
|
// If those 8 bytes were not equal, XOR the two 8 byte values, and return
|
||||||
|
// the index of the first byte that differs.
|
||||||
|
// RBIT reverses the bit order, then CLZ counts the leading zeros, the
|
||||||
|
// combination of which finds the least significant bit which is set.
|
||||||
|
// The arm64 architecture is little-endian, and the shift by 3 converts
|
||||||
|
// a bit index to a byte index.
|
||||||
|
EOR R3, R4, R4
|
||||||
|
RBIT R4, R4
|
||||||
|
CLZ R4, R4
|
||||||
|
ADD R4>>3, R7, R7
|
||||||
|
|
||||||
|
// Convert from &src[ret] to ret.
|
||||||
|
SUB R6, R7, R7
|
||||||
|
MOVD R7, ret+40(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
cmp1:
|
||||||
|
// In src's tail, compare 1 byte at a time.
|
||||||
|
CMP R7, R14
|
||||||
|
BLS extendMatchEnd
|
||||||
|
MOVB (R15), R3
|
||||||
|
MOVB (R7), R4
|
||||||
|
CMP R4, R3
|
||||||
|
BNE extendMatchEnd
|
||||||
|
ADD $1, R15, R15
|
||||||
|
ADD $1, R7, R7
|
||||||
|
B cmp1
|
||||||
|
|
||||||
|
extendMatchEnd:
|
||||||
|
// Convert from &src[ret] to ret.
|
||||||
|
SUB R6, R7, R7
|
||||||
|
MOVD R7, ret+40(FP)
|
||||||
|
RET
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// func encodeBlock(dst, src []byte) (d int)
|
||||||
|
//
|
||||||
|
// All local variables fit into registers, other than "var table". The register
|
||||||
|
// allocation:
|
||||||
|
// - R3 . .
|
||||||
|
// - R4 . .
|
||||||
|
// - R5 64 shift
|
||||||
|
// - R6 72 &src[0], tableSize
|
||||||
|
// - R7 80 &src[s]
|
||||||
|
// - R8 88 &dst[d]
|
||||||
|
// - R9 96 sLimit
|
||||||
|
// - R10 . &src[nextEmit]
|
||||||
|
// - R11 104 prevHash, currHash, nextHash, offset
|
||||||
|
// - R12 112 &src[base], skip
|
||||||
|
// - R13 . &src[nextS], &src[len(src) - 8]
|
||||||
|
// - R14 . len(src), bytesBetweenHashLookups, &src[len(src)], x
|
||||||
|
// - R15 120 candidate
|
||||||
|
// - R16 . hash constant, 0x1e35a7bd
|
||||||
|
// - R17 . &table
|
||||||
|
// - . 128 table
|
||||||
|
//
|
||||||
|
// The second column (64, 72, etc) is the stack offset to spill the registers
|
||||||
|
// when calling other functions. We could pack this slightly tighter, but it's
|
||||||
|
// simpler to have a dedicated spill map independent of the function called.
|
||||||
|
//
|
||||||
|
// "var table [maxTableSize]uint16" takes up 32768 bytes of stack space. An
|
||||||
|
// extra 64 bytes, to call other functions, and an extra 64 bytes, to spill
|
||||||
|
// local variables (registers) during calls gives 32768 + 64 + 64 = 32896.
|
||||||
|
TEXT ·encodeBlock(SB), 0, $32896-56
|
||||||
|
MOVD dst_base+0(FP), R8
|
||||||
|
MOVD src_base+24(FP), R7
|
||||||
|
MOVD src_len+32(FP), R14
|
||||||
|
|
||||||
|
// shift, tableSize := uint32(32-8), 1<<8
|
||||||
|
MOVD $24, R5
|
||||||
|
MOVD $256, R6
|
||||||
|
MOVW $0xa7bd, R16
|
||||||
|
MOVKW $(0x1e35<<16), R16
|
||||||
|
|
||||||
|
calcShift:
|
||||||
|
// for ; tableSize < maxTableSize && tableSize < len(src); tableSize *= 2 {
|
||||||
|
// shift--
|
||||||
|
// }
|
||||||
|
MOVD $16384, R2
|
||||||
|
CMP R2, R6
|
||||||
|
BGE varTable
|
||||||
|
CMP R14, R6
|
||||||
|
BGE varTable
|
||||||
|
SUB $1, R5, R5
|
||||||
|
LSL $1, R6, R6
|
||||||
|
B calcShift
|
||||||
|
|
||||||
|
varTable:
|
||||||
|
// var table [maxTableSize]uint16
|
||||||
|
//
|
||||||
|
// In the asm code, unlike the Go code, we can zero-initialize only the
|
||||||
|
// first tableSize elements. Each uint16 element is 2 bytes and each VST1
|
||||||
|
// writes 64 bytes, so we can do only tableSize/32 writes instead of the
|
||||||
|
// 2048 writes that would zero-initialize all of table's 32768 bytes.
|
||||||
|
// This clear could overrun the first tableSize elements, but it won't
|
||||||
|
// overrun the allocated stack size.
|
||||||
|
ADD $128, RSP, R17
|
||||||
|
MOVD R17, R4
|
||||||
|
|
||||||
|
// !!! R6 = &src[tableSize]
|
||||||
|
ADD R6<<1, R17, R6
|
||||||
|
|
||||||
|
// zero the SIMD registers
|
||||||
|
VEOR V0.B16, V0.B16, V0.B16
|
||||||
|
VEOR V1.B16, V1.B16, V1.B16
|
||||||
|
VEOR V2.B16, V2.B16, V2.B16
|
||||||
|
VEOR V3.B16, V3.B16, V3.B16
|
||||||
|
|
||||||
|
memclr:
|
||||||
|
VST1.P [V0.B16, V1.B16, V2.B16, V3.B16], 64(R4)
|
||||||
|
CMP R4, R6
|
||||||
|
BHI memclr
|
||||||
|
|
||||||
|
// !!! R6 = &src[0]
|
||||||
|
MOVD R7, R6
|
||||||
|
|
||||||
|
// sLimit := len(src) - inputMargin
|
||||||
|
MOVD R14, R9
|
||||||
|
SUB $15, R9, R9
|
||||||
|
|
||||||
|
// !!! Pre-emptively spill R5, R6 and R9 to the stack. Their values don't
|
||||||
|
// change for the rest of the function.
|
||||||
|
MOVD R5, 64(RSP)
|
||||||
|
MOVD R6, 72(RSP)
|
||||||
|
MOVD R9, 96(RSP)
|
||||||
|
|
||||||
|
// nextEmit := 0
|
||||||
|
MOVD R6, R10
|
||||||
|
|
||||||
|
// s := 1
|
||||||
|
ADD $1, R7, R7
|
||||||
|
|
||||||
|
// nextHash := hash(load32(src, s), shift)
|
||||||
|
MOVW 0(R7), R11
|
||||||
|
MULW R16, R11, R11
|
||||||
|
LSRW R5, R11, R11
|
||||||
|
|
||||||
|
outer:
|
||||||
|
// for { etc }
|
||||||
|
|
||||||
|
// skip := 32
|
||||||
|
MOVD $32, R12
|
||||||
|
|
||||||
|
// nextS := s
|
||||||
|
MOVD R7, R13
|
||||||
|
|
||||||
|
// candidate := 0
|
||||||
|
MOVD $0, R15
|
||||||
|
|
||||||
|
inner0:
|
||||||
|
// for { etc }
|
||||||
|
|
||||||
|
// s := nextS
|
||||||
|
MOVD R13, R7
|
||||||
|
|
||||||
|
// bytesBetweenHashLookups := skip >> 5
|
||||||
|
MOVD R12, R14
|
||||||
|
LSR $5, R14, R14
|
||||||
|
|
||||||
|
// nextS = s + bytesBetweenHashLookups
|
||||||
|
ADD R14, R13, R13
|
||||||
|
|
||||||
|
// skip += bytesBetweenHashLookups
|
||||||
|
ADD R14, R12, R12
|
||||||
|
|
||||||
|
// if nextS > sLimit { goto emitRemainder }
|
||||||
|
MOVD R13, R3
|
||||||
|
SUB R6, R3, R3
|
||||||
|
CMP R9, R3
|
||||||
|
BHI emitRemainder
|
||||||
|
|
||||||
|
// candidate = int(table[nextHash])
|
||||||
|
MOVHU 0(R17)(R11<<1), R15
|
||||||
|
|
||||||
|
// table[nextHash] = uint16(s)
|
||||||
|
MOVD R7, R3
|
||||||
|
SUB R6, R3, R3
|
||||||
|
|
||||||
|
MOVH R3, 0(R17)(R11<<1)
|
||||||
|
|
||||||
|
// nextHash = hash(load32(src, nextS), shift)
|
||||||
|
MOVW 0(R13), R11
|
||||||
|
MULW R16, R11
|
||||||
|
LSRW R5, R11, R11
|
||||||
|
|
||||||
|
// if load32(src, s) != load32(src, candidate) { continue } break
|
||||||
|
MOVW 0(R7), R3
|
||||||
|
MOVW (R6)(R15*1), R4
|
||||||
|
CMPW R4, R3
|
||||||
|
BNE inner0
|
||||||
|
|
||||||
|
fourByteMatch:
|
||||||
|
// As per the encode_other.go code:
|
||||||
|
//
|
||||||
|
// A 4-byte match has been found. We'll later see etc.
|
||||||
|
|
||||||
|
// !!! Jump to a fast path for short (<= 16 byte) literals. See the comment
|
||||||
|
// on inputMargin in encode.go.
|
||||||
|
MOVD R7, R3
|
||||||
|
SUB R10, R3, R3
|
||||||
|
MOVD $16, R2
|
||||||
|
CMP R2, R3
|
||||||
|
BLE emitLiteralFastPath
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
// Begin inline of the emitLiteral call.
|
||||||
|
//
|
||||||
|
// d += emitLiteral(dst[d:], src[nextEmit:s])
|
||||||
|
|
||||||
|
MOVW R3, R4
|
||||||
|
SUBW $1, R4, R4
|
||||||
|
|
||||||
|
MOVW $60, R2
|
||||||
|
CMPW R2, R4
|
||||||
|
BLT inlineEmitLiteralOneByte
|
||||||
|
MOVW $256, R2
|
||||||
|
CMPW R2, R4
|
||||||
|
BLT inlineEmitLiteralTwoBytes
|
||||||
|
|
||||||
|
inlineEmitLiteralThreeBytes:
|
||||||
|
MOVD $0xf4, R1
|
||||||
|
MOVB R1, 0(R8)
|
||||||
|
MOVW R4, 1(R8)
|
||||||
|
ADD $3, R8, R8
|
||||||
|
B inlineEmitLiteralMemmove
|
||||||
|
|
||||||
|
inlineEmitLiteralTwoBytes:
|
||||||
|
MOVD $0xf0, R1
|
||||||
|
MOVB R1, 0(R8)
|
||||||
|
MOVB R4, 1(R8)
|
||||||
|
ADD $2, R8, R8
|
||||||
|
B inlineEmitLiteralMemmove
|
||||||
|
|
||||||
|
inlineEmitLiteralOneByte:
|
||||||
|
LSLW $2, R4, R4
|
||||||
|
MOVB R4, 0(R8)
|
||||||
|
ADD $1, R8, R8
|
||||||
|
|
||||||
|
inlineEmitLiteralMemmove:
|
||||||
|
// Spill local variables (registers) onto the stack; call; unspill.
|
||||||
|
//
|
||||||
|
// copy(dst[i:], lit)
|
||||||
|
//
|
||||||
|
// This means calling runtime·memmove(&dst[i], &lit[0], len(lit)), so we push
|
||||||
|
// R8, R10 and R3 as arguments.
|
||||||
|
MOVD R8, 8(RSP)
|
||||||
|
MOVD R10, 16(RSP)
|
||||||
|
MOVD R3, 24(RSP)
|
||||||
|
|
||||||
|
// Finish the "d +=" part of "d += emitLiteral(etc)".
|
||||||
|
ADD R3, R8, R8
|
||||||
|
MOVD R7, 80(RSP)
|
||||||
|
MOVD R8, 88(RSP)
|
||||||
|
MOVD R15, 120(RSP)
|
||||||
|
CALL runtime·memmove(SB)
|
||||||
|
MOVD 64(RSP), R5
|
||||||
|
MOVD 72(RSP), R6
|
||||||
|
MOVD 80(RSP), R7
|
||||||
|
MOVD 88(RSP), R8
|
||||||
|
MOVD 96(RSP), R9
|
||||||
|
MOVD 120(RSP), R15
|
||||||
|
B inner1
|
||||||
|
|
||||||
|
inlineEmitLiteralEnd:
|
||||||
|
// End inline of the emitLiteral call.
|
||||||
|
// ----------------------------------------
|
||||||
|
|
||||||
|
emitLiteralFastPath:
|
||||||
|
// !!! Emit the 1-byte encoding "uint8(len(lit)-1)<<2".
|
||||||
|
MOVB R3, R4
|
||||||
|
SUBW $1, R4, R4
|
||||||
|
AND $0xff, R4, R4
|
||||||
|
LSLW $2, R4, R4
|
||||||
|
MOVB R4, (R8)
|
||||||
|
ADD $1, R8, R8
|
||||||
|
|
||||||
|
// !!! Implement the copy from lit to dst as a 16-byte load and store.
|
||||||
|
// (Encode's documentation says that dst and src must not overlap.)
|
||||||
|
//
|
||||||
|
// This always copies 16 bytes, instead of only len(lit) bytes, but that's
|
||||||
|
// OK. Subsequent iterations will fix up the overrun.
|
||||||
|
//
|
||||||
|
// Note that on arm64, it is legal and cheap to issue unaligned 8-byte or
|
||||||
|
// 16-byte loads and stores. This technique probably wouldn't be as
|
||||||
|
// effective on architectures that are fussier about alignment.
|
||||||
|
VLD1 0(R10), [V0.B16]
|
||||||
|
VST1 [V0.B16], 0(R8)
|
||||||
|
ADD R3, R8, R8
|
||||||
|
|
||||||
|
inner1:
|
||||||
|
// for { etc }
|
||||||
|
|
||||||
|
// base := s
|
||||||
|
MOVD R7, R12
|
||||||
|
|
||||||
|
// !!! offset := base - candidate
|
||||||
|
MOVD R12, R11
|
||||||
|
SUB R15, R11, R11
|
||||||
|
SUB R6, R11, R11
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
// Begin inline of the extendMatch call.
|
||||||
|
//
|
||||||
|
// s = extendMatch(src, candidate+4, s+4)
|
||||||
|
|
||||||
|
// !!! R14 = &src[len(src)]
|
||||||
|
MOVD src_len+32(FP), R14
|
||||||
|
ADD R6, R14, R14
|
||||||
|
|
||||||
|
// !!! R13 = &src[len(src) - 8]
|
||||||
|
MOVD R14, R13
|
||||||
|
SUB $8, R13, R13
|
||||||
|
|
||||||
|
// !!! R15 = &src[candidate + 4]
|
||||||
|
ADD $4, R15, R15
|
||||||
|
ADD R6, R15, R15
|
||||||
|
|
||||||
|
// !!! s += 4
|
||||||
|
ADD $4, R7, R7
|
||||||
|
|
||||||
|
inlineExtendMatchCmp8:
|
||||||
|
// As long as we are 8 or more bytes before the end of src, we can load and
|
||||||
|
// compare 8 bytes at a time. If those 8 bytes are equal, repeat.
|
||||||
|
CMP R13, R7
|
||||||
|
BHI inlineExtendMatchCmp1
|
||||||
|
MOVD (R15), R3
|
||||||
|
MOVD (R7), R4
|
||||||
|
CMP R4, R3
|
||||||
|
BNE inlineExtendMatchBSF
|
||||||
|
ADD $8, R15, R15
|
||||||
|
ADD $8, R7, R7
|
||||||
|
B inlineExtendMatchCmp8
|
||||||
|
|
||||||
|
inlineExtendMatchBSF:
|
||||||
|
// If those 8 bytes were not equal, XOR the two 8 byte values, and return
|
||||||
|
// the index of the first byte that differs.
|
||||||
|
// RBIT reverses the bit order, then CLZ counts the leading zeros, the
|
||||||
|
// combination of which finds the least significant bit which is set.
|
||||||
|
// The arm64 architecture is little-endian, and the shift by 3 converts
|
||||||
|
// a bit index to a byte index.
|
||||||
|
EOR R3, R4, R4
|
||||||
|
RBIT R4, R4
|
||||||
|
CLZ R4, R4
|
||||||
|
ADD R4>>3, R7, R7
|
||||||
|
B inlineExtendMatchEnd
|
||||||
|
|
||||||
|
inlineExtendMatchCmp1:
|
||||||
|
// In src's tail, compare 1 byte at a time.
|
||||||
|
CMP R7, R14
|
||||||
|
BLS inlineExtendMatchEnd
|
||||||
|
MOVB (R15), R3
|
||||||
|
MOVB (R7), R4
|
||||||
|
CMP R4, R3
|
||||||
|
BNE inlineExtendMatchEnd
|
||||||
|
ADD $1, R15, R15
|
||||||
|
ADD $1, R7, R7
|
||||||
|
B inlineExtendMatchCmp1
|
||||||
|
|
||||||
|
inlineExtendMatchEnd:
|
||||||
|
// End inline of the extendMatch call.
|
||||||
|
// ----------------------------------------
|
||||||
|
|
||||||
|
// ----------------------------------------
|
||||||
|
// Begin inline of the emitCopy call.
|
||||||
|
//
|
||||||
|
// d += emitCopy(dst[d:], base-candidate, s-base)
|
||||||
|
|
||||||
|
// !!! length := s - base
|
||||||
|
MOVD R7, R3
|
||||||
|
SUB R12, R3, R3
|
||||||
|
|
||||||
|
inlineEmitCopyLoop0:
|
||||||
|
// for length >= 68 { etc }
|
||||||
|
MOVW $68, R2
|
||||||
|
CMPW R2, R3
|
||||||
|
BLT inlineEmitCopyStep1
|
||||||
|
|
||||||
|
// Emit a length 64 copy, encoded as 3 bytes.
|
||||||
|
MOVD $0xfe, R1
|
||||||
|
MOVB R1, 0(R8)
|
||||||
|
MOVW R11, 1(R8)
|
||||||
|
ADD $3, R8, R8
|
||||||
|
SUBW $64, R3, R3
|
||||||
|
B inlineEmitCopyLoop0
|
||||||
|
|
||||||
|
inlineEmitCopyStep1:
|
||||||
|
// if length > 64 { etc }
|
||||||
|
MOVW $64, R2
|
||||||
|
CMPW R2, R3
|
||||||
|
BLE inlineEmitCopyStep2
|
||||||
|
|
||||||
|
// Emit a length 60 copy, encoded as 3 bytes.
|
||||||
|
MOVD $0xee, R1
|
||||||
|
MOVB R1, 0(R8)
|
||||||
|
MOVW R11, 1(R8)
|
||||||
|
ADD $3, R8, R8
|
||||||
|
SUBW $60, R3, R3
|
||||||
|
|
||||||
|
inlineEmitCopyStep2:
|
||||||
|
// if length >= 12 || offset >= 2048 { goto inlineEmitCopyStep3 }
|
||||||
|
MOVW $12, R2
|
||||||
|
CMPW R2, R3
|
||||||
|
BGE inlineEmitCopyStep3
|
||||||
|
MOVW $2048, R2
|
||||||
|
CMPW R2, R11
|
||||||
|
BGE inlineEmitCopyStep3
|
||||||
|
|
||||||
|
// Emit the remaining copy, encoded as 2 bytes.
|
||||||
|
MOVB R11, 1(R8)
|
||||||
|
LSRW $8, R11, R11
|
||||||
|
LSLW $5, R11, R11
|
||||||
|
SUBW $4, R3, R3
|
||||||
|
AND $0xff, R3, R3
|
||||||
|
LSLW $2, R3, R3
|
||||||
|
ORRW R3, R11, R11
|
||||||
|
ORRW $1, R11, R11
|
||||||
|
MOVB R11, 0(R8)
|
||||||
|
ADD $2, R8, R8
|
||||||
|
B inlineEmitCopyEnd
|
||||||
|
|
||||||
|
inlineEmitCopyStep3:
|
||||||
|
// Emit the remaining copy, encoded as 3 bytes.
|
||||||
|
SUBW $1, R3, R3
|
||||||
|
LSLW $2, R3, R3
|
||||||
|
ORRW $2, R3, R3
|
||||||
|
MOVB R3, 0(R8)
|
||||||
|
MOVW R11, 1(R8)
|
||||||
|
ADD $3, R8, R8
|
||||||
|
|
||||||
|
inlineEmitCopyEnd:
|
||||||
|
// End inline of the emitCopy call.
|
||||||
|
// ----------------------------------------
|
||||||
|
|
||||||
|
// nextEmit = s
|
||||||
|
MOVD R7, R10
|
||||||
|
|
||||||
|
// if s >= sLimit { goto emitRemainder }
|
||||||
|
MOVD R7, R3
|
||||||
|
SUB R6, R3, R3
|
||||||
|
CMP R3, R9
|
||||||
|
BLS emitRemainder
|
||||||
|
|
||||||
|
// As per the encode_other.go code:
|
||||||
|
//
|
||||||
|
// We could immediately etc.
|
||||||
|
|
||||||
|
// x := load64(src, s-1)
|
||||||
|
MOVD -1(R7), R14
|
||||||
|
|
||||||
|
// prevHash := hash(uint32(x>>0), shift)
|
||||||
|
MOVW R14, R11
|
||||||
|
MULW R16, R11, R11
|
||||||
|
LSRW R5, R11, R11
|
||||||
|
|
||||||
|
// table[prevHash] = uint16(s-1)
|
||||||
|
MOVD R7, R3
|
||||||
|
SUB R6, R3, R3
|
||||||
|
SUB $1, R3, R3
|
||||||
|
|
||||||
|
MOVHU R3, 0(R17)(R11<<1)
|
||||||
|
|
||||||
|
// currHash := hash(uint32(x>>8), shift)
|
||||||
|
LSR $8, R14, R14
|
||||||
|
MOVW R14, R11
|
||||||
|
MULW R16, R11, R11
|
||||||
|
LSRW R5, R11, R11
|
||||||
|
|
||||||
|
// candidate = int(table[currHash])
|
||||||
|
MOVHU 0(R17)(R11<<1), R15
|
||||||
|
|
||||||
|
// table[currHash] = uint16(s)
|
||||||
|
ADD $1, R3, R3
|
||||||
|
MOVHU R3, 0(R17)(R11<<1)
|
||||||
|
|
||||||
|
// if uint32(x>>8) == load32(src, candidate) { continue }
|
||||||
|
MOVW (R6)(R15*1), R4
|
||||||
|
CMPW R4, R14
|
||||||
|
BEQ inner1
|
||||||
|
|
||||||
|
// nextHash = hash(uint32(x>>16), shift)
|
||||||
|
LSR $8, R14, R14
|
||||||
|
MOVW R14, R11
|
||||||
|
MULW R16, R11, R11
|
||||||
|
LSRW R5, R11, R11
|
||||||
|
|
||||||
|
// s++
|
||||||
|
ADD $1, R7, R7
|
||||||
|
|
||||||
|
// break out of the inner1 for loop, i.e. continue the outer loop.
|
||||||
|
B outer
|
||||||
|
|
||||||
|
emitRemainder:
|
||||||
|
// if nextEmit < len(src) { etc }
|
||||||
|
MOVD src_len+32(FP), R3
|
||||||
|
ADD R6, R3, R3
|
||||||
|
CMP R3, R10
|
||||||
|
BEQ encodeBlockEnd
|
||||||
|
|
||||||
|
// d += emitLiteral(dst[d:], src[nextEmit:])
|
||||||
|
//
|
||||||
|
// Push args.
|
||||||
|
MOVD R8, 8(RSP)
|
||||||
|
MOVD $0, 16(RSP) // Unnecessary, as the callee ignores it, but conservative.
|
||||||
|
MOVD $0, 24(RSP) // Unnecessary, as the callee ignores it, but conservative.
|
||||||
|
MOVD R10, 32(RSP)
|
||||||
|
SUB R10, R3, R3
|
||||||
|
MOVD R3, 40(RSP)
|
||||||
|
MOVD R3, 48(RSP) // Unnecessary, as the callee ignores it, but conservative.
|
||||||
|
|
||||||
|
// Spill local variables (registers) onto the stack; call; unspill.
|
||||||
|
MOVD R8, 88(RSP)
|
||||||
|
CALL ·emitLiteral(SB)
|
||||||
|
MOVD 88(RSP), R8
|
||||||
|
|
||||||
|
// Finish the "d +=" part of "d += emitLiteral(etc)".
|
||||||
|
MOVD 56(RSP), R1
|
||||||
|
ADD R1, R8, R8
|
||||||
|
|
||||||
|
encodeBlockEnd:
|
||||||
|
MOVD dst_base+0(FP), R3
|
||||||
|
SUB R3, R8, R8
|
||||||
|
MOVD R8, d+48(FP)
|
||||||
|
RET
|
|
@ -5,6 +5,7 @@
|
||||||
// +build !appengine
|
// +build !appengine
|
||||||
// +build gc
|
// +build gc
|
||||||
// +build !noasm
|
// +build !noasm
|
||||||
|
// +build amd64 arm64
|
||||||
|
|
||||||
package snappy
|
package snappy
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// +build !amd64 appengine !gc noasm
|
// +build !amd64,!arm64 appengine !gc noasm
|
||||||
|
|
||||||
package snappy
|
package snappy
|
||||||
|
|
||||||
|
|
|
@ -222,9 +222,11 @@ func (c *Config) Merge(o *Config) *Config {
|
||||||
r.Wait = r.Wait.Merge(o.Wait)
|
r.Wait = r.Wait.Merge(o.Wait)
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Once = o.Once
|
if o.BlockQueryWaitTime != nil {
|
||||||
|
|
||||||
r.BlockQueryWaitTime = o.BlockQueryWaitTime
|
r.BlockQueryWaitTime = o.BlockQueryWaitTime
|
||||||
|
}
|
||||||
|
|
||||||
|
r.Once = o.Once
|
||||||
|
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
@ -415,8 +417,8 @@ func (c *Config) GoString() string {
|
||||||
"Syslog:%#v, "+
|
"Syslog:%#v, "+
|
||||||
"Templates:%#v, "+
|
"Templates:%#v, "+
|
||||||
"Vault:%#v, "+
|
"Vault:%#v, "+
|
||||||
"Wait:%#v,"+
|
"Wait:%#v, "+
|
||||||
"Once:%#v"+
|
"Once:%#v, "+
|
||||||
"BlockQueryWaitTime:%#v"+
|
"BlockQueryWaitTime:%#v"+
|
||||||
"}",
|
"}",
|
||||||
c.Consul,
|
c.Consul,
|
||||||
|
@ -450,8 +452,14 @@ func (expected *Config) Diff(actual *Config) string {
|
||||||
fo := va.Field(i)
|
fo := va.Field(i)
|
||||||
if !reflect.DeepEqual(fc.Interface(), fo.Interface()) {
|
if !reflect.DeepEqual(fc.Interface(), fo.Interface()) {
|
||||||
fmt.Fprintf(&b, "%s:\n", ct.Field(i).Name)
|
fmt.Fprintf(&b, "%s:\n", ct.Field(i).Name)
|
||||||
|
fi := fc.Interface()
|
||||||
|
if _, ok := fi.(fmt.GoStringer); ok {
|
||||||
fmt.Fprintf(&b, "\texp: %#v\n", fc.Interface())
|
fmt.Fprintf(&b, "\texp: %#v\n", fc.Interface())
|
||||||
fmt.Fprintf(&b, "\tact: %#v\n", fo.Interface())
|
fmt.Fprintf(&b, "\tact: %#v\n", fo.Interface())
|
||||||
|
} else {
|
||||||
|
fmt.Fprintf(&b, "\texp: %+v\n", fc.Interface())
|
||||||
|
fmt.Fprintf(&b, "\tact: %+v\n", fo.Interface())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
package dependency
|
package dependency
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
"github.com/hashicorp/vault/api"
|
"github.com/hashicorp/vault/api"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -301,6 +303,9 @@ func isKVv2(client *api.Client, path string) (string, bool, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", false, err
|
return "", false, err
|
||||||
}
|
}
|
||||||
|
if secret == nil {
|
||||||
|
return "", false, fmt.Errorf("secret at path %s does not exist", path)
|
||||||
|
}
|
||||||
var mountPath string
|
var mountPath string
|
||||||
if mountPathRaw, ok := secret.Data["path"]; ok {
|
if mountPathRaw, ok := secret.Data["path"]; ok {
|
||||||
mountPath = mountPathRaw.(string)
|
mountPath = mountPathRaw.(string)
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/go-syslog"
|
"github.com/hashicorp/go-syslog"
|
||||||
"github.com/hashicorp/logutils"
|
"github.com/hashicorp/logutils"
|
||||||
|
@ -14,6 +15,14 @@ import (
|
||||||
// Levels are the log levels we respond to=o.
|
// Levels are the log levels we respond to=o.
|
||||||
var Levels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERR"}
|
var Levels = []logutils.LogLevel{"TRACE", "DEBUG", "INFO", "WARN", "ERR"}
|
||||||
|
|
||||||
|
type logWriter struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// writer to output date / time in a standard format
|
||||||
|
func (writer logWriter) Write(bytes []byte) (int, error) {
|
||||||
|
return fmt.Print(time.Now().Format("2006-01-02T15:04:05.000Z0700") + " " + string(bytes))
|
||||||
|
}
|
||||||
|
|
||||||
// Config is the configuration for this log setup.
|
// Config is the configuration for this log setup.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Level is the log level to use.
|
// Level is the log level to use.
|
||||||
|
@ -33,6 +42,9 @@ type Config struct {
|
||||||
func Setup(config *Config) error {
|
func Setup(config *Config) error {
|
||||||
var logOutput io.Writer
|
var logOutput io.Writer
|
||||||
|
|
||||||
|
log.SetFlags(0)
|
||||||
|
log.SetOutput(new(logWriter))
|
||||||
|
|
||||||
// Setup the default logging
|
// Setup the default logging
|
||||||
logFilter := NewLogFilter()
|
logFilter := NewLogFilter()
|
||||||
logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.Level))
|
logFilter.MinLevel = logutils.LogLevel(strings.ToUpper(config.Level))
|
||||||
|
@ -60,8 +72,8 @@ func Setup(config *Config) error {
|
||||||
logOutput = io.MultiWriter(logFilter)
|
logOutput = io.MultiWriter(logFilter)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.SetFlags(log.Ldate | log.Ltime | log.Lmicroseconds | log.LUTC)
|
|
||||||
log.SetOutput(logOutput)
|
log.SetOutput(logOutput)
|
||||||
|
log.SetOutput(new(logWriter))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -225,7 +225,7 @@ func (r *Runner) Start() {
|
||||||
// Warn the user if they are watching too many dependencies.
|
// Warn the user if they are watching too many dependencies.
|
||||||
if r.watcher.Size() > saneViewLimit {
|
if r.watcher.Size() > saneViewLimit {
|
||||||
log.Printf("[WARN] (runner) watching %d dependencies - watching this "+
|
log.Printf("[WARN] (runner) watching %d dependencies - watching this "+
|
||||||
"many dependencies could DDoS your consul cluster", r.watcher.Size())
|
"many dependencies could DDoS your servers", r.watcher.Size())
|
||||||
} else {
|
} else {
|
||||||
log.Printf("[DEBUG] (runner) watching %d dependencies", r.watcher.Size())
|
log.Printf("[DEBUG] (runner) watching %d dependencies", r.watcher.Size())
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,8 @@ func Wrap(outer, inner error) error {
|
||||||
//
|
//
|
||||||
// format is the format of the error message. The string '{{err}}' will
|
// format is the format of the error message. The string '{{err}}' will
|
||||||
// be replaced with the original error message.
|
// be replaced with the original error message.
|
||||||
|
//
|
||||||
|
// Deprecated: Use fmt.Errorf()
|
||||||
func Wrapf(format string, err error) error {
|
func Wrapf(format string, err error) error {
|
||||||
outerMsg := "<nil>"
|
outerMsg := "<nil>"
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -148,6 +150,9 @@ func Walk(err error, cb WalkFunc) {
|
||||||
for _, err := range e.WrappedErrors() {
|
for _, err := range e.WrappedErrors() {
|
||||||
Walk(err, cb)
|
Walk(err, cb)
|
||||||
}
|
}
|
||||||
|
case interface{ Unwrap() error }:
|
||||||
|
cb(err)
|
||||||
|
Walk(e.Unwrap(), cb)
|
||||||
default:
|
default:
|
||||||
cb(err)
|
cb(err)
|
||||||
}
|
}
|
||||||
|
@ -167,3 +172,7 @@ func (w *wrappedError) Error() string {
|
||||||
func (w *wrappedError) WrappedErrors() []error {
|
func (w *wrappedError) WrappedErrors() []error {
|
||||||
return []error{w.Outer, w.Inner}
|
return []error{w.Outer, w.Inner}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *wrappedError) Unwrap() error {
|
||||||
|
return w.Inner
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
language: go
|
|
||||||
go:
|
|
||||||
- tip
|
|
|
@ -1,3 +1,15 @@
|
||||||
|
# 1.3.0 (September 17th, 2020)
|
||||||
|
|
||||||
|
FEATURES
|
||||||
|
|
||||||
|
* Add reverse tree traversal [[GH-30](https://github.com/hashicorp/go-immutable-radix/pull/30)]
|
||||||
|
|
||||||
|
# 1.2.0 (March 18th, 2020)
|
||||||
|
|
||||||
|
FEATURES
|
||||||
|
|
||||||
|
* Adds a `Clone` method to `Txn` allowing transactions to be split either into two independently mutable trees. [[GH-26](https://github.com/hashicorp/go-immutable-radix/pull/26)]
|
||||||
|
|
||||||
# 1.1.0 (May 22nd, 2019)
|
# 1.1.0 (May 22nd, 2019)
|
||||||
|
|
||||||
FEATURES
|
FEATURES
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
go-immutable-radix [![Build Status](https://travis-ci.org/hashicorp/go-immutable-radix.png)](https://travis-ci.org/hashicorp/go-immutable-radix)
|
go-immutable-radix [![CircleCI](https://circleci.com/gh/hashicorp/go-immutable-radix/tree/master.svg?style=svg)](https://circleci.com/gh/hashicorp/go-immutable-radix/tree/master)
|
||||||
=========
|
=========
|
||||||
|
|
||||||
Provides the `iradix` package that implements an immutable [radix tree](http://en.wikipedia.org/wiki/Radix_tree).
|
Provides the `iradix` package that implements an immutable [radix tree](http://en.wikipedia.org/wiki/Radix_tree).
|
||||||
|
|
|
@ -86,6 +86,20 @@ func (t *Tree) Txn() *Txn {
|
||||||
return txn
|
return txn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clone makes an independent copy of the transaction. The new transaction
|
||||||
|
// does not track any nodes and has TrackMutate turned off. The cloned transaction will contain any uncommitted writes in the original transaction but further mutations to either will be independent and result in different radix trees on Commit. A cloned transaction may be passed to another goroutine and mutated there independently however each transaction may only be mutated in a single thread.
|
||||||
|
func (t *Txn) Clone() *Txn {
|
||||||
|
// reset the writable node cache to avoid leaking future writes into the clone
|
||||||
|
t.writable = nil
|
||||||
|
|
||||||
|
txn := &Txn{
|
||||||
|
root: t.root,
|
||||||
|
snap: t.snap,
|
||||||
|
size: t.size,
|
||||||
|
}
|
||||||
|
return txn
|
||||||
|
}
|
||||||
|
|
||||||
// TrackMutate can be used to toggle if mutations are tracked. If this is enabled
|
// TrackMutate can be used to toggle if mutations are tracked. If this is enabled
|
||||||
// then notifications will be issued for affected internal nodes and leaves when
|
// then notifications will be issued for affected internal nodes and leaves when
|
||||||
// the transaction is committed.
|
// the transaction is committed.
|
||||||
|
|
|
@ -155,7 +155,7 @@ func (i *Iterator) Next() ([]byte, interface{}, bool) {
|
||||||
// Initialize our stack if needed
|
// Initialize our stack if needed
|
||||||
if i.stack == nil && i.node != nil {
|
if i.stack == nil && i.node != nil {
|
||||||
i.stack = []edges{
|
i.stack = []edges{
|
||||||
edges{
|
{
|
||||||
edge{node: i.node},
|
edge{node: i.node},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,6 +211,12 @@ func (n *Node) Iterator() *Iterator {
|
||||||
return &Iterator{node: n}
|
return &Iterator{node: n}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ReverseIterator is used to return an iterator at
|
||||||
|
// the given node to walk the tree backwards
|
||||||
|
func (n *Node) ReverseIterator() *ReverseIterator {
|
||||||
|
return NewReverseIterator(n)
|
||||||
|
}
|
||||||
|
|
||||||
// rawIterator is used to return a raw iterator at the given node to walk the
|
// rawIterator is used to return a raw iterator at the given node to walk the
|
||||||
// tree.
|
// tree.
|
||||||
func (n *Node) rawIterator() *rawIterator {
|
func (n *Node) rawIterator() *rawIterator {
|
||||||
|
@ -224,6 +230,11 @@ func (n *Node) Walk(fn WalkFn) {
|
||||||
recursiveWalk(n, fn)
|
recursiveWalk(n, fn)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WalkBackwards is used to walk the tree in reverse order
|
||||||
|
func (n *Node) WalkBackwards(fn WalkFn) {
|
||||||
|
reverseRecursiveWalk(n, fn)
|
||||||
|
}
|
||||||
|
|
||||||
// WalkPrefix is used to walk the tree under a prefix
|
// WalkPrefix is used to walk the tree under a prefix
|
||||||
func (n *Node) WalkPrefix(prefix []byte, fn WalkFn) {
|
func (n *Node) WalkPrefix(prefix []byte, fn WalkFn) {
|
||||||
search := prefix
|
search := prefix
|
||||||
|
@ -302,3 +313,22 @@ func recursiveWalk(n *Node, fn WalkFn) bool {
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reverseRecursiveWalk is used to do a reverse pre-order
|
||||||
|
// walk of a node recursively. Returns true if the walk
|
||||||
|
// should be aborted
|
||||||
|
func reverseRecursiveWalk(n *Node, fn WalkFn) bool {
|
||||||
|
// Visit the leaf values if any
|
||||||
|
if n.leaf != nil && fn(n.leaf.key, n.leaf.val) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recurse on the children in reverse order
|
||||||
|
for i := len(n.edges) - 1; i >= 0; i-- {
|
||||||
|
e := n.edges[i]
|
||||||
|
if reverseRecursiveWalk(e.node, fn) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ func (i *rawIterator) Next() {
|
||||||
// Initialize our stack if needed.
|
// Initialize our stack if needed.
|
||||||
if i.stack == nil && i.node != nil {
|
if i.stack == nil && i.node != nil {
|
||||||
i.stack = []rawStackEntry{
|
i.stack = []rawStackEntry{
|
||||||
rawStackEntry{
|
{
|
||||||
edges: edges{
|
edges: edges{
|
||||||
edge{node: i.node},
|
edge{node: i.node},
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,177 @@
|
||||||
|
package iradix
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ReverseIterator is used to iterate over a set of nodes
|
||||||
|
// in reverse in-order
|
||||||
|
type ReverseIterator struct {
|
||||||
|
i *Iterator
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewReverseIterator returns a new ReverseIterator at a node
|
||||||
|
func NewReverseIterator(n *Node) *ReverseIterator {
|
||||||
|
return &ReverseIterator{
|
||||||
|
i: &Iterator{node: n},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SeekPrefixWatch is used to seek the iterator to a given prefix
|
||||||
|
// and returns the watch channel of the finest granularity
|
||||||
|
func (ri *ReverseIterator) SeekPrefixWatch(prefix []byte) (watch <-chan struct{}) {
|
||||||
|
return ri.i.SeekPrefixWatch(prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
// SeekPrefix is used to seek the iterator to a given prefix
|
||||||
|
func (ri *ReverseIterator) SeekPrefix(prefix []byte) {
|
||||||
|
ri.i.SeekPrefixWatch(prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ri *ReverseIterator) recurseMax(n *Node) *Node {
|
||||||
|
// Traverse to the maximum child
|
||||||
|
if n.leaf != nil {
|
||||||
|
return n
|
||||||
|
}
|
||||||
|
if len(n.edges) > 0 {
|
||||||
|
// Add all the other edges to the stack (the max node will be added as
|
||||||
|
// we recurse)
|
||||||
|
m := len(n.edges)
|
||||||
|
ri.i.stack = append(ri.i.stack, n.edges[:m-1])
|
||||||
|
return ri.recurseMax(n.edges[m-1].node)
|
||||||
|
}
|
||||||
|
// Shouldn't be possible
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// SeekReverseLowerBound is used to seek the iterator to the largest key that is
|
||||||
|
// lower or equal to the given key. There is no watch variant as it's hard to
|
||||||
|
// predict based on the radix structure which node(s) changes might affect the
|
||||||
|
// result.
|
||||||
|
func (ri *ReverseIterator) SeekReverseLowerBound(key []byte) {
|
||||||
|
// Wipe the stack. Unlike Prefix iteration, we need to build the stack as we
|
||||||
|
// go because we need only a subset of edges of many nodes in the path to the
|
||||||
|
// leaf with the lower bound.
|
||||||
|
ri.i.stack = []edges{}
|
||||||
|
n := ri.i.node
|
||||||
|
search := key
|
||||||
|
|
||||||
|
found := func(n *Node) {
|
||||||
|
ri.i.node = n
|
||||||
|
ri.i.stack = append(ri.i.stack, edges{edge{node: n}})
|
||||||
|
}
|
||||||
|
|
||||||
|
for {
|
||||||
|
// Compare current prefix with the search key's same-length prefix.
|
||||||
|
var prefixCmp int
|
||||||
|
if len(n.prefix) < len(search) {
|
||||||
|
prefixCmp = bytes.Compare(n.prefix, search[0:len(n.prefix)])
|
||||||
|
} else {
|
||||||
|
prefixCmp = bytes.Compare(n.prefix, search)
|
||||||
|
}
|
||||||
|
|
||||||
|
if prefixCmp < 0 {
|
||||||
|
// Prefix is smaller than search prefix, that means there is no lower bound.
|
||||||
|
// But we are looking in reverse, so the reverse lower bound will be the
|
||||||
|
// largest leaf under this subtree, since it is the value that would come
|
||||||
|
// right before the current search prefix if it were in the tree. So we need
|
||||||
|
// to follow the maximum path in this subtree to find it.
|
||||||
|
n = ri.recurseMax(n)
|
||||||
|
if n != nil {
|
||||||
|
found(n)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if prefixCmp > 0 {
|
||||||
|
// Prefix is larger than search prefix, that means there is no reverse lower
|
||||||
|
// bound since nothing comes before our current search prefix.
|
||||||
|
ri.i.node = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Prefix is equal, we are still heading for an exact match. If this is a
|
||||||
|
// leaf we're done.
|
||||||
|
if n.leaf != nil {
|
||||||
|
if bytes.Compare(n.leaf.key, key) < 0 {
|
||||||
|
ri.i.node = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
found(n)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consume the search prefix
|
||||||
|
if len(n.prefix) > len(search) {
|
||||||
|
search = []byte{}
|
||||||
|
} else {
|
||||||
|
search = search[len(n.prefix):]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, take the lower bound next edge.
|
||||||
|
idx, lbNode := n.getLowerBoundEdge(search[0])
|
||||||
|
|
||||||
|
// From here, we need to update the stack with all values lower than
|
||||||
|
// the lower bound edge. Since getLowerBoundEdge() returns -1 when the
|
||||||
|
// search prefix is larger than all edges, we need to place idx at the
|
||||||
|
// last edge index so they can all be place in the stack, since they
|
||||||
|
// come before our search prefix.
|
||||||
|
if idx == -1 {
|
||||||
|
idx = len(n.edges)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create stack edges for the all strictly lower edges in this node.
|
||||||
|
if len(n.edges[:idx]) > 0 {
|
||||||
|
ri.i.stack = append(ri.i.stack, n.edges[:idx])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit if there's not lower bound edge. The stack will have the
|
||||||
|
// previous nodes already.
|
||||||
|
if lbNode == nil {
|
||||||
|
ri.i.node = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ri.i.node = lbNode
|
||||||
|
// Recurse
|
||||||
|
n = lbNode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Previous returns the previous node in reverse order
|
||||||
|
func (ri *ReverseIterator) Previous() ([]byte, interface{}, bool) {
|
||||||
|
// Initialize our stack if needed
|
||||||
|
if ri.i.stack == nil && ri.i.node != nil {
|
||||||
|
ri.i.stack = []edges{
|
||||||
|
{
|
||||||
|
edge{node: ri.i.node},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for len(ri.i.stack) > 0 {
|
||||||
|
// Inspect the last element of the stack
|
||||||
|
n := len(ri.i.stack)
|
||||||
|
last := ri.i.stack[n-1]
|
||||||
|
m := len(last)
|
||||||
|
elem := last[m-1].node
|
||||||
|
|
||||||
|
// Update the stack
|
||||||
|
if m > 1 {
|
||||||
|
ri.i.stack[n-1] = last[:m-1]
|
||||||
|
} else {
|
||||||
|
ri.i.stack = ri.i.stack[:n-1]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Push the edges onto the frontier
|
||||||
|
if len(elem.edges) > 0 {
|
||||||
|
ri.i.stack = append(ri.i.stack, elem.edges)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Return the leaf values if any
|
||||||
|
if elem.leaf != nil {
|
||||||
|
return elem.leaf.key, elem.leaf.val, true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, nil, false
|
||||||
|
}
|
|
@ -85,6 +85,22 @@ func (c *Cache) ContainsOrAdd(key, value interface{}) (ok, evicted bool) {
|
||||||
return false, evicted
|
return false, evicted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PeekOrAdd checks if a key is in the cache without updating the
|
||||||
|
// recent-ness or deleting it for being stale, and if not, adds the value.
|
||||||
|
// Returns whether found and whether an eviction occurred.
|
||||||
|
func (c *Cache) PeekOrAdd(key, value interface{}) (previous interface{}, ok, evicted bool) {
|
||||||
|
c.lock.Lock()
|
||||||
|
defer c.lock.Unlock()
|
||||||
|
|
||||||
|
previous, ok = c.lru.Peek(key)
|
||||||
|
if ok {
|
||||||
|
return previous, true, false
|
||||||
|
}
|
||||||
|
|
||||||
|
evicted = c.lru.Add(key, value)
|
||||||
|
return nil, false, evicted
|
||||||
|
}
|
||||||
|
|
||||||
// Remove removes the provided key from the cache.
|
// Remove removes the provided key from the cache.
|
||||||
func (c *Cache) Remove(key interface{}) (present bool) {
|
func (c *Cache) Remove(key interface{}) (present bool) {
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
|
@ -27,6 +28,7 @@ const (
|
||||||
backgroundRed = 0x40
|
backgroundRed = 0x40
|
||||||
backgroundIntensity = 0x80
|
backgroundIntensity = 0x80
|
||||||
backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity)
|
backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity)
|
||||||
|
commonLvbUnderscore = 0x8000
|
||||||
|
|
||||||
cENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
|
cENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4
|
||||||
)
|
)
|
||||||
|
@ -93,6 +95,7 @@ type Writer struct {
|
||||||
oldattr word
|
oldattr word
|
||||||
oldpos coord
|
oldpos coord
|
||||||
rest bytes.Buffer
|
rest bytes.Buffer
|
||||||
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewColorable returns new instance of Writer which handles escape sequence from File.
|
// NewColorable returns new instance of Writer which handles escape sequence from File.
|
||||||
|
@ -432,6 +435,8 @@ func atoiWithDefault(s string, def int) (int, error) {
|
||||||
|
|
||||||
// Write writes data on console
|
// Write writes data on console
|
||||||
func (w *Writer) Write(data []byte) (n int, err error) {
|
func (w *Writer) Write(data []byte) (n int, err error) {
|
||||||
|
w.mutex.Lock()
|
||||||
|
defer w.mutex.Unlock()
|
||||||
var csbi consoleScreenBufferInfo
|
var csbi consoleScreenBufferInfo
|
||||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||||
|
|
||||||
|
@ -683,14 +688,19 @@ loop:
|
||||||
switch {
|
switch {
|
||||||
case n == 0 || n == 100:
|
case n == 0 || n == 100:
|
||||||
attr = w.oldattr
|
attr = w.oldattr
|
||||||
case 1 <= n && n <= 5:
|
case n == 4:
|
||||||
|
attr |= commonLvbUnderscore
|
||||||
|
case (1 <= n && n <= 3) || n == 5:
|
||||||
attr |= foregroundIntensity
|
attr |= foregroundIntensity
|
||||||
case n == 7:
|
case n == 7 || n == 27:
|
||||||
attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
|
attr =
|
||||||
case n == 22 || n == 25:
|
(attr &^ (foregroundMask | backgroundMask)) |
|
||||||
attr |= foregroundIntensity
|
((attr & foregroundMask) << 4) |
|
||||||
case n == 27:
|
((attr & backgroundMask) >> 4)
|
||||||
attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
|
case n == 22:
|
||||||
|
attr &^= foregroundIntensity
|
||||||
|
case n == 24:
|
||||||
|
attr &^= commonLvbUnderscore
|
||||||
case 30 <= n && n <= 37:
|
case 30 <= n && n <= 37:
|
||||||
attr &= backgroundMask
|
attr &= backgroundMask
|
||||||
if (n-30)&1 != 0 {
|
if (n-30)&1 != 0 {
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
language: go
|
language: go
|
||||||
|
sudo: false
|
||||||
go:
|
go:
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
before_install:
|
before_install:
|
||||||
- go get github.com/mattn/goveralls
|
- go get -t -v ./...
|
||||||
- go get golang.org/x/tools/cmd/cover
|
|
||||||
script:
|
script:
|
||||||
- $HOME/gopath/bin/goveralls -repotoken 2FMhp57u8LcstKL9B190fLTcEnBtAAiEL
|
- ./go.test.sh
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
# go-shellwords
|
# go-shellwords
|
||||||
|
|
||||||
[![Coverage Status](https://coveralls.io/repos/mattn/go-shellwords/badge.png?branch=master)](https://coveralls.io/r/mattn/go-shellwords?branch=master)
|
[![codecov](https://codecov.io/gh/mattn/go-shellwords/branch/master/graph/badge.svg)](https://codecov.io/gh/mattn/go-shellwords)
|
||||||
[![Build Status](https://travis-ci.org/mattn/go-shellwords.svg?branch=master)](https://travis-ci.org/mattn/go-shellwords)
|
[![Build Status](https://travis-ci.org/mattn/go-shellwords.svg?branch=master)](https://travis-ci.org/mattn/go-shellwords)
|
||||||
|
[![GoDoc](https://godoc.org/github.com/mattn/go-shellwords?status.svg)](http://godoc.org/github.com/mattn/go-shellwords)
|
||||||
|
|
||||||
Parse line as shell words.
|
Parse line as shell words.
|
||||||
|
|
||||||
|
|
|
@ -1 +1,3 @@
|
||||||
module github.com/mattn/go-shellwords
|
module github.com/mattn/go-shellwords
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
|
@ -4,7 +4,7 @@ set -e
|
||||||
echo "" > coverage.txt
|
echo "" > coverage.txt
|
||||||
|
|
||||||
for d in $(go list ./... | grep -v vendor); do
|
for d in $(go list ./... | grep -v vendor); do
|
||||||
go test -v -race -coverprofile=profile.out -covermode=atomic $d
|
go test -coverprofile=profile.out -covermode=atomic "$d"
|
||||||
if [ -f profile.out ]; then
|
if [ -f profile.out ]; then
|
||||||
cat profile.out >> coverage.txt
|
cat profile.out >> coverage.txt
|
||||||
rm profile.out
|
rm profile.out
|
|
@ -40,6 +40,7 @@ type Parser struct {
|
||||||
ParseEnv bool
|
ParseEnv bool
|
||||||
ParseBacktick bool
|
ParseBacktick bool
|
||||||
Position int
|
Position int
|
||||||
|
Dir string
|
||||||
|
|
||||||
// If ParseEnv is true, use this for getenv.
|
// If ParseEnv is true, use this for getenv.
|
||||||
// If nil, use os.Getenv.
|
// If nil, use os.Getenv.
|
||||||
|
@ -51,6 +52,7 @@ func NewParser() *Parser {
|
||||||
ParseEnv: ParseEnv,
|
ParseEnv: ParseEnv,
|
||||||
ParseBacktick: ParseBacktick,
|
ParseBacktick: ParseBacktick,
|
||||||
Position: 0,
|
Position: 0,
|
||||||
|
Dir: "",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -86,9 +88,17 @@ loop:
|
||||||
backtick += string(r)
|
backtick += string(r)
|
||||||
} else if got {
|
} else if got {
|
||||||
if p.ParseEnv {
|
if p.ParseEnv {
|
||||||
buf = replaceEnv(p.Getenv, buf)
|
parser := &Parser{ParseEnv: false, ParseBacktick: false, Position: 0, Dir: p.Dir}
|
||||||
|
strs, err := parser.Parse(replaceEnv(p.Getenv, buf))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
for _, str := range strs {
|
||||||
|
args = append(args, str)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
args = append(args, buf)
|
args = append(args, buf)
|
||||||
|
}
|
||||||
buf = ""
|
buf = ""
|
||||||
got = false
|
got = false
|
||||||
}
|
}
|
||||||
|
@ -100,11 +110,11 @@ loop:
|
||||||
if !singleQuoted && !doubleQuoted && !dollarQuote {
|
if !singleQuoted && !doubleQuoted && !dollarQuote {
|
||||||
if p.ParseBacktick {
|
if p.ParseBacktick {
|
||||||
if backQuote {
|
if backQuote {
|
||||||
out, err := shellRun(backtick)
|
out, err := shellRun(backtick, p.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
buf = out
|
buf = buf[:len(buf)-len(backtick)] + out
|
||||||
}
|
}
|
||||||
backtick = ""
|
backtick = ""
|
||||||
backQuote = !backQuote
|
backQuote = !backQuote
|
||||||
|
@ -117,15 +127,11 @@ loop:
|
||||||
if !singleQuoted && !doubleQuoted && !backQuote {
|
if !singleQuoted && !doubleQuoted && !backQuote {
|
||||||
if p.ParseBacktick {
|
if p.ParseBacktick {
|
||||||
if dollarQuote {
|
if dollarQuote {
|
||||||
out, err := shellRun(backtick)
|
out, err := shellRun(backtick, p.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if r == ')' {
|
|
||||||
buf = buf[:len(buf)-len(backtick)-2] + out
|
buf = buf[:len(buf)-len(backtick)-2] + out
|
||||||
} else {
|
|
||||||
buf = buf[:len(buf)-len(backtick)-1] + out
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
backtick = ""
|
backtick = ""
|
||||||
dollarQuote = !dollarQuote
|
dollarQuote = !dollarQuote
|
||||||
|
@ -146,16 +152,22 @@ loop:
|
||||||
}
|
}
|
||||||
case '"':
|
case '"':
|
||||||
if !singleQuoted && !dollarQuote {
|
if !singleQuoted && !dollarQuote {
|
||||||
|
if doubleQuoted {
|
||||||
|
got = true
|
||||||
|
}
|
||||||
doubleQuoted = !doubleQuoted
|
doubleQuoted = !doubleQuoted
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
case '\'':
|
case '\'':
|
||||||
if !doubleQuoted && !dollarQuote {
|
if !doubleQuoted && !dollarQuote {
|
||||||
|
if singleQuoted {
|
||||||
|
got = true
|
||||||
|
}
|
||||||
singleQuoted = !singleQuoted
|
singleQuoted = !singleQuoted
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
case ';', '&', '|', '<', '>':
|
case ';', '&', '|', '<', '>':
|
||||||
if !(escaped || singleQuoted || doubleQuoted || backQuote) {
|
if !(escaped || singleQuoted || doubleQuoted || backQuote || dollarQuote) {
|
||||||
if r == '>' && len(buf) > 0 {
|
if r == '>' && len(buf) > 0 {
|
||||||
if c := buf[0]; '0' <= c && c <= '9' {
|
if c := buf[0]; '0' <= c && c <= '9' {
|
||||||
i -= 1
|
i -= 1
|
||||||
|
@ -176,10 +188,18 @@ loop:
|
||||||
|
|
||||||
if got {
|
if got {
|
||||||
if p.ParseEnv {
|
if p.ParseEnv {
|
||||||
buf = replaceEnv(p.Getenv, buf)
|
parser := &Parser{ParseEnv: false, ParseBacktick: false, Position: 0, Dir: p.Dir}
|
||||||
|
strs, err := parser.Parse(replaceEnv(p.Getenv, buf))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
|
for _, str := range strs {
|
||||||
|
args = append(args, str)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
args = append(args, buf)
|
args = append(args, buf)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if escaped || singleQuoted || doubleQuoted || backQuote || dollarQuote {
|
if escaped || singleQuoted || doubleQuoted || backQuote || dollarQuote {
|
||||||
return nil, errors.New("invalid command line string")
|
return nil, errors.New("invalid command line string")
|
||||||
|
|
|
@ -1,24 +0,0 @@
|
||||||
// +build !go1.6
|
|
||||||
|
|
||||||
package shellwords
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"os/exec"
|
|
||||||
"runtime"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
func shellRun(line string) (string, error) {
|
|
||||||
var b []byte
|
|
||||||
var err error
|
|
||||||
if runtime.GOOS == "windows" {
|
|
||||||
b, err = exec.Command(os.Getenv("COMSPEC"), "/c", line).Output()
|
|
||||||
} else {
|
|
||||||
b, err = exec.Command(os.Getenv("SHELL"), "-c", line).Output()
|
|
||||||
}
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
return strings.TrimSpace(string(b)), nil
|
|
||||||
}
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build !windows,go1.6
|
// +build !windows
|
||||||
|
|
||||||
package shellwords
|
package shellwords
|
||||||
|
|
||||||
|
@ -9,9 +9,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func shellRun(line string) (string, error) {
|
func shellRun(line, dir string) (string, error) {
|
||||||
shell := os.Getenv("SHELL")
|
var shell string
|
||||||
b, err := exec.Command(shell, "-c", line).Output()
|
if shell = os.Getenv("SHELL"); shell == "" {
|
||||||
|
shell = "/bin/sh"
|
||||||
|
}
|
||||||
|
cmd := exec.Command(shell, "-c", line)
|
||||||
|
if dir != "" {
|
||||||
|
cmd.Dir = dir
|
||||||
|
}
|
||||||
|
b, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if eerr, ok := err.(*exec.ExitError); ok {
|
if eerr, ok := err.(*exec.ExitError); ok {
|
||||||
b = eerr.Stderr
|
b = eerr.Stderr
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// +build windows,go1.6
|
// +build windows
|
||||||
|
|
||||||
package shellwords
|
package shellwords
|
||||||
|
|
||||||
|
@ -9,9 +9,16 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func shellRun(line string) (string, error) {
|
func shellRun(line, dir string) (string, error) {
|
||||||
shell := os.Getenv("COMSPEC")
|
var shell string
|
||||||
b, err := exec.Command(shell, "/c", line).Output()
|
if shell = os.Getenv("COMSPEC"); shell == "" {
|
||||||
|
shell = "cmd"
|
||||||
|
}
|
||||||
|
cmd := exec.Command(shell, "/c", line)
|
||||||
|
if dir != "" {
|
||||||
|
cmd.Dir = dir
|
||||||
|
}
|
||||||
|
b, err := cmd.Output()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if eerr, ok := err.(*exec.ExitError); ok {
|
if eerr, ok := err.(*exec.ExitError); ok {
|
||||||
b = eerr.Stderr
|
b = eerr.Stderr
|
||||||
|
|
|
@ -2,15 +2,12 @@ language: go
|
||||||
sudo: false
|
sudo: false
|
||||||
|
|
||||||
go:
|
go:
|
||||||
- 1.10.x
|
- "1.12.x"
|
||||||
- 1.11.x
|
- "1.13.x"
|
||||||
- 1.12.x
|
|
||||||
- tip
|
- tip
|
||||||
|
|
||||||
before_install:
|
env:
|
||||||
# don't use the miekg/dns when testing forks
|
- GO111MODULE=on
|
||||||
- mkdir -p $GOPATH/src/github.com/miekg
|
|
||||||
- ln -s $TRAVIS_BUILD_DIR $GOPATH/src/github.com/miekg/ || true
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
|
- go test -race -v -bench=. -coverprofile=coverage.txt -covermode=atomic ./...
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
* @miekg @tmthrgd
|
|
@ -1,33 +0,0 @@
|
||||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
|
||||||
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/crypto"
|
|
||||||
packages = ["ed25519","ed25519/internal/edwards25519"]
|
|
||||||
revision = "20be4c3c3ed52bfccdb2d59a412ee1a936d175a7"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/net"
|
|
||||||
packages = ["bpf","internal/iana","internal/socket","ipv4","ipv6"]
|
|
||||||
revision = "60506f45cf65977eb3a9c6e30f995f54a721c271"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/sync"
|
|
||||||
packages = ["errgroup"]
|
|
||||||
revision = "112230192c580c3556b8cee6403af37a4fc5f28c"
|
|
||||||
|
|
||||||
[[projects]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/sys"
|
|
||||||
packages = ["unix","windows"]
|
|
||||||
revision = "4c4f7f33c9ed00de01c4c741d2177abfcfe19307"
|
|
||||||
|
|
||||||
[solve-meta]
|
|
||||||
analyzer-name = "dep"
|
|
||||||
analyzer-version = 1
|
|
||||||
inputs-digest = "fc70ece982d3660454fe1b9ccd5c91162a1cc080b58ad82aa065ad4a2ec93ce9"
|
|
||||||
solver-name = "gps-cdcl"
|
|
||||||
solver-version = 1
|
|
|
@ -1,38 +0,0 @@
|
||||||
|
|
||||||
# Gopkg.toml example
|
|
||||||
#
|
|
||||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
|
||||||
# for detailed Gopkg.toml documentation.
|
|
||||||
#
|
|
||||||
# required = ["github.com/user/thing/cmd/thing"]
|
|
||||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project"
|
|
||||||
# version = "1.0.0"
|
|
||||||
#
|
|
||||||
# [[constraint]]
|
|
||||||
# name = "github.com/user/project2"
|
|
||||||
# branch = "dev"
|
|
||||||
# source = "github.com/myfork/project2"
|
|
||||||
#
|
|
||||||
# [[override]]
|
|
||||||
# name = "github.com/x/y"
|
|
||||||
# version = "2.4.0"
|
|
||||||
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/crypto"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/net"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/sys"
|
|
||||||
|
|
||||||
[[constraint]]
|
|
||||||
branch = "master"
|
|
||||||
name = "golang.org/x/sync"
|
|
|
@ -1,7 +1,3 @@
|
||||||
Extensions of the original work are copyright (c) 2011 Miek Gieben
|
|
||||||
|
|
||||||
As this is fork of the official Go code the same license applies:
|
|
||||||
|
|
||||||
Copyright (c) 2009 The Go Authors. All rights reserved.
|
Copyright (c) 2009 The Go Authors. All rights reserved.
|
||||||
|
|
||||||
Redistribution and use in source and binary forms, with or without
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -30,3 +26,5 @@ THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
|
||||||
|
As this is fork of the official Go code the same license applies.
|
||||||
|
Extensions of the original work are copyright (c) 2011 Miek Gieben
|
||||||
|
|
|
@ -94,8 +94,8 @@ DNS Authors 2012-
|
||||||
|
|
||||||
# Building
|
# Building
|
||||||
|
|
||||||
Building is done with the `go` tool. If you have setup your GOPATH correctly, the following should
|
This library uses Go modules and uses semantic versioning. Building is done with the `go` tool, so
|
||||||
work:
|
the following should work:
|
||||||
|
|
||||||
go get github.com/miekg/dns
|
go get github.com/miekg/dns
|
||||||
go build github.com/miekg/dns
|
go build github.com/miekg/dns
|
||||||
|
|
|
@ -6,13 +6,20 @@ type MsgAcceptFunc func(dh Header) MsgAcceptAction
|
||||||
|
|
||||||
// DefaultMsgAcceptFunc checks the request and will reject if:
|
// DefaultMsgAcceptFunc checks the request and will reject if:
|
||||||
//
|
//
|
||||||
// * isn't a request (don't respond in that case).
|
// * isn't a request (don't respond in that case)
|
||||||
|
//
|
||||||
// * opcode isn't OpcodeQuery or OpcodeNotify
|
// * opcode isn't OpcodeQuery or OpcodeNotify
|
||||||
|
//
|
||||||
// * Zero bit isn't zero
|
// * Zero bit isn't zero
|
||||||
|
//
|
||||||
// * has more than 1 question in the question section
|
// * has more than 1 question in the question section
|
||||||
|
//
|
||||||
// * has more than 1 RR in the Answer section
|
// * has more than 1 RR in the Answer section
|
||||||
|
//
|
||||||
// * has more than 0 RRs in the Authority section
|
// * has more than 0 RRs in the Authority section
|
||||||
|
//
|
||||||
// * has more than 2 RRs in the Additional section
|
// * has more than 2 RRs in the Additional section
|
||||||
|
//
|
||||||
var DefaultMsgAcceptFunc MsgAcceptFunc = defaultMsgAcceptFunc
|
var DefaultMsgAcceptFunc MsgAcceptFunc = defaultMsgAcceptFunc
|
||||||
|
|
||||||
// MsgAcceptAction represents the action to be taken.
|
// MsgAcceptAction represents the action to be taken.
|
||||||
|
|
|
@ -83,7 +83,7 @@ with:
|
||||||
|
|
||||||
in, err := dns.Exchange(m1, "127.0.0.1:53")
|
in, err := dns.Exchange(m1, "127.0.0.1:53")
|
||||||
|
|
||||||
When this functions returns you will get dns message. A dns message consists
|
When this functions returns you will get DNS message. A DNS message consists
|
||||||
out of four sections.
|
out of four sections.
|
||||||
The question section: in.Question, the answer section: in.Answer,
|
The question section: in.Question, the answer section: in.Answer,
|
||||||
the authority section: in.Ns and the additional section: in.Extra.
|
the authority section: in.Ns and the additional section: in.Extra.
|
||||||
|
@ -221,7 +221,7 @@ RFC 6895 sets aside a range of type codes for private use. This range is 65,280
|
||||||
- 65,534 (0xFF00 - 0xFFFE). When experimenting with new Resource Records these
|
- 65,534 (0xFF00 - 0xFFFE). When experimenting with new Resource Records these
|
||||||
can be used, before requesting an official type code from IANA.
|
can be used, before requesting an official type code from IANA.
|
||||||
|
|
||||||
See https://miek.nl/2014/September/21/idn-and-private-rr-in-go-dns/ for more
|
See https://miek.nl/2014/september/21/idn-and-private-rr-in-go-dns/ for more
|
||||||
information.
|
information.
|
||||||
|
|
||||||
EDNS0
|
EDNS0
|
||||||
|
@ -238,9 +238,8 @@ Basic use pattern for creating an (empty) OPT RR:
|
||||||
|
|
||||||
The rdata of an OPT RR consists out of a slice of EDNS0 (RFC 6891) interfaces.
|
The rdata of an OPT RR consists out of a slice of EDNS0 (RFC 6891) interfaces.
|
||||||
Currently only a few have been standardized: EDNS0_NSID (RFC 5001) and
|
Currently only a few have been standardized: EDNS0_NSID (RFC 5001) and
|
||||||
EDNS0_SUBNET (draft-vandergaast-edns-client-subnet-02). Note that these options
|
EDNS0_SUBNET (RFC 7871). Note that these options may be combined in an OPT RR.
|
||||||
may be combined in an OPT RR. Basic use pattern for a server to check if (and
|
Basic use pattern for a server to check if (and which) options are set:
|
||||||
which) options are set:
|
|
||||||
|
|
||||||
// o is a dns.OPT
|
// o is a dns.OPT
|
||||||
for _, s := range o.Option {
|
for _, s := range o.Option {
|
||||||
|
|
|
@ -5,7 +5,7 @@ package dns
|
||||||
// IsDuplicate checks of r1 and r2 are duplicates of each other, excluding the TTL.
|
// IsDuplicate checks of r1 and r2 are duplicates of each other, excluding the TTL.
|
||||||
// So this means the header data is equal *and* the RDATA is the same. Return true
|
// So this means the header data is equal *and* the RDATA is the same. Return true
|
||||||
// is so, otherwise false.
|
// is so, otherwise false.
|
||||||
// It's is a protocol violation to have identical RRs in a message.
|
// It's a protocol violation to have identical RRs in a message.
|
||||||
func IsDuplicate(r1, r2 RR) bool {
|
func IsDuplicate(r1, r2 RR) bool {
|
||||||
// Check whether the record header is identical.
|
// Check whether the record header is identical.
|
||||||
if !r1.Header().isDuplicate(r2.Header()) {
|
if !r1.Header().isDuplicate(r2.Header()) {
|
||||||
|
|
|
@ -360,7 +360,7 @@ func (e *EDNS0_COOKIE) copy() EDNS0 { return &EDNS0_COOKIE{e.Code, e.C
|
||||||
// The EDNS0_UL (Update Lease) (draft RFC) option is used to tell the server to set
|
// The EDNS0_UL (Update Lease) (draft RFC) option is used to tell the server to set
|
||||||
// an expiration on an update RR. This is helpful for clients that cannot clean
|
// an expiration on an update RR. This is helpful for clients that cannot clean
|
||||||
// up after themselves. This is a draft RFC and more information can be found at
|
// up after themselves. This is a draft RFC and more information can be found at
|
||||||
// http://files.dns-sd.org/draft-sekar-dns-ul.txt
|
// https://tools.ietf.org/html/draft-sekar-dns-ul-02
|
||||||
//
|
//
|
||||||
// o := new(dns.OPT)
|
// o := new(dns.OPT)
|
||||||
// o.Hdr.Name = "."
|
// o.Hdr.Name = "."
|
||||||
|
@ -372,22 +372,34 @@ func (e *EDNS0_COOKIE) copy() EDNS0 { return &EDNS0_COOKIE{e.Code, e.C
|
||||||
type EDNS0_UL struct {
|
type EDNS0_UL struct {
|
||||||
Code uint16 // Always EDNS0UL
|
Code uint16 // Always EDNS0UL
|
||||||
Lease uint32
|
Lease uint32
|
||||||
|
KeyLease uint32
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option implements the EDNS0 interface.
|
// Option implements the EDNS0 interface.
|
||||||
func (e *EDNS0_UL) Option() uint16 { return EDNS0UL }
|
func (e *EDNS0_UL) Option() uint16 { return EDNS0UL }
|
||||||
func (e *EDNS0_UL) String() string { return strconv.FormatUint(uint64(e.Lease), 10) }
|
func (e *EDNS0_UL) String() string { return fmt.Sprintf("%d %d", e.Lease, e.KeyLease) }
|
||||||
func (e *EDNS0_UL) copy() EDNS0 { return &EDNS0_UL{e.Code, e.Lease} }
|
func (e *EDNS0_UL) copy() EDNS0 { return &EDNS0_UL{e.Code, e.Lease, e.KeyLease} }
|
||||||
|
|
||||||
// Copied: http://golang.org/src/pkg/net/dnsmsg.go
|
// Copied: http://golang.org/src/pkg/net/dnsmsg.go
|
||||||
func (e *EDNS0_UL) pack() ([]byte, error) {
|
func (e *EDNS0_UL) pack() ([]byte, error) {
|
||||||
b := make([]byte, 4)
|
var b []byte
|
||||||
|
if e.KeyLease == 0 {
|
||||||
|
b = make([]byte, 4)
|
||||||
|
} else {
|
||||||
|
b = make([]byte, 8)
|
||||||
|
binary.BigEndian.PutUint32(b[4:], e.KeyLease)
|
||||||
|
}
|
||||||
binary.BigEndian.PutUint32(b, e.Lease)
|
binary.BigEndian.PutUint32(b, e.Lease)
|
||||||
return b, nil
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *EDNS0_UL) unpack(b []byte) error {
|
func (e *EDNS0_UL) unpack(b []byte) error {
|
||||||
if len(b) < 4 {
|
switch len(b) {
|
||||||
|
case 4:
|
||||||
|
e.KeyLease = 0
|
||||||
|
case 8:
|
||||||
|
e.KeyLease = binary.BigEndian.Uint32(b[4:])
|
||||||
|
default:
|
||||||
return ErrBuf
|
return ErrBuf
|
||||||
}
|
}
|
||||||
e.Lease = binary.BigEndian.Uint32(b)
|
e.Lease = binary.BigEndian.Uint32(b)
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
package dns
|
package dns
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
func Fuzz(data []byte) int {
|
func Fuzz(data []byte) int {
|
||||||
msg := new(Msg)
|
msg := new(Msg)
|
||||||
|
|
||||||
|
@ -16,7 +18,14 @@ func Fuzz(data []byte) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func FuzzNewRR(data []byte) int {
|
func FuzzNewRR(data []byte) int {
|
||||||
if _, err := NewRR(string(data)); err != nil {
|
str := string(data)
|
||||||
|
// Do not fuzz lines that include the $INCLUDE keyword and hint the fuzzer
|
||||||
|
// at avoiding them.
|
||||||
|
// See GH#1025 for context.
|
||||||
|
if strings.Contains(strings.ToUpper(str), "$INCLUDE") {
|
||||||
|
return -1
|
||||||
|
}
|
||||||
|
if _, err := NewRR(str); err != nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
return 1
|
return 1
|
||||||
|
|
|
@ -49,11 +49,15 @@ func (zp *ZoneParser) generate(l lex) (RR, bool) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return zp.setParseError("bad stop in $GENERATE range", l)
|
return zp.setParseError("bad stop in $GENERATE range", l)
|
||||||
}
|
}
|
||||||
if end < 0 || start < 0 || end < start {
|
if end < 0 || start < 0 || end < start || (end-start)/step > 65535 {
|
||||||
return zp.setParseError("bad range in $GENERATE range", l)
|
return zp.setParseError("bad range in $GENERATE range", l)
|
||||||
}
|
}
|
||||||
|
|
||||||
zp.c.Next() // _BLANK
|
// _BLANK
|
||||||
|
l, ok := zp.c.Next()
|
||||||
|
if !ok || l.value != zBlank {
|
||||||
|
return zp.setParseError("garbage after $GENERATE range", l)
|
||||||
|
}
|
||||||
|
|
||||||
// Create a complete new string, which we then parse again.
|
// Create a complete new string, which we then parse again.
|
||||||
var s string
|
var s string
|
||||||
|
@ -81,6 +85,7 @@ func (zp *ZoneParser) generate(l lex) (RR, bool) {
|
||||||
}
|
}
|
||||||
zp.sub = NewZoneParser(r, zp.origin, zp.file)
|
zp.sub = NewZoneParser(r, zp.origin, zp.file)
|
||||||
zp.sub.includeDepth, zp.sub.includeAllowed = zp.includeDepth, zp.includeAllowed
|
zp.sub.includeDepth, zp.sub.includeAllowed = zp.includeDepth, zp.includeAllowed
|
||||||
|
zp.sub.generateDisallowed = true
|
||||||
zp.sub.SetDefaultTTL(defaultTtl)
|
zp.sub.SetDefaultTTL(defaultTtl)
|
||||||
return zp.subNext()
|
return zp.subNext()
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
module github.com/miekg/dns
|
||||||
|
|
||||||
|
go 1.12
|
||||||
|
|
||||||
|
require (
|
||||||
|
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392
|
||||||
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58
|
||||||
|
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe
|
||||||
|
golang.org/x/text v0.3.2 // indirect
|
||||||
|
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18 // indirect
|
||||||
|
)
|
|
@ -0,0 +1,33 @@
|
||||||
|
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4 h1:Vk3wNqEZwyGyei9yq5ekj7frek2u7HUfffJ1/opblzc=
|
||||||
|
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||||
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
|
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 h1:Gv7RPwsi3eZ2Fgewe3CBsuOebPwO27PoXzRpJPsvSSM=
|
||||||
|
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
|
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
|
||||||
|
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||||
|
golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3 h1:dgd4x4kJt7G4k4m93AYLzM8Ni6h2qLTfh9n9vXJT3/0=
|
||||||
|
golang.org/x/net v0.0.0-20180926154720-4dfa2610cdf3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
|
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||||
|
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 h1:k7pJ2yAPLPgbskkFdhRCsA77k2fySZ1zf2zCjvQCiIM=
|
||||||
|
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
|
||||||
|
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
||||||
|
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||||
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
golang.org/x/sys v0.0.0-20180928133829-e4b3c5e90611 h1:O33LKL7WyJgjN9CvxfTIomjIClbd/Kq86/iipowHQU0=
|
||||||
|
golang.org/x/sys v0.0.0-20180928133829-e4b3c5e90611/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||||
|
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd h1:DBH9mDw0zluJT/R+nGuV3jWFWLFaHyYZWD4tOT+cjn0=
|
||||||
|
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M=
|
||||||
|
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||||
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
|
@ -126,20 +126,23 @@ func Split(s string) []int {
|
||||||
// The bool end is true when the end of the string has been reached.
|
// The bool end is true when the end of the string has been reached.
|
||||||
// Also see PrevLabel.
|
// Also see PrevLabel.
|
||||||
func NextLabel(s string, offset int) (i int, end bool) {
|
func NextLabel(s string, offset int) (i int, end bool) {
|
||||||
quote := false
|
if s == "" {
|
||||||
|
return 0, true
|
||||||
|
}
|
||||||
for i = offset; i < len(s)-1; i++ {
|
for i = offset; i < len(s)-1; i++ {
|
||||||
switch s[i] {
|
if s[i] != '.' {
|
||||||
case '\\':
|
|
||||||
quote = !quote
|
|
||||||
default:
|
|
||||||
quote = false
|
|
||||||
case '.':
|
|
||||||
if quote {
|
|
||||||
quote = !quote
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
return i + 1, false
|
j := i - 1
|
||||||
|
for j >= 0 && s[j] == '\\' {
|
||||||
|
j--
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (j-i)%2 == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
return i + 1, false
|
||||||
}
|
}
|
||||||
return i + 1, true
|
return i + 1, true
|
||||||
}
|
}
|
||||||
|
@ -149,17 +152,38 @@ func NextLabel(s string, offset int) (i int, end bool) {
|
||||||
// The bool start is true when the start of the string has been overshot.
|
// The bool start is true when the start of the string has been overshot.
|
||||||
// Also see NextLabel.
|
// Also see NextLabel.
|
||||||
func PrevLabel(s string, n int) (i int, start bool) {
|
func PrevLabel(s string, n int) (i int, start bool) {
|
||||||
|
if s == "" {
|
||||||
|
return 0, true
|
||||||
|
}
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
return len(s), false
|
return len(s), false
|
||||||
}
|
}
|
||||||
lab := Split(s)
|
|
||||||
if lab == nil {
|
l := len(s) - 1
|
||||||
return 0, true
|
if s[l] == '.' {
|
||||||
|
l--
|
||||||
}
|
}
|
||||||
if n > len(lab) {
|
|
||||||
return 0, true
|
for ; l >= 0 && n > 0; l-- {
|
||||||
|
if s[l] != '.' {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
return lab[len(lab)-n], false
|
j := l - 1
|
||||||
|
for j >= 0 && s[j] == '\\' {
|
||||||
|
j--
|
||||||
|
}
|
||||||
|
|
||||||
|
if (j-l)%2 == 0 {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
n--
|
||||||
|
if n == 0 {
|
||||||
|
return l + 1, false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0, n > 1
|
||||||
}
|
}
|
||||||
|
|
||||||
// equal compares a and b while ignoring case. It returns true when equal otherwise false.
|
// equal compares a and b while ignoring case. It returns true when equal otherwise false.
|
||||||
|
|
|
@ -11,14 +11,12 @@ package dns
|
||||||
//go:generate go run msg_generate.go
|
//go:generate go run msg_generate.go
|
||||||
|
|
||||||
import (
|
import (
|
||||||
crand "crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"math/rand"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -73,53 +71,23 @@ var (
|
||||||
ErrTime error = &Error{err: "bad time"} // ErrTime indicates a timing error in TSIG authentication.
|
ErrTime error = &Error{err: "bad time"} // ErrTime indicates a timing error in TSIG authentication.
|
||||||
)
|
)
|
||||||
|
|
||||||
// Id by default, returns a 16 bits random number to be used as a
|
// Id by default returns a 16-bit random number to be used as a message id. The
|
||||||
// message id. The random provided should be good enough. This being a
|
// number is drawn from a cryptographically secure random number generator.
|
||||||
// variable the function can be reassigned to a custom function.
|
// This being a variable the function can be reassigned to a custom function.
|
||||||
// For instance, to make it return a static value:
|
// For instance, to make it return a static value for testing:
|
||||||
//
|
//
|
||||||
// dns.Id = func() uint16 { return 3 }
|
// dns.Id = func() uint16 { return 3 }
|
||||||
var Id = id
|
var Id = id
|
||||||
|
|
||||||
var (
|
|
||||||
idLock sync.Mutex
|
|
||||||
idRand *rand.Rand
|
|
||||||
)
|
|
||||||
|
|
||||||
// id returns a 16 bits random number to be used as a
|
// id returns a 16 bits random number to be used as a
|
||||||
// message id. The random provided should be good enough.
|
// message id. The random provided should be good enough.
|
||||||
func id() uint16 {
|
func id() uint16 {
|
||||||
idLock.Lock()
|
var output uint16
|
||||||
|
err := binary.Read(rand.Reader, binary.BigEndian, &output)
|
||||||
if idRand == nil {
|
if err != nil {
|
||||||
// This (partially) works around
|
panic("dns: reading random id failed: " + err.Error())
|
||||||
// https://github.com/golang/go/issues/11833 by only
|
|
||||||
// seeding idRand upon the first call to id.
|
|
||||||
|
|
||||||
var seed int64
|
|
||||||
var buf [8]byte
|
|
||||||
|
|
||||||
if _, err := crand.Read(buf[:]); err == nil {
|
|
||||||
seed = int64(binary.LittleEndian.Uint64(buf[:]))
|
|
||||||
} else {
|
|
||||||
seed = rand.Int63()
|
|
||||||
}
|
}
|
||||||
|
return output
|
||||||
idRand = rand.New(rand.NewSource(seed))
|
|
||||||
}
|
|
||||||
|
|
||||||
// The call to idRand.Uint32 must be within the
|
|
||||||
// mutex lock because *rand.Rand is not safe for
|
|
||||||
// concurrent use.
|
|
||||||
//
|
|
||||||
// There is no added performance overhead to calling
|
|
||||||
// idRand.Uint32 inside a mutex lock over just
|
|
||||||
// calling rand.Uint32 as the global math/rand rng
|
|
||||||
// is internally protected by a sync.Mutex.
|
|
||||||
id := uint16(idRand.Uint32())
|
|
||||||
|
|
||||||
idLock.Unlock()
|
|
||||||
return id
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// MsgHdr is a a manually-unpacked version of (id, bits).
|
// MsgHdr is a a manually-unpacked version of (id, bits).
|
||||||
|
|
|
@ -265,24 +265,36 @@ func unpackString(msg []byte, off int) (string, int, error) {
|
||||||
return "", off, &Error{err: "overflow unpacking txt"}
|
return "", off, &Error{err: "overflow unpacking txt"}
|
||||||
}
|
}
|
||||||
l := int(msg[off])
|
l := int(msg[off])
|
||||||
if off+l+1 > len(msg) {
|
off++
|
||||||
|
if off+l > len(msg) {
|
||||||
return "", off, &Error{err: "overflow unpacking txt"}
|
return "", off, &Error{err: "overflow unpacking txt"}
|
||||||
}
|
}
|
||||||
var s strings.Builder
|
var s strings.Builder
|
||||||
s.Grow(l)
|
consumed := 0
|
||||||
for _, b := range msg[off+1 : off+1+l] {
|
for i, b := range msg[off : off+l] {
|
||||||
switch {
|
switch {
|
||||||
case b == '"' || b == '\\':
|
case b == '"' || b == '\\':
|
||||||
|
if consumed == 0 {
|
||||||
|
s.Grow(l * 2)
|
||||||
|
}
|
||||||
|
s.Write(msg[off+consumed : off+i])
|
||||||
s.WriteByte('\\')
|
s.WriteByte('\\')
|
||||||
s.WriteByte(b)
|
s.WriteByte(b)
|
||||||
|
consumed = i + 1
|
||||||
case b < ' ' || b > '~': // unprintable
|
case b < ' ' || b > '~': // unprintable
|
||||||
|
if consumed == 0 {
|
||||||
|
s.Grow(l * 2)
|
||||||
|
}
|
||||||
|
s.Write(msg[off+consumed : off+i])
|
||||||
s.WriteString(escapeByte(b))
|
s.WriteString(escapeByte(b))
|
||||||
default:
|
consumed = i + 1
|
||||||
s.WriteByte(b)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
off += 1 + l
|
if consumed == 0 { // no escaping needed
|
||||||
return s.String(), off, nil
|
return string(msg[off : off+l]), off + l, nil
|
||||||
|
}
|
||||||
|
s.Write(msg[off+consumed : off+l])
|
||||||
|
return s.String(), off + l, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func packString(s string, msg []byte, off int) (int, error) {
|
func packString(s string, msg []byte, off int) (int, error) {
|
||||||
|
@ -433,6 +445,13 @@ Option:
|
||||||
}
|
}
|
||||||
edns = append(edns, e)
|
edns = append(edns, e)
|
||||||
off += int(optlen)
|
off += int(optlen)
|
||||||
|
case EDNS0EXPIRE:
|
||||||
|
e := new(EDNS0_EXPIRE)
|
||||||
|
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
|
||||||
|
return nil, len(msg), err
|
||||||
|
}
|
||||||
|
edns = append(edns, e)
|
||||||
|
off += int(optlen)
|
||||||
case EDNS0UL:
|
case EDNS0UL:
|
||||||
e := new(EDNS0_UL)
|
e := new(EDNS0_UL)
|
||||||
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
|
if err := e.unpack(msg[off : off+int(optlen)]); err != nil {
|
||||||
|
|
|
@ -134,7 +134,7 @@ func ReadRR(r io.Reader, file string) (RR, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseZone reads a RFC 1035 style zonefile from r. It returns
|
// ParseZone reads a RFC 1035 style zonefile from r. It returns
|
||||||
// *Tokens on the returned channel, each consisting of either a
|
// Tokens on the returned channel, each consisting of either a
|
||||||
// parsed RR and optional comment or a nil RR and an error. The
|
// parsed RR and optional comment or a nil RR and an error. The
|
||||||
// channel is closed by ParseZone when the end of r is reached.
|
// channel is closed by ParseZone when the end of r is reached.
|
||||||
//
|
//
|
||||||
|
@ -143,7 +143,8 @@ func ReadRR(r io.Reader, file string) (RR, error) {
|
||||||
// origin, as if the file would start with an $ORIGIN directive.
|
// origin, as if the file would start with an $ORIGIN directive.
|
||||||
//
|
//
|
||||||
// The directives $INCLUDE, $ORIGIN, $TTL and $GENERATE are all
|
// The directives $INCLUDE, $ORIGIN, $TTL and $GENERATE are all
|
||||||
// supported.
|
// supported. Note that $GENERATE's range support up to a maximum of
|
||||||
|
// of 65535 steps.
|
||||||
//
|
//
|
||||||
// Basic usage pattern when reading from a string (z) containing the
|
// Basic usage pattern when reading from a string (z) containing the
|
||||||
// zone data:
|
// zone data:
|
||||||
|
@ -203,6 +204,7 @@ func parseZone(r io.Reader, origin, file string, t chan *Token) {
|
||||||
//
|
//
|
||||||
// The directives $INCLUDE, $ORIGIN, $TTL and $GENERATE are all
|
// The directives $INCLUDE, $ORIGIN, $TTL and $GENERATE are all
|
||||||
// supported. Although $INCLUDE is disabled by default.
|
// supported. Although $INCLUDE is disabled by default.
|
||||||
|
// Note that $GENERATE's range support up to a maximum of 65535 steps.
|
||||||
//
|
//
|
||||||
// Basic usage pattern when reading from a string (z) containing the
|
// Basic usage pattern when reading from a string (z) containing the
|
||||||
// zone data:
|
// zone data:
|
||||||
|
@ -246,6 +248,7 @@ type ZoneParser struct {
|
||||||
includeDepth uint8
|
includeDepth uint8
|
||||||
|
|
||||||
includeAllowed bool
|
includeAllowed bool
|
||||||
|
generateDisallowed bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewZoneParser returns an RFC 1035 style zonefile parser that reads
|
// NewZoneParser returns an RFC 1035 style zonefile parser that reads
|
||||||
|
@ -545,6 +548,9 @@ func (zp *ZoneParser) Next() (RR, bool) {
|
||||||
|
|
||||||
st = zExpectDirGenerate
|
st = zExpectDirGenerate
|
||||||
case zExpectDirGenerate:
|
case zExpectDirGenerate:
|
||||||
|
if zp.generateDisallowed {
|
||||||
|
return zp.setParseError("nested $GENERATE directive not allowed", l)
|
||||||
|
}
|
||||||
if l.value != zString {
|
if l.value != zString {
|
||||||
return zp.setParseError("expecting $GENERATE value, not this...", l)
|
return zp.setParseError("expecting $GENERATE value, not this...", l)
|
||||||
}
|
}
|
||||||
|
@ -968,6 +974,11 @@ func (zl *zlexer) Next() (lex, bool) {
|
||||||
// was inside braces and we delayed adding it until now.
|
// was inside braces and we delayed adding it until now.
|
||||||
com[comi] = ' ' // convert newline to space
|
com[comi] = ' ' // convert newline to space
|
||||||
comi++
|
comi++
|
||||||
|
if comi >= len(com) {
|
||||||
|
l.token = "comment length insufficient for parsing"
|
||||||
|
l.err = true
|
||||||
|
return *l, true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
com[comi] = ';'
|
com[comi] = ';'
|
||||||
|
|
|
@ -36,33 +36,9 @@ func (mux *ServeMux) match(q string, t uint16) Handler {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
q = strings.ToLower(q)
|
||||||
|
|
||||||
var handler Handler
|
var handler Handler
|
||||||
|
|
||||||
// TODO(tmthrgd): Once https://go-review.googlesource.com/c/go/+/137575
|
|
||||||
// lands in a go release, replace the following with strings.ToLower.
|
|
||||||
var sb strings.Builder
|
|
||||||
for i := 0; i < len(q); i++ {
|
|
||||||
c := q[i]
|
|
||||||
if !(c >= 'A' && c <= 'Z') {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.Grow(len(q))
|
|
||||||
sb.WriteString(q[:i])
|
|
||||||
|
|
||||||
for ; i < len(q); i++ {
|
|
||||||
c := q[i]
|
|
||||||
if c >= 'A' && c <= 'Z' {
|
|
||||||
c += 'a' - 'A'
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.WriteByte(c)
|
|
||||||
}
|
|
||||||
|
|
||||||
q = sb.String()
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
for off, end := 0, false; !end; off, end = NextLabel(q, off) {
|
for off, end := 0, false; !end; off, end = NextLabel(q, off) {
|
||||||
if h, ok := mux.z[q[off:]]; ok {
|
if h, ok := mux.z[q[off:]]; ok {
|
||||||
if t != TypeDS {
|
if t != TypeDS {
|
||||||
|
|
|
@ -40,7 +40,7 @@ type TSIG struct {
|
||||||
// TSIG has no official presentation format, but this will suffice.
|
// TSIG has no official presentation format, but this will suffice.
|
||||||
|
|
||||||
func (rr *TSIG) String() string {
|
func (rr *TSIG) String() string {
|
||||||
s := "\n;; TSIG PSEUDOSECTION:\n"
|
s := "\n;; TSIG PSEUDOSECTION:\n; " // add another semi-colon to signify TSIG does not have a presentation format
|
||||||
s += rr.Hdr.String() +
|
s += rr.Hdr.String() +
|
||||||
" " + rr.Algorithm +
|
" " + rr.Algorithm +
|
||||||
" " + tsigTimeToString(rr.TimeSigned) +
|
" " + tsigTimeToString(rr.TimeSigned) +
|
||||||
|
|
|
@ -438,24 +438,53 @@ func (rr *TXT) String() string { return rr.Hdr.String() + sprintTxt(rr.Txt) }
|
||||||
|
|
||||||
func sprintName(s string) string {
|
func sprintName(s string) string {
|
||||||
var dst strings.Builder
|
var dst strings.Builder
|
||||||
dst.Grow(len(s))
|
|
||||||
for i := 0; i < len(s); {
|
for i := 0; i < len(s); {
|
||||||
if i+1 < len(s) && s[i] == '\\' && s[i+1] == '.' {
|
if i+1 < len(s) && s[i] == '\\' && s[i+1] == '.' {
|
||||||
|
if dst.Len() != 0 {
|
||||||
dst.WriteString(s[i : i+2])
|
dst.WriteString(s[i : i+2])
|
||||||
|
}
|
||||||
i += 2
|
i += 2
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
b, n := nextByte(s, i)
|
b, n := nextByte(s, i)
|
||||||
switch {
|
if n == 0 {
|
||||||
case n == 0:
|
i++
|
||||||
i++ // dangling back slash
|
continue
|
||||||
case b == '.':
|
}
|
||||||
|
if b == '.' {
|
||||||
|
if dst.Len() != 0 {
|
||||||
dst.WriteByte('.')
|
dst.WriteByte('.')
|
||||||
default:
|
|
||||||
writeDomainNameByte(&dst, b)
|
|
||||||
}
|
}
|
||||||
i += n
|
i += n
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
switch b {
|
||||||
|
case ' ', '\'', '@', ';', '(', ')', '"', '\\': // additional chars to escape
|
||||||
|
if dst.Len() == 0 {
|
||||||
|
dst.Grow(len(s) * 2)
|
||||||
|
dst.WriteString(s[:i])
|
||||||
|
}
|
||||||
|
dst.WriteByte('\\')
|
||||||
|
dst.WriteByte(b)
|
||||||
|
default:
|
||||||
|
if ' ' <= b && b <= '~' {
|
||||||
|
if dst.Len() != 0 {
|
||||||
|
dst.WriteByte(b)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if dst.Len() == 0 {
|
||||||
|
dst.Grow(len(s) * 2)
|
||||||
|
dst.WriteString(s[:i])
|
||||||
|
}
|
||||||
|
dst.WriteString(escapeByte(b))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
i += n
|
||||||
|
}
|
||||||
|
if dst.Len() == 0 {
|
||||||
|
return s
|
||||||
}
|
}
|
||||||
return dst.String()
|
return dst.String()
|
||||||
}
|
}
|
||||||
|
@ -510,16 +539,6 @@ func sprintTxt(txt []string) string {
|
||||||
return out.String()
|
return out.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func writeDomainNameByte(s *strings.Builder, b byte) {
|
|
||||||
switch b {
|
|
||||||
case '.', ' ', '\'', '@', ';', '(', ')': // additional chars to escape
|
|
||||||
s.WriteByte('\\')
|
|
||||||
s.WriteByte(b)
|
|
||||||
default:
|
|
||||||
writeTXTStringByte(s, b)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func writeTXTStringByte(s *strings.Builder, b byte) {
|
func writeTXTStringByte(s *strings.Builder, b byte) {
|
||||||
switch {
|
switch {
|
||||||
case b == '"' || b == '\\':
|
case b == '"' || b == '\\':
|
||||||
|
|
|
@ -3,7 +3,7 @@ package dns
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
// Version is current version of this library.
|
// Version is current version of this library.
|
||||||
var Version = V{1, 1, 15}
|
var Version = V{1, 1, 26}
|
||||||
|
|
||||||
// V holds the version of this library.
|
// V holds the version of this library.
|
||||||
type V struct {
|
type V struct {
|
||||||
|
|
|
@ -182,14 +182,17 @@ func (t *Transfer) inIxfr(q *Msg, c chan *Envelope) {
|
||||||
//
|
//
|
||||||
// ch := make(chan *dns.Envelope)
|
// ch := make(chan *dns.Envelope)
|
||||||
// tr := new(dns.Transfer)
|
// tr := new(dns.Transfer)
|
||||||
// go tr.Out(w, r, ch)
|
// var wg sync.WaitGroup
|
||||||
|
// go func() {
|
||||||
|
// tr.Out(w, r, ch)
|
||||||
|
// wg.Done()
|
||||||
|
// }()
|
||||||
// ch <- &dns.Envelope{RR: []dns.RR{soa, rr1, rr2, rr3, soa}}
|
// ch <- &dns.Envelope{RR: []dns.RR{soa, rr1, rr2, rr3, soa}}
|
||||||
// close(ch)
|
// close(ch)
|
||||||
// w.Hijack()
|
// wg.Wait() // wait until everything is written out
|
||||||
// // w.Close() // Client closes connection
|
// w.Close() // close connection
|
||||||
//
|
//
|
||||||
// The server is responsible for sending the correct sequence of RRs through the
|
// The server is responsible for sending the correct sequence of RRs through the channel ch.
|
||||||
// channel ch.
|
|
||||||
func (t *Transfer) Out(w ResponseWriter, q *Msg, ch chan *Envelope) error {
|
func (t *Transfer) Out(w ResponseWriter, q *Msg, ch chan *Envelope) error {
|
||||||
for x := range ch {
|
for x := range ch {
|
||||||
r := new(Msg)
|
r := new(Msg)
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
language: go
|
language: go
|
||||||
sudo: false
|
|
||||||
go:
|
go:
|
||||||
- 1.11
|
- tip
|
||||||
|
- 1.12.x
|
||||||
|
- 1.11.x
|
||||||
- 1.10.x
|
- 1.10.x
|
||||||
- 1.9
|
|
||||||
- 1.8
|
|
||||||
|
|
||||||
before_install:
|
|
||||||
- go get -u -t ./...
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- GO111MODULE=on ./test.sh
|
- go test -race -coverprofile=coverage.txt -covermode=atomic ./...
|
||||||
|
|
||||||
after_success:
|
after_success:
|
||||||
- bash <(curl -s https://codecov.io/bash)
|
- bash <(curl -s https://codecov.io/bash)
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
allow_failures:
|
||||||
|
- go: tip
|
|
@ -1,28 +1,29 @@
|
||||||
# complete
|
# complete
|
||||||
|
|
||||||
A tool for bash writing bash completion in go, and bash completion for the go command line.
|
|
||||||
|
|
||||||
[![Build Status](https://travis-ci.org/posener/complete.svg?branch=master)](https://travis-ci.org/posener/complete)
|
[![Build Status](https://travis-ci.org/posener/complete.svg?branch=master)](https://travis-ci.org/posener/complete)
|
||||||
[![codecov](https://codecov.io/gh/posener/complete/branch/master/graph/badge.svg)](https://codecov.io/gh/posener/complete)
|
[![codecov](https://codecov.io/gh/posener/complete/branch/master/graph/badge.svg)](https://codecov.io/gh/posener/complete)
|
||||||
[![golangci](https://golangci.com/badges/github.com/posener/complete.svg)](https://golangci.com/r/github.com/posener/complete)
|
[![golangci](https://golangci.com/badges/github.com/posener/complete.svg)](https://golangci.com/r/github.com/posener/complete)
|
||||||
[![GoDoc](https://godoc.org/github.com/posener/complete?status.svg)](http://godoc.org/github.com/posener/complete)
|
[![GoDoc](https://godoc.org/github.com/posener/complete?status.svg)](http://godoc.org/github.com/posener/complete)
|
||||||
[![Go Report Card](https://goreportcard.com/badge/github.com/posener/complete)](https://goreportcard.com/report/github.com/posener/complete)
|
[![goreadme](https://goreadme.herokuapp.com/badge/posener/complete.svg)](https://goreadme.herokuapp.com)
|
||||||
|
|
||||||
|
Package complete provides a tool for bash writing bash completion in go, and bash completion for the go command line.
|
||||||
|
|
||||||
Writing bash completion scripts is a hard work. This package provides an easy way
|
Writing bash completion scripts is a hard work. This package provides an easy way
|
||||||
to create bash completion scripts for any command, and also an easy way to install/uninstall
|
to create bash completion scripts for any command, and also an easy way to install/uninstall
|
||||||
the completion of the command.
|
the completion of the command.
|
||||||
|
|
||||||
## go command bash completion
|
#### Go Command Bash Completion
|
||||||
|
|
||||||
In [gocomplete](./gocomplete) there is an example for bash completion for the `go` command line.
|
In [./cmd/gocomplete](./cmd/gocomplete) there is an example for bash completion for the `go` command line.
|
||||||
|
|
||||||
This is an example that uses the `complete` package on the `go` command - the `complete` package
|
This is an example that uses the `complete` package on the `go` command - the `complete` package
|
||||||
can also be used to implement any completions, see [Usage](#usage).
|
can also be used to implement any completions, see #usage.
|
||||||
|
|
||||||
### Install
|
#### Install
|
||||||
|
|
||||||
1. Type in your shell:
|
1. Type in your shell:
|
||||||
```
|
|
||||||
|
```go
|
||||||
go get -u github.com/posener/complete/gocomplete
|
go get -u github.com/posener/complete/gocomplete
|
||||||
gocomplete -install
|
gocomplete -install
|
||||||
```
|
```
|
||||||
|
@ -31,13 +32,13 @@ gocomplete -install
|
||||||
|
|
||||||
Uninstall by `gocomplete -uninstall`
|
Uninstall by `gocomplete -uninstall`
|
||||||
|
|
||||||
### Features
|
#### Features
|
||||||
|
|
||||||
- Complete `go` command, including sub commands and all flags.
|
- Complete `go` command, including sub commands and all flags.
|
||||||
- Complete packages names or `.go` files when necessary.
|
- Complete packages names or `.go` files when necessary.
|
||||||
- Complete test names after `-run` flag.
|
- Complete test names after `-run` flag.
|
||||||
|
|
||||||
## complete package
|
#### Complete package
|
||||||
|
|
||||||
Supported shells:
|
Supported shells:
|
||||||
|
|
||||||
|
@ -45,7 +46,7 @@ Supported shells:
|
||||||
- [x] zsh
|
- [x] zsh
|
||||||
- [x] fish
|
- [x] fish
|
||||||
|
|
||||||
### Usage
|
#### Usage
|
||||||
|
|
||||||
Assuming you have program called `run` and you want to have bash completion
|
Assuming you have program called `run` and you want to have bash completion
|
||||||
for it, meaning, if you type `run` then space, then press the `Tab` key,
|
for it, meaning, if you type `run` then space, then press the `Tab` key,
|
||||||
|
@ -110,9 +111,21 @@ func main() {
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Self completing program
|
#### Self completing program
|
||||||
|
|
||||||
In case that the program that we want to complete is written in go we
|
In case that the program that we want to complete is written in go we
|
||||||
can make it self completing.
|
can make it self completing.
|
||||||
|
Here is an example: [./example/self/main.go](./example/self/main.go) .
|
||||||
|
|
||||||
Here is an [example](./example/self/main.go)
|
## Sub Packages
|
||||||
|
|
||||||
|
* [cmd](./cmd): Package cmd used for command line options for the complete tool
|
||||||
|
|
||||||
|
* [gocomplete](./gocomplete): Package main is complete tool for the go command line
|
||||||
|
|
||||||
|
* [match](./match): Package match contains matchers that decide if to apply completion.
|
||||||
|
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
Created by [goreadme](https://github.com/apps/goreadme)
|
|
@ -28,6 +28,8 @@ type Args struct {
|
||||||
// Directory gives the directory of the current written
|
// Directory gives the directory of the current written
|
||||||
// last argument if it represents a file name being written.
|
// last argument if it represents a file name being written.
|
||||||
// in case that it is not, we fall back to the current directory.
|
// in case that it is not, we fall back to the current directory.
|
||||||
|
//
|
||||||
|
// Deprecated.
|
||||||
func (a Args) Directory() string {
|
func (a Args) Directory() string {
|
||||||
if info, err := os.Stat(a.Last); err == nil && info.IsDir() {
|
if info, err := os.Stat(a.Last); err == nil && info.IsDir() {
|
||||||
return fixPathForm(a.Last, a.Last)
|
return fixPathForm(a.Last, a.Last)
|
||||||
|
@ -83,16 +85,17 @@ func splitLastEqual(line []string) []string {
|
||||||
return append(line[:len(line)-1], parts...)
|
return append(line[:len(line)-1], parts...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// from returns a copy of Args of all arguments after the i'th argument.
|
||||||
func (a Args) from(i int) Args {
|
func (a Args) from(i int) Args {
|
||||||
if i > len(a.All) {
|
if i >= len(a.All) {
|
||||||
i = len(a.All)
|
i = len(a.All) - 1
|
||||||
}
|
}
|
||||||
a.All = a.All[i:]
|
a.All = a.All[i+1:]
|
||||||
|
|
||||||
if i > len(a.Completed) {
|
if i >= len(a.Completed) {
|
||||||
i = len(a.Completed)
|
i = len(a.Completed) - 1
|
||||||
}
|
}
|
||||||
a.Completed = a.Completed[i:]
|
a.Completed = a.Completed[i+1:]
|
||||||
return a
|
return a
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,20 +10,25 @@ type bash struct {
|
||||||
rc string
|
rc string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b bash) Install(cmd, bin string) error {
|
func (b bash) IsInstalled(cmd, bin string) bool {
|
||||||
completeCmd := b.cmd(cmd, bin)
|
completeCmd := b.cmd(cmd, bin)
|
||||||
if lineInFile(b.rc, completeCmd) {
|
return lineInFile(b.rc, completeCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b bash) Install(cmd, bin string) error {
|
||||||
|
if b.IsInstalled(cmd, bin) {
|
||||||
return fmt.Errorf("already installed in %s", b.rc)
|
return fmt.Errorf("already installed in %s", b.rc)
|
||||||
}
|
}
|
||||||
|
completeCmd := b.cmd(cmd, bin)
|
||||||
return appendToFile(b.rc, completeCmd)
|
return appendToFile(b.rc, completeCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b bash) Uninstall(cmd, bin string) error {
|
func (b bash) Uninstall(cmd, bin string) error {
|
||||||
completeCmd := b.cmd(cmd, bin)
|
if !b.IsInstalled(cmd, bin) {
|
||||||
if !lineInFile(b.rc, completeCmd) {
|
|
||||||
return fmt.Errorf("does not installed in %s", b.rc)
|
return fmt.Errorf("does not installed in %s", b.rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
completeCmd := b.cmd(cmd, bin)
|
||||||
return removeFromFile(b.rc, completeCmd)
|
return removeFromFile(b.rc, completeCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,39 +14,52 @@ type fish struct {
|
||||||
configDir string
|
configDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f fish) IsInstalled(cmd, bin string) bool {
|
||||||
|
completionFile := f.getCompletionFilePath(cmd)
|
||||||
|
if _, err := os.Stat(completionFile); err == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func (f fish) Install(cmd, bin string) error {
|
func (f fish) Install(cmd, bin string) error {
|
||||||
completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
|
if f.IsInstalled(cmd, bin) {
|
||||||
|
return fmt.Errorf("already installed at %s", f.getCompletionFilePath(cmd))
|
||||||
|
}
|
||||||
|
|
||||||
|
completionFile := f.getCompletionFilePath(cmd)
|
||||||
completeCmd, err := f.cmd(cmd, bin)
|
completeCmd, err := f.cmd(cmd, bin)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if _, err := os.Stat(completionFile); err == nil {
|
|
||||||
return fmt.Errorf("already installed at %s", completionFile)
|
|
||||||
}
|
|
||||||
|
|
||||||
return createFile(completionFile, completeCmd)
|
return createFile(completionFile, completeCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f fish) Uninstall(cmd, bin string) error {
|
func (f fish) Uninstall(cmd, bin string) error {
|
||||||
completionFile := filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
|
if !f.IsInstalled(cmd, bin) {
|
||||||
if _, err := os.Stat(completionFile); err != nil {
|
|
||||||
return fmt.Errorf("does not installed in %s", f.configDir)
|
return fmt.Errorf("does not installed in %s", f.configDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
completionFile := f.getCompletionFilePath(cmd)
|
||||||
return os.Remove(completionFile)
|
return os.Remove(completionFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f fish) getCompletionFilePath(cmd string) string {
|
||||||
|
return filepath.Join(f.configDir, "completions", fmt.Sprintf("%s.fish", cmd))
|
||||||
|
}
|
||||||
|
|
||||||
func (f fish) cmd(cmd, bin string) (string, error) {
|
func (f fish) cmd(cmd, bin string) (string, error) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
params := struct{ Cmd, Bin string }{cmd, bin}
|
params := struct{ Cmd, Bin string }{cmd, bin}
|
||||||
tmpl := template.Must(template.New("cmd").Parse(`
|
tmpl := template.Must(template.New("cmd").Parse(`
|
||||||
function __complete_{{.Cmd}}
|
function __complete_{{.Cmd}}
|
||||||
set -lx COMP_LINE (string join ' ' (commandline -o))
|
set -lx COMP_LINE (commandline -cp)
|
||||||
test (commandline -ct) = ""
|
test -z (commandline -ct)
|
||||||
and set COMP_LINE "$COMP_LINE "
|
and set COMP_LINE "$COMP_LINE "
|
||||||
{{.Bin}}
|
{{.Bin}}
|
||||||
end
|
end
|
||||||
complete -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
|
complete -f -c {{.Cmd}} -a "(__complete_{{.Cmd}})"
|
||||||
`))
|
`))
|
||||||
err := tmpl.Execute(&buf, params)
|
err := tmpl.Execute(&buf, params)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,11 +5,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/hashicorp/go-multierror"
|
"github.com/hashicorp/go-multierror"
|
||||||
)
|
)
|
||||||
|
|
||||||
type installer interface {
|
type installer interface {
|
||||||
|
IsInstalled(cmd, bin string) bool
|
||||||
Install(cmd, bin string) error
|
Install(cmd, bin string) error
|
||||||
Uninstall(cmd, bin string) error
|
Uninstall(cmd, bin string) error
|
||||||
}
|
}
|
||||||
|
@ -36,6 +38,24 @@ func Install(cmd string) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsInstalled returns true if the completion
|
||||||
|
// for the given cmd is installed.
|
||||||
|
func IsInstalled(cmd string) bool {
|
||||||
|
bin, err := getBinaryPath()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, i := range installers() {
|
||||||
|
installed := i.IsInstalled(cmd, bin)
|
||||||
|
if installed {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
// Uninstall complete command given:
|
// Uninstall complete command given:
|
||||||
// cmd: is the command name
|
// cmd: is the command name
|
||||||
func Uninstall(cmd string) error {
|
func Uninstall(cmd string) error {
|
||||||
|
@ -59,7 +79,16 @@ func Uninstall(cmd string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func installers() (i []installer) {
|
func installers() (i []installer) {
|
||||||
for _, rc := range [...]string{".bashrc", ".bash_profile", ".bash_login", ".profile"} {
|
// The list of bash config files candidates where it is
|
||||||
|
// possible to install the completion command.
|
||||||
|
var bashConfFiles []string
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "darwin":
|
||||||
|
bashConfFiles = []string{".bash_profile"}
|
||||||
|
default:
|
||||||
|
bashConfFiles = []string{".bashrc", ".bash_profile", ".bash_login", ".profile"}
|
||||||
|
}
|
||||||
|
for _, rc := range bashConfFiles {
|
||||||
if f := rcFile(rc); f != "" {
|
if f := rcFile(rc); f != "" {
|
||||||
i = append(i, bash{f})
|
i = append(i, bash{f})
|
||||||
break
|
break
|
||||||
|
|
|
@ -11,12 +11,17 @@ type zsh struct {
|
||||||
rc string
|
rc string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z zsh) Install(cmd, bin string) error {
|
func (z zsh) IsInstalled(cmd, bin string) bool {
|
||||||
completeCmd := z.cmd(cmd, bin)
|
completeCmd := z.cmd(cmd, bin)
|
||||||
if lineInFile(z.rc, completeCmd) {
|
return lineInFile(z.rc, completeCmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (z zsh) Install(cmd, bin string) error {
|
||||||
|
if z.IsInstalled(cmd, bin) {
|
||||||
return fmt.Errorf("already installed in %s", z.rc)
|
return fmt.Errorf("already installed in %s", z.rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
completeCmd := z.cmd(cmd, bin)
|
||||||
bashCompInit := "autoload -U +X bashcompinit && bashcompinit"
|
bashCompInit := "autoload -U +X bashcompinit && bashcompinit"
|
||||||
if !lineInFile(z.rc, bashCompInit) {
|
if !lineInFile(z.rc, bashCompInit) {
|
||||||
completeCmd = bashCompInit + "\n" + completeCmd
|
completeCmd = bashCompInit + "\n" + completeCmd
|
||||||
|
@ -26,11 +31,11 @@ func (z zsh) Install(cmd, bin string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (z zsh) Uninstall(cmd, bin string) error {
|
func (z zsh) Uninstall(cmd, bin string) error {
|
||||||
completeCmd := z.cmd(cmd, bin)
|
if !z.IsInstalled(cmd, bin) {
|
||||||
if !lineInFile(z.rc, completeCmd) {
|
|
||||||
return fmt.Errorf("does not installed in %s", z.rc)
|
return fmt.Errorf("does not installed in %s", z.rc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
completeCmd := z.cmd(cmd, bin)
|
||||||
return removeFromFile(z.rc, completeCmd)
|
return removeFromFile(z.rc, completeCmd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
// Package complete provides a tool for bash writing bash completion in go.
|
|
||||||
//
|
|
||||||
// Writing bash completion scripts is a hard work. This package provides an easy way
|
|
||||||
// to create bash completion scripts for any command, and also an easy way to install/uninstall
|
|
||||||
// the completion of the command.
|
|
||||||
package complete
|
package complete
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -11,9 +6,9 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/posener/complete/cmd"
|
"github.com/posener/complete/cmd"
|
||||||
"github.com/posener/complete/match"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -77,7 +72,7 @@ func (c *Complete) Complete() bool {
|
||||||
// filter only options that match the last argument
|
// filter only options that match the last argument
|
||||||
matches := []string{}
|
matches := []string{}
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
if match.Prefix(option, a.Last) {
|
if strings.HasPrefix(option, a.Last) {
|
||||||
matches = append(matches, option)
|
matches = append(matches, option)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,110 @@
|
||||||
|
/*
|
||||||
|
Package complete provides a tool for bash writing bash completion in go, and bash completion for the go command line.
|
||||||
|
|
||||||
|
Writing bash completion scripts is a hard work. This package provides an easy way
|
||||||
|
to create bash completion scripts for any command, and also an easy way to install/uninstall
|
||||||
|
the completion of the command.
|
||||||
|
|
||||||
|
Go Command Bash Completion
|
||||||
|
|
||||||
|
In ./cmd/gocomplete there is an example for bash completion for the `go` command line.
|
||||||
|
|
||||||
|
This is an example that uses the `complete` package on the `go` command - the `complete` package
|
||||||
|
can also be used to implement any completions, see #usage.
|
||||||
|
|
||||||
|
Install
|
||||||
|
|
||||||
|
1. Type in your shell:
|
||||||
|
|
||||||
|
go get -u github.com/posener/complete/gocomplete
|
||||||
|
gocomplete -install
|
||||||
|
|
||||||
|
2. Restart your shell
|
||||||
|
|
||||||
|
Uninstall by `gocomplete -uninstall`
|
||||||
|
|
||||||
|
Features
|
||||||
|
|
||||||
|
- Complete `go` command, including sub commands and all flags.
|
||||||
|
- Complete packages names or `.go` files when necessary.
|
||||||
|
- Complete test names after `-run` flag.
|
||||||
|
|
||||||
|
Complete package
|
||||||
|
|
||||||
|
Supported shells:
|
||||||
|
|
||||||
|
- [x] bash
|
||||||
|
- [x] zsh
|
||||||
|
- [x] fish
|
||||||
|
|
||||||
|
Usage
|
||||||
|
|
||||||
|
Assuming you have program called `run` and you want to have bash completion
|
||||||
|
for it, meaning, if you type `run` then space, then press the `Tab` key,
|
||||||
|
the shell will suggest relevant complete options.
|
||||||
|
|
||||||
|
In that case, we will create a program called `runcomplete`, a go program,
|
||||||
|
with a `func main()` and so, that will make the completion of the `run`
|
||||||
|
program. Once the `runcomplete` will be in a binary form, we could
|
||||||
|
`runcomplete -install` and that will add to our shell all the bash completion
|
||||||
|
options for `run`.
|
||||||
|
|
||||||
|
So here it is:
|
||||||
|
|
||||||
|
import "github.com/posener/complete"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
// create a Command object, that represents the command we want
|
||||||
|
// to complete.
|
||||||
|
run := complete.Command{
|
||||||
|
|
||||||
|
// Sub defines a list of sub commands of the program,
|
||||||
|
// this is recursive, since every command is of type command also.
|
||||||
|
Sub: complete.Commands{
|
||||||
|
|
||||||
|
// add a build sub command
|
||||||
|
"build": complete.Command {
|
||||||
|
|
||||||
|
// define flags of the build sub command
|
||||||
|
Flags: complete.Flags{
|
||||||
|
// build sub command has a flag '-cpus', which
|
||||||
|
// expects number of cpus after it. in that case
|
||||||
|
// anything could complete this flag.
|
||||||
|
"-cpus": complete.PredictAnything,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
// define flags of the 'run' main command
|
||||||
|
Flags: complete.Flags{
|
||||||
|
// a flag -o, which expects a file ending with .out after
|
||||||
|
// it, the tab completion will auto complete for files matching
|
||||||
|
// the given pattern.
|
||||||
|
"-o": complete.PredictFiles("*.out"),
|
||||||
|
},
|
||||||
|
|
||||||
|
// define global flags of the 'run' main command
|
||||||
|
// those will show up also when a sub command was entered in the
|
||||||
|
// command line
|
||||||
|
GlobalFlags: complete.Flags{
|
||||||
|
|
||||||
|
// a flag '-h' which does not expects anything after it
|
||||||
|
"-h": complete.PredictNothing,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
// run the command completion, as part of the main() function.
|
||||||
|
// this triggers the autocompletion when needed.
|
||||||
|
// name must be exactly as the binary that we want to complete.
|
||||||
|
complete.New("run", run).Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
Self completing program
|
||||||
|
|
||||||
|
In case that the program that we want to complete is written in go we
|
||||||
|
can make it self completing.
|
||||||
|
Here is an example: ./example/self/main.go .
|
||||||
|
|
||||||
|
*/
|
||||||
|
package complete
|
|
@ -1,3 +1,8 @@
|
||||||
module github.com/posener/complete
|
module github.com/posener/complete
|
||||||
|
|
||||||
require github.com/hashicorp/go-multierror v1.0.0
|
require (
|
||||||
|
github.com/hashicorp/go-multierror v1.0.0
|
||||||
|
github.com/stretchr/testify v1.4.0
|
||||||
|
)
|
||||||
|
|
||||||
|
go 1.13
|
||||||
|
|
|
@ -1,4 +1,15 @@
|
||||||
|
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
github.com/hashicorp/errwrap v1.0.0 h1:hLrqtEDnRye3+sgx6z4qVLNuviH3MR5aQ0ykNJa/UYA=
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
|
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
|
||||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||||
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
|
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.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||||
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
{
|
||||||
|
"badges": {
|
||||||
|
"travis_ci": true,
|
||||||
|
"code_cov": true,
|
||||||
|
"golang_ci": true,
|
||||||
|
"go_doc": true,
|
||||||
|
"goreadme": true
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,19 +0,0 @@
|
||||||
package match
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
// File returns true if prefix can match the file
|
|
||||||
func File(file, prefix string) bool {
|
|
||||||
// special case for current directory completion
|
|
||||||
if file == "./" && (prefix == "." || prefix == "") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
if prefix == "." && strings.HasPrefix(file, ".") {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
file = strings.TrimPrefix(file, "./")
|
|
||||||
prefix = strings.TrimPrefix(prefix, "./")
|
|
||||||
|
|
||||||
return strings.HasPrefix(file, prefix)
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package match
|
|
||||||
|
|
||||||
// Match matches two strings
|
|
||||||
// it is used for comparing a term to the last typed
|
|
||||||
// word, the prefix, and see if it is a possible auto complete option.
|
|
||||||
type Match func(term, prefix string) bool
|
|
|
@ -1,9 +0,0 @@
|
||||||
package match
|
|
||||||
|
|
||||||
import "strings"
|
|
||||||
|
|
||||||
// Prefix is a simple Matcher, if the word is it's prefix, there is a match
|
|
||||||
// Match returns true if a has the prefix as prefix
|
|
||||||
func Prefix(long, prefix string) bool {
|
|
||||||
return strings.HasPrefix(long, prefix)
|
|
||||||
}
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/posener/complete/match"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// PredictDirs will search for directories in the given started to be typed
|
// PredictDirs will search for directories in the given started to be typed
|
||||||
|
@ -53,7 +51,7 @@ func predictFiles(a Args, pattern string, allowFiles bool) []string {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
dir := a.Directory()
|
dir := directory(a.Last)
|
||||||
files := listFiles(dir, pattern, allowFiles)
|
files := listFiles(dir, pattern, allowFiles)
|
||||||
|
|
||||||
// add dir if match
|
// add dir if match
|
||||||
|
@ -62,6 +60,19 @@ func predictFiles(a Args, pattern string, allowFiles bool) []string {
|
||||||
return PredictFilesSet(files).Predict(a)
|
return PredictFilesSet(files).Predict(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// directory gives the directory of the given partial path
|
||||||
|
// in case that it is not, we fall back to the current directory.
|
||||||
|
func directory(path string) string {
|
||||||
|
if info, err := os.Stat(path); err == nil && info.IsDir() {
|
||||||
|
return fixPathForm(path, path)
|
||||||
|
}
|
||||||
|
dir := filepath.Dir(path)
|
||||||
|
if info, err := os.Stat(dir); err == nil && info.IsDir() {
|
||||||
|
return fixPathForm(path, dir)
|
||||||
|
}
|
||||||
|
return "./"
|
||||||
|
}
|
||||||
|
|
||||||
// PredictFilesSet predict according to file rules to a given set of file names
|
// PredictFilesSet predict according to file rules to a given set of file names
|
||||||
func PredictFilesSet(files []string) PredictFunc {
|
func PredictFilesSet(files []string) PredictFunc {
|
||||||
return func(a Args) (prediction []string) {
|
return func(a Args) (prediction []string) {
|
||||||
|
@ -70,7 +81,7 @@ func PredictFilesSet(files []string) PredictFunc {
|
||||||
f = fixPathForm(a.Last, f)
|
f = fixPathForm(a.Last, f)
|
||||||
|
|
||||||
// test matching of file to the argument
|
// test matching of file to the argument
|
||||||
if match.File(f, a.Last) {
|
if matchFile(f, a.Last) {
|
||||||
prediction = append(prediction, f)
|
prediction = append(prediction, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,3 +117,58 @@ func listFiles(dir, pattern string, allowFiles bool) []string {
|
||||||
}
|
}
|
||||||
return list
|
return list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MatchFile returns true if prefix can match the file
|
||||||
|
func matchFile(file, prefix string) bool {
|
||||||
|
// special case for current directory completion
|
||||||
|
if file == "./" && (prefix == "." || prefix == "") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if prefix == "." && strings.HasPrefix(file, ".") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
file = strings.TrimPrefix(file, "./")
|
||||||
|
prefix = strings.TrimPrefix(prefix, "./")
|
||||||
|
|
||||||
|
return strings.HasPrefix(file, prefix)
|
||||||
|
}
|
||||||
|
|
||||||
|
// fixPathForm changes a file name to a relative name
|
||||||
|
func fixPathForm(last string, file string) string {
|
||||||
|
// get wording directory for relative name
|
||||||
|
workDir, err := os.Getwd()
|
||||||
|
if err != nil {
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
|
abs, err := filepath.Abs(file)
|
||||||
|
if err != nil {
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
|
// if last is absolute, return path as absolute
|
||||||
|
if filepath.IsAbs(last) {
|
||||||
|
return fixDirPath(abs)
|
||||||
|
}
|
||||||
|
|
||||||
|
rel, err := filepath.Rel(workDir, abs)
|
||||||
|
if err != nil {
|
||||||
|
return file
|
||||||
|
}
|
||||||
|
|
||||||
|
// fix ./ prefix of path
|
||||||
|
if rel != "." && strings.HasPrefix(last, ".") {
|
||||||
|
rel = "./" + rel
|
||||||
|
}
|
||||||
|
|
||||||
|
return fixDirPath(rel)
|
||||||
|
}
|
||||||
|
|
||||||
|
func fixDirPath(path string) string {
|
||||||
|
info, err := os.Stat(path)
|
||||||
|
if err == nil && info.IsDir() && !strings.HasSuffix(path, "/") {
|
||||||
|
path += "/"
|
||||||
|
}
|
||||||
|
return path
|
||||||
|
}
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
package complete
|
|
||||||
|
|
||||||
import (
|
|
||||||
"os"
|
|
||||||
"path/filepath"
|
|
||||||
"strings"
|
|
||||||
)
|
|
||||||
|
|
||||||
// fixPathForm changes a file name to a relative name
|
|
||||||
func fixPathForm(last string, file string) string {
|
|
||||||
// get wording directory for relative name
|
|
||||||
workDir, err := os.Getwd()
|
|
||||||
if err != nil {
|
|
||||||
return file
|
|
||||||
}
|
|
||||||
|
|
||||||
abs, err := filepath.Abs(file)
|
|
||||||
if err != nil {
|
|
||||||
return file
|
|
||||||
}
|
|
||||||
|
|
||||||
// if last is absolute, return path as absolute
|
|
||||||
if filepath.IsAbs(last) {
|
|
||||||
return fixDirPath(abs)
|
|
||||||
}
|
|
||||||
|
|
||||||
rel, err := filepath.Rel(workDir, abs)
|
|
||||||
if err != nil {
|
|
||||||
return file
|
|
||||||
}
|
|
||||||
|
|
||||||
// fix ./ prefix of path
|
|
||||||
if rel != "." && strings.HasPrefix(last, ".") {
|
|
||||||
rel = "./" + rel
|
|
||||||
}
|
|
||||||
|
|
||||||
return fixDirPath(rel)
|
|
||||||
}
|
|
||||||
|
|
||||||
func fixDirPath(path string) string {
|
|
||||||
info, err := os.Stat(path)
|
|
||||||
if err == nil && info.IsDir() && !strings.HasSuffix(path, "/") {
|
|
||||||
path += "/"
|
|
||||||
}
|
|
||||||
return path
|
|
||||||
}
|
|
|
@ -1694,6 +1694,7 @@ func (sc *serverConn) processData(f *DataFrame) error {
|
||||||
if len(data) > 0 {
|
if len(data) > 0 {
|
||||||
wrote, err := st.body.Write(data)
|
wrote, err := st.body.Write(data)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
sc.sendWindowUpdate(nil, int(f.Length)-wrote)
|
||||||
return streamError(id, ErrCodeStreamClosed)
|
return streamError(id, ErrCodeStreamClosed)
|
||||||
}
|
}
|
||||||
if wrote != len(data) {
|
if wrote != len(data) {
|
||||||
|
@ -2020,7 +2021,11 @@ func (sc *serverConn) newWriterAndRequest(st *stream, f *MetaHeadersFrame) (*res
|
||||||
}
|
}
|
||||||
if bodyOpen {
|
if bodyOpen {
|
||||||
if vv, ok := rp.header["Content-Length"]; ok {
|
if vv, ok := rp.header["Content-Length"]; ok {
|
||||||
req.ContentLength, _ = strconv.ParseInt(vv[0], 10, 64)
|
if cl, err := strconv.ParseUint(vv[0], 10, 63); err == nil {
|
||||||
|
req.ContentLength = int64(cl)
|
||||||
|
} else {
|
||||||
|
req.ContentLength = 0
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
req.ContentLength = -1
|
req.ContentLength = -1
|
||||||
}
|
}
|
||||||
|
@ -2403,9 +2408,8 @@ func (rws *responseWriterState) writeChunk(p []byte) (n int, err error) {
|
||||||
var ctype, clen string
|
var ctype, clen string
|
||||||
if clen = rws.snapHeader.Get("Content-Length"); clen != "" {
|
if clen = rws.snapHeader.Get("Content-Length"); clen != "" {
|
||||||
rws.snapHeader.Del("Content-Length")
|
rws.snapHeader.Del("Content-Length")
|
||||||
clen64, err := strconv.ParseInt(clen, 10, 64)
|
if cl, err := strconv.ParseUint(clen, 10, 63); err == nil {
|
||||||
if err == nil && clen64 >= 0 {
|
rws.sentContentLen = int64(cl)
|
||||||
rws.sentContentLen = clen64
|
|
||||||
} else {
|
} else {
|
||||||
clen = ""
|
clen = ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -2006,8 +2006,8 @@ func (rl *clientConnReadLoop) handleResponse(cs *clientStream, f *MetaHeadersFra
|
||||||
if !streamEnded || isHead {
|
if !streamEnded || isHead {
|
||||||
res.ContentLength = -1
|
res.ContentLength = -1
|
||||||
if clens := res.Header["Content-Length"]; len(clens) == 1 {
|
if clens := res.Header["Content-Length"]; len(clens) == 1 {
|
||||||
if clen64, err := strconv.ParseInt(clens[0], 10, 64); err == nil {
|
if cl, err := strconv.ParseUint(clens[0], 10, 63); err == nil {
|
||||||
res.ContentLength = clen64
|
res.ContentLength = int64(cl)
|
||||||
} else {
|
} else {
|
||||||
// TODO: care? unlike http/1, it won't mess up our framing, so it's
|
// TODO: care? unlike http/1, it won't mess up our framing, so it's
|
||||||
// more safe smuggling-wise to ignore.
|
// more safe smuggling-wise to ignore.
|
||||||
|
@ -2525,6 +2525,7 @@ func strSliceContains(ss []string, s string) bool {
|
||||||
|
|
||||||
type erringRoundTripper struct{ err error }
|
type erringRoundTripper struct{ err error }
|
||||||
|
|
||||||
|
func (rt erringRoundTripper) RoundTripErr() error { return rt.err }
|
||||||
func (rt erringRoundTripper) RoundTrip(*http.Request) (*http.Response, error) { return nil, rt.err }
|
func (rt erringRoundTripper) RoundTrip(*http.Request) (*http.Response, error) { return nil, rt.err }
|
||||||
|
|
||||||
// gzipReader wraps a response body so it can lazily
|
// gzipReader wraps a response body so it can lazily
|
||||||
|
|
|
@ -6,9 +6,19 @@
|
||||||
|
|
||||||
package socket
|
package socket
|
||||||
|
|
||||||
type cmsghdr struct{}
|
func controlHeaderLen() int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
const sizeofCmsghdr = 0
|
func controlMessageLen(dataLen int) int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
func controlMessageSpace(dataLen int) int {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
type cmsghdr struct{}
|
||||||
|
|
||||||
func (h *cmsghdr) len() int { return 0 }
|
func (h *cmsghdr) len() int { return 0 }
|
||||||
func (h *cmsghdr) lvl() int { return 0 }
|
func (h *cmsghdr) lvl() int { return 0 }
|
||||||
|
|
|
@ -0,0 +1,21 @@
|
||||||
|
// Copyright 2020 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
|
||||||
|
|
||||||
|
package socket
|
||||||
|
|
||||||
|
import "golang.org/x/sys/unix"
|
||||||
|
|
||||||
|
func controlHeaderLen() int {
|
||||||
|
return unix.CmsgLen(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func controlMessageLen(dataLen int) int {
|
||||||
|
return unix.CmsgLen(dataLen)
|
||||||
|
}
|
||||||
|
|
||||||
|
func controlMessageSpace(dataLen int) int {
|
||||||
|
return unix.CmsgSpace(dataLen)
|
||||||
|
}
|
|
@ -90,17 +90,9 @@ func (o *Option) SetInt(c *Conn, v int) error {
|
||||||
return o.set(c, b)
|
return o.set(c, b)
|
||||||
}
|
}
|
||||||
|
|
||||||
func controlHeaderLen() int {
|
|
||||||
return roundup(sizeofCmsghdr)
|
|
||||||
}
|
|
||||||
|
|
||||||
func controlMessageLen(dataLen int) int {
|
|
||||||
return roundup(sizeofCmsghdr) + dataLen
|
|
||||||
}
|
|
||||||
|
|
||||||
// ControlMessageSpace returns the whole length of control message.
|
// ControlMessageSpace returns the whole length of control message.
|
||||||
func ControlMessageSpace(dataLen int) int {
|
func ControlMessageSpace(dataLen int) int {
|
||||||
return roundup(sizeofCmsghdr) + roundup(dataLen)
|
return controlMessageSpace(dataLen)
|
||||||
}
|
}
|
||||||
|
|
||||||
// A ControlMessage represents the head message in a stream of control
|
// A ControlMessage represents the head message in a stream of control
|
||||||
|
|
|
@ -9,13 +9,8 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
// NativeEndian is the machine native endian implementation of ByteOrder.
|
||||||
// NativeEndian is the machine native endian implementation of
|
var NativeEndian binary.ByteOrder
|
||||||
// ByteOrder.
|
|
||||||
NativeEndian binary.ByteOrder
|
|
||||||
|
|
||||||
kernelAlign int
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
i := uint32(1)
|
i := uint32(1)
|
||||||
|
@ -25,9 +20,4 @@ func init() {
|
||||||
} else {
|
} else {
|
||||||
NativeEndian = binary.BigEndian
|
NativeEndian = binary.BigEndian
|
||||||
}
|
}
|
||||||
kernelAlign = probeProtocolStack()
|
|
||||||
}
|
|
||||||
|
|
||||||
func roundup(l int) int {
|
|
||||||
return (l + kernelAlign - 1) &^ (kernelAlign - 1)
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
// Copyright 2017 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build aix freebsd netbsd openbsd
|
|
||||||
|
|
||||||
package socket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"runtime"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func probeProtocolStack() int {
|
|
||||||
if (runtime.GOOS == "netbsd" || runtime.GOOS == "openbsd") && runtime.GOARCH == "arm" {
|
|
||||||
return 8
|
|
||||||
}
|
|
||||||
if runtime.GOOS == "aix" {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
var p uintptr
|
|
||||||
return int(unsafe.Sizeof(p))
|
|
||||||
}
|
|
|
@ -1,7 +0,0 @@
|
||||||
// Copyright 2017 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package socket
|
|
||||||
|
|
||||||
func probeProtocolStack() int { return 4 }
|
|
|
@ -1,32 +0,0 @@
|
||||||
// Copyright 2017 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package socket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"sync"
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// See version list in https://github.com/DragonFlyBSD/DragonFlyBSD/blob/master/sys/sys/param.h
|
|
||||||
var (
|
|
||||||
osreldateOnce sync.Once
|
|
||||||
osreldate uint32
|
|
||||||
)
|
|
||||||
|
|
||||||
// First __DragonFly_version after September 2019 ABI changes
|
|
||||||
// http://lists.dragonflybsd.org/pipermail/users/2019-September/358280.html
|
|
||||||
const _dragonflyABIChangeVersion = 500705
|
|
||||||
|
|
||||||
func probeProtocolStack() int {
|
|
||||||
osreldateOnce.Do(func() { osreldate, _ = syscall.SysctlUint32("kern.osreldate") })
|
|
||||||
var p uintptr
|
|
||||||
if int(unsafe.Sizeof(p)) == 8 && osreldate >= _dragonflyABIChangeVersion {
|
|
||||||
return int(unsafe.Sizeof(p))
|
|
||||||
}
|
|
||||||
// 64-bit Dragonfly before the September 2019 ABI changes still requires
|
|
||||||
// 32-bit aligned access to network subsystem.
|
|
||||||
return 4
|
|
||||||
}
|
|
|
@ -1,33 +0,0 @@
|
||||||
// Copyright 2018 The Go Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a BSD-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
// +build !go1.12
|
|
||||||
|
|
||||||
package socket
|
|
||||||
|
|
||||||
import (
|
|
||||||
"syscall"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
func getsockopt(s uintptr, level, name int, b []byte) (int, error) {
|
|
||||||
l := uint32(len(b))
|
|
||||||
_, _, errno := syscall.Syscall6(syscall.SYS_GETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(unsafe.Pointer(&l)), 0)
|
|
||||||
return int(l), errnoErr(errno)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setsockopt(s uintptr, level, name int, b []byte) error {
|
|
||||||
_, _, errno := syscall.Syscall6(syscall.SYS_SETSOCKOPT, s, uintptr(level), uintptr(name), uintptr(unsafe.Pointer(&b[0])), uintptr(len(b)), 0)
|
|
||||||
return errnoErr(errno)
|
|
||||||
}
|
|
||||||
|
|
||||||
func recvmsg(s uintptr, h *msghdr, flags int) (int, error) {
|
|
||||||
n, _, errno := syscall.Syscall(syscall.SYS_RECVMSG, s, uintptr(unsafe.Pointer(h)), uintptr(flags))
|
|
||||||
return int(n), errnoErr(errno)
|
|
||||||
}
|
|
||||||
|
|
||||||
func sendmsg(s uintptr, h *msghdr, flags int) (int, error) {
|
|
||||||
n, _, errno := syscall.Syscall(syscall.SYS_SENDMSG, s, uintptr(unsafe.Pointer(h)), uintptr(flags))
|
|
||||||
return int(n), errnoErr(errno)
|
|
||||||
}
|
|
|
@ -11,11 +11,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func probeProtocolStack() int {
|
|
||||||
var p uintptr
|
|
||||||
return int(unsafe.Sizeof(p))
|
|
||||||
}
|
|
||||||
|
|
||||||
func recvmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
func recvmmsg(s uintptr, hs []mmsghdr, flags int) (int, error) {
|
||||||
n, _, errno := syscall.Syscall6(sysRECVMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
|
n, _, errno := syscall.Syscall6(sysRECVMMSG, s, uintptr(unsafe.Pointer(&hs[0])), uintptr(len(hs)), uintptr(flags), 0, 0)
|
||||||
return int(n), errnoErr(errno)
|
return int(n), errnoErr(errno)
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func probeProtocolStack() int { return 4 }
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sysSETSOCKOPT = 0xe
|
sysSETSOCKOPT = 0xe
|
||||||
sysGETSOCKOPT = 0xf
|
sysGETSOCKOPT = 0xf
|
||||||
|
|
|
@ -9,8 +9,6 @@ import (
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func probeProtocolStack() int { return 8 }
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sysSETSOCKOPT = 0xe
|
sysSETSOCKOPT = 0xe
|
||||||
sysGETSOCKOPT = 0xf
|
sysGETSOCKOPT = 0xf
|
||||||
|
|
|
@ -5,21 +5,10 @@
|
||||||
package socket
|
package socket
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"runtime"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
)
|
)
|
||||||
|
|
||||||
func probeProtocolStack() int {
|
|
||||||
switch runtime.GOARCH {
|
|
||||||
case "amd64":
|
|
||||||
return 4
|
|
||||||
default:
|
|
||||||
var p uintptr
|
|
||||||
return int(unsafe.Sizeof(p))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//go:cgo_import_dynamic libc___xnet_getsockopt __xnet_getsockopt "libsocket.so"
|
//go:cgo_import_dynamic libc___xnet_getsockopt __xnet_getsockopt "libsocket.so"
|
||||||
//go:cgo_import_dynamic libc_setsockopt setsockopt "libsocket.so"
|
//go:cgo_import_dynamic libc_setsockopt setsockopt "libsocket.so"
|
||||||
//go:cgo_import_dynamic libc___xnet_recvmsg __xnet_recvmsg "libsocket.so"
|
//go:cgo_import_dynamic libc___xnet_recvmsg __xnet_recvmsg "libsocket.so"
|
||||||
|
|
|
@ -6,11 +6,7 @@
|
||||||
|
|
||||||
package socket
|
package socket
|
||||||
|
|
||||||
import (
|
import "net"
|
||||||
"net"
|
|
||||||
"runtime"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
const (
|
||||||
sysAF_UNSPEC = 0x0
|
sysAF_UNSPEC = 0x0
|
||||||
|
@ -20,16 +16,6 @@ const (
|
||||||
sysSOCK_RAW = 0x3
|
sysSOCK_RAW = 0x3
|
||||||
)
|
)
|
||||||
|
|
||||||
func probeProtocolStack() int {
|
|
||||||
switch runtime.GOARCH {
|
|
||||||
case "amd64p32", "mips64p32":
|
|
||||||
return 4
|
|
||||||
default:
|
|
||||||
var p uintptr
|
|
||||||
return int(unsafe.Sizeof(p))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func marshalInetAddr(ip net.IP, port int, zone string) []byte {
|
func marshalInetAddr(ip net.IP, port int, zone string) []byte {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x10
|
sizeofIovec = 0x10
|
||||||
sizeofMsghdr = 0x30
|
sizeofMsghdr = 0x30
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
|
@ -44,7 +44,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x8
|
sizeofIovec = 0x8
|
||||||
sizeofMsghdr = 0x1c
|
sizeofMsghdr = 0x1c
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
|
@ -46,7 +46,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x10
|
sizeofIovec = 0x10
|
||||||
sizeofMsghdr = 0x30
|
sizeofMsghdr = 0x30
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
|
@ -44,7 +44,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x8
|
sizeofIovec = 0x8
|
||||||
sizeofMsghdr = 0x1c
|
sizeofMsghdr = 0x1c
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
|
@ -46,7 +46,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x10
|
sizeofIovec = 0x10
|
||||||
sizeofMsghdr = 0x30
|
sizeofMsghdr = 0x30
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
|
@ -46,7 +46,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x10
|
sizeofIovec = 0x10
|
||||||
sizeofMsghdr = 0x30
|
sizeofMsghdr = 0x30
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
|
@ -44,7 +44,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x8
|
sizeofIovec = 0x8
|
||||||
sizeofMsghdr = 0x1c
|
sizeofMsghdr = 0x1c
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
|
@ -46,7 +46,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x10
|
sizeofIovec = 0x10
|
||||||
sizeofMsghdr = 0x30
|
sizeofMsghdr = 0x30
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
|
@ -44,7 +44,6 @@ type sockaddrInet6 struct {
|
||||||
const (
|
const (
|
||||||
sizeofIovec = 0x8
|
sizeofIovec = 0x8
|
||||||
sizeofMsghdr = 0x1c
|
sizeofMsghdr = 0x1c
|
||||||
sizeofCmsghdr = 0xc
|
|
||||||
|
|
||||||
sizeofSockaddrInet = 0x10
|
sizeofSockaddrInet = 0x10
|
||||||
sizeofSockaddrInet6 = 0x1c
|
sizeofSockaddrInet6 = 0x1c
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue