chore_: upgrade go to 1.21 (#5216)

This commit is contained in:
Siddarth Kumar 2024-05-30 14:22:57 +05:30 committed by GitHub
parent 8d17918c37
commit fb88f541f2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
21 changed files with 397 additions and 199 deletions

8
go.mod
View File

@ -1,6 +1,8 @@
module github.com/status-im/status-go
go 1.20
go 1.21
toolchain go1.21.8
replace github.com/ethereum/go-ethereum v1.10.26 => github.com/status-im/go-ethereum v1.10.25-status.13
@ -111,8 +113,8 @@ require (
github.com/anacrolix/confluence v1.9.0 // indirect
github.com/anacrolix/dht/v2 v2.15.2-0.20220123034220-0538803801cb // indirect
github.com/anacrolix/envpprof v1.1.1 // indirect
github.com/anacrolix/go-libutp v1.2.0 // indirect
github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8 // indirect
github.com/anacrolix/go-libutp v1.3.1 // indirect
github.com/anacrolix/log v0.13.1 // indirect
github.com/anacrolix/missinggo v1.3.0 // indirect
github.com/anacrolix/missinggo/perf v1.0.0 // indirect
github.com/anacrolix/missinggo/v2 v2.5.2 // indirect

19
go.sum
View File

@ -225,8 +225,9 @@ github.com/anacrolix/go-libutp v0.0.0-20180522111405-6baeb806518d/go.mod h1:beQS
github.com/anacrolix/go-libutp v1.0.2/go.mod h1:uIH0A72V++j0D1nnmTjjZUiH/ujPkFxYWkxQ02+7S0U=
github.com/anacrolix/go-libutp v1.0.4/go.mod h1:8vSGX5g0b4eebsDBNVQHUXSCwYaN18Lnkse0hUW8/5w=
github.com/anacrolix/go-libutp v1.1.0/go.mod h1:so9zroOUhFPGnIkddyflaCCl+xdTsRSq97/AOQ2/Hjk=
github.com/anacrolix/go-libutp v1.2.0 h1:sjxoB+/ARiKUR7IK/6wLWyADIBqGmu1fm0xo+8Yy7u0=
github.com/anacrolix/go-libutp v1.2.0/go.mod h1:RrJ3KcaDcf9Jqp33YL5V/5CBEc6xMc7aJL8wXfuWL50=
github.com/anacrolix/go-libutp v1.3.1 h1:idJzreNLl+hNjGC3ZnUOjujEaryeOGgkwHLqSGoige0=
github.com/anacrolix/go-libutp v1.3.1/go.mod h1:heF41EC8kN0qCLMokLBVkB8NXiLwx3t8R8810MTNI5o=
github.com/anacrolix/log v0.0.0-20180412014343-2323884b361d/go.mod h1:sf/7c2aTldL6sRQj/4UKyjgVZBu2+M2z9wf7MmwPiew=
github.com/anacrolix/log v0.3.0/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgwU9jwU=
github.com/anacrolix/log v0.3.1-0.20190913000754-831e4ffe0174/go.mod h1:lWvLTqzAnCWPJA08T2HCstZi0L1y2Wyvm3FJgwU9jwU=
@ -239,8 +240,9 @@ github.com/anacrolix/log v0.7.1-0.20200604014615-c244de44fd2d/go.mod h1:s5yBP/j0
github.com/anacrolix/log v0.8.0/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/log v0.9.0/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/log v0.10.0/go.mod h1:s5yBP/j046fm9odtUTbHOfDUq/zh1W8OkPpJtnX0oQI=
github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8 h1:o1KNFCLJ6f5SRMVb70SUFiPnNiazVd0gpMxYfYCsvK4=
github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8/go.mod h1:GmnE2c0nvz8pOIPUSC9Rawgefy1sDXqposC2wgtBZE4=
github.com/anacrolix/log v0.13.1 h1:BmVwTdxHd5VcNrLylgKwph4P4wf+5VvPgOK4yi91fTY=
github.com/anacrolix/log v0.13.1/go.mod h1:D4+CvN8SnruK6zIFS/xPoRJmtvtnxs+CSfDQ+BFxZ68=
github.com/anacrolix/lsan v0.0.0-20211126052245-807000409a62 h1:P04VG6Td13FHMgS5ZBcJX23NPC/fiC4cp9bXwYujdYM=
github.com/anacrolix/lsan v0.0.0-20211126052245-807000409a62/go.mod h1:66cFKPCO7Sl4vbFnAaSq7e4OXtdMhRSBagJGWgmpJbM=
github.com/anacrolix/missinggo v0.0.0-20180522035225-b4a5853e62ff/go.mod h1:b0p+7cn+rWMIphK1gDH2hrDuwGOcbB6V4VXeSsEfHVk=
@ -668,6 +670,7 @@ github.com/deckarep/golang-set v1.7.1/go.mod h1:93vsz/8Wt4joVM7c2AVqh+YRMiUSc14y
github.com/deckarep/golang-set v1.8.0 h1:sk9/l/KqpunDwP7pSjUg0keiOOLEnOBHzykLrsPppp4=
github.com/deckarep/golang-set v1.8.0/go.mod h1:5nI87KwE7wgsBU1F4GKAw2Qod7p5kyS383rP6+o6qqo=
github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y=
github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 h1:8UrgZ3GkP4i/CLijOJx79Yu+etlyjdBU4sfcs2WYQMs=
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0=
github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218=
@ -780,6 +783,7 @@ github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4
github.com/fsnotify/fsnotify v1.5.1/go.mod h1:T3375wBYaZdLLcVNkcVbzGHY7f1l/uK5T5Ai1i3InKU=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
github.com/fsouza/fake-gcs-server v1.7.0/go.mod h1:5XIRs4YvwNbNoz+1JF8j6KLAyDh7RHGAyAK3EP2EsNk=
github.com/fsouza/fake-gcs-server v1.17.0/go.mod h1:D1rTE4YCyHFNa99oyJJ5HyclvN/0uQR+pM/VdlL83bw=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
@ -822,6 +826,7 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA=
github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/go-logr/logr v0.2.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v0.4.0/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
@ -829,6 +834,7 @@ github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbV
github.com/go-logr/logr v1.2.1/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ=
github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/stdr v1.2.0/go.mod h1:YkVgnZu1ZjjL7xTxrfm/LLZBfkhTqSR1ydtm6jTKKwI=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8=
@ -993,6 +999,7 @@ github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-containerregistry v0.5.1/go.mod h1:Ct15B4yir3PLOP5jsy0GNeYVaIZs/MK/Jz5any1wFW0=
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
github.com/google/go-github/v39 v39.2.0/go.mod h1:C1s8C5aCC9L+JXIYpJM5GYytdX52vC1bLvHEF1IhBrE=
@ -1081,6 +1088,7 @@ github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t
github.com/grpc-ecosystem/grpc-gateway v1.9.5/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
github.com/gyuho/goraph v0.0.0-20220410190906-ad625acf7ae3 h1:sqdhbHgf04uwTLE03/FdSoaQbSy2z/hmimOAR/3OmcM=
github.com/gyuho/goraph v0.0.0-20220410190906-ad625acf7ae3/go.mod h1:NtSxZCD+s3sZFwbW6WceOcUD83HM9XD5OE2r4c0P8eg=
github.com/hailocab/go-hostpool v0.0.0-20160125115350-e80d13ce29ed/go.mod h1:tMWxXQ9wFIaZeTI9F+hmhFiGpFmhOHzyShyFUhRm0H4=
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
github.com/hashicorp/consul/api v1.3.0/go.mod h1:MmDNSzIMUjNpY/mQ398R4bk2FnqQLoPndWW5VkKPlCE=
@ -1120,6 +1128,7 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e h1:pIYdhNkDh+YENVNi3gto8n9hAmRxKxoar0iE6BLucjw=
github.com/holiman/big v0.0.0-20221017200358-a027dc42d04e/go.mod h1:j9cQbcqHQujT0oKJ38PylVfqohClLr3CvDC+Qcg+lhU=
github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao=
github.com/holiman/bloomfilter/v2 v2.0.3/go.mod h1:zpoh+gs7qcpqrHr3dB55AMiJwo0iURXE7ZOP9L9hSkA=
github.com/holiman/uint256 v1.2.0 h1:gpSYcPLWGv4sG43I2mVLiDZCNDh/EpGjSk8tmtxitHM=
@ -1313,6 +1322,7 @@ github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/pty v1.1.5/go.mod h1:9r2w37qlBe7rQ6e1fg1S/9xpWHSnaqNdHD3WcMdbPDA=
@ -1357,6 +1367,7 @@ github.com/libp2p/go-libp2p-mplex v0.9.0/go.mod h1:ro1i4kuwiFT+uMPbIDIFkcLs1KRbN
github.com/libp2p/go-libp2p-pubsub v0.10.1 h1:/RqOZpEtAolsr8/9CC8KqROJSOZeu7lK7fPftn4MwNg=
github.com/libp2p/go-libp2p-pubsub v0.10.1/go.mod h1:1OxbaT/pFRO5h+Dpze8hdHQ63R0ke55XTs6b6NwLLkw=
github.com/libp2p/go-libp2p-testing v0.12.0 h1:EPvBb4kKMWO29qP4mZGyhVzUyR25dvfUIK5WDu6iPUA=
github.com/libp2p/go-libp2p-testing v0.12.0/go.mod h1:KcGDRXyN7sQCllucn1cOOS+Dmm7ujhfEyXQL5lvkcPg=
github.com/libp2p/go-maddr-filter v0.1.0/go.mod h1:VzZhTXkMucEGGEOSKddrwGiOv0tUhgnKqNEmIAz/bPU=
github.com/libp2p/go-mplex v0.7.0 h1:BDhFZdlk5tbr0oyFq/xv/NPGfjbnrsDam1EvutpBDbY=
github.com/libp2p/go-mplex v0.7.0/go.mod h1:rW8ThnRcYWft/Jb2jeORBmPd6xuG3dGxWN/W168L9EU=
@ -1621,6 +1632,7 @@ github.com/onsi/gomega v1.15.0/go.mod h1:cIuvLEne0aoVhAgh/O6ac0Op8WWw9H6eYCriF+t
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI=
github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M=
github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk=
github.com/opencontainers/go-digest v0.0.0-20170106003457-a6d0ee40d420/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v0.0.0-20180430190053-c9281466c8b2/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
@ -1894,6 +1906,7 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc=
github.com/rogpeppe/go-internal v1.8.0/go.mod h1:WmiCO8CzOY8rg0OYDC4/i/2WRWAB6poM+XZ2dLUbcbE=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/rs/dnscache v0.0.0-20190621150935-06bb5526f76b/go.mod h1:qe5TWALJ8/a1Lqznoc5BDHpYX/8HU60Hm2AwRmqzxqA=
@ -2260,6 +2273,7 @@ go.uber.org/goleak v1.1.10/go.mod h1:8a7PlsEVH3e/a/GLqe5IIrQx6GzcnRmZEufDUTk4A7A
go.uber.org/goleak v1.1.11-0.20210813005559-691160354723/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.1.12/go.mod h1:cwTWslyiVhfpKIDGSZEM2HlOvcqm+tG4zioyIeLoqMQ=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.uber.org/mock v0.3.0 h1:3mUxI1No2/60yUYax92Pt8eNOEecx2D3lcXZh2NEZJo=
go.uber.org/mock v0.3.0/go.mod h1:a6FSlNadKUHUa9IP5Vyt1zh4fC7uAwxMutEAscFbkZc=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
@ -2476,6 +2490,7 @@ golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
golang.org/x/net v0.4.0/go.mod h1:MBQ8lrhLObU/6UmLb4fmbmk5OcyYmqtbGd/9yIeKjEE=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.8.0/go.mod h1:QVkue5JL9kW//ek3r6jTKnTFis1tRmNAW2P1shuFdJc=
golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=

View File

@ -22,20 +22,20 @@ in rec {
];
};
go = prev.go_1_20;
buildGoModule = prev.buildGo120Module;
buildGoPackage = prev.buildGo120Package;
go = prev.go_1_21;
buildGoModule = prev.buildGo121Module;
buildGoPackage = prev.buildGo121Package;
golangci-lint = prev.golangci-lint.override {
buildGoModule = args: prev.buildGo120Module ( args // rec {
version = "1.52.2";
buildGoModule = args: prev.buildGo121Module ( args // rec {
version = "1.54.0";
src = prev.fetchFromGitHub {
owner = "golangci";
repo = "golangci-lint";
rev = "v${version}";
hash = "sha256-FmNXjOMDDdGxMQvy5f1NoaqrKFpmlPWclXooMxXP8zg=";
hash = "sha256-UXN5gN1SNv3uvBCliJQ+5PSGHRL7RyU6pmZtGUTFsrQ=";
};
vendorHash = "sha256-BhD3a0LNc3hpiH4QC8FpmNn3swx3to8+6gfcgZT8TLg=";
vendorHash = "sha256-jUlK/A0HxBrIby2C0zYFtnxQX1bgKVyypI3QdH4u/rg=";
});
};

View File

@ -1,21 +0,0 @@
image:
- Visual Studio 2017
environment:
GOPATH: c:\gopath
install:
- set PATH=%GOPATH%\bin;%PATH%
- set PATH=C:\msys64\mingw64\bin;%PATH%
- go get github.com/anacrolix/envpprof
- go get github.com/anacrolix/tagflag
- go get github.com/stretchr/testify/assert
- go get github.com/anacrolix/mmsg
- go get golang.org/x/net/nettest
- go get github.com/anacrolix/sync
build_script:
- go build -v -x -a
before_test:
- go test -v

View File

@ -11,9 +11,17 @@ import (
"strings"
"sync/atomic"
"unsafe"
"github.com/anacrolix/log"
)
func (a *C.utp_callback_arguments) bufBytes() []byte {
type utpCallbackArguments C.utp_callback_arguments
func (a *utpCallbackArguments) goContext() *utpContext {
return (*utpContext)(a.context)
}
func (a *utpCallbackArguments) bufBytes() []byte {
return *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
uintptr(unsafe.Pointer(a.buf)),
int(a.len),
@ -21,27 +29,27 @@ func (a *C.utp_callback_arguments) bufBytes() []byte {
}))
}
func (a *C.utp_callback_arguments) state() C.int {
func (a *utpCallbackArguments) state() C.int {
return *(*C.int)(unsafe.Pointer(&a.anon0))
}
func (a *C.utp_callback_arguments) error_code() C.int {
func (a *utpCallbackArguments) error_code() C.int {
return *(*C.int)(unsafe.Pointer(&a.anon0))
}
func (a *C.utp_callback_arguments) address() *C.struct_sockaddr {
func (a *utpCallbackArguments) address() *C.struct_sockaddr {
return *(**C.struct_sockaddr)(unsafe.Pointer(&a.anon0[0]))
}
func (a *C.utp_callback_arguments) addressLen() C.socklen_t {
func (a *utpCallbackArguments) addressLen() C.socklen_t {
return *(*C.socklen_t)(unsafe.Pointer(&a.anon1[0]))
}
var sends int64
//export sendtoCallback
func sendtoCallback(a *C.utp_callback_arguments) (ret C.uint64) {
s := getSocketForLibContext(a.context)
func sendtoCallback(a *utpCallbackArguments) (ret C.uint64) {
s := getSocketForLibContext(a.goContext())
b := a.bufBytes()
var sendToUdpAddr net.UDPAddr
if err := structSockaddrToUDPAddr(a.address(), &sendToUdpAddr); err != nil {
@ -68,7 +76,7 @@ func sendtoCallback(a *C.utp_callback_arguments) (ret C.uint64) {
// Rate-limited. Probably Linux. The implementation might try
// again later.
} else {
s.logger.Printf("error sending packet: %s", err)
s.logger.Levelf(log.Debug, "error sending packet: %v", err)
}
return
}
@ -80,26 +88,26 @@ func sendtoCallback(a *C.utp_callback_arguments) (ret C.uint64) {
}
//export errorCallback
func errorCallback(a *C.utp_callback_arguments) C.uint64 {
s := getSocketForLibContext(a.context)
func errorCallback(a *utpCallbackArguments) C.uint64 {
s := getSocketForLibContext(a.goContext())
err := errorForCode(a.error_code())
if logCallbacks {
s.logger.Printf("error callback: socket %p: %s", a.socket, err)
}
libContextToSocket[a.context].conns[a.socket].onError(err)
libContextToSocket[a.goContext()].conns[a.socket].onError(err)
return 0
}
//export logCallback
func logCallback(a *C.utp_callback_arguments) C.uint64 {
s := getSocketForLibContext(a.context)
func logCallback(a *utpCallbackArguments) C.uint64 {
s := getSocketForLibContext(a.goContext())
s.logger.Printf("libutp: %s", C.GoString((*C.char)(unsafe.Pointer(a.buf))))
return 0
}
//export stateChangeCallback
func stateChangeCallback(a *C.utp_callback_arguments) C.uint64 {
s := libContextToSocket[a.context]
func stateChangeCallback(a *utpCallbackArguments) C.uint64 {
s := libContextToSocket[a.goContext()]
c := s.conns[a.socket]
if logCallbacks {
s.logger.Printf("state changed: conn %p: %s", c, libStateName(a.state()))
@ -126,8 +134,8 @@ func stateChangeCallback(a *C.utp_callback_arguments) C.uint64 {
}
//export readCallback
func readCallback(a *C.utp_callback_arguments) C.uint64 {
s := libContextToSocket[a.context]
func readCallback(a *utpCallbackArguments) C.uint64 {
s := libContextToSocket[a.goContext()]
c := s.conns[a.socket]
b := a.bufBytes()
if logCallbacks {
@ -142,8 +150,8 @@ func readCallback(a *C.utp_callback_arguments) C.uint64 {
}
//export acceptCallback
func acceptCallback(a *C.utp_callback_arguments) C.uint64 {
s := getSocketForLibContext(a.context)
func acceptCallback(a *utpCallbackArguments) C.uint64 {
s := getSocketForLibContext(a.goContext())
if logCallbacks {
s.logger.Printf("accept callback: %#v", *a)
}
@ -154,8 +162,8 @@ func acceptCallback(a *C.utp_callback_arguments) C.uint64 {
}
//export getReadBufferSizeCallback
func getReadBufferSizeCallback(a *C.utp_callback_arguments) (ret C.uint64) {
s := libContextToSocket[a.context]
func getReadBufferSizeCallback(a *utpCallbackArguments) (ret C.uint64) {
s := libContextToSocket[a.goContext()]
c := s.conns[a.socket]
if c == nil {
// socket hasn't been added to the Socket.conns yet. The read buffer
@ -168,8 +176,8 @@ func getReadBufferSizeCallback(a *C.utp_callback_arguments) (ret C.uint64) {
}
//export firewallCallback
func firewallCallback(a *C.utp_callback_arguments) C.uint64 {
s := getSocketForLibContext(a.context)
func firewallCallback(a *utpCallbackArguments) C.uint64 {
s := getSocketForLibContext(a.goContext())
if s.syncFirewallCallback != nil {
var addr net.UDPAddr
structSockaddrToUDPAddr(a.address(), &addr)

View File

@ -26,10 +26,10 @@ const (
var (
mu sync.Mutex
libContextToSocket = map[*C.utp_context]*Socket{}
libContextToSocket = map[*utpContext]*Socket{}
)
func getSocketForLibContext(uc *C.utp_context) *Socket {
func getSocketForLibContext(uc *utpContext) *Socket {
return libContextToSocket[uc]
}

View File

@ -53,7 +53,7 @@ const (
type Socket struct {
pc net.PacketConn
ctx *C.utp_context
ctx *utpContext
backlog chan *Conn
closed bool
conns map[*C.utp_socket]*Conn
@ -130,7 +130,7 @@ func NewSocket(network, addr string, opts ...NewSocketOpt) (*Socket, error) {
func() {
mu.Lock()
defer mu.Unlock()
ctx := C.utp_init(2)
ctx := (*utpContext)(C.utp_init(2))
if ctx == nil {
panic(ctx)
}
@ -244,7 +244,7 @@ func (s *Socket) processReceivedMessages(ms []mmsg.Message) {
rsa, a.sal = netAddrToLibSockaddr(m.Addr)
a.sa = (*C.struct_sockaddr)(unsafe.Pointer(&rsa))
}
C.process_received_messages(s.ctx, &args[0], C.size_t(len(ms)))
C.process_received_messages(s.ctx.asCPtr(), &args[0], C.size_t(len(ms)))
} else {
gotUtp := false
for _, m := range ms {
@ -266,12 +266,12 @@ func (s *Socket) afterReceivingUtpMessages() {
func (s *Socket) issueDeferredAcks() {
expMap.Add("utp_issue_deferred_acks calls", 1)
C.utp_issue_deferred_acks(s.ctx)
C.utp_issue_deferred_acks(s.ctx.asCPtr())
}
func (s *Socket) checkUtpTimeouts() {
expMap.Add("utp_check_timeouts calls", 1)
C.utp_check_timeouts(s.ctx)
C.utp_check_timeouts(s.ctx.asCPtr())
}
func (s *Socket) ackTimerFunc() {
@ -328,7 +328,7 @@ func (s *Socket) utpProcessUdp(b []byte, addr net.Addr) (utp bool) {
}
var sal C.socklen_t
staticRsa, sal = netAddrToLibSockaddr(addr)
ret := C.utp_process_udp(s.ctx, (*C.byte)(&b[0]), C.size_t(len(b)), (*C.struct_sockaddr)(unsafe.Pointer(&staticRsa)), sal)
ret := C.utp_process_udp(s.ctx.asCPtr(), (*C.byte)(&b[0]), C.size_t(len(b)), (*C.struct_sockaddr)(unsafe.Pointer(&staticRsa)), sal)
switch ret {
case 1:
return true
@ -363,7 +363,7 @@ func (s *Socket) closeLocked() error {
}
// Calling this deletes the pointer. It must not be referred to after
// this.
C.utp_destroy(s.ctx)
C.utp_destroy(s.ctx.asCPtr())
s.ctx = nil
s.pc.Close()
close(s.backlog)
@ -436,7 +436,7 @@ func (s *Socket) DialContext(ctx context.Context, network, addr string) (_ net.C
if s.closed {
return nil, errSocketClosed
}
utpSock := utpCreateSocketAndConnect(s.ctx, sa, sl)
utpSock := utpCreateSocketAndConnect(s.ctx.asCPtr(), sa, sl)
c := s.newConn(utpSock)
c.setRemoteAddr()
err = c.waitForConnect(ctx)
@ -498,19 +498,19 @@ func (s *Socket) WriteTo(b []byte, addr net.Addr) (int, error) {
func (s *Socket) ReadBufferLen() int {
mu.Lock()
defer mu.Unlock()
return int(C.utp_context_get_option(s.ctx, C.UTP_RCVBUF))
return int(C.utp_context_get_option(s.ctx.asCPtr(), C.UTP_RCVBUF))
}
func (s *Socket) WriteBufferLen() int {
mu.Lock()
defer mu.Unlock()
return int(C.utp_context_get_option(s.ctx, C.UTP_SNDBUF))
return int(C.utp_context_get_option(s.ctx.asCPtr(), C.UTP_SNDBUF))
}
func (s *Socket) SetWriteBufferLen(len int) {
mu.Lock()
defer mu.Unlock()
i := C.utp_context_set_option(s.ctx, C.UTP_SNDBUF, C.int(len))
i := C.utp_context_set_option(s.ctx.asCPtr(), C.UTP_SNDBUF, C.int(len))
if i != 0 {
panic(i)
}
@ -519,7 +519,7 @@ func (s *Socket) SetWriteBufferLen(len int) {
func (s *Socket) SetOption(opt Option, val int) int {
mu.Lock()
defer mu.Unlock()
return int(C.utp_context_set_option(s.ctx, opt, C.int(val)))
return int(C.utp_context_set_option(s.ctx.asCPtr(), opt, C.int(val)))
}
// The callback is used before each packet is processed by libutp without the this package's mutex

View File

@ -26,25 +26,31 @@ import "unsafe"
type socklen C.socklen_t
func (ctx *C.utp_context) setCallbacks() {
C.utp_set_callback(ctx, C.UTP_ON_FIREWALL, (*C.utp_callback_t)(C.firewallCallback))
C.utp_set_callback(ctx, C.UTP_LOG, (*C.utp_callback_t)(C.logCallback))
C.utp_set_callback(ctx, C.UTP_ON_ACCEPT, (*C.utp_callback_t)(C.acceptCallback))
C.utp_set_callback(ctx, C.UTP_SENDTO, (*C.utp_callback_t)(C.sendtoCallback))
C.utp_set_callback(ctx, C.UTP_ON_STATE_CHANGE, (*C.utp_callback_t)(C.stateChangeCallback))
C.utp_set_callback(ctx, C.UTP_ON_READ, (*C.utp_callback_t)(C.readCallback))
C.utp_set_callback(ctx, C.UTP_ON_ERROR, (*C.utp_callback_t)(C.errorCallback))
C.utp_set_callback(ctx, C.UTP_GET_READ_BUFFER_SIZE, (*C.utp_callback_t)(C.getReadBufferSizeCallback))
type utpContext C.utp_context
func (ctx *utpContext) asCPtr() *C.utp_context {
return (*C.utp_context)(ctx)
}
func (ctx *C.utp_context) setOption(opt Option, val int) int {
return int(C.utp_context_set_option(ctx, opt, C.int(val)))
func (ctx *utpContext) setCallbacks() {
C.utp_set_callback(ctx.asCPtr(), C.UTP_ON_FIREWALL, (*C.utp_callback_t)(C.firewallCallback))
C.utp_set_callback(ctx.asCPtr(), C.UTP_LOG, (*C.utp_callback_t)(C.logCallback))
C.utp_set_callback(ctx.asCPtr(), C.UTP_ON_ACCEPT, (*C.utp_callback_t)(C.acceptCallback))
C.utp_set_callback(ctx.asCPtr(), C.UTP_SENDTO, (*C.utp_callback_t)(C.sendtoCallback))
C.utp_set_callback(ctx.asCPtr(), C.UTP_ON_STATE_CHANGE, (*C.utp_callback_t)(C.stateChangeCallback))
C.utp_set_callback(ctx.asCPtr(), C.UTP_ON_READ, (*C.utp_callback_t)(C.readCallback))
C.utp_set_callback(ctx.asCPtr(), C.UTP_ON_ERROR, (*C.utp_callback_t)(C.errorCallback))
C.utp_set_callback(ctx.asCPtr(), C.UTP_GET_READ_BUFFER_SIZE, (*C.utp_callback_t)(C.getReadBufferSizeCallback))
}
func (ctx *utpContext) setOption(opt Option, val int) int {
return int(C.utp_context_set_option(ctx.asCPtr(), opt, C.int(val)))
}
func libStateName(state C.int) string {
return C.GoString((*[5]*C.char)(unsafe.Pointer(&C.utp_state_names))[state])
}
func libErrorCodeNames(error_code C.int) string {
return C.GoString((*[3]*C.char)(unsafe.Pointer(&C.utp_error_code_names))[error_code])
func libErrorCodeNames(errorCode C.int) string {
return C.GoString((*[3]*C.char)(unsafe.Pointer(&C.utp_error_code_names))[errorCode])
}

15
vendor/github.com/anacrolix/log/context.go generated vendored Normal file
View File

@ -0,0 +1,15 @@
package log
import (
"context"
)
var loggerContextKey interface{} = (*Logger)(nil)
func ContextWithLogger(ctx context.Context, logger Logger) context.Context {
return context.WithValue(ctx, loggerContextKey, logger)
}
func ContextLogger(ctx context.Context) Logger {
return ctx.Value(loggerContextKey).(Logger)
}

8
vendor/github.com/anacrolix/log/doc.go generated vendored Normal file
View File

@ -0,0 +1,8 @@
// Package log implements a std log compatible logging system that draws some inspiration from the
// Python standard library [logging module](https://docs.python.org/3/library/logging.html). It
// supports multiple handlers, log levels, zero-allocation, scopes, custom formatting, and
// environment and runtime configuration.
//
// When not used to replace std log, the import should use the package name "analog" as in:
// import analog "github.com/anacrolix/log".
package log

View File

@ -11,11 +11,7 @@ var (
W: os.Stderr,
Fmt: LineFormatter,
}
Default = Logger{
nonZero: true,
filterLevel: Error,
Handlers: []Handler{DefaultHandler},
}
Default Logger // Inited after GO_LOG is parsed.
DiscardHandler = StreamHandler{
W: ioutil.Discard,
Fmt: func(Record) []byte { return nil },
@ -37,3 +33,9 @@ func Print(a ...interface{}) {
// TODO: There's no "Print" equivalent constructor for a Msg, and I don't know what I'd call it.
Str(fmt.Sprint(a...)).Skip(1).Log(Default)
}
func Println(a ...interface{}) {
Default.LazyLogDefaultLevel(func() Msg {
return Str(fmt.Sprintln(a...)).Skip(1)
})
}

22
vendor/github.com/anacrolix/log/init.go generated vendored Normal file
View File

@ -0,0 +1,22 @@
package log
import (
"os"
)
func init() {
var err error
rules, err = parseEnvRules()
if err != nil {
panic(err)
}
Default = loggerCore{
nonZero: true,
filterLevel: Error,
Handlers: []Handler{DefaultHandler},
}.withFilterLevelFromRules()
Default.defaultLevel, _, err = levelFromString(os.Getenv("GO_LOG_DEFAULT_LEVEL"))
if err != nil {
panic(err)
}
}

View File

@ -1,43 +1,45 @@
package log
import (
"encoding"
"fmt"
"strconv"
"strings"
)
type Level struct {
rank int
logStr string
rank int
}
var levelKey = new(struct{})
var (
NotSet = Level{0, "UNSET"}
Debug = Level{1, "DEBUG"}
Info = Level{2, "INFO"}
Warning = Level{3, "WARN"}
Error = Level{4, "ERROR"}
Critical = Level{5, "CRIT"}
// Will this get special treatment? Not yet.
Fatal = Level{6, "FATAL"}
Never = Level{-1} // A message at this level should never be logged.
NotSet = Level{0}
Debug = Level{1}
Info = Level{2}
Warning = Level{3}
Error = Level{4}
Critical = Level{5}
disabled = Level{6} // It shouldn't be possible to define a message at this level.
)
func (l Level) isNotSet() bool {
return l.rank == 0
}
func (l Level) LogString() string {
switch l.rank {
case NotSet.rank:
return "unset"
return "NIL"
case Debug.rank:
return "debug"
return "DBG"
case Info.rank:
return "info"
return "INF"
case Warning.rank:
return "warn"
return "WRN"
case Error.rank:
return "error"
return "ERR"
case Critical.rank:
return "crit"
case Fatal.rank:
return "fatal"
return "CRT"
default:
return strconv.FormatInt(int64(l.rank), 10)
}
@ -49,3 +51,25 @@ func (l Level) LessThan(r Level) bool {
}
return l.rank < r.rank
}
var _ encoding.TextUnmarshaler = (*Level)(nil)
func (l *Level) UnmarshalText(text []byte) error {
switch strings.ToLower(string(text)) {
case "nil", "notset", "unset", "all", "*":
*l = NotSet
case "dbg", "debug":
*l = Debug
case "inf", "info":
*l = Info
case "wrn", "warning", "warn":
*l = Warning
case "err", "error":
*l = Error
case "crt", "critical", "crit":
*l = Critical
default:
return fmt.Errorf("unknown log level: %q", text)
}
return nil
}

102
vendor/github.com/anacrolix/log/logger-core.go generated vendored Normal file
View File

@ -0,0 +1,102 @@
package log
import (
"fmt"
)
// loggerCore is the essential part of Logger.
type loggerCore struct {
nonZero bool
names []string
values []interface{}
defaultLevel Level
filterLevel Level
msgMaps []func(Msg) Msg
Handlers []Handler
}
func (l loggerCore) asLogger() Logger {
return Logger{l}
}
// Returns a logger that adds the given values to logged messages.
func (l loggerCore) WithValues(v ...interface{}) Logger {
l.values = append(l.values, v...)
return l.asLogger()
}
// Returns a logger that for a given message propagates the result of `f` instead.
func (l loggerCore) WithMap(f func(m Msg) Msg) Logger {
l.msgMaps = append(l.msgMaps, f)
return l.asLogger()
}
func (l loggerCore) WithDefaultLevel(level Level) Logger {
l.defaultLevel = level
return l.asLogger()
}
func (l loggerCore) FilterLevel(minLevel Level) Logger {
if _, ok := levelFromRules(l.names); !ok {
l.filterLevel = minLevel
}
return l.asLogger()
}
func (l loggerCore) IsZero() bool {
return !l.nonZero
}
func (l loggerCore) IsEnabledFor(level Level) bool {
return !level.LessThan(l.filterLevel)
}
func (l loggerCore) LazyLog(level Level, f func() Msg) {
l.lazyLog(level, 1, f)
}
func (l loggerCore) LazyLogDefaultLevel(f func() Msg) {
l.lazyLog(l.defaultLevel, 1, f)
}
func (l loggerCore) lazyLog(level Level, skip int, f func() Msg) {
if !l.IsEnabledFor(level) {
// have a big sook
//internalLogger.Levelf(Debug, "skipped logging %v for %q", level, l.names)
return
}
r := f().Skip(skip + 1)
for i := len(l.msgMaps) - 1; i >= 0; i-- {
r = l.msgMaps[i](r)
}
l.handle(level, r)
}
func (l loggerCore) handle(level Level, m Msg) {
r := Record{
Msg: m.Skip(1),
Level: level,
Names: l.names,
}
if !l.nonZero {
panic(fmt.Sprintf("Logger uninitialized. names=%q", l.names))
}
for _, h := range l.Handlers {
h.Handle(r)
}
}
func (l loggerCore) WithNames(names ...string) Logger {
// Avoid sharing after appending. This might not be enough because some formatters might add
// more elements concurrently, or names could be empty.
l.names = append(l.names[:len(l.names):len(l.names)], names...)
return l.withFilterLevelFromRules()
}
func (l loggerCore) withFilterLevelFromRules() Logger {
level, ok := levelFromRules(l.names)
if ok {
l.filterLevel = level
}
return l.asLogger()
}

View File

@ -4,27 +4,10 @@ import (
"fmt"
)
// Logger is a helper wrapping LoggerImpl.
// Logger handles logging in a specific context. It includes a bunch of helpers and compatibility
// over the loggerCore.
type Logger struct {
nonZero bool
names []string
values []interface{}
defaultLevel Level
filterLevel Level
msgMaps []func(Msg) Msg
Handlers []Handler
}
// Returns a logger that adds the given values to logged messages.
func (l Logger) WithValues(v ...interface{}) Logger {
l.values = append(l.values, v...)
return l
}
// Returns a logger that for a given message propagates the result of `f` instead.
func (l Logger) WithMap(f func(m Msg) Msg) Logger {
l.msgMaps = append(l.msgMaps, f)
return l
loggerCore
}
func (l Logger) WithText(f func(Msg) string) Logger {
@ -58,16 +41,6 @@ func (l Logger) Print(v ...interface{}) {
})
}
func (l Logger) WithDefaultLevel(level Level) Logger {
l.defaultLevel = level
return l
}
func (l Logger) FilterLevel(minLevel Level) Logger {
l.filterLevel = minLevel
return l
}
func (l Logger) WithContextValue(v interface{}) Logger {
return l.WithText(func(m Msg) string {
return fmt.Sprintf("%v: %v", v, m)
@ -80,56 +53,20 @@ func (l Logger) WithContextText(s string) Logger {
})
}
func (l Logger) IsZero() bool {
return !l.nonZero
}
func (l Logger) SkipCallers(skip int) Logger {
return l.WithMap(func(m Msg) Msg {
return m.Skip(skip)
})
}
func (l Logger) IsEnabledFor(level Level) bool {
for i := len(rules) - 1; i >= 0; i-- {
r := rules[i]
minLevel, matched := r(l.names)
if matched {
//log.Print(level, minLevel)
return !level.LessThan(minLevel)
}
}
return !level.LessThan(l.filterLevel)
}
func (l Logger) LazyLog(level Level, f func() Msg) {
l.lazyLog(level, 1, f)
}
func (l Logger) lazyLog(level Level, skip int, f func() Msg) {
if l.IsEnabledFor(level) {
l.handle(level, f().Skip(skip+1))
}
}
func (l Logger) handle(level Level, m Msg) {
r := Record{
Msg: m.Skip(1),
Level: level,
Names: l.names,
}
for _, h := range l.Handlers {
h.Handle(r)
}
}
func (l Logger) WithNames(names ...string) Logger {
l.names = append(l.names, names...)
return l
}
func (l Logger) Levelf(level Level, format string, a ...interface{}) {
l.LazyLog(level, func() Msg {
return Fmsg(format, a...).Skip(1)
})
}
func (l Logger) Println(a ...interface{}) {
l.LazyLogDefaultLevel(func() Msg {
return Str(fmt.Sprintln(a...)).Skip(1)
})
}

View File

@ -2,8 +2,6 @@ package log
import (
"fmt"
"github.com/anacrolix/missinggo/iter"
)
type Msg struct {
@ -61,7 +59,7 @@ type msgWithValues struct {
values []interface{}
}
func (me msgWithValues) Values(cb iter.Callback) {
func (me msgWithValues) Values(cb valueIterCallback) {
for _, v := range me.values {
if !cb(v) {
return

View File

@ -2,10 +2,10 @@ package log
import (
"runtime"
"github.com/anacrolix/missinggo/iter"
)
type valueIterCallback func(value interface{}) (more bool)
// The minimal interface required for the Msg helper/wrapper to operate on.
type MsgImpl interface {
// Returns the message text. Allows for lazy evaluation/prefixing etc.
@ -14,7 +14,7 @@ type MsgImpl interface {
// for serialization etc.
Callers(skip int, pc []uintptr) int
// Iterates over the values as added LIFO.
Values(callback iter.Callback)
Values(callback valueIterCallback)
}
// maybe implement finalizer to ensure msgs are sunk
@ -30,4 +30,4 @@ func (m rootMsgImpl) Callers(skip int, pc []uintptr) int {
return runtime.Callers(skip+2, pc)
}
func (m rootMsgImpl) Values(iter.Callback) {}
func (m rootMsgImpl) Values(valueIterCallback) {}

View File

@ -1,15 +1,21 @@
package log
var rules = []Rule{
//func(names []string) (level Level, matched bool) {
// //log.Print(names)
// return Info, true
//},
//ContainsAllNames([]string{"reader"}, Debug),
}
import (
"fmt"
"os"
"strings"
)
var rules []Rule
type Rule func(names []string) (level Level, matched bool)
func alwaysLevel(level Level) Rule {
return func(names []string) (Level, bool) {
return level, true
}
}
func stringSliceContains(s string, ss []string) bool {
for _, sss := range ss {
if s == sss {
@ -19,7 +25,7 @@ func stringSliceContains(s string, ss []string) bool {
return false
}
func ContainsAllNames(all []string, level Level) Rule {
func containsAllNames(all []string, level Level) Rule {
return func(names []string) (_ Level, matched bool) {
for _, s := range all {
//log.Println(s, all, names)
@ -30,3 +36,65 @@ func ContainsAllNames(all []string, level Level) Rule {
return level, true
}
}
func parseRuleString(s string) (_ Rule, ok bool, _ error) {
if s == "" {
return
}
ss := strings.SplitN(s, "=", 2)
level := NotSet
var names []string
if ss[0] != "*" {
names = []string{ss[0]}
}
if len(ss) > 1 {
var ok bool
var err error
level, ok, err = levelFromString(ss[1])
if !ok {
// blah= means disable the name, but just blah means to always include it
level = disabled
}
if err != nil {
return nil, false, fmt.Errorf("parsing level %q: %w", ss[1], err)
}
}
return containsAllNames(names, level), true, nil
}
func parseEnvRules() (rules []Rule, err error) {
rulesStr := os.Getenv("GO_LOG")
ruleStrs := strings.Split(rulesStr, ",")
for _, ruleStr := range ruleStrs {
rule, ok, err := parseRuleString(ruleStr)
if err != nil {
return nil, fmt.Errorf("parsing rule %q: %w", ruleStr, err)
}
if !ok {
continue
}
rules = append(rules, rule)
}
return
}
func levelFromString(s string) (level Level, ok bool, err error) {
if s == "" {
return
}
ok = true
err = level.UnmarshalText([]byte(s))
return
}
func levelFromRules(names []string) (_ Level, ok bool) {
// Later rules take precedence
for i := len(rules) - 1; i >= 0; i-- {
r := rules[i]
level, ok := r(names)
if ok {
return level, true
}
}
return
}

12
vendor/github.com/anacrolix/log/stdlog.go generated vendored Normal file
View File

@ -0,0 +1,12 @@
package log
import (
"log"
)
// Deprecated: Logging shouldn't include control flow.
var (
Panicf = log.Panicf
Fatalf = log.Fatalf
Fatal = log.Fatal
)

View File

@ -27,7 +27,7 @@ func LineFormatter(msg Record) []byte {
names = pcNames(pc[0], names)
}
ret := []byte(fmt.Sprintf(
"%s %-5s %s: %s",
"%s %s %s: %s",
time.Now().Format("2006-01-02T15:04:05-0700"),
msg.Level.LogString(),
names,

6
vendor/modules.txt vendored
View File

@ -42,10 +42,10 @@ github.com/anacrolix/dht/v2/types
# github.com/anacrolix/envpprof v1.1.1
## explicit; go 1.12
github.com/anacrolix/envpprof
# github.com/anacrolix/go-libutp v1.2.0
# github.com/anacrolix/go-libutp v1.3.1
## explicit; go 1.14
github.com/anacrolix/go-libutp
# github.com/anacrolix/log v0.10.1-0.20220123034749-3920702c17f8
# github.com/anacrolix/log v0.13.1
## explicit; go 1.12
github.com/anacrolix/log
# github.com/anacrolix/missinggo v1.3.0
@ -1128,7 +1128,7 @@ github.com/xeipuuv/gojsonreference
## explicit
github.com/xeipuuv/gojsonschema
# github.com/xrash/smetrics v0.0.0-20240312152122-5f08fbb34913
## explicit; go 1.15
## explicit; go 1.15.0
github.com/xrash/smetrics
# github.com/yeqown/go-qrcode/v2 v2.2.1
## explicit; go 1.18