From f7f17a19bcaebe9afaaf89a2adfbb63682f0e3db Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 11 Jul 2023 12:21:04 -0700 Subject: [PATCH 01/23] Update go.mod files --- go.mod | 22 +++++++++++----------- go.sum | 46 +++++++++++++++++++++++----------------------- test-plans/go.mod | 22 +++++++++++----------- test-plans/go.sum | 46 +++++++++++++++++++++++----------------------- 4 files changed, 68 insertions(+), 68 deletions(-) diff --git a/go.mod b/go.mod index 4f67444695..5e7446d0a2 100644 --- a/go.mod +++ b/go.mod @@ -47,17 +47,17 @@ require ( github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/prometheus/client_golang v1.14.0 github.com/prometheus/client_model v0.4.0 - github.com/quic-go/quic-go v0.33.0 + github.com/quic-go/quic-go v0.36.1 github.com/quic-go/webtransport-go v0.5.3 github.com/raulk/go-watchdog v1.3.0 github.com/stretchr/testify v1.8.2 go.uber.org/fx v1.19.2 go.uber.org/goleak v1.1.12 - golang.org/x/crypto v0.7.0 + golang.org/x/crypto v0.11.0 golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df - golang.org/x/sync v0.2.0 - golang.org/x/sys v0.8.0 - golang.org/x/tools v0.9.1 + golang.org/x/sync v0.3.0 + golang.org/x/sys v0.10.0 + golang.org/x/tools v0.11.0 google.golang.org/protobuf v1.30.0 ) @@ -81,7 +81,7 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db // indirect - github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect + github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect github.com/google/uuid v1.3.0 // indirect github.com/huin/goupnp v1.2.0 // indirect github.com/jackpal/go-nat-pmp v1.0.2 // indirect @@ -95,7 +95,7 @@ require ( github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect github.com/multiformats/go-base36 v0.2.0 // indirect github.com/onsi/ginkgo v1.16.5 // indirect - github.com/onsi/ginkgo/v2 v2.9.7 // indirect + github.com/onsi/ginkgo/v2 v2.11.0 // indirect github.com/opencontainers/runtime-spec v1.0.2 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect @@ -103,16 +103,16 @@ require ( github.com/prometheus/procfs v0.8.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect + github.com/quic-go/qtls-go1-20 v0.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/dig v1.17.0 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/mod v0.11.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/text v0.9.0 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.12.0 // indirect + golang.org/x/text v0.11.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/go.sum b/go.sum index 0c7c595c35..5ea9da05e4 100644 --- a/go.sum +++ b/go.sum @@ -210,8 +210,8 @@ github.com/google/pprof v0.0.0-20200212024743-f11f1df84d12/go.mod h1:ZgVRPoUq/hf github.com/google/pprof v0.0.0-20200229191704-1ebb73c60ed3/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200430221834-fc25d7d30c6d/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= github.com/google/pprof v0.0.0-20200708004538-1a94d8640e99/go.mod h1:ZgVRPoUq/hfqzAqh7sHMqb3I9Rq5C59dIz2SbBwJ4eM= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= +github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 h1:n6vlPhxsA+BW/XsS5+uqi7GyzaLa5MH7qlSLBZtRdiA= +github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= @@ -383,12 +383,12 @@ github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= -github.com/onsi/ginkgo/v2 v2.9.7 h1:06xGQy5www2oN160RtEZoTvnP2sPhEfePYmCDc2szss= -github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0= +github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= +github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= -github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU= +github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= @@ -434,10 +434,10 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= -github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= -github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= +github.com/quic-go/qtls-go1-20 v0.3.0 h1:NrCXmDl8BddZwO67vlvEpBTwT89bJfKYygxv4HQvuDk= +github.com/quic-go/qtls-go1-20 v0.3.0/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= +github.com/quic-go/quic-go v0.36.1 h1:WsG73nVtnDy1TiACxFxhQ3TqaW+DipmqzLEtNlAwZyY= +github.com/quic-go/quic-go v0.36.1/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= @@ -551,8 +551,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -588,8 +588,8 @@ golang.org/x/mod v0.1.1-0.20191107180719-034126e5016b/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= -golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -631,8 +631,8 @@ golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT golang.org/x/net v0.0.0-20210525063256-abc453219eb5/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -654,8 +654,8 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -716,8 +716,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -727,8 +727,8 @@ golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -783,8 +783,8 @@ golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4f golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= -golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= +golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/test-plans/go.mod b/test-plans/go.mod index f06f689f25..2683b9ab87 100644 --- a/test-plans/go.mod +++ b/test-plans/go.mod @@ -27,7 +27,7 @@ require ( github.com/golang/mock v1.6.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/gopacket v1.1.19 // indirect - github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 // indirect + github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect github.com/gorilla/websocket v1.5.0 // indirect github.com/huin/goupnp v1.2.0 // indirect github.com/ipfs/go-cid v0.4.1 // indirect @@ -64,7 +64,7 @@ require ( github.com/multiformats/go-multihash v0.2.2 // indirect github.com/multiformats/go-multistream v0.4.1 // indirect github.com/multiformats/go-varint v0.0.7 // indirect - github.com/onsi/ginkgo/v2 v2.9.7 // indirect + github.com/onsi/ginkgo/v2 v2.11.0 // indirect github.com/opencontainers/runtime-spec v1.0.2 // indirect github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect github.com/pkg/errors v0.9.1 // indirect @@ -74,8 +74,8 @@ require ( github.com/prometheus/procfs v0.10.1 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect - github.com/quic-go/quic-go v0.33.0 // indirect + github.com/quic-go/qtls-go1-20 v0.3.0 // indirect + github.com/quic-go/quic-go v0.36.1 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect @@ -84,14 +84,14 @@ require ( go.uber.org/fx v1.19.2 // indirect go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect - golang.org/x/crypto v0.7.0 // indirect + golang.org/x/crypto v0.11.0 // indirect golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect - golang.org/x/mod v0.11.0 // indirect - golang.org/x/net v0.10.0 // indirect - golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect - golang.org/x/text v0.9.0 // indirect - golang.org/x/tools v0.9.1 // indirect + golang.org/x/mod v0.12.0 // indirect + golang.org/x/net v0.12.0 // indirect + golang.org/x/sync v0.3.0 // indirect + golang.org/x/sys v0.10.0 // indirect + golang.org/x/text v0.11.0 // indirect + golang.org/x/tools v0.11.0 // indirect google.golang.org/protobuf v1.30.0 // indirect lukechampine.com/blake3 v1.2.1 // indirect ) diff --git a/test-plans/go.sum b/test-plans/go.sum index f26383db39..7ff60e30e1 100644 --- a/test-plans/go.sum +++ b/test-plans/go.sum @@ -93,8 +93,8 @@ github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo= github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs= github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751 h1:hR7/MlvK23p6+lIw9SN1TigNLn9ZnF3W4SYRKq2gAHs= -github.com/google/pprof v0.0.0-20230602150820-91b7bce49751/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= +github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 h1:n6vlPhxsA+BW/XsS5+uqi7GyzaLa5MH7qlSLBZtRdiA= +github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8/go.mod h1:Jh3hGz2jkYak8qXPD19ryItVnUgpgeqzdkY/D0EaeuA= github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY= github.com/googleapis/gax-go/v2 v2.0.3/go.mod h1:LLvjysVCY1JZeum8Z6l8qUty8fiNwE08qbEPm1M08qg= github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY= @@ -211,9 +211,9 @@ github.com/neelance/astrewrite v0.0.0-20160511093645-99348263ae86/go.mod h1:kHJE github.com/neelance/sourcemap v0.0.0-20151028013722-8c68805598ab/go.mod h1:Qr6/a/Q4r9LP1IltGz7tA7iOK1WonHEYhu1HRBA7ZiM= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= -github.com/onsi/ginkgo/v2 v2.9.7 h1:06xGQy5www2oN160RtEZoTvnP2sPhEfePYmCDc2szss= -github.com/onsi/ginkgo/v2 v2.9.7/go.mod h1:cxrmXWykAwTwhQsJOPfdIDiJ+l2RYq7U8hFU+M/1uw0= -github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU= +github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= +github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= +github.com/onsi/gomega v1.27.8 h1:gegWiwZjBsf2DgiSbf5hpokZ98JVDMcWkUiigk6/KXc= github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0= github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8= @@ -240,10 +240,10 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= -github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.33.0 h1:ItNoTDN/Fm/zBlq769lLJc8ECe9gYaW40veHCCco7y0= -github.com/quic-go/quic-go v0.33.0/go.mod h1:YMuhaAV9/jIu0XclDXwZPAsP/2Kgr5yMYhe9oxhhOFA= +github.com/quic-go/qtls-go1-20 v0.3.0 h1:NrCXmDl8BddZwO67vlvEpBTwT89bJfKYygxv4HQvuDk= +github.com/quic-go/qtls-go1-20 v0.3.0/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= +github.com/quic-go/quic-go v0.36.1 h1:WsG73nVtnDy1TiACxFxhQ3TqaW+DipmqzLEtNlAwZyY= +github.com/quic-go/quic-go v0.36.1/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= @@ -320,8 +320,8 @@ golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200602180216-279210d13fed/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= -golang.org/x/crypto v0.7.0 h1:AvwMYaRytfdeVt3u6mLaxYtErKYjxA2OXjJ1HHq6t3A= -golang.org/x/crypto v0.7.0/go.mod h1:pYwdfH91IfpZVANVyUOhSIPZaFoJGxTFbZhFTx+dXZU= +golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= +golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= @@ -334,8 +334,8 @@ golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzB golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.11.0 h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU= -golang.org/x/mod v0.11.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/mod v0.12.0 h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= +golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -352,8 +352,8 @@ golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwY golang.org/x/net v0.0.0-20210119194325-5f4716e94777/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= -golang.org/x/net v0.10.0 h1:X2//UzNDwYmtCLn7To6G58Wr6f5ahEAQgKNzv9Y951M= -golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50= +golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= @@ -367,8 +367,8 @@ golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.2.0 h1:PUR+T4wwASmuSTYdKjYHI5TD22Wy5ogLU5qZCOLxBrI= -golang.org/x/sync v0.2.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.3.0 h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= +golang.org/x/sync v0.3.0/go.mod h1:FU7BRWz2tNW+3quACPkgCx/L+uEAv1htQ0V83Z9Rj+Y= golang.org/x/sys v0.0.0-20180810173357-98c5dad5d1a0/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -387,14 +387,14 @@ golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= -golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= +golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= -golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= +golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= @@ -410,8 +410,8 @@ golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roY golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= -golang.org/x/tools v0.9.1 h1:8WMNJAz3zrtPmnYC7ISf5dEn3MT0gY7jBJfw27yrrLo= -golang.org/x/tools v0.9.1/go.mod h1:owI94Op576fPu3cIGQeHs3joujW/2Oc6MtlxbF5dfNc= +golang.org/x/tools v0.11.0 h1:EMCa6U9S2LtZXLAMoWiR/R8dAQFRqbAitmbJ2UKhoi8= +golang.org/x/tools v0.11.0/go.mod h1:anzJrxPjNtfgiYQYirP2CPGzGLxrH2u2QBhn6Bf3qY8= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= From 6c6c5416402e9046f386425e72c5c1f3adae9577 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 11 Jul 2023 12:26:36 -0700 Subject: [PATCH 02/23] Update to new quic-go API --- p2p/transport/quic/transport.go | 2 +- p2p/transport/quicreuse/connmgr.go | 63 +++++--- p2p/transport/quicreuse/connmgr_test.go | 102 +++++------- p2p/transport/quicreuse/listener.go | 18 +-- p2p/transport/quicreuse/reuse.go | 158 ++++++++++++------- p2p/transport/quicreuse/reuse_test.go | 50 +++--- p2p/transport/quicreuse/tracer.go | 33 ++-- p2p/transport/quicreuse/tracer_test.go | 7 +- p2p/transport/webtransport/transport_test.go | 2 +- 9 files changed, 240 insertions(+), 195 deletions(-) diff --git a/p2p/transport/quic/transport.go b/p2p/transport/quic/transport.go index f279aed755..72b6839adc 100644 --- a/p2p/transport/quic/transport.go +++ b/p2p/transport/quic/transport.go @@ -190,7 +190,7 @@ func (t *transport) holePunch(ctx context.Context, raddr ma.Multiaddr, p peer.ID if err != nil { return nil, err } - pconn, err := t.connManager.Dial(network, addr) + pconn, err := t.connManager.TransportForDial(network, addr) if err != nil { return nil, err } diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 0e2793eee7..07ee966396 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -13,8 +13,6 @@ import ( quiclogging "github.com/quic-go/quic-go/logging" ) -var quicDialContext = quic.DialContext // so we can mock it in tests - type ConnManager struct { reuseUDP4 *reuse reuseUDP6 *reuse @@ -27,6 +25,9 @@ type ConnManager struct { connsMu sync.Mutex conns map[string]connListenerEntry + + srk quic.StatelessResetKey + metricsTracer *metricsTracer } type connListenerEntry struct { @@ -39,6 +40,7 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* enableReuseport: true, enableDraft29: true, conns: make(map[string]connListenerEntry), + srk: statelessResetKey, } for _, o := range opts { if err := o(cm); err != nil { @@ -47,17 +49,23 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* } quicConf := quicConfig.Clone() - quicConf.StatelessResetKey = &statelessResetKey var tracers []quiclogging.Tracer - if qlogTracer != nil { - tracers = append(tracers, qlogTracer) - } + if cm.enableMetrics { - tracers = append(tracers, newMetricsTracer()) + cm.metricsTracer = newMetricsTracer() } if len(tracers) > 0 { - quicConf.Tracer = quiclogging.NewMultiplexedTracer(tracers...) + quicConf.Tracer = func(ctx context.Context, p quiclogging.Perspective, ci quic.ConnectionID) quiclogging.ConnectionTracer { + tracers := make([]quiclogging.ConnectionTracer, 0, 2) + if qlogTracerDir != "" { + tracers = append(tracers, qloggerForDir(qlogTracerDir, p, ci)) + } + if cm.metricsTracer != nil { + tracers = append(tracers, cm.metricsTracer.TracerForConnection(ctx, p, ci)) + } + return quiclogging.NewMultiplexedConnectionTracer(tracers...) + } } serverConfig := quicConf.Clone() if !cm.enableDraft29 { @@ -67,8 +75,8 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* cm.clientConfig = quicConf cm.serverConfig = serverConfig if cm.enableReuseport { - cm.reuseUDP4 = newReuse() - cm.reuseUDP6 = newReuse() + cm.reuseUDP4 = newReuse(&statelessResetKey, cm.metricsTracer) + cm.reuseUDP6 = newReuse(&statelessResetKey, cm.metricsTracer) } return cm, nil } @@ -106,7 +114,7 @@ func (c *ConnManager) ListenQUIC(addr ma.Multiaddr, tlsConf *tls.Config, allowWi key := laddr.String() entry, ok := c.conns[key] if !ok { - conn, err := c.listen(netw, laddr) + conn, err := c.transportForListen(netw, laddr) if err != nil { return nil, err } @@ -143,20 +151,20 @@ func (c *ConnManager) onListenerClosed(key string) { } } -func (c *ConnManager) listen(network string, laddr *net.UDPAddr) (pConn, error) { +func (c *ConnManager) transportForListen(network string, laddr *net.UDPAddr) (refCountedQuicTransport, error) { if c.enableReuseport { reuse, err := c.getReuse(network) if err != nil { return nil, err } - return reuse.Listen(network, laddr) + return reuse.TransportForListen(network, laddr) } - conn, err := net.ListenUDP(network, laddr) + conn, err := listenAndOptimize(network, laddr) if err != nil { return nil, err } - return &noreuseConn{conn}, nil + return &singleOwnerTransport{tr: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}}, nil } func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (quic.Connection, error) { @@ -164,7 +172,7 @@ func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf if err != nil { return nil, err } - netw, host, err := manet.DialArgs(raddr) + netw, _, err := manet.DialArgs(raddr) if err != nil { return nil, err } @@ -181,25 +189,25 @@ func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf return nil, errors.New("unknown QUIC version") } - pconn, err := c.Dial(netw, naddr) + tr, err := c.TransportForDial(netw, naddr) if err != nil { return nil, err } - conn, err := quicDialContext(ctx, pconn, naddr, host, tlsConf, quicConf) + conn, err := tr.Transport().Dial(ctx, naddr, tlsConf, quicConf) if err != nil { - pconn.DecreaseCount() + tr.DecreaseCount() return nil, err } return conn, nil } -func (c *ConnManager) Dial(network string, raddr *net.UDPAddr) (pConn, error) { +func (c *ConnManager) TransportForDial(network string, raddr *net.UDPAddr) (refCountedQuicTransport, error) { if c.enableReuseport { reuse, err := c.getReuse(network) if err != nil { return nil, err } - return reuse.Dial(network, raddr) + return reuse.TransportForDial(network, raddr) } var laddr *net.UDPAddr @@ -209,11 +217,11 @@ func (c *ConnManager) Dial(network string, raddr *net.UDPAddr) (pConn, error) { case "udp6": laddr = &net.UDPAddr{IP: net.IPv6zero, Port: 0} } - conn, err := net.ListenUDP(network, laddr) + conn, err := listenAndOptimize(network, laddr) if err != nil { return nil, err } - return &noreuseConn{conn}, nil + return &singleOwnerTransport{tr: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}}, nil } func (c *ConnManager) Protocols() []int { @@ -232,3 +240,12 @@ func (c *ConnManager) Close() error { } return c.reuseUDP4.Close() } + +// listenAndOptimize same as net.ListenUDP, but also calls quic.OptimizeConn +func listenAndOptimize(network string, laddr *net.UDPAddr) (net.PacketConn, error) { + conn, err := net.ListenUDP(network, laddr) + if err != nil { + return nil, err + } + return quic.OptimizeConn(conn) +} diff --git a/p2p/transport/quicreuse/connmgr_test.go b/p2p/transport/quicreuse/connmgr_test.go index 59aad639bc..ad2b4ec095 100644 --- a/p2p/transport/quicreuse/connmgr_test.go +++ b/p2p/transport/quicreuse/connmgr_test.go @@ -4,7 +4,6 @@ import ( "context" "crypto/rand" "crypto/tls" - "errors" "fmt" "net" "testing" @@ -16,6 +15,7 @@ import ( libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls" ma "github.com/multiformats/go-multiaddr" + manet "github.com/multiformats/go-multiaddr/net" "github.com/quic-go/quic-go" "github.com/stretchr/testify/require" ) @@ -92,66 +92,52 @@ func testListenOnSameProto(t *testing.T, enableReuseport bool) { // The conn passed to quic-go should be a conn that quic-go can be // type-asserted to a UDPConn. That way, it can use all kinds of optimizations. func TestConnectionPassedToQUICForListening(t *testing.T) { - origQuicListen := quicListen - t.Cleanup(func() { quicListen = origQuicListen }) - - var conn net.PacketConn - quicListen = func(c net.PacketConn, _ *tls.Config, _ *quic.Config) (quic.Listener, error) { - conn = c - return nil, errors.New("listen error") - } - cm, err := NewConnManager([32]byte{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() - _, err = cm.ListenQUIC(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1"), &tls.Config{NextProtos: []string{"proto"}}, nil) - require.EqualError(t, err, "listen error") - require.NotNil(t, conn) - defer conn.Close() - if _, ok := conn.(quic.OOBCapablePacketConn); !ok { - t.Fatal("connection passed to quic-go cannot be type asserted to a *net.UDPConn") - } -} - -type mockFailAcceptListener struct { - addr net.Addr -} - -// Accept implements quic.Listener -func (l *mockFailAcceptListener) Accept(context.Context) (quic.Connection, error) { - return nil, fmt.Errorf("Some error") -} + raddr := ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1") -// Addr implements quic.Listener -func (l *mockFailAcceptListener) Addr() net.Addr { - return l.addr -} + naddr, _, err := FromQuicMultiaddr(raddr) + require.NoError(t, err) + netw, _, err := manet.DialArgs(raddr) + require.NoError(t, err) -// Close implements quic.Listener -func (l *mockFailAcceptListener) Close() error { - return nil + _, err = cm.ListenQUIC(raddr, &tls.Config{NextProtos: []string{"proto"}}, nil) + require.NoError(t, err) + quicTr, err := cm.transportForListen(netw, naddr) + require.NoError(t, err) + defer quicTr.Transport().Close() + if _, ok := quicTr.Transport().Conn.(quic.OOBCapablePacketConn); !ok { + t.Fatal("connection passed to quic-go cannot be type asserted to a *net.UDPConn") + } } -var _ quic.Listener = &mockFailAcceptListener{} - func TestAcceptErrorGetCleanedUp(t *testing.T) { - origQuicListen := quicListen - t.Cleanup(func() { quicListen = origQuicListen }) + t.Skip("Not sure how to test this") - quicListen = func(c net.PacketConn, _ *tls.Config, _ *quic.Config) (quic.Listener, error) { - return &mockFailAcceptListener{ - addr: c.LocalAddr(), - }, nil - } + raddr := ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1") cm, err := NewConnManager([32]byte{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() - l, err := cm.ListenQUIC(ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1"), &tls.Config{NextProtos: []string{"proto"}}, nil) + naddr, _, err := FromQuicMultiaddr(raddr) + require.NoError(t, err) + netw, _, err := manet.DialArgs(raddr) + require.NoError(t, err) + + quicTr, err := cm.transportForListen(netw, naddr) + require.NoError(t, err) + + l, err := cm.ListenQUIC(raddr, &tls.Config{NextProtos: []string{"proto"}}, nil) require.NoError(t, err) defer l.Close() + go func() { + // Close the quic Transport to trigger an Accept error + quicTr.Transport().Close() + quicTr.Transport().Conn.Close() + }() _, err = l.Accept(context.Background()) require.ErrorIs(t, err, transport.ErrListenerClosed) } @@ -159,24 +145,22 @@ func TestAcceptErrorGetCleanedUp(t *testing.T) { // The connection passed to quic-go needs to be type-assertable to a net.UDPConn, // in order to enable features like batch processing and ECN. func TestConnectionPassedToQUICForDialing(t *testing.T) { - origQuicDialContext := quicDialContext - defer func() { quicDialContext = origQuicDialContext }() - - var conn net.PacketConn - quicDialContext = func(_ context.Context, c net.PacketConn, _ net.Addr, _ string, _ *tls.Config, _ *quic.Config) (quic.Connection, error) { - conn = c - return nil, errors.New("dial error") - } - cm, err := NewConnManager([32]byte{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() - _, err = cm.DialQUIC(context.Background(), ma.StringCast("/ip4/127.0.0.1/udp/1234/quic-v1"), &tls.Config{}, nil) - require.EqualError(t, err, "dial error") - require.NotNil(t, conn) - defer conn.Close() - if _, ok := conn.(quic.OOBCapablePacketConn); !ok { + raddr := ma.StringCast("/ip4/127.0.0.1/udp/1234/quic-v1") + + naddr, _, err := FromQuicMultiaddr(raddr) + require.NoError(t, err) + netw, _, err := manet.DialArgs(raddr) + require.NoError(t, err) + + quicTr, err := cm.TransportForDial(netw, naddr) + + require.NoError(t, err, "dial error") + defer quicTr.Transport().Conn.Close() + if _, ok := quicTr.Transport().Conn.(quic.OOBCapablePacketConn); !ok { t.Fatal("connection passed to quic-go cannot be type asserted to a *net.UDPConn") } } @@ -210,7 +194,7 @@ func connectWithProtocol(t *testing.T, addr net.Addr, alpn string) (peer.ID, err cconn, err := net.ListenUDP("udp4", nil) tlsConf.NextProtos = []string{alpn} require.NoError(t, err) - c, err := quic.Dial(cconn, addr, "localhost", tlsConf, nil) + c, err := quic.Dial(context.Background(), cconn, addr, tlsConf, nil) if err != nil { return "", err } diff --git a/p2p/transport/quicreuse/listener.go b/p2p/transport/quicreuse/listener.go index e7c0101718..abd2f6b741 100644 --- a/p2p/transport/quicreuse/listener.go +++ b/p2p/transport/quicreuse/listener.go @@ -15,8 +15,6 @@ import ( "github.com/quic-go/quic-go" ) -var quicListen = quic.Listen // so we can mock it in tests - type Listener interface { Accept(context.Context) (quic.Connection, error) Addr() net.Addr @@ -31,16 +29,16 @@ type protoConf struct { } type connListener struct { - l quic.Listener - conn pConn - running chan struct{} - addrs []ma.Multiaddr + l *quic.Listener + transport refCountedQuicTransport + running chan struct{} + addrs []ma.Multiaddr protocolsMu sync.Mutex protocols map[string]protoConf } -func newConnListener(c pConn, quicConfig *quic.Config, enableDraft29 bool) (*connListener, error) { +func newConnListener(c refCountedQuicTransport, quicConfig *quic.Config, enableDraft29 bool) (*connListener, error) { localMultiaddrs := make([]ma.Multiaddr, 0, 2) a, err := ToQuicMultiaddr(c.LocalAddr(), quic.Version1) if err != nil { @@ -57,7 +55,7 @@ func newConnListener(c pConn, quicConfig *quic.Config, enableDraft29 bool) (*con cl := &connListener{ protocols: map[string]protoConf{}, running: make(chan struct{}), - conn: c, + transport: c, addrs: localMultiaddrs, } tlsConf := &tls.Config{ @@ -78,7 +76,7 @@ func newConnListener(c pConn, quicConfig *quic.Config, enableDraft29 bool) (*con } quicConf := quicConfig.Clone() quicConf.AllowConnectionWindowIncrease = cl.allowWindowIncrease - ln, err := quicListen(c, tlsConf, quicConf) + ln, err := c.Transport().Listen(tlsConf, quicConf) if err != nil { return nil, err } @@ -132,7 +130,7 @@ func (l *connListener) Add(tlsConf *tls.Config, allowWindowIncrease func(conn qu func (l *connListener) Run() error { defer close(l.running) - defer l.conn.DecreaseCount() + defer l.transport.DecreaseCount() for { conn, err := l.l.Accept(context.Background()) if err != nil { diff --git a/p2p/transport/quicreuse/reuse.go b/p2p/transport/quicreuse/reuse.go index cc90038efe..2bb7734b6c 100644 --- a/p2p/transport/quicreuse/reuse.go +++ b/p2p/transport/quicreuse/reuse.go @@ -7,23 +7,45 @@ import ( "github.com/google/gopacket/routing" "github.com/libp2p/go-netroute" + "github.com/quic-go/quic-go" ) -type pConn interface { - net.PacketConn +type refCountedQuicTransport interface { + Transport() *quic.Transport + WriteTo([]byte, net.Addr) (int, error) + LocalAddr() net.Addr + + Close() error // count conn reference DecreaseCount() IncreaseCount() } -type noreuseConn struct { - *net.UDPConn +type singleOwnerTransport struct { + tr quic.Transport +} + +func (c *singleOwnerTransport) IncreaseCount() {} +func (c *singleOwnerTransport) DecreaseCount() { + c.tr.Close() +} + +func (c *singleOwnerTransport) Transport() *quic.Transport { + return &c.tr } -func (c *noreuseConn) IncreaseCount() {} -func (c *noreuseConn) DecreaseCount() { - c.UDPConn.Close() +func (c *singleOwnerTransport) LocalAddr() net.Addr { + return c.tr.Conn.LocalAddr() +} + +func (c *singleOwnerTransport) WriteTo(b []byte, addr net.Addr) (int, error) { + // Safe because we called quic.OptimizeConn ourselves. + return c.tr.Conn.WriteTo(b, addr) +} + +func (c *singleOwnerTransport) Close() error { + return c.tr.Close() } // Constant. Defined as variables to simplify testing. @@ -32,26 +54,39 @@ var ( maxUnusedDuration = 10 * time.Second ) -type reuseConn struct { - *net.UDPConn +type refcountedTransport struct { + tr quic.Transport mutex sync.Mutex refCount int unusedSince time.Time } -func newReuseConn(conn *net.UDPConn) *reuseConn { - return &reuseConn{UDPConn: conn} -} - -func (c *reuseConn) IncreaseCount() { +func (c *refcountedTransport) IncreaseCount() { c.mutex.Lock() c.refCount++ c.unusedSince = time.Time{} c.mutex.Unlock() } -func (c *reuseConn) DecreaseCount() { +func (c *refcountedTransport) Transport() *quic.Transport { + return &c.tr +} + +func (c *refcountedTransport) Close() error { + return c.tr.Close() +} + +func (c *refcountedTransport) WriteTo(b []byte, addr net.Addr) (int, error) { + // Safe because we called quic.OptimizeConn ourselves. + return c.tr.Conn.WriteTo(b, addr) +} + +func (c *refcountedTransport) LocalAddr() net.Addr { + return c.tr.Conn.LocalAddr() +} + +func (c *refcountedTransport) DecreaseCount() { c.mutex.Lock() c.refCount-- if c.refCount == 0 { @@ -60,7 +95,7 @@ func (c *reuseConn) DecreaseCount() { c.mutex.Unlock() } -func (c *reuseConn) ShouldGarbageCollect(now time.Time) bool { +func (c *refcountedTransport) ShouldGarbageCollect(now time.Time) bool { c.mutex.Lock() defer c.mutex.Unlock() return !c.unusedSince.IsZero() && c.unusedSince.Add(maxUnusedDuration).Before(now) @@ -73,22 +108,27 @@ type reuse struct { gcStopChan chan struct{} routes routing.Router - unicast map[string] /* IP.String() */ map[int] /* port */ *reuseConn - // globalListeners contains connections that are listening on 0.0.0.0 / :: - globalListeners map[int]*reuseConn - // globalDialers contains connections that we've dialed out from. These connections are listening on 0.0.0.0 / :: - // On Dial, connections are reused from this map if no connection is available in the globalListeners - // On Listen, connections are reused from this map if the requested port is 0, and then moved to globalListeners - globalDialers map[int]*reuseConn + unicast map[string] /* IP.String() */ map[int] /* port */ *refcountedTransport + // globalListeners contains transports that are listening on 0.0.0.0 / :: + globalListeners map[int]*refcountedTransport + // globalDialers contains transports that we've dialed out from. These transports are listening on 0.0.0.0 / :: + // On Dial, transports are reused from this map if no transport is available in the globalListeners + // On Listen, transport are reused from this map if the requested port is 0, and then moved to globalListeners + globalDialers map[int]*refcountedTransport + + statelessResetKey *quic.StatelessResetKey + metricsTracer *metricsTracer } -func newReuse() *reuse { +func newReuse(srk *quic.StatelessResetKey, mt *metricsTracer) *reuse { r := &reuse{ - unicast: make(map[string]map[int]*reuseConn), - globalListeners: make(map[int]*reuseConn), - globalDialers: make(map[int]*reuseConn), - closeChan: make(chan struct{}), - gcStopChan: make(chan struct{}), + unicast: make(map[string]map[int]*refcountedTransport), + globalListeners: make(map[int]*refcountedTransport), + globalDialers: make(map[int]*refcountedTransport), + closeChan: make(chan struct{}), + gcStopChan: make(chan struct{}), + statelessResetKey: srk, + metricsTracer: mt, } go r.gc() return r @@ -158,7 +198,7 @@ func (r *reuse) gc() { } } -func (r *reuse) Dial(network string, raddr *net.UDPAddr) (*reuseConn, error) { +func (r *reuse) TransportForDial(network string, raddr *net.UDPAddr) (*refcountedTransport, error) { var ip *net.IP // Only bother looking up the source address if we actually _have_ non 0.0.0.0 listeners. @@ -178,15 +218,15 @@ func (r *reuse) Dial(network string, raddr *net.UDPAddr) (*reuseConn, error) { r.mutex.Lock() defer r.mutex.Unlock() - conn, err := r.dialLocked(network, ip) + tr, err := r.transportForDialLocked(network, ip) if err != nil { return nil, err } - conn.IncreaseCount() - return conn, nil + tr.IncreaseCount() + return tr, nil } -func (r *reuse) dialLocked(network string, source *net.IP) (*reuseConn, error) { +func (r *reuse) transportForDialLocked(network string, source *net.IP) (*refcountedTransport, error) { if source != nil { // We already have at least one suitable connection... if conns, ok := r.unicast[source.String()]; ok { @@ -217,16 +257,20 @@ func (r *reuse) dialLocked(network string, source *net.IP) (*reuseConn, error) { case "udp6": addr = &net.UDPAddr{IP: net.IPv6zero, Port: 0} } - conn, err := net.ListenUDP(network, addr) + conn, err := listenAndOptimize(network, addr) if err != nil { return nil, err } - rconn := newReuseConn(conn) + rconn := &refcountedTransport{tr: quic.Transport{ + Conn: conn, + StatelessResetKey: r.statelessResetKey, + Tracer: r.metricsTracer, + }} r.globalDialers[conn.LocalAddr().(*net.UDPAddr).Port] = rconn return rconn, nil } -func (r *reuse) Listen(network string, laddr *net.UDPAddr) (*reuseConn, error) { +func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcountedTransport, error) { r.mutex.Lock() defer r.mutex.Unlock() @@ -236,50 +280,54 @@ func (r *reuse) Listen(network string, laddr *net.UDPAddr) (*reuseConn, error) { // If we are reusing a connection from globalDialers, we move the globalDialers entry to // globalListeners if laddr.IP.IsUnspecified() { - var rconn *reuseConn + var rTr *refcountedTransport var localAddr *net.UDPAddr if laddr.Port == 0 { // the requested port is 0, we can reuse any connection - for _, conn := range r.globalDialers { - rconn = conn - localAddr = rconn.UDPConn.LocalAddr().(*net.UDPAddr) + for _, tr := range r.globalDialers { + rTr = tr + localAddr = rTr.LocalAddr().(*net.UDPAddr) delete(r.globalDialers, localAddr.Port) break } } else if _, ok := r.globalDialers[laddr.Port]; ok { - rconn = r.globalDialers[laddr.Port] - localAddr = rconn.UDPConn.LocalAddr().(*net.UDPAddr) + rTr = r.globalDialers[laddr.Port] + localAddr = rTr.LocalAddr().(*net.UDPAddr) delete(r.globalDialers, localAddr.Port) } // found a match - if rconn != nil { - rconn.IncreaseCount() - r.globalListeners[localAddr.Port] = rconn - return rconn, nil + if rTr != nil { + rTr.IncreaseCount() + r.globalListeners[localAddr.Port] = rTr + return rTr, nil } } - conn, err := net.ListenUDP(network, laddr) + conn, err := listenAndOptimize(network, laddr) if err != nil { return nil, err } localAddr := conn.LocalAddr().(*net.UDPAddr) - rconn := newReuseConn(conn) + tr := &refcountedTransport{tr: quic.Transport{ + Conn: conn, + StatelessResetKey: r.statelessResetKey, + Tracer: r.metricsTracer, + }} - rconn.IncreaseCount() + tr.IncreaseCount() // Deal with listen on a global address if localAddr.IP.IsUnspecified() { // The kernel already checked that the laddr is not already listen // so we need not check here (when we create ListenUDP). - r.globalListeners[localAddr.Port] = rconn - return rconn, nil + r.globalListeners[localAddr.Port] = tr + return tr, nil } // Deal with listen on a unicast address if _, ok := r.unicast[localAddr.IP.String()]; !ok { - r.unicast[localAddr.IP.String()] = make(map[int]*reuseConn) + r.unicast[localAddr.IP.String()] = make(map[int]*refcountedTransport) // Assume the system's routes may have changed if we're adding a new listener. // Ignore the error, there's nothing we can do. r.routes, _ = netroute.New() @@ -287,8 +335,8 @@ func (r *reuse) Listen(network string, laddr *net.UDPAddr) (*reuseConn, error) { // The kernel already checked that the laddr is not already listen // so we need not check here (when we create ListenUDP). - r.unicast[localAddr.IP.String()][localAddr.Port] = rconn - return rconn, nil + r.unicast[localAddr.IP.String()][localAddr.Port] = tr + return tr, nil } func (r *reuse) Close() error { diff --git a/p2p/transport/quicreuse/reuse_test.go b/p2p/transport/quicreuse/reuse_test.go index 0cd62f0d51..5cd9fbf3fd 100644 --- a/p2p/transport/quicreuse/reuse_test.go +++ b/p2p/transport/quicreuse/reuse_test.go @@ -13,7 +13,7 @@ import ( "github.com/stretchr/testify/require" ) -func (c *reuseConn) GetCount() int { +func (c *refcountedTransport) GetCount() int { c.mutex.Lock() defer c.mutex.Unlock() return c.refCount @@ -61,36 +61,36 @@ func cleanup(t *testing.T, reuse *reuse) { } func TestReuseListenOnAllIPv4(t *testing.T) { - reuse := newReuse() + reuse := newReuse(nil, nil) require.Eventually(t, isGarbageCollectorRunning, 500*time.Millisecond, 50*time.Millisecond, "expected garbage collector to be running") cleanup(t, reuse) addr, err := net.ResolveUDPAddr("udp4", "0.0.0.0:0") require.NoError(t, err) - conn, err := reuse.Listen("udp4", addr) + conn, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) require.Equal(t, conn.GetCount(), 1) } func TestReuseListenOnAllIPv6(t *testing.T) { - reuse := newReuse() + reuse := newReuse(nil, nil) require.Eventually(t, isGarbageCollectorRunning, 500*time.Millisecond, 50*time.Millisecond, "expected garbage collector to be running") cleanup(t, reuse) addr, err := net.ResolveUDPAddr("udp6", "[::]:1234") require.NoError(t, err) - conn, err := reuse.Listen("udp6", addr) + conn, err := reuse.TransportForListen("udp6", addr) require.NoError(t, err) require.Equal(t, conn.GetCount(), 1) } func TestReuseCreateNewGlobalConnOnDial(t *testing.T) { - reuse := newReuse() + reuse := newReuse(nil, nil) cleanup(t, reuse) addr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234") require.NoError(t, err) - conn, err := reuse.Dial("udp4", addr) + conn, err := reuse.TransportForDial("udp4", addr) require.NoError(t, err) require.Equal(t, conn.GetCount(), 1) laddr := conn.LocalAddr().(*net.UDPAddr) @@ -99,63 +99,63 @@ func TestReuseCreateNewGlobalConnOnDial(t *testing.T) { } func TestReuseConnectionWhenDialing(t *testing.T) { - reuse := newReuse() + reuse := newReuse(nil, nil) cleanup(t, reuse) addr, err := net.ResolveUDPAddr("udp4", "0.0.0.0:0") require.NoError(t, err) - lconn, err := reuse.Listen("udp4", addr) + lconn, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) require.Equal(t, lconn.GetCount(), 1) // dial raddr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234") require.NoError(t, err) - conn, err := reuse.Dial("udp4", raddr) + conn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) require.Equal(t, conn.GetCount(), 2) } func TestReuseConnectionWhenListening(t *testing.T) { - reuse := newReuse() + reuse := newReuse(nil, nil) cleanup(t, reuse) raddr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234") require.NoError(t, err) - conn, err := reuse.Dial("udp4", raddr) + conn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - laddr := &net.UDPAddr{IP: net.IPv4zero, Port: conn.UDPConn.LocalAddr().(*net.UDPAddr).Port} - lconn, err := reuse.Listen("udp4", laddr) + laddr := &net.UDPAddr{IP: net.IPv4zero, Port: conn.Transport().Conn.LocalAddr().(*net.UDPAddr).Port} + lconn, err := reuse.TransportForListen("udp4", laddr) require.NoError(t, err) require.Equal(t, lconn.GetCount(), 2) require.Equal(t, conn.GetCount(), 2) } func TestReuseConnectionWhenDialBeforeListen(t *testing.T) { - reuse := newReuse() + reuse := newReuse(nil, nil) cleanup(t, reuse) // dial any address raddr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234") require.NoError(t, err) - rconn, err := reuse.Dial("udp4", raddr) + rconn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) // open a listener laddr := &net.UDPAddr{IP: net.IPv4zero, Port: 1234} - lconn, err := reuse.Listen("udp4", laddr) + lconn, err := reuse.TransportForListen("udp4", laddr) require.NoError(t, err) // new dials should go via the listener connection raddr, err = net.ResolveUDPAddr("udp4", "1.1.1.1:1235") require.NoError(t, err) - conn, err := reuse.Dial("udp4", raddr) + conn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) require.Equal(t, conn, lconn) require.Equal(t, conn.GetCount(), 2) // a listener on an unspecified port should reuse the dialer laddr2 := &net.UDPAddr{IP: net.IPv4zero, Port: 0} - lconn2, err := reuse.Listen("udp4", laddr2) + lconn2, err := reuse.TransportForListen("udp4", laddr2) require.NoError(t, err) require.Equal(t, lconn2, rconn) require.Equal(t, lconn2.GetCount(), 2) @@ -165,7 +165,7 @@ func TestReuseListenOnSpecificInterface(t *testing.T) { if platformHasRoutingTables() { t.Skip("this test only works on platforms that support routing tables") } - reuse := newReuse() + reuse := newReuse(nil, nil) cleanup(t, reuse) router, err := netroute.New() @@ -178,11 +178,11 @@ func TestReuseListenOnSpecificInterface(t *testing.T) { // listen addr, err := net.ResolveUDPAddr("udp4", ip.String()+":0") require.NoError(t, err) - lconn, err := reuse.Listen("udp4", addr) + lconn, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) require.Equal(t, lconn.GetCount(), 1) // dial - conn, err := reuse.Dial("udp4", raddr) + conn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) require.Equal(t, conn.GetCount(), 1) } @@ -202,7 +202,7 @@ func TestReuseGarbageCollect(t *testing.T) { maxUnusedDuration = 10 * maxUnusedDuration } - reuse := newReuse() + reuse := newReuse(nil, nil) cleanup(t, reuse) numGlobals := func() int { @@ -213,13 +213,13 @@ func TestReuseGarbageCollect(t *testing.T) { raddr, err := net.ResolveUDPAddr("udp4", "1.2.3.4:1234") require.NoError(t, err) - dconn, err := reuse.Dial("udp4", raddr) + dconn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) require.Equal(t, dconn.GetCount(), 1) addr, err := net.ResolveUDPAddr("udp4", "0.0.0.0:1234") require.NoError(t, err) - lconn, err := reuse.Listen("udp4", addr) + lconn, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) require.Equal(t, lconn.GetCount(), 1) diff --git a/p2p/transport/quicreuse/tracer.go b/p2p/transport/quicreuse/tracer.go index 46a683cbce..1386a5c3d1 100644 --- a/p2p/transport/quicreuse/tracer.go +++ b/p2p/transport/quicreuse/tracer.go @@ -9,31 +9,28 @@ import ( golog "github.com/ipfs/go-log/v2" "github.com/klauspost/compress/zstd" + "github.com/quic-go/quic-go" "github.com/quic-go/quic-go/logging" "github.com/quic-go/quic-go/qlog" ) var log = golog.Logger("quic-utils") -// QLOGTracer holds a qlog tracer, if qlogging is enabled (enabled using the QLOGDIR environment variable). -// Otherwise it is nil. -var qlogTracer logging.Tracer +// QLOGTracer holds a qlog tracer dir, if qlogging is enabled (enabled using the QLOGDIR environment variable). +// Otherwise it is an empty string. +var qlogTracerDir string func init() { - if qlogDir := os.Getenv("QLOGDIR"); len(qlogDir) > 0 { - qlogTracer = initQlogger(qlogDir) - } + qlogTracerDir = os.Getenv("QLOGDIR") } -func initQlogger(qlogDir string) logging.Tracer { - return qlog.NewTracer(func(role logging.Perspective, connID []byte) io.WriteCloser { - // create the QLOGDIR, if it doesn't exist - if err := os.MkdirAll(qlogDir, 0777); err != nil { - log.Errorf("creating the QLOGDIR failed: %s", err) - return nil - } - return newQlogger(qlogDir, role, connID) - }) +func qloggerForDir(qlogDir string, p logging.Perspective, ci quic.ConnectionID) logging.ConnectionTracer { + // create the QLOGDIR, if it doesn't exist + if err := os.MkdirAll(qlogDir, 0777); err != nil { + log.Errorf("creating the QLOGDIR failed: %s", err) + return nil + } + return qlog.NewConnectionTracer(newQlogger(qlogDir, p, ci), p, ci) } // The qlogger logs qlog events to a temporary file: ..qlog.swp. @@ -46,14 +43,14 @@ type qlogger struct { *bufio.Writer // buffering the f } -func newQlogger(qlogDir string, role logging.Perspective, connID []byte) io.WriteCloser { +func newQlogger(qlogDir string, role logging.Perspective, connID quic.ConnectionID) io.WriteCloser { t := time.Now().UTC().Format("2006-01-02T15-04-05.999999999UTC") r := "server" if role == logging.PerspectiveClient { r = "client" } - finalFilename := fmt.Sprintf("%s%clog_%s_%s_%x.qlog.zst", qlogDir, os.PathSeparator, t, r, connID) - filename := fmt.Sprintf("%s%c.log_%s_%s_%x.qlog.swp", qlogDir, os.PathSeparator, t, r, connID) + finalFilename := fmt.Sprintf("%s%clog_%s_%s_%s.qlog.zst", qlogDir, os.PathSeparator, t, r, connID) + filename := fmt.Sprintf("%s%c.log_%s_%s_%s.qlog.swp", qlogDir, os.PathSeparator, t, r, connID) f, err := os.Create(filename) if err != nil { log.Errorf("unable to create qlog file %s: %s", filename, err) diff --git a/p2p/transport/quicreuse/tracer_test.go b/p2p/transport/quicreuse/tracer_test.go index c5b5a9833b..5d1d74feef 100644 --- a/p2p/transport/quicreuse/tracer_test.go +++ b/p2p/transport/quicreuse/tracer_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/klauspost/compress/zstd" + "github.com/quic-go/quic-go" "github.com/quic-go/quic-go/logging" "github.com/stretchr/testify/require" ) @@ -30,7 +31,7 @@ func getFile(t *testing.T, dir string) os.FileInfo { func TestSaveQlog(t *testing.T) { qlogDir := createLogDir(t) - logger := newQlogger(qlogDir, logging.PerspectiveServer, []byte{0xde, 0xad, 0xbe, 0xef}) + logger := newQlogger(qlogDir, logging.PerspectiveServer, quic.ConnectionIDFromBytes([]byte{0xde, 0xad, 0xbe, 0xef})) file := getFile(t, qlogDir) require.Equal(t, string(file.Name()[0]), ".") require.Truef(t, strings.HasSuffix(file.Name(), ".qlog.swp"), "expected %s to have the .qlog.swp file ending", file.Name()) @@ -45,7 +46,7 @@ func TestSaveQlog(t *testing.T) { func TestQlogBuffering(t *testing.T) { qlogDir := createLogDir(t) - logger := newQlogger(qlogDir, logging.PerspectiveServer, []byte("connid")) + logger := newQlogger(qlogDir, logging.PerspectiveServer, quic.ConnectionIDFromBytes([]byte("connid"))) initialSize := getFile(t, qlogDir).Size() // Do a small write. // Since the writter is buffered, this should not be written to disk yet. @@ -60,7 +61,7 @@ func TestQlogBuffering(t *testing.T) { func TestQlogCompression(t *testing.T) { qlogDir := createLogDir(t) - logger := newQlogger(qlogDir, logging.PerspectiveServer, []byte("connid")) + logger := newQlogger(qlogDir, logging.PerspectiveServer, quic.ConnectionIDFromBytes([]byte("connid"))) logger.Write([]byte("foobar")) require.NoError(t, logger.Close()) compressed, err := os.ReadFile(qlogDir + "/" + getFile(t, qlogDir).Name()) diff --git a/p2p/transport/webtransport/transport_test.go b/p2p/transport/webtransport/transport_test.go index 4eac7fe2c6..aa669add07 100644 --- a/p2p/transport/webtransport/transport_test.go +++ b/p2p/transport/webtransport/transport_test.go @@ -669,7 +669,7 @@ func serverSendsBackValidCert(t *testing.T, timeSinceUnixEpoch time.Duration, ke require.NoError(t, err) defer l.Close() - conn, err := quic.DialAddr(l.Addr().String(), &tls.Config{ + conn, err := quic.DialAddr(context.Background(), l.Addr().String(), &tls.Config{ NextProtos: []string{http3.NextProtoH3}, InsecureSkipVerify: true, VerifyPeerCertificate: func(rawCerts [][]byte, verifiedChains [][]*x509.Certificate) error { From cda4ebc68ba773d1ec02d5e4563991443c1611de Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 11 Jul 2023 20:38:52 -0700 Subject: [PATCH 03/23] More renaming --- p2p/transport/quic/transport.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/transport/quic/transport.go b/p2p/transport/quic/transport.go index 72b6839adc..aef3f4c9de 100644 --- a/p2p/transport/quic/transport.go +++ b/p2p/transport/quic/transport.go @@ -190,11 +190,11 @@ func (t *transport) holePunch(ctx context.Context, raddr ma.Multiaddr, p peer.ID if err != nil { return nil, err } - pconn, err := t.connManager.TransportForDial(network, addr) + tr, err := t.connManager.TransportForDial(network, addr) if err != nil { return nil, err } - defer pconn.DecreaseCount() + defer tr.DecreaseCount() ctx, cancel := context.WithTimeout(ctx, HolePunchTimeout) defer cancel() @@ -227,7 +227,7 @@ loop: punchErr = err break } - if _, err := pconn.WriteTo(payload, addr); err != nil { + if _, err := tr.WriteTo(payload, addr); err != nil { punchErr = err break } From 511bb13dbe1864461d80d72f9c8f7826b8d156d4 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 11 Jul 2023 20:39:00 -0700 Subject: [PATCH 04/23] Add test back in --- p2p/transport/quicreuse/connmgr_test.go | 40 ++++++++++++++----------- 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/p2p/transport/quicreuse/connmgr_test.go b/p2p/transport/quicreuse/connmgr_test.go index ad2b4ec095..81bb61f998 100644 --- a/p2p/transport/quicreuse/connmgr_test.go +++ b/p2p/transport/quicreuse/connmgr_test.go @@ -6,12 +6,12 @@ import ( "crypto/tls" "fmt" "net" + "runtime" "testing" "time" "github.com/libp2p/go-libp2p/core/crypto" "github.com/libp2p/go-libp2p/core/peer" - "github.com/libp2p/go-libp2p/core/transport" libp2ptls "github.com/libp2p/go-libp2p/p2p/security/tls" ma "github.com/multiformats/go-multiaddr" @@ -114,32 +114,36 @@ func TestConnectionPassedToQUICForListening(t *testing.T) { } func TestAcceptErrorGetCleanedUp(t *testing.T) { - t.Skip("Not sure how to test this") - raddr := ma.StringCast("/ip4/127.0.0.1/udp/0/quic-v1") cm, err := NewConnManager([32]byte{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() - naddr, _, err := FromQuicMultiaddr(raddr) - require.NoError(t, err) - netw, _, err := manet.DialArgs(raddr) - require.NoError(t, err) - - quicTr, err := cm.transportForListen(netw, naddr) - require.NoError(t, err) + originalNumberOfGoroutines := runtime.NumGoroutine() + t.Log("num goroutines:", originalNumberOfGoroutines) + // This spawns a background goroutine for the listener l, err := cm.ListenQUIC(raddr, &tls.Config{NextProtos: []string{"proto"}}, nil) require.NoError(t, err) - defer l.Close() - go func() { - // Close the quic Transport to trigger an Accept error - quicTr.Transport().Close() - quicTr.Transport().Conn.Close() - }() - _, err = l.Accept(context.Background()) - require.ErrorIs(t, err, transport.ErrListenerClosed) + + // We spawned a goroutine for the listener + require.Greater(t, runtime.NumGoroutine(), originalNumberOfGoroutines) + l.Close() + + // Now make sure we have less goroutines than before + // Manually doing the same as require.Eventually, except avoiding adding a goroutine + goRoutinesCleanedUp := false + for i := 0; i < 50; i++ { + t.Log("num goroutines:", runtime.NumGoroutine()) + if runtime.NumGoroutine() <= originalNumberOfGoroutines { + goRoutinesCleanedUp = true + break + } + time.Sleep(100 * time.Millisecond) + } + + require.True(t, goRoutinesCleanedUp, "goroutines were not cleaned up") } // The connection passed to quic-go needs to be type-assertable to a net.UDPConn, From 291f1501bc62b9d889312086dd9d69e95caf67b4 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 11 Jul 2023 20:43:18 -0700 Subject: [PATCH 05/23] Workaround quic-go#3947 --- p2p/transport/quicreuse/connmgr.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 07ee966396..79e50594ed 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -247,5 +247,8 @@ func listenAndOptimize(network string, laddr *net.UDPAddr) (net.PacketConn, erro if err != nil { return nil, err } - return quic.OptimizeConn(conn) + // We aren't actually calling optimizeConn here because of https://github.com/quic-go/quic-go/issues/3947 + // Either enable this or remove this function depending on how that issue is resolved. + // return quic.OptimizeConn(conn) + return conn, err } From 843c17c8f7cbc57107a3dd14089bf93335f1235a Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 11 Jul 2023 20:58:07 -0700 Subject: [PATCH 06/23] Fix transitive dep --- go.mod | 2 +- go.sum | 4 ++-- test-plans/go.mod | 2 +- test-plans/go.sum | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 5e7446d0a2..3a682b914c 100644 --- a/go.mod +++ b/go.mod @@ -103,7 +103,7 @@ require ( github.com/prometheus/procfs v0.8.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.3.0 // indirect + github.com/quic-go/qtls-go1-20 v0.2.2 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/go.sum b/go.sum index 5ea9da05e4..d77f681e24 100644 --- a/go.sum +++ b/go.sum @@ -434,8 +434,8 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.3.0 h1:NrCXmDl8BddZwO67vlvEpBTwT89bJfKYygxv4HQvuDk= -github.com/quic-go/qtls-go1-20 v0.3.0/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= +github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= +github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= github.com/quic-go/quic-go v0.36.1 h1:WsG73nVtnDy1TiACxFxhQ3TqaW+DipmqzLEtNlAwZyY= github.com/quic-go/quic-go v0.36.1/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= diff --git a/test-plans/go.mod b/test-plans/go.mod index 2683b9ab87..9d16c6db74 100644 --- a/test-plans/go.mod +++ b/test-plans/go.mod @@ -74,7 +74,7 @@ require ( github.com/prometheus/procfs v0.10.1 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.3.0 // indirect + github.com/quic-go/qtls-go1-20 v0.2.2 // indirect github.com/quic-go/quic-go v0.36.1 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect diff --git a/test-plans/go.sum b/test-plans/go.sum index 7ff60e30e1..7dfc698df2 100644 --- a/test-plans/go.sum +++ b/test-plans/go.sum @@ -240,8 +240,8 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.3.0 h1:NrCXmDl8BddZwO67vlvEpBTwT89bJfKYygxv4HQvuDk= -github.com/quic-go/qtls-go1-20 v0.3.0/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= +github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= +github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= github.com/quic-go/quic-go v0.36.1 h1:WsG73nVtnDy1TiACxFxhQ3TqaW+DipmqzLEtNlAwZyY= github.com/quic-go/quic-go v0.36.1/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= From 3c2e7c4854c4c49374b7860a8ce1e1b707e7518b Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Tue, 11 Jul 2023 21:06:51 -0700 Subject: [PATCH 07/23] Use own pointer to packetConn --- p2p/transport/quicreuse/connmgr.go | 4 ++-- p2p/transport/quicreuse/reuse.go | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 79e50594ed..1a3f23a431 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -164,7 +164,7 @@ func (c *ConnManager) transportForListen(network string, laddr *net.UDPAddr) (re if err != nil { return nil, err } - return &singleOwnerTransport{tr: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}}, nil + return &singleOwnerTransport{tr: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}, nil } func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (quic.Connection, error) { @@ -221,7 +221,7 @@ func (c *ConnManager) TransportForDial(network string, raddr *net.UDPAddr) (refC if err != nil { return nil, err } - return &singleOwnerTransport{tr: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}}, nil + return &singleOwnerTransport{tr: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}, nil } func (c *ConnManager) Protocols() []int { diff --git a/p2p/transport/quicreuse/reuse.go b/p2p/transport/quicreuse/reuse.go index 2bb7734b6c..47936216bc 100644 --- a/p2p/transport/quicreuse/reuse.go +++ b/p2p/transport/quicreuse/reuse.go @@ -24,6 +24,9 @@ type refCountedQuicTransport interface { type singleOwnerTransport struct { tr quic.Transport + + // Used to write packets directly around QUIC. + packetConn net.PacketConn } func (c *singleOwnerTransport) IncreaseCount() {} @@ -41,7 +44,7 @@ func (c *singleOwnerTransport) LocalAddr() net.Addr { func (c *singleOwnerTransport) WriteTo(b []byte, addr net.Addr) (int, error) { // Safe because we called quic.OptimizeConn ourselves. - return c.tr.Conn.WriteTo(b, addr) + return c.packetConn.WriteTo(b, addr) } func (c *singleOwnerTransport) Close() error { @@ -57,6 +60,9 @@ var ( type refcountedTransport struct { tr quic.Transport + // Used to write packets directly around QUIC. + packetConn net.PacketConn + mutex sync.Mutex refCount int unusedSince time.Time @@ -79,7 +85,7 @@ func (c *refcountedTransport) Close() error { func (c *refcountedTransport) WriteTo(b []byte, addr net.Addr) (int, error) { // Safe because we called quic.OptimizeConn ourselves. - return c.tr.Conn.WriteTo(b, addr) + return c.packetConn.WriteTo(b, addr) } func (c *refcountedTransport) LocalAddr() net.Addr { @@ -265,7 +271,7 @@ func (r *reuse) transportForDialLocked(network string, source *net.IP) (*refcoun Conn: conn, StatelessResetKey: r.statelessResetKey, Tracer: r.metricsTracer, - }} + }, packetConn: conn} r.globalDialers[conn.LocalAddr().(*net.UDPAddr).Port] = rconn return rconn, nil } @@ -313,7 +319,7 @@ func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcoun Conn: conn, StatelessResetKey: r.statelessResetKey, Tracer: r.metricsTracer, - }} + }, packetConn: conn} tr.IncreaseCount() From 688fbc97bcff2537cd40a403a5934488a225bd91 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 11:22:17 -0700 Subject: [PATCH 08/23] Update to quic-go v0.36.2 --- go.mod | 6 +++--- go.sum | 6 ++++++ test-plans/go.mod | 6 +++--- test-plans/go.sum | 12 ++++++------ 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 3a682b914c..5b91237fed 100644 --- a/go.mod +++ b/go.mod @@ -47,14 +47,14 @@ require ( github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 github.com/prometheus/client_golang v1.14.0 github.com/prometheus/client_model v0.4.0 - github.com/quic-go/quic-go v0.36.1 + github.com/quic-go/quic-go v0.36.2 github.com/quic-go/webtransport-go v0.5.3 github.com/raulk/go-watchdog v1.3.0 github.com/stretchr/testify v1.8.2 go.uber.org/fx v1.19.2 go.uber.org/goleak v1.1.12 golang.org/x/crypto v0.11.0 - golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df + golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb golang.org/x/sync v0.3.0 golang.org/x/sys v0.10.0 golang.org/x/tools v0.11.0 @@ -103,7 +103,7 @@ require ( github.com/prometheus/procfs v0.8.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect + github.com/quic-go/qtls-go1-20 v0.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/go.sum b/go.sum index d77f681e24..fb3e4988da 100644 --- a/go.sum +++ b/go.sum @@ -436,8 +436,12 @@ github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc8 github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= +github.com/quic-go/qtls-go1-20 v0.3.0 h1:NrCXmDl8BddZwO67vlvEpBTwT89bJfKYygxv4HQvuDk= +github.com/quic-go/qtls-go1-20 v0.3.0/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= github.com/quic-go/quic-go v0.36.1 h1:WsG73nVtnDy1TiACxFxhQ3TqaW+DipmqzLEtNlAwZyY= github.com/quic-go/quic-go v0.36.1/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= +github.com/quic-go/quic-go v0.36.2 h1:ZX/UNQ4gvpCv2RmwdbA6lrRjF6EBm5yZ7TMoT4NQVrA= +github.com/quic-go/quic-go v0.36.2/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= @@ -565,6 +569,8 @@ golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EH golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb h1:xIApU0ow1zwMa2uL1VDNeQlNVFTWMQxZUZCMDy0Q4Us= +golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= diff --git a/test-plans/go.mod b/test-plans/go.mod index 9d16c6db74..155404aa66 100644 --- a/test-plans/go.mod +++ b/test-plans/go.mod @@ -74,8 +74,8 @@ require ( github.com/prometheus/procfs v0.10.1 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.2.2 // indirect - github.com/quic-go/quic-go v0.36.1 // indirect + github.com/quic-go/qtls-go1-20 v0.3.0 // indirect + github.com/quic-go/quic-go v0.36.2 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect @@ -85,7 +85,7 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.uber.org/zap v1.24.0 // indirect golang.org/x/crypto v0.11.0 // indirect - golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df // indirect + golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.12.0 // indirect golang.org/x/sync v0.3.0 // indirect diff --git a/test-plans/go.sum b/test-plans/go.sum index 7dfc698df2..0344da5171 100644 --- a/test-plans/go.sum +++ b/test-plans/go.sum @@ -240,10 +240,10 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= -github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/quic-go v0.36.1 h1:WsG73nVtnDy1TiACxFxhQ3TqaW+DipmqzLEtNlAwZyY= -github.com/quic-go/quic-go v0.36.1/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= +github.com/quic-go/qtls-go1-20 v0.3.0 h1:NrCXmDl8BddZwO67vlvEpBTwT89bJfKYygxv4HQvuDk= +github.com/quic-go/qtls-go1-20 v0.3.0/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= +github.com/quic-go/quic-go v0.36.2 h1:ZX/UNQ4gvpCv2RmwdbA6lrRjF6EBm5yZ7TMoT4NQVrA= +github.com/quic-go/quic-go v0.36.2/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= github.com/quic-go/webtransport-go v0.5.3/go.mod h1:OhmmgJIzTTqXK5xvtuX0oBpLV2GkLWNDA+UeTGJXErU= github.com/raulk/go-watchdog v1.3.0 h1:oUmdlHxdkXRJlwfG0O9omj8ukerm8MEQavSiDTEtBsk= @@ -323,8 +323,8 @@ golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2/go.mod h1:T9bdIzuCu7OtxOm golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA= golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= -golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= -golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= +golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb h1:xIApU0ow1zwMa2uL1VDNeQlNVFTWMQxZUZCMDy0Q4Us= +golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= From 6f1d91c0174cc3a519c72aa5b220ff7cefecf555 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 11:22:34 -0700 Subject: [PATCH 09/23] Remove workaround --- p2p/transport/quicreuse/connmgr.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 1a3f23a431..6ce76b4b7e 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -247,8 +247,5 @@ func listenAndOptimize(network string, laddr *net.UDPAddr) (net.PacketConn, erro if err != nil { return nil, err } - // We aren't actually calling optimizeConn here because of https://github.com/quic-go/quic-go/issues/3947 - // Either enable this or remove this function depending on how that issue is resolved. - // return quic.OptimizeConn(conn) - return conn, err + return quic.OptimizeConn(conn) } From 4dc8399d78f8150212fe5bc5d72b7b59f32c3d5a Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 11:39:36 -0700 Subject: [PATCH 10/23] Embed quic.Transport --- p2p/transport/quicreuse/connmgr.go | 15 ++++++-- p2p/transport/quicreuse/connmgr_test.go | 8 ++-- p2p/transport/quicreuse/listener.go | 2 +- p2p/transport/quicreuse/reuse.go | 50 +++++++++++-------------- p2p/transport/quicreuse/reuse_test.go | 6 +-- 5 files changed, 41 insertions(+), 40 deletions(-) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 6ce76b4b7e..73f9b56a16 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -164,7 +164,11 @@ func (c *ConnManager) transportForListen(network string, laddr *net.UDPAddr) (re if err != nil { return nil, err } - return &singleOwnerTransport{tr: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}, nil + tr := &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn} + if c.metricsTracer != nil { + tr.Transport.Tracer = c.metricsTracer + } + return tr, nil } func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool) (quic.Connection, error) { @@ -193,7 +197,7 @@ func (c *ConnManager) DialQUIC(ctx context.Context, raddr ma.Multiaddr, tlsConf if err != nil { return nil, err } - conn, err := tr.Transport().Dial(ctx, naddr, tlsConf, quicConf) + conn, err := tr.Dial(ctx, naddr, tlsConf, quicConf) if err != nil { tr.DecreaseCount() return nil, err @@ -221,7 +225,12 @@ func (c *ConnManager) TransportForDial(network string, raddr *net.UDPAddr) (refC if err != nil { return nil, err } - return &singleOwnerTransport{tr: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn}, nil + tr := &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn} + if c.metricsTracer != nil { + tr.Transport.Tracer = c.metricsTracer + } + + return tr, nil } func (c *ConnManager) Protocols() []int { diff --git a/p2p/transport/quicreuse/connmgr_test.go b/p2p/transport/quicreuse/connmgr_test.go index 81bb61f998..7c5aa5f16b 100644 --- a/p2p/transport/quicreuse/connmgr_test.go +++ b/p2p/transport/quicreuse/connmgr_test.go @@ -107,8 +107,8 @@ func TestConnectionPassedToQUICForListening(t *testing.T) { require.NoError(t, err) quicTr, err := cm.transportForListen(netw, naddr) require.NoError(t, err) - defer quicTr.Transport().Close() - if _, ok := quicTr.Transport().Conn.(quic.OOBCapablePacketConn); !ok { + defer quicTr.Close() + if _, ok := quicTr.(*singleOwnerTransport).Transport.Conn.(quic.OOBCapablePacketConn); !ok { t.Fatal("connection passed to quic-go cannot be type asserted to a *net.UDPConn") } } @@ -163,8 +163,8 @@ func TestConnectionPassedToQUICForDialing(t *testing.T) { quicTr, err := cm.TransportForDial(netw, naddr) require.NoError(t, err, "dial error") - defer quicTr.Transport().Conn.Close() - if _, ok := quicTr.Transport().Conn.(quic.OOBCapablePacketConn); !ok { + defer quicTr.Close() + if _, ok := quicTr.(*singleOwnerTransport).Transport.Conn.(quic.OOBCapablePacketConn); !ok { t.Fatal("connection passed to quic-go cannot be type asserted to a *net.UDPConn") } } diff --git a/p2p/transport/quicreuse/listener.go b/p2p/transport/quicreuse/listener.go index abd2f6b741..42ac6217a9 100644 --- a/p2p/transport/quicreuse/listener.go +++ b/p2p/transport/quicreuse/listener.go @@ -76,7 +76,7 @@ func newConnListener(c refCountedQuicTransport, quicConfig *quic.Config, enableD } quicConf := quicConfig.Clone() quicConf.AllowConnectionWindowIncrease = cl.allowWindowIncrease - ln, err := c.Transport().Listen(tlsConf, quicConf) + ln, err := c.Listen(tlsConf, quicConf) if err != nil { return nil, err } diff --git a/p2p/transport/quicreuse/reuse.go b/p2p/transport/quicreuse/reuse.go index 47936216bc..da3cecb0bb 100644 --- a/p2p/transport/quicreuse/reuse.go +++ b/p2p/transport/quicreuse/reuse.go @@ -1,6 +1,8 @@ package quicreuse import ( + "context" + "crypto/tls" "net" "sync" "time" @@ -11,7 +13,6 @@ import ( ) type refCountedQuicTransport interface { - Transport() *quic.Transport WriteTo([]byte, net.Addr) (int, error) LocalAddr() net.Addr @@ -20,10 +21,13 @@ type refCountedQuicTransport interface { // count conn reference DecreaseCount() IncreaseCount() + + Dial(ctx context.Context, addr net.Addr, tlsConf *tls.Config, conf *quic.Config) (quic.Connection, error) + Listen(tlsConf *tls.Config, conf *quic.Config) (*quic.Listener, error) } type singleOwnerTransport struct { - tr quic.Transport + quic.Transport // Used to write packets directly around QUIC. packetConn net.PacketConn @@ -31,15 +35,11 @@ type singleOwnerTransport struct { func (c *singleOwnerTransport) IncreaseCount() {} func (c *singleOwnerTransport) DecreaseCount() { - c.tr.Close() -} - -func (c *singleOwnerTransport) Transport() *quic.Transport { - return &c.tr + c.Transport.Close() } func (c *singleOwnerTransport) LocalAddr() net.Addr { - return c.tr.Conn.LocalAddr() + return c.Transport.Conn.LocalAddr() } func (c *singleOwnerTransport) WriteTo(b []byte, addr net.Addr) (int, error) { @@ -47,10 +47,6 @@ func (c *singleOwnerTransport) WriteTo(b []byte, addr net.Addr) (int, error) { return c.packetConn.WriteTo(b, addr) } -func (c *singleOwnerTransport) Close() error { - return c.tr.Close() -} - // Constant. Defined as variables to simplify testing. var ( garbageCollectInterval = 30 * time.Second @@ -58,7 +54,7 @@ var ( ) type refcountedTransport struct { - tr quic.Transport + quic.Transport // Used to write packets directly around QUIC. packetConn net.PacketConn @@ -75,21 +71,13 @@ func (c *refcountedTransport) IncreaseCount() { c.mutex.Unlock() } -func (c *refcountedTransport) Transport() *quic.Transport { - return &c.tr -} - -func (c *refcountedTransport) Close() error { - return c.tr.Close() -} - func (c *refcountedTransport) WriteTo(b []byte, addr net.Addr) (int, error) { // Safe because we called quic.OptimizeConn ourselves. return c.packetConn.WriteTo(b, addr) } func (c *refcountedTransport) LocalAddr() net.Addr { - return c.tr.Conn.LocalAddr() + return c.Transport.Conn.LocalAddr() } func (c *refcountedTransport) DecreaseCount() { @@ -119,7 +107,7 @@ type reuse struct { globalListeners map[int]*refcountedTransport // globalDialers contains transports that we've dialed out from. These transports are listening on 0.0.0.0 / :: // On Dial, transports are reused from this map if no transport is available in the globalListeners - // On Listen, transport are reused from this map if the requested port is 0, and then moved to globalListeners + // On Listen, transports are reused from this map if the requested port is 0, and then moved to globalListeners globalDialers map[int]*refcountedTransport statelessResetKey *quic.StatelessResetKey @@ -267,13 +255,15 @@ func (r *reuse) transportForDialLocked(network string, source *net.IP) (*refcoun if err != nil { return nil, err } - rconn := &refcountedTransport{tr: quic.Transport{ + tr := &refcountedTransport{Transport: quic.Transport{ Conn: conn, StatelessResetKey: r.statelessResetKey, - Tracer: r.metricsTracer, }, packetConn: conn} - r.globalDialers[conn.LocalAddr().(*net.UDPAddr).Port] = rconn - return rconn, nil + if r.metricsTracer != nil { + tr.Transport.Tracer = r.metricsTracer + } + r.globalDialers[conn.LocalAddr().(*net.UDPAddr).Port] = tr + return tr, nil } func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcountedTransport, error) { @@ -315,11 +305,13 @@ func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcoun return nil, err } localAddr := conn.LocalAddr().(*net.UDPAddr) - tr := &refcountedTransport{tr: quic.Transport{ + tr := &refcountedTransport{Transport: quic.Transport{ Conn: conn, StatelessResetKey: r.statelessResetKey, - Tracer: r.metricsTracer, }, packetConn: conn} + if r.metricsTracer != nil { + tr.Transport.Tracer = r.metricsTracer + } tr.IncreaseCount() diff --git a/p2p/transport/quicreuse/reuse_test.go b/p2p/transport/quicreuse/reuse_test.go index 5cd9fbf3fd..0b36a4c337 100644 --- a/p2p/transport/quicreuse/reuse_test.go +++ b/p2p/transport/quicreuse/reuse_test.go @@ -121,13 +121,13 @@ func TestReuseConnectionWhenListening(t *testing.T) { raddr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234") require.NoError(t, err) - conn, err := reuse.TransportForDial("udp4", raddr) + tr, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - laddr := &net.UDPAddr{IP: net.IPv4zero, Port: conn.Transport().Conn.LocalAddr().(*net.UDPAddr).Port} + laddr := &net.UDPAddr{IP: net.IPv4zero, Port: tr.LocalAddr().(*net.UDPAddr).Port} lconn, err := reuse.TransportForListen("udp4", laddr) require.NoError(t, err) require.Equal(t, lconn.GetCount(), 2) - require.Equal(t, conn.GetCount(), 2) + require.Equal(t, tr.GetCount(), 2) } func TestReuseConnectionWhenDialBeforeListen(t *testing.T) { From 1fa604a7d062adfec3ac84462b5851cfba464072 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 11:40:26 -0700 Subject: [PATCH 11/23] Downgrade qtls-go1-20 --- go.mod | 2 +- go.sum | 6 ------ test-plans/go.mod | 2 +- test-plans/go.sum | 4 ++-- 4 files changed, 4 insertions(+), 10 deletions(-) diff --git a/go.mod b/go.mod index 5b91237fed..faed810d21 100644 --- a/go.mod +++ b/go.mod @@ -103,7 +103,7 @@ require ( github.com/prometheus/procfs v0.8.0 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.3.0 // indirect + github.com/quic-go/qtls-go1-20 v0.2.2 // indirect github.com/spaolacci/murmur3 v1.1.0 // indirect github.com/syndtr/goleveldb v1.0.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/go.sum b/go.sum index fb3e4988da..a31cb28485 100644 --- a/go.sum +++ b/go.sum @@ -436,10 +436,6 @@ github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc8 github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= -github.com/quic-go/qtls-go1-20 v0.3.0 h1:NrCXmDl8BddZwO67vlvEpBTwT89bJfKYygxv4HQvuDk= -github.com/quic-go/qtls-go1-20 v0.3.0/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= -github.com/quic-go/quic-go v0.36.1 h1:WsG73nVtnDy1TiACxFxhQ3TqaW+DipmqzLEtNlAwZyY= -github.com/quic-go/quic-go v0.36.1/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/quic-go v0.36.2 h1:ZX/UNQ4gvpCv2RmwdbA6lrRjF6EBm5yZ7TMoT4NQVrA= github.com/quic-go/quic-go v0.36.2/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= @@ -567,8 +563,6 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0 golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4= golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM= golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU= -golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df h1:UA2aFVmmsIlefxMk29Dp2juaUSth8Pyn3Tq5Y5mJGME= -golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb h1:xIApU0ow1zwMa2uL1VDNeQlNVFTWMQxZUZCMDy0Q4Us= golang.org/x/exp v0.0.0-20230711153332-06a737ee72cb/go.mod h1:FXUEEKJgO7OQYeo8N01OfiKP8RXMtf6e8aTskBGqWdc= golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= diff --git a/test-plans/go.mod b/test-plans/go.mod index 155404aa66..68c1792621 100644 --- a/test-plans/go.mod +++ b/test-plans/go.mod @@ -74,7 +74,7 @@ require ( github.com/prometheus/procfs v0.10.1 // indirect github.com/quic-go/qpack v0.4.0 // indirect github.com/quic-go/qtls-go1-19 v0.3.2 // indirect - github.com/quic-go/qtls-go1-20 v0.3.0 // indirect + github.com/quic-go/qtls-go1-20 v0.2.2 // indirect github.com/quic-go/quic-go v0.36.2 // indirect github.com/quic-go/webtransport-go v0.5.3 // indirect github.com/raulk/go-watchdog v1.3.0 // indirect diff --git a/test-plans/go.sum b/test-plans/go.sum index 0344da5171..73bd302c05 100644 --- a/test-plans/go.sum +++ b/test-plans/go.sum @@ -240,8 +240,8 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo= github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A= github.com/quic-go/qtls-go1-19 v0.3.2 h1:tFxjCFcTQzK+oMxG6Zcvp4Dq8dx4yD3dDiIiyc86Z5U= github.com/quic-go/qtls-go1-19 v0.3.2/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI= -github.com/quic-go/qtls-go1-20 v0.3.0 h1:NrCXmDl8BddZwO67vlvEpBTwT89bJfKYygxv4HQvuDk= -github.com/quic-go/qtls-go1-20 v0.3.0/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k= +github.com/quic-go/qtls-go1-20 v0.2.2 h1:WLOPx6OY/hxtTxKV1Zrq20FtXtDEkeY00CGQm8GEa3E= +github.com/quic-go/qtls-go1-20 v0.2.2/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM= github.com/quic-go/quic-go v0.36.2 h1:ZX/UNQ4gvpCv2RmwdbA6lrRjF6EBm5yZ7TMoT4NQVrA= github.com/quic-go/quic-go v0.36.2/go.mod h1:zPetvwDlILVxt15n3hr3Gf/I3mDf7LpLKPhR4Ez0AZQ= github.com/quic-go/webtransport-go v0.5.3 h1:5XMlzemqB4qmOlgIus5zB45AcZ2kCgCy2EptUrfOPWU= From b8d768a6a449aac369b8312aace32da31c20d8d6 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 11:42:32 -0700 Subject: [PATCH 12/23] Rename ConnManager.metricsTracer to mt --- p2p/transport/quicreuse/connmgr.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 73f9b56a16..8be1755419 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -26,8 +26,8 @@ type ConnManager struct { connsMu sync.Mutex conns map[string]connListenerEntry - srk quic.StatelessResetKey - metricsTracer *metricsTracer + srk quic.StatelessResetKey + mt *metricsTracer } type connListenerEntry struct { @@ -53,7 +53,7 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* var tracers []quiclogging.Tracer if cm.enableMetrics { - cm.metricsTracer = newMetricsTracer() + cm.mt = newMetricsTracer() } if len(tracers) > 0 { quicConf.Tracer = func(ctx context.Context, p quiclogging.Perspective, ci quic.ConnectionID) quiclogging.ConnectionTracer { @@ -61,8 +61,8 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* if qlogTracerDir != "" { tracers = append(tracers, qloggerForDir(qlogTracerDir, p, ci)) } - if cm.metricsTracer != nil { - tracers = append(tracers, cm.metricsTracer.TracerForConnection(ctx, p, ci)) + if cm.mt != nil { + tracers = append(tracers, cm.mt.TracerForConnection(ctx, p, ci)) } return quiclogging.NewMultiplexedConnectionTracer(tracers...) } @@ -75,8 +75,8 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* cm.clientConfig = quicConf cm.serverConfig = serverConfig if cm.enableReuseport { - cm.reuseUDP4 = newReuse(&statelessResetKey, cm.metricsTracer) - cm.reuseUDP6 = newReuse(&statelessResetKey, cm.metricsTracer) + cm.reuseUDP4 = newReuse(&statelessResetKey, cm.mt) + cm.reuseUDP6 = newReuse(&statelessResetKey, cm.mt) } return cm, nil } @@ -165,8 +165,8 @@ func (c *ConnManager) transportForListen(network string, laddr *net.UDPAddr) (re return nil, err } tr := &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn} - if c.metricsTracer != nil { - tr.Transport.Tracer = c.metricsTracer + if c.mt != nil { + tr.Transport.Tracer = c.mt } return tr, nil } @@ -226,8 +226,8 @@ func (c *ConnManager) TransportForDial(network string, raddr *net.UDPAddr) (refC return nil, err } tr := &singleOwnerTransport{Transport: quic.Transport{Conn: conn, StatelessResetKey: &c.srk}, packetConn: conn} - if c.metricsTracer != nil { - tr.Transport.Tracer = c.metricsTracer + if c.mt != nil { + tr.Transport.Tracer = c.mt } return tr, nil From d1ad906fd22d44cece2059a117430f8f89b04b6f Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 13:32:08 -0700 Subject: [PATCH 13/23] Close transport after test ends --- p2p/transport/quicreuse/reuse_test.go | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/p2p/transport/quicreuse/reuse_test.go b/p2p/transport/quicreuse/reuse_test.go index 0b36a4c337..e55cdd328b 100644 --- a/p2p/transport/quicreuse/reuse_test.go +++ b/p2p/transport/quicreuse/reuse_test.go @@ -79,9 +79,10 @@ func TestReuseListenOnAllIPv6(t *testing.T) { addr, err := net.ResolveUDPAddr("udp6", "[::]:1234") require.NoError(t, err) - conn, err := reuse.TransportForListen("udp6", addr) + tr, err := reuse.TransportForListen("udp6", addr) require.NoError(t, err) - require.Equal(t, conn.GetCount(), 1) + defer tr.Close() + require.Equal(t, tr.GetCount(), 1) } func TestReuseCreateNewGlobalConnOnDial(t *testing.T) { @@ -142,15 +143,16 @@ func TestReuseConnectionWhenDialBeforeListen(t *testing.T) { // open a listener laddr := &net.UDPAddr{IP: net.IPv4zero, Port: 1234} - lconn, err := reuse.TransportForListen("udp4", laddr) + tr, err := reuse.TransportForListen("udp4", laddr) require.NoError(t, err) + defer tr.Close() // new dials should go via the listener connection raddr, err = net.ResolveUDPAddr("udp4", "1.1.1.1:1235") require.NoError(t, err) conn, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - require.Equal(t, conn, lconn) + require.Equal(t, conn, tr) require.Equal(t, conn.GetCount(), 2) // a listener on an unspecified port should reuse the dialer @@ -213,19 +215,19 @@ func TestReuseGarbageCollect(t *testing.T) { raddr, err := net.ResolveUDPAddr("udp4", "1.2.3.4:1234") require.NoError(t, err) - dconn, err := reuse.TransportForDial("udp4", raddr) + dTr, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - require.Equal(t, dconn.GetCount(), 1) + require.Equal(t, dTr.GetCount(), 1) addr, err := net.ResolveUDPAddr("udp4", "0.0.0.0:1234") require.NoError(t, err) - lconn, err := reuse.TransportForListen("udp4", addr) + lTr, err := reuse.TransportForListen("udp4", addr) require.NoError(t, err) - require.Equal(t, lconn.GetCount(), 1) + require.Equal(t, lTr.GetCount(), 1) closeTime := time.Now() - lconn.DecreaseCount() - dconn.DecreaseCount() + lTr.DecreaseCount() + dTr.DecreaseCount() for { num := numGlobals() From efe0d08a33bce72961bec529ef4add6f4f1973f3 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 16:13:39 -0700 Subject: [PATCH 14/23] Close conn when transport closes --- p2p/transport/quicreuse/reuse.go | 26 +++++++++++++++------ p2p/transport/quicreuse/reuse_test.go | 33 +++++++++++++-------------- 2 files changed, 35 insertions(+), 24 deletions(-) diff --git a/p2p/transport/quicreuse/reuse.go b/p2p/transport/quicreuse/reuse.go index da3cecb0bb..76715139b9 100644 --- a/p2p/transport/quicreuse/reuse.go +++ b/p2p/transport/quicreuse/reuse.go @@ -42,6 +42,12 @@ func (c *singleOwnerTransport) LocalAddr() net.Addr { return c.Transport.Conn.LocalAddr() } +func (c *singleOwnerTransport) Close() error { + // TODO(when we drop support for go 1.19) use errors.Join + c.Transport.Close() + return c.packetConn.Close() +} + func (c *singleOwnerTransport) WriteTo(b []byte, addr net.Addr) (int, error) { // Safe because we called quic.OptimizeConn ourselves. return c.packetConn.WriteTo(b, addr) @@ -71,6 +77,12 @@ func (c *refcountedTransport) IncreaseCount() { c.mutex.Unlock() } +func (c *refcountedTransport) Close() error { + // TODO(when we drop support for go 1.19) use errors.Join + c.Transport.Close() + return c.packetConn.Close() +} + func (c *refcountedTransport) WriteTo(b []byte, addr net.Addr) (int, error) { // Safe because we called quic.OptimizeConn ourselves. return c.packetConn.WriteTo(b, addr) @@ -131,15 +143,15 @@ func newReuse(srk *quic.StatelessResetKey, mt *metricsTracer) *reuse { func (r *reuse) gc() { defer func() { r.mutex.Lock() - for _, conn := range r.globalListeners { - conn.Close() + for _, tr := range r.globalListeners { + tr.Close() } - for _, conn := range r.globalDialers { - conn.Close() + for _, tr := range r.globalDialers { + tr.Close() } - for _, conns := range r.unicast { - for _, conn := range conns { - conn.Close() + for _, trs := range r.unicast { + for _, tr := range trs { + tr.Close() } } r.mutex.Unlock() diff --git a/p2p/transport/quicreuse/reuse_test.go b/p2p/transport/quicreuse/reuse_test.go index e55cdd328b..b373f31fe4 100644 --- a/p2p/transport/quicreuse/reuse_test.go +++ b/p2p/transport/quicreuse/reuse_test.go @@ -21,20 +21,20 @@ func (c *refcountedTransport) GetCount() int { func closeAllConns(reuse *reuse) { reuse.mutex.Lock() - for _, conn := range reuse.globalListeners { - for conn.GetCount() > 0 { - conn.DecreaseCount() + for _, tr := range reuse.globalListeners { + for tr.GetCount() > 0 { + tr.DecreaseCount() } } - for _, conn := range reuse.globalDialers { - for conn.GetCount() > 0 { - conn.DecreaseCount() + for _, tr := range reuse.globalDialers { + for tr.GetCount() > 0 { + tr.DecreaseCount() } } - for _, conns := range reuse.unicast { - for _, conn := range conns { - for conn.GetCount() > 0 { - conn.DecreaseCount() + for _, trs := range reuse.unicast { + for _, tr := range trs { + for tr.GetCount() > 0 { + tr.DecreaseCount() } } } @@ -138,28 +138,27 @@ func TestReuseConnectionWhenDialBeforeListen(t *testing.T) { // dial any address raddr, err := net.ResolveUDPAddr("udp4", "1.1.1.1:1234") require.NoError(t, err) - rconn, err := reuse.TransportForDial("udp4", raddr) + rTr, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) // open a listener laddr := &net.UDPAddr{IP: net.IPv4zero, Port: 1234} - tr, err := reuse.TransportForListen("udp4", laddr) + lTr, err := reuse.TransportForListen("udp4", laddr) require.NoError(t, err) - defer tr.Close() // new dials should go via the listener connection raddr, err = net.ResolveUDPAddr("udp4", "1.1.1.1:1235") require.NoError(t, err) - conn, err := reuse.TransportForDial("udp4", raddr) + tr, err := reuse.TransportForDial("udp4", raddr) require.NoError(t, err) - require.Equal(t, conn, tr) - require.Equal(t, conn.GetCount(), 2) + require.Equal(t, tr, lTr) + require.Equal(t, tr.GetCount(), 2) // a listener on an unspecified port should reuse the dialer laddr2 := &net.UDPAddr{IP: net.IPv4zero, Port: 0} lconn2, err := reuse.TransportForListen("udp4", laddr2) require.NoError(t, err) - require.Equal(t, lconn2, rconn) + require.Equal(t, lconn2, rTr) require.Equal(t, lconn2.GetCount(), 2) } From c49d3d9be9487a1555077c888b1358fd21c839c9 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 17:34:03 -0700 Subject: [PATCH 15/23] Return better error --- p2p/transport/webtransport/transport.go | 5 ++++- p2p/transport/webtransport/transport_test.go | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/p2p/transport/webtransport/transport.go b/p2p/transport/webtransport/transport.go index 2b2c3e709f..957d2ff1c1 100644 --- a/p2p/transport/webtransport/transport.go +++ b/p2p/transport/webtransport/transport.go @@ -295,10 +295,13 @@ func (t *transport) CanDial(addr ma.Multiaddr) bool { } func (t *transport) Listen(laddr ma.Multiaddr) (tpt.Listener, error) { - isWebTransport, _ := IsWebtransportMultiaddr(laddr) + isWebTransport, certhashCount := IsWebtransportMultiaddr(laddr) if !isWebTransport { return nil, fmt.Errorf("cannot listen on non-WebTransport addr: %s", laddr) } + if certhashCount > 0 { + return nil, fmt.Errorf("cannot listen on a specific certhash non-WebTransport addr: %s", laddr) + } if t.staticTLSConf == nil { t.listenOnce.Do(func() { t.certManager, t.listenOnceErr = newCertManager(t.privKey, t.clock) diff --git a/p2p/transport/webtransport/transport_test.go b/p2p/transport/webtransport/transport_test.go index aa669add07..8d47d83c47 100644 --- a/p2p/transport/webtransport/transport_test.go +++ b/p2p/transport/webtransport/transport_test.go @@ -224,10 +224,10 @@ func TestListenAddrValidity(t *testing.T) { } invalid := []ma.Multiaddr{ - ma.StringCast("/ip4/127.0.0.1/udp/1234"), // missing webtransport - ma.StringCast("/ip4/127.0.0.1/udp/1234/webtransport"), // missing quic - ma.StringCast("/ip4/127.0.0.1/tcp/1234/webtransport"), // WebTransport over TCP? Is this a joke? - ma.StringCast("/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/" + randomMultihash(t)), + ma.StringCast("/ip4/127.0.0.1/udp/1234"), // missing webtransport + ma.StringCast("/ip4/127.0.0.1/udp/1234/webtransport"), // missing quic + ma.StringCast("/ip4/127.0.0.1/tcp/1234/webtransport"), // WebTransport over TCP? Is this a joke? + ma.StringCast("/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/" + randomMultihash(t)), // We can't listen on a specific certhash } _, key := newIdentity(t) From ee672cb23cab725cbb42b4897f0f98d0a0026f12 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 17:35:59 -0700 Subject: [PATCH 16/23] Avoid conflicts with parallel tests --- p2p/transport/webtransport/transport_test.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/p2p/transport/webtransport/transport_test.go b/p2p/transport/webtransport/transport_test.go index 8d47d83c47..56c381ccc1 100644 --- a/p2p/transport/webtransport/transport_test.go +++ b/p2p/transport/webtransport/transport_test.go @@ -220,14 +220,14 @@ func TestCanDial(t *testing.T) { func TestListenAddrValidity(t *testing.T) { valid := []ma.Multiaddr{ ma.StringCast("/ip6/::/udp/0/quic-v1/webtransport/"), - ma.StringCast("/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/"), + ma.StringCast("/ip4/127.0.0.1/udp/11234/quic-v1/webtransport/"), } invalid := []ma.Multiaddr{ - ma.StringCast("/ip4/127.0.0.1/udp/1234"), // missing webtransport - ma.StringCast("/ip4/127.0.0.1/udp/1234/webtransport"), // missing quic - ma.StringCast("/ip4/127.0.0.1/tcp/1234/webtransport"), // WebTransport over TCP? Is this a joke? - ma.StringCast("/ip4/127.0.0.1/udp/1234/quic-v1/webtransport/certhash/" + randomMultihash(t)), // We can't listen on a specific certhash + ma.StringCast("/ip4/127.0.0.1/udp/11234"), // missing webtransport + ma.StringCast("/ip4/127.0.0.1/udp/11234/webtransport"), // missing quic + ma.StringCast("/ip4/127.0.0.1/tcp/11234/webtransport"), // WebTransport over TCP? Is this a joke? + ma.StringCast("/ip4/127.0.0.1/udp/11234/quic-v1/webtransport/certhash/" + randomMultihash(t)), // We can't listen on a specific certhash } _, key := newIdentity(t) From d0c0cf9b443e8db397feeeb9b288fd6f6e4efe4f Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Wed, 12 Jul 2023 18:26:10 -0700 Subject: [PATCH 17/23] Skip conn assert on windows --- p2p/transport/quicreuse/connmgr_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/p2p/transport/quicreuse/connmgr_test.go b/p2p/transport/quicreuse/connmgr_test.go index 7c5aa5f16b..8b8846c3f2 100644 --- a/p2p/transport/quicreuse/connmgr_test.go +++ b/p2p/transport/quicreuse/connmgr_test.go @@ -92,6 +92,9 @@ func testListenOnSameProto(t *testing.T, enableReuseport bool) { // The conn passed to quic-go should be a conn that quic-go can be // type-asserted to a UDPConn. That way, it can use all kinds of optimizations. func TestConnectionPassedToQUICForListening(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("skipping on windows. Not sure why this fails") + } cm, err := NewConnManager([32]byte{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() @@ -149,6 +152,9 @@ func TestAcceptErrorGetCleanedUp(t *testing.T) { // The connection passed to quic-go needs to be type-assertable to a net.UDPConn, // in order to enable features like batch processing and ECN. func TestConnectionPassedToQUICForDialing(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("skipping on windows. Not sure why this fails") + } cm, err := NewConnManager([32]byte{}, DisableReuseport()) require.NoError(t, err) defer cm.Close() From eb830c13da5d73bffc7dc4af61e53c7e4ce502cf Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 13 Jul 2023 09:24:06 -0700 Subject: [PATCH 18/23] Add metrics tracer back in --- p2p/transport/quicreuse/connmgr.go | 1 + 1 file changed, 1 insertion(+) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 8be1755419..ae94f5a173 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -54,6 +54,7 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* if cm.enableMetrics { cm.mt = newMetricsTracer() + tracers = append(tracers, cm.mt) } if len(tracers) > 0 { quicConf.Tracer = func(ctx context.Context, p quiclogging.Perspective, ci quic.ConnectionID) quiclogging.ConnectionTracer { From 69bf8837c8c649b1a7b6ff2272d3857a1ce74e31 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 13 Jul 2023 09:30:04 -0700 Subject: [PATCH 19/23] Don't use tracers here --- p2p/transport/quicreuse/connmgr.go | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index ae94f5a173..1ce809e7d6 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -50,23 +50,18 @@ func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (* quicConf := quicConfig.Clone() - var tracers []quiclogging.Tracer - if cm.enableMetrics { cm.mt = newMetricsTracer() - tracers = append(tracers, cm.mt) } - if len(tracers) > 0 { - quicConf.Tracer = func(ctx context.Context, p quiclogging.Perspective, ci quic.ConnectionID) quiclogging.ConnectionTracer { - tracers := make([]quiclogging.ConnectionTracer, 0, 2) - if qlogTracerDir != "" { - tracers = append(tracers, qloggerForDir(qlogTracerDir, p, ci)) - } - if cm.mt != nil { - tracers = append(tracers, cm.mt.TracerForConnection(ctx, p, ci)) - } - return quiclogging.NewMultiplexedConnectionTracer(tracers...) + quicConf.Tracer = func(ctx context.Context, p quiclogging.Perspective, ci quic.ConnectionID) quiclogging.ConnectionTracer { + tracers := make([]quiclogging.ConnectionTracer, 0, 2) + if qlogTracerDir != "" { + tracers = append(tracers, qloggerForDir(qlogTracerDir, p, ci)) + } + if cm.mt != nil { + tracers = append(tracers, cm.mt.TracerForConnection(ctx, p, ci)) } + return quiclogging.NewMultiplexedConnectionTracer(tracers...) } serverConfig := quicConf.Clone() if !cm.enableDraft29 { From a451cfa3dcaf1eb014673371ab9d6f60d41b2754 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 13 Jul 2023 11:38:42 -0700 Subject: [PATCH 20/23] Add comment to WriteTo --- p2p/transport/quicreuse/reuse.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/p2p/transport/quicreuse/reuse.go b/p2p/transport/quicreuse/reuse.go index 76715139b9..c7352733d1 100644 --- a/p2p/transport/quicreuse/reuse.go +++ b/p2p/transport/quicreuse/reuse.go @@ -13,9 +13,11 @@ import ( ) type refCountedQuicTransport interface { - WriteTo([]byte, net.Addr) (int, error) LocalAddr() net.Addr + // Used to send packets directly around QUIC. Useful for hole punching. + WriteTo([]byte, net.Addr) (int, error) + Close() error // count conn reference From 7773888b80bdab3c1e6292941898cd3348122575 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 13 Jul 2023 11:46:38 -0700 Subject: [PATCH 21/23] Finish renaming conn -> transport where appropriate --- p2p/transport/quicreuse/connmgr.go | 36 +++++++-------- p2p/transport/quicreuse/connmgr_test.go | 14 +++--- p2p/transport/quicreuse/listener.go | 14 +++--- p2p/transport/quicreuse/reuse.go | 58 ++++++++++++------------- 4 files changed, 61 insertions(+), 61 deletions(-) diff --git a/p2p/transport/quicreuse/connmgr.go b/p2p/transport/quicreuse/connmgr.go index 1ce809e7d6..c12b86671a 100644 --- a/p2p/transport/quicreuse/connmgr.go +++ b/p2p/transport/quicreuse/connmgr.go @@ -23,23 +23,23 @@ type ConnManager struct { serverConfig *quic.Config clientConfig *quic.Config - connsMu sync.Mutex - conns map[string]connListenerEntry + quicListenersMu sync.Mutex + quicListeners map[string]quicListenerEntry srk quic.StatelessResetKey mt *metricsTracer } -type connListenerEntry struct { +type quicListenerEntry struct { refCount int - ln *connListener + ln *quicListener } func NewConnManager(statelessResetKey quic.StatelessResetKey, opts ...Option) (*ConnManager, error) { cm := &ConnManager{ enableReuseport: true, enableDraft29: true, - conns: make(map[string]connListenerEntry), + quicListeners: make(map[string]quicListenerEntry), srk: statelessResetKey, } for _, o := range opts { @@ -104,22 +104,22 @@ func (c *ConnManager) ListenQUIC(addr ma.Multiaddr, tlsConf *tls.Config, allowWi return nil, err } - c.connsMu.Lock() - defer c.connsMu.Unlock() + c.quicListenersMu.Lock() + defer c.quicListenersMu.Unlock() key := laddr.String() - entry, ok := c.conns[key] + entry, ok := c.quicListeners[key] if !ok { - conn, err := c.transportForListen(netw, laddr) + tr, err := c.transportForListen(netw, laddr) if err != nil { return nil, err } - ln, err := newConnListener(conn, c.serverConfig, c.enableDraft29) + ln, err := newQuicListener(tr, c.serverConfig, c.enableDraft29) if err != nil { return nil, err } - key = conn.LocalAddr().String() - entry = connListenerEntry{ln: ln} + key = tr.LocalAddr().String() + entry = quicListenerEntry{ln: ln} } l, err := entry.ln.Add(tlsConf, allowWindowIncrease, func() { c.onListenerClosed(key) }) if err != nil { @@ -129,21 +129,21 @@ func (c *ConnManager) ListenQUIC(addr ma.Multiaddr, tlsConf *tls.Config, allowWi return nil, err } entry.refCount++ - c.conns[key] = entry + c.quicListeners[key] = entry return l, nil } func (c *ConnManager) onListenerClosed(key string) { - c.connsMu.Lock() - defer c.connsMu.Unlock() + c.quicListenersMu.Lock() + defer c.quicListenersMu.Unlock() - entry := c.conns[key] + entry := c.quicListeners[key] entry.refCount = entry.refCount - 1 if entry.refCount <= 0 { - delete(c.conns, key) + delete(c.quicListeners, key) entry.ln.Close() } else { - c.conns[key] = entry + c.quicListeners[key] = entry } } diff --git a/p2p/transport/quicreuse/connmgr_test.go b/p2p/transport/quicreuse/connmgr_test.go index 8b8846c3f2..92c7e31250 100644 --- a/p2p/transport/quicreuse/connmgr_test.go +++ b/p2p/transport/quicreuse/connmgr_test.go @@ -26,12 +26,12 @@ func checkClosed(t *testing.T, cm *ConnManager) { continue } r.mutex.Lock() - for _, conn := range r.globalListeners { - require.Zero(t, conn.GetCount()) + for _, tr := range r.globalListeners { + require.Zero(t, tr.GetCount()) } - for _, conns := range r.unicast { - for _, conn := range conns { - require.Zero(t, conn.GetCount()) + for _, trs := range r.unicast { + for _, tr := range trs { + require.Zero(t, tr.GetCount()) } } r.mutex.Unlock() @@ -93,7 +93,7 @@ func testListenOnSameProto(t *testing.T, enableReuseport bool) { // type-asserted to a UDPConn. That way, it can use all kinds of optimizations. func TestConnectionPassedToQUICForListening(t *testing.T) { if runtime.GOOS == "windows" { - t.Skip("skipping on windows. Not sure why this fails") + t.Skip("skipping on windows. Windows doesn't support these optimizations") } cm, err := NewConnManager([32]byte{}, DisableReuseport()) require.NoError(t, err) @@ -153,7 +153,7 @@ func TestAcceptErrorGetCleanedUp(t *testing.T) { // in order to enable features like batch processing and ECN. func TestConnectionPassedToQUICForDialing(t *testing.T) { if runtime.GOOS == "windows" { - t.Skip("skipping on windows. Not sure why this fails") + t.Skip("skipping on windows. Windows doesn't support these optimizations") } cm, err := NewConnManager([32]byte{}, DisableReuseport()) require.NoError(t, err) diff --git a/p2p/transport/quicreuse/listener.go b/p2p/transport/quicreuse/listener.go index 42ac6217a9..cd1fbcb5c2 100644 --- a/p2p/transport/quicreuse/listener.go +++ b/p2p/transport/quicreuse/listener.go @@ -28,7 +28,7 @@ type protoConf struct { allowWindowIncrease func(conn quic.Connection, delta uint64) bool } -type connListener struct { +type quicListener struct { l *quic.Listener transport refCountedQuicTransport running chan struct{} @@ -38,7 +38,7 @@ type connListener struct { protocols map[string]protoConf } -func newConnListener(c refCountedQuicTransport, quicConfig *quic.Config, enableDraft29 bool) (*connListener, error) { +func newQuicListener(c refCountedQuicTransport, quicConfig *quic.Config, enableDraft29 bool) (*quicListener, error) { localMultiaddrs := make([]ma.Multiaddr, 0, 2) a, err := ToQuicMultiaddr(c.LocalAddr(), quic.Version1) if err != nil { @@ -52,7 +52,7 @@ func newConnListener(c refCountedQuicTransport, quicConfig *quic.Config, enableD } localMultiaddrs = append(localMultiaddrs, a) } - cl := &connListener{ + cl := &quicListener{ protocols: map[string]protoConf{}, running: make(chan struct{}), transport: c, @@ -85,7 +85,7 @@ func newConnListener(c refCountedQuicTransport, quicConfig *quic.Config, enableD return cl, nil } -func (l *connListener) allowWindowIncrease(conn quic.Connection, delta uint64) bool { +func (l *quicListener) allowWindowIncrease(conn quic.Connection, delta uint64) bool { l.protocolsMu.Lock() defer l.protocolsMu.Unlock() @@ -96,7 +96,7 @@ func (l *connListener) allowWindowIncrease(conn quic.Connection, delta uint64) b return conf.allowWindowIncrease(conn, delta) } -func (l *connListener) Add(tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool, onRemove func()) (Listener, error) { +func (l *quicListener) Add(tlsConf *tls.Config, allowWindowIncrease func(conn quic.Connection, delta uint64) bool, onRemove func()) (Listener, error) { l.protocolsMu.Lock() defer l.protocolsMu.Unlock() @@ -128,7 +128,7 @@ func (l *connListener) Add(tlsConf *tls.Config, allowWindowIncrease func(conn qu return ln, nil } -func (l *connListener) Run() error { +func (l *quicListener) Run() error { defer close(l.running) defer l.transport.DecreaseCount() for { @@ -152,7 +152,7 @@ func (l *connListener) Run() error { } } -func (l *connListener) Close() error { +func (l *quicListener) Close() error { err := l.l.Close() <-l.running // wait for Run to return return err diff --git a/p2p/transport/quicreuse/reuse.go b/p2p/transport/quicreuse/reuse.go index c7352733d1..1584b29254 100644 --- a/p2p/transport/quicreuse/reuse.go +++ b/p2p/transport/quicreuse/reuse.go @@ -20,7 +20,7 @@ type refCountedQuicTransport interface { Close() error - // count conn reference + // count transport reference DecreaseCount() IncreaseCount() @@ -169,28 +169,28 @@ func (r *reuse) gc() { case <-ticker.C: now := time.Now() r.mutex.Lock() - for key, conn := range r.globalListeners { - if conn.ShouldGarbageCollect(now) { - conn.Close() + for key, tr := range r.globalListeners { + if tr.ShouldGarbageCollect(now) { + tr.Close() delete(r.globalListeners, key) } } - for key, conn := range r.globalDialers { - if conn.ShouldGarbageCollect(now) { - conn.Close() + for key, tr := range r.globalDialers { + if tr.ShouldGarbageCollect(now) { + tr.Close() delete(r.globalDialers, key) } } - for ukey, conns := range r.unicast { - for key, conn := range conns { - if conn.ShouldGarbageCollect(now) { - conn.Close() - delete(conns, key) + for ukey, trs := range r.unicast { + for key, tr := range trs { + if tr.ShouldGarbageCollect(now) { + tr.Close() + delete(trs, key) } } - if len(conns) == 0 { + if len(trs) == 0 { delete(r.unicast, ukey) - // If we've dropped all connections with a unicast binding, + // If we've dropped all transports with a unicast binding, // assume our routes may have changed. if len(r.unicast) == 0 { r.routes = nil @@ -236,27 +236,27 @@ func (r *reuse) TransportForDial(network string, raddr *net.UDPAddr) (*refcounte func (r *reuse) transportForDialLocked(network string, source *net.IP) (*refcountedTransport, error) { if source != nil { - // We already have at least one suitable connection... - if conns, ok := r.unicast[source.String()]; ok { + // We already have at least one suitable transport... + if trs, ok := r.unicast[source.String()]; ok { // ... we don't care which port we're dialing from. Just use the first. - for _, c := range conns { - return c, nil + for _, tr := range trs { + return tr, nil } } } - // Use a connection listening on 0.0.0.0 (or ::). + // Use a transport listening on 0.0.0.0 (or ::). // Again, we don't care about the port number. - for _, conn := range r.globalListeners { - return conn, nil + for _, tr := range r.globalListeners { + return tr, nil } - // Use a connection we've previously dialed from - for _, conn := range r.globalDialers { - return conn, nil + // Use a transport we've previously dialed from + for _, tr := range r.globalDialers { + return tr, nil } - // We don't have a connection that we can use for dialing. + // We don't have a transport that we can use for dialing. // Dial a new connection from a random port. var addr *net.UDPAddr switch network { @@ -284,17 +284,17 @@ func (r *reuse) TransportForListen(network string, laddr *net.UDPAddr) (*refcoun r.mutex.Lock() defer r.mutex.Unlock() - // Check if we can reuse a connection we have already dialed out from. - // We reuse a connection from globalDialers when the requested port is 0 or the requested + // Check if we can reuse a transport we have already dialed out from. + // We reuse a transport from globalDialers when the requested port is 0 or the requested // port is already in the globalDialers. - // If we are reusing a connection from globalDialers, we move the globalDialers entry to + // If we are reusing a transport from globalDialers, we move the globalDialers entry to // globalListeners if laddr.IP.IsUnspecified() { var rTr *refcountedTransport var localAddr *net.UDPAddr if laddr.Port == 0 { - // the requested port is 0, we can reuse any connection + // the requested port is 0, we can reuse any transport for _, tr := range r.globalDialers { rTr = tr localAddr = rTr.LocalAddr().(*net.UDPAddr) From 0f7e912a027b832df191ea33388209cbfb70080a Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 13 Jul 2023 11:54:15 -0700 Subject: [PATCH 22/23] Back out unrelated change --- p2p/transport/webtransport/transport.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/p2p/transport/webtransport/transport.go b/p2p/transport/webtransport/transport.go index 957d2ff1c1..2b2c3e709f 100644 --- a/p2p/transport/webtransport/transport.go +++ b/p2p/transport/webtransport/transport.go @@ -295,13 +295,10 @@ func (t *transport) CanDial(addr ma.Multiaddr) bool { } func (t *transport) Listen(laddr ma.Multiaddr) (tpt.Listener, error) { - isWebTransport, certhashCount := IsWebtransportMultiaddr(laddr) + isWebTransport, _ := IsWebtransportMultiaddr(laddr) if !isWebTransport { return nil, fmt.Errorf("cannot listen on non-WebTransport addr: %s", laddr) } - if certhashCount > 0 { - return nil, fmt.Errorf("cannot listen on a specific certhash non-WebTransport addr: %s", laddr) - } if t.staticTLSConf == nil { t.listenOnce.Do(func() { t.certManager, t.listenOnceErr = newCertManager(t.privKey, t.clock) From b632427422943b002b60c3f150e590dd11619316 Mon Sep 17 00:00:00 2001 From: Marco Munizaga Date: Thu, 13 Jul 2023 13:18:24 -0700 Subject: [PATCH 23/23] One more rename --- p2p/transport/quicreuse/listener.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/p2p/transport/quicreuse/listener.go b/p2p/transport/quicreuse/listener.go index cd1fbcb5c2..50b793451a 100644 --- a/p2p/transport/quicreuse/listener.go +++ b/p2p/transport/quicreuse/listener.go @@ -38,15 +38,15 @@ type quicListener struct { protocols map[string]protoConf } -func newQuicListener(c refCountedQuicTransport, quicConfig *quic.Config, enableDraft29 bool) (*quicListener, error) { +func newQuicListener(tr refCountedQuicTransport, quicConfig *quic.Config, enableDraft29 bool) (*quicListener, error) { localMultiaddrs := make([]ma.Multiaddr, 0, 2) - a, err := ToQuicMultiaddr(c.LocalAddr(), quic.Version1) + a, err := ToQuicMultiaddr(tr.LocalAddr(), quic.Version1) if err != nil { return nil, err } localMultiaddrs = append(localMultiaddrs, a) if enableDraft29 { - a, err := ToQuicMultiaddr(c.LocalAddr(), quic.VersionDraft29) + a, err := ToQuicMultiaddr(tr.LocalAddr(), quic.VersionDraft29) if err != nil { return nil, err } @@ -55,7 +55,7 @@ func newQuicListener(c refCountedQuicTransport, quicConfig *quic.Config, enableD cl := &quicListener{ protocols: map[string]protoConf{}, running: make(chan struct{}), - transport: c, + transport: tr, addrs: localMultiaddrs, } tlsConf := &tls.Config{ @@ -76,7 +76,7 @@ func newQuicListener(c refCountedQuicTransport, quicConfig *quic.Config, enableD } quicConf := quicConfig.Clone() quicConf.AllowConnectionWindowIncrease = cl.allowWindowIncrease - ln, err := c.Listen(tlsConf, quicConf) + ln, err := tr.Listen(tlsConf, quicConf) if err != nil { return nil, err }