private/server: use quic implementation from storj.io/common
Change-Id: I820cf6444a3ddccee0d7c647dc84c80b2752068c
This commit is contained in:
parent
c074a5666b
commit
077ec96d94
@ -15,8 +15,8 @@ import (
|
||||
"storj.io/common/identity"
|
||||
"storj.io/common/peertls/tlsopts"
|
||||
"storj.io/common/rpc"
|
||||
"storj.io/common/rpc/quic"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/storj/private/quic"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
@ -21,10 +21,10 @@ import (
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"storj.io/common/fpath"
|
||||
"storj.io/common/rpc"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/private/cfgstruct"
|
||||
"storj.io/private/process"
|
||||
"storj.io/storj/private/server"
|
||||
"storj.io/storj/private/version/checker"
|
||||
"storj.io/uplink"
|
||||
privateAccess "storj.io/uplink/private/access"
|
||||
@ -95,7 +95,7 @@ func (cliCfg *UplinkFlags) getProject(ctx context.Context, encryptionBypass bool
|
||||
uplinkCfg.UserAgent = cliCfg.Client.UserAgent
|
||||
uplinkCfg.DialTimeout = cliCfg.Client.DialTimeout
|
||||
if cliCfg.Client.EnableQUIC {
|
||||
transport.SetConnector(&uplinkCfg, server.NewDefaultHybridConnector(nil, nil))
|
||||
transport.SetConnector(&uplinkCfg, rpc.NewHybridConnector())
|
||||
}
|
||||
|
||||
if encryptionBypass {
|
||||
|
@ -7,6 +7,7 @@ import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
_ "storj.io/common/rpc/quic" // This enables quic connector
|
||||
"storj.io/private/process"
|
||||
"storj.io/storj/cmd/uplink/cmd"
|
||||
_ "storj.io/storj/private/version" // This attaches version information during release builds.
|
||||
|
5
go.mod
5
go.mod
@ -24,7 +24,6 @@ require (
|
||||
github.com/jackc/pgx/v4 v4.10.1
|
||||
github.com/jtolds/monkit-hw/v2 v2.0.0-20191108235325-141a0da276b3
|
||||
github.com/loov/hrtime v1.0.3
|
||||
github.com/lucas-clemente/quic-go v0.21.0
|
||||
github.com/mattn/go-sqlite3 v2.0.3+incompatible
|
||||
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce
|
||||
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1
|
||||
@ -49,13 +48,13 @@ require (
|
||||
go.uber.org/zap v1.16.0
|
||||
golang.org/x/crypto v0.0.0-20210415154028-4f45737414dc
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
|
||||
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1
|
||||
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e
|
||||
google.golang.org/api v0.20.0 // indirect
|
||||
gopkg.in/segmentio/analytics-go.v3 v3.1.0
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
|
||||
storj.io/common v0.0.0-20210805073808-8e0feb09e92a
|
||||
storj.io/common v0.0.0-20210805230333-1ba6d8c2bfb1
|
||||
storj.io/drpc v0.0.24
|
||||
storj.io/monkit-jaeger v0.0.0-20210426161729-debb1cbcbbd7
|
||||
storj.io/private v0.0.0-20210625132526-af46b647eda5
|
||||
|
56
go.sum
56
go.sum
@ -130,6 +130,8 @@ github.com/go-redis/redis/v8 v8.7.1/go.mod h1:BRxHBWn3pO3CfjyX6vAoyeRmCquvxr6QG+
|
||||
github.com/go-rod/rod v0.100.0 h1:tEKIb5wS3pGUpW4oJPYDxOKmRXaZbd6S+YVjJ6BHBBY=
|
||||
github.com/go-rod/rod v0.100.0/go.mod h1:h9igqSGReLmOWyHtdf0AtUd0mdkHFu3gFwBeV+stleM=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
|
||||
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
@ -147,8 +149,8 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71h+4=
|
||||
github.com/golang/mock v1.5.0 h1:jlYHihg//f7RRwuPfptm04yp4s7O6Kw8EZiVYIGcH0g=
|
||||
github.com/golang/mock v1.5.0/go.mod h1:CWnOUgYIOo4TcNZ0wHX3YZCqsaM1I1Jvs6v3mP3KVu8=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
@ -159,8 +161,9 @@ github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:W
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
@ -317,21 +320,21 @@ github.com/lib/pq v1.3.0 h1:/qkRGz8zljWiDcFvgpwUpwIAPu3r07TDvs3Rws+o/pU=
|
||||
github.com/lib/pq v1.3.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
|
||||
github.com/loov/hrtime v1.0.3 h1:LiWKU3B9skJwRPUf0Urs9+0+OE3TxdMuiRPOTwR0gcU=
|
||||
github.com/loov/hrtime v1.0.3/go.mod h1:yDY3Pwv2izeY4sq7YcPX/dtLwzg5NU1AxWuWxKwd0p0=
|
||||
github.com/lucas-clemente/quic-go v0.20.1/go.mod h1:fZq/HUDIM+mW6X6wtzORjC0E/WDBMKe5Hf9bgjISwLk=
|
||||
github.com/lucas-clemente/quic-go v0.21.0 h1:ZdC8UBxUSBdPlEv1+4y4SqIBy54VA8bRxN7DmkQ0URs=
|
||||
github.com/lucas-clemente/quic-go v0.21.0/go.mod h1:BWkfkkOSJD1AxFNBqdjBZi6FznZ96bhdcvZiA+LDrY8=
|
||||
github.com/lucas-clemente/quic-go v0.22.0 h1:o8NIiHaavjoHe6z8Bqm6fw7g0YIP6AFKMYer+oNxInA=
|
||||
github.com/lucas-clemente/quic-go v0.22.0/go.mod h1:vF5M1XqhBAHgbjKcJOXY3JZz3GP0T3FQhz/uyOUS38Q=
|
||||
github.com/lunixbochs/vtclean v1.0.0/go.mod h1:pHhQNgMf3btfWnGBVipUOjRYhoOsdGqdm/+2c2E2WMI=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/magiconair/properties v1.8.5 h1:b6kJs+EmPFMYGkow9GiUyCyOvIwYetYJ3fSaWak/Gls=
|
||||
github.com/magiconair/properties v1.8.5/go.mod h1:y3VJvCyxH9uVvJTWEGAELF3aiYNyPKd5NZ3oSwXrF60=
|
||||
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/marten-seemann/qpack v0.2.1/go.mod h1:F7Gl5L1jIgN1D11ucXefiuJS9UMVP2opoCp2jDKb7wc=
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.4 h1:RehYMOyRW8hPVEja1KBVsFVNSm35Jj9Mvs5yNoZZ28A=
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.4/go.mod h1:GyFwywLKkRt+6mfU99csTEY1joMZz5vmB1WNZH3P81I=
|
||||
github.com/marten-seemann/qtls-go1-16 v0.1.3 h1:XEZ1xGorVy9u+lJq+WXNE+hiqRYLNvJGYmwfwKQN2gU=
|
||||
github.com/marten-seemann/qtls-go1-16 v0.1.3/go.mod h1:gNpI2Ol+lRS3WwSOtIUUtRwZEQMXjYK+dQSBFbethAk=
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.0-alpha.1 h1:LRFa3YRSlOAf9y56Szfhlh60CQrIMBSK/rneZD1gtuk=
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.0-alpha.1/go.mod h1:lQDiKZDfPagLmg1zMtEgoBMSTAORq6M08lBogD5FtBY=
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.5 h1:Ci4EIUN6Rlb+D6GmLdej/bCQ4nPYNtVXQB+xjiXE1nk=
|
||||
github.com/marten-seemann/qtls-go1-15 v0.1.5/go.mod h1:GyFwywLKkRt+6mfU99csTEY1joMZz5vmB1WNZH3P81I=
|
||||
github.com/marten-seemann/qtls-go1-16 v0.1.4 h1:xbHbOGGhrenVtII6Co8akhLEdrawwB2iHl5yhJRpnco=
|
||||
github.com/marten-seemann/qtls-go1-16 v0.1.4/go.mod h1:gNpI2Ol+lRS3WwSOtIUUtRwZEQMXjYK+dQSBFbethAk=
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.0-rc.1 h1:/rpmWuGvceLwwWuaKPdjpR4JJEUH0tq64/I3hvzaNLM=
|
||||
github.com/marten-seemann/qtls-go1-17 v0.1.0-rc.1/go.mod h1:fz4HIxByo+LlWcreM4CZOYNuz3taBQ8rN2X6FqvaWo8=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
@ -374,21 +377,25 @@ github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce h1:RPclfga2SEJmgMmz2k
|
||||
github.com/nsf/jsondiff v0.0.0-20200515183724-f29ed568f4ce/go.mod h1:uFMI8w+ref4v2r9jz+c9i1IfIttS/OkmLfrk1jne5hs=
|
||||
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1 h1:lh3PyZvY+B9nFliSGTn5uFuqQQJGuNrD0MLCokv09ag=
|
||||
github.com/nsf/termbox-go v0.0.0-20200418040025-38ba6e5628f1/go.mod h1:IuKpRQcYE1Tfu+oAQqaLisqDeXgjyyltCfsaoYN18NQ=
|
||||
github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.10.3/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||
github.com/onsi/ginkgo v1.15.0 h1:1V1NfVQR87RtWAgp1lv9JZJ5Jap+XFGKPi00andXGi4=
|
||||
github.com/onsi/ginkgo v1.15.0/go.mod h1:hF8qUzuuC8DJGygJH3726JnCZX4MYbRB8yFfISqnKUg=
|
||||
github.com/onsi/ginkgo v1.16.2/go.mod h1:CObGmKUOKaSC0RjmoAK7tKyn4Azo5P2IWuoMnvwxz1E=
|
||||
github.com/onsi/ginkgo v1.16.4 h1:29JGrr5oVBm5ulCWet69zQkzWipVXIol6ygQUe/EzNc=
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
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.10.5 h1:7n6FEkpFmfCoo2t+YYqXH0evK+a9ICQz0xcAy9dYcaQ=
|
||||
github.com/onsi/gomega v1.10.5/go.mod h1:gza4q3jKQJijlu05nKWRCW/GavJumGt8aNRxWg7mt48=
|
||||
github.com/onsi/gomega v1.13.0 h1:7lLHu94wT9Ij0o6EWWclhu0aOh32VxhkwEJvzuWPeak=
|
||||
github.com/onsi/gomega v1.13.0/go.mod h1:lRk9szgn8TxENtWd0Tp4c3wjlRfMTMH27I+3Je41yGY=
|
||||
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
@ -532,6 +539,7 @@ github.com/ysmood/leakless v0.7.0 h1:XCGdaPExyoreoQd+H5qgxM3ReNbSPFsEXpSKwbXbwQw
|
||||
github.com/ysmood/leakless v0.7.0/go.mod h1:R8iAXPRaG97QJwqxs74RdwzcRHT1SWCGTNqY8q0JvMQ=
|
||||
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb h1:ZkM6LRnq40pR1Ox0hTHlnpkcOTuFIDQpZ1IN8rKKhX0=
|
||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb/go.mod h1:gqRgreBUhTSL0GeU64rtZ3Uq3wtjOa/TB2YfrtkCbVQ=
|
||||
github.com/zeebo/admission/v2 v2.0.0/go.mod h1:gSeHGelDHW7Vq6UyJo2boeSt/6Dsnqpisv0i4YZSOyM=
|
||||
@ -636,8 +644,9 @@ golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKG
|
||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
|
||||
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.3.0 h1:RM4zey1++hCTbCVQfnWeKs9/IEsaBLA8vTkd0WVtmH4=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2 h1:Gz96sIWK3OalVv/I/qNygP42zyoKp3xptRVCWRFEBvo=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
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=
|
||||
@ -665,8 +674,10 @@ golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/
|
||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
|
||||
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.0.0-20210428140749-89ef3d95e781 h1:DzZ89McO9/gWPsQXS/FVKAlG02ZjaQ6AlZRBimEYOd0=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
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=
|
||||
@ -723,11 +734,13 @@ golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200610111108-226ff32320da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201231184435-2d18734c6014/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210415045647-66c3f260301c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe h1:WdX7u8s3yOigWAhHEaDl8r9G+4XwFQEQFtBMYyN+kXQ=
|
||||
golang.org/x/sys v0.0.0-20210420072515-93ed5bcd2bfe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007 h1:gG67DSER+11cZvqIMb8S8bt0vZtiN6xWYARwirrOSfE=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
||||
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=
|
||||
@ -770,8 +783,9 @@ golang.org/x/tools v0.0.0-20191125144606-a911d9008d1f/go.mod h1:b+2E5dAYhXwXZwtn
|
||||
golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a h1:CB3a9Nez8M13wwlr/E2YtwoU+qYHKfC+JrDa45RXXoQ=
|
||||
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.1 h1:wGiQel/hW0NnEkJUk8lbzkX2gFJU6PFxf1v5OlCfuOs=
|
||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/xerrors v0.0.0-20190410155217-1f06c39b4373/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190513163551-3ee3066db522/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@ -876,8 +890,8 @@ sourcegraph.com/sqs/pbtypes v0.0.0-20180604144634-d3ebe8f20ae4/go.mod h1:ketZ/q3
|
||||
storj.io/common v0.0.0-20200424175742-65ac59022f4f/go.mod h1:pZyXiIE7bGETIRXtfs0nICqMwp7PM8HqnDuyUeldNA0=
|
||||
storj.io/common v0.0.0-20201026135900-1aaeec90670b/go.mod h1:GqdmNf3fLm2UZX/7Zr0BLFCJ4gFjgm6eHrk/fnmr5jQ=
|
||||
storj.io/common v0.0.0-20210504141454-bcb03a80052f/go.mod h1:PdP3eTld9RqSV3E4K44JSlw7Z/zNsymj9rnKuHFKhJE=
|
||||
storj.io/common v0.0.0-20210805073808-8e0feb09e92a h1:NXO/ZnLMWD67eYu2DPxGix5HVFzpv8teGexyR5xURjI=
|
||||
storj.io/common v0.0.0-20210805073808-8e0feb09e92a/go.mod h1:mhZYWpTojKsACxWE66RfXNz19zbyr/uEDVWHJH8dHog=
|
||||
storj.io/common v0.0.0-20210805230333-1ba6d8c2bfb1 h1:TA7ntnF1Gs2Kxm1PNGRk6mxMVhGdFPxbVHdkPrzsdVk=
|
||||
storj.io/common v0.0.0-20210805230333-1ba6d8c2bfb1/go.mod h1:ubZQYZozoKgjEkvaqmgBXqhLzKMXlLyDlK7EQdkGp/s=
|
||||
storj.io/drpc v0.0.11/go.mod h1:TiFc2obNjL9/3isMW1Rpxjy8V9uE0B2HMeMFGiiI7Iw=
|
||||
storj.io/drpc v0.0.14/go.mod h1:82nfl+6YwRwF6UG31cEWWUqv/FaKvP5SGqUvoqTxCMA=
|
||||
storj.io/drpc v0.0.20/go.mod h1:eAxUDk8HWvGl9iqznpuphtZ+WIjIGPJFqNXuKHgRiMM=
|
||||
|
@ -1,16 +0,0 @@
|
||||
// Copyright (C) 2021 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package quic
|
||||
|
||||
import (
|
||||
"github.com/spacemonkeygo/monkit/v3"
|
||||
"github.com/zeebo/errs"
|
||||
)
|
||||
|
||||
var (
|
||||
mon = monkit.Package()
|
||||
|
||||
// Error is a pkg/quic error.
|
||||
Error = errs.Class("quic")
|
||||
)
|
@ -1,249 +0,0 @@
|
||||
// Copyright (C) 2021 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package quic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"io"
|
||||
"net"
|
||||
"runtime"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/rpc"
|
||||
"storj.io/storj/private/quic/qtls"
|
||||
)
|
||||
|
||||
// Conn is a wrapper around a quic connection and fulfills net.Conn interface.
|
||||
type Conn struct {
|
||||
once sync.Once
|
||||
// The Conn.stream varible should never be directly accessed.
|
||||
// Always use Conn.getStream() instead.
|
||||
stream quic.Stream
|
||||
|
||||
acceptErr error
|
||||
session quic.Session
|
||||
}
|
||||
|
||||
// Read implements the Conn Read method.
|
||||
func (c *Conn) Read(b []byte) (n int, err error) {
|
||||
defer func() {
|
||||
if isSessionSuccessfulExit(err) {
|
||||
err = io.EOF
|
||||
}
|
||||
}()
|
||||
|
||||
stream, err := c.getStream()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
n, err = stream.Read(b)
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
// Write implements the Conn Write method.
|
||||
func (c *Conn) Write(b []byte) (_ int, err error) {
|
||||
defer func() {
|
||||
err = c.captureWriteErr(err)
|
||||
}()
|
||||
|
||||
stream, err := c.getStream()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
n, err := stream.Write(b)
|
||||
if err != nil {
|
||||
return n, err
|
||||
}
|
||||
return n, nil
|
||||
}
|
||||
|
||||
func (c *Conn) getStream() (quic.Stream, error) {
|
||||
// Outgoing connections `stream` gets set when the Conn is initialized.
|
||||
// It's only with incoming connections that `stream == nil` and this
|
||||
// AcceptStream() code happens.
|
||||
if c.stream == nil {
|
||||
// When this function completes, it guarantees either c.acceptErr is not nil or c.stream is not nil
|
||||
c.once.Do(func() {
|
||||
stream, err := c.session.AcceptStream(context.Background())
|
||||
if err != nil {
|
||||
c.acceptErr = err
|
||||
return
|
||||
}
|
||||
|
||||
c.stream = stream
|
||||
})
|
||||
if c.acceptErr != nil {
|
||||
return nil, c.acceptErr
|
||||
}
|
||||
}
|
||||
|
||||
return c.stream, nil
|
||||
}
|
||||
|
||||
// ConnectionState converts quic session state to tls connection state and returns tls state.
|
||||
func (c *Conn) ConnectionState() tls.ConnectionState {
|
||||
return qtls.ToTLSConnectionState(c.session.ConnectionState())
|
||||
}
|
||||
|
||||
// Close closes the quic connection.
|
||||
func (c *Conn) Close() error {
|
||||
return c.session.CloseWithError(0, "")
|
||||
}
|
||||
|
||||
// LocalAddr returns the local address.
|
||||
func (c *Conn) LocalAddr() net.Addr {
|
||||
return c.session.LocalAddr()
|
||||
}
|
||||
|
||||
// RemoteAddr returns the address of the peer.
|
||||
func (c *Conn) RemoteAddr() net.Addr {
|
||||
return c.session.RemoteAddr()
|
||||
}
|
||||
|
||||
// SetReadDeadline sets the deadline for future Read calls
|
||||
// and any currently-blocked Read call.
|
||||
func (c *Conn) SetReadDeadline(t time.Time) error {
|
||||
stream, err := c.getStream()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return stream.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
// SetWriteDeadline sets the deadline for future Write calls
|
||||
// and any currently-blocked Write call.
|
||||
func (c *Conn) SetWriteDeadline(t time.Time) error {
|
||||
stream, err := c.getStream()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return stream.SetWriteDeadline(t)
|
||||
}
|
||||
|
||||
// SetDeadline sets the read and write deadlines associated
|
||||
// with the connection. It is equivalent to calling both
|
||||
// SetReadDeadline and SetWriteDeadline.
|
||||
func (c *Conn) SetDeadline(t time.Time) error {
|
||||
stream, err := c.getStream()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return stream.SetDeadline(t)
|
||||
}
|
||||
|
||||
// isSessionSuccessfulExit determines whether an error as returned from a network
|
||||
// operation is a QUIC "successful exit" application code.
|
||||
//
|
||||
// This is pretty awful.
|
||||
//
|
||||
// The reason is that quic-go, in its wisdom, has decided not to export any
|
||||
// fields or interfaces whatsoever that we could use to access the error code
|
||||
// from a "github.com/lucas-clemente/quic-go/internal/qerr".(*QuicError)
|
||||
// instance.
|
||||
func isSessionSuccessfulExit(err error) bool {
|
||||
return err != nil && err.Error() == "Application error 0x0"
|
||||
}
|
||||
|
||||
func (c *Conn) captureWriteErr(err error) error {
|
||||
if isSessionSuccessfulExit(err) {
|
||||
opErr := &net.OpError{
|
||||
Op: "write",
|
||||
Net: "quic",
|
||||
Source: c.LocalAddr(),
|
||||
Addr: c.RemoteAddr(),
|
||||
Err: syscall.ECONNRESET,
|
||||
}
|
||||
|
||||
if c.acceptErr != nil {
|
||||
opErr.Op = "accept"
|
||||
}
|
||||
return opErr
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
//
|
||||
// timed conns
|
||||
//
|
||||
|
||||
// timedConn wraps a rpc.ConnectorConn so that all reads and writes get the specified timeout and
|
||||
// return bytes no faster than the rate. If the timeout or rate are zero, they are
|
||||
// ignored.
|
||||
type timedConn struct {
|
||||
rpc.ConnectorConn
|
||||
rate memory.Size
|
||||
}
|
||||
|
||||
// now returns time.Now if there's a nonzero rate.
|
||||
func (t *timedConn) now() (now time.Time) {
|
||||
if t.rate > 0 {
|
||||
now = time.Now()
|
||||
}
|
||||
return now
|
||||
}
|
||||
|
||||
// delay ensures that we sleep to keep the rate if it is nonzero. n is the number of
|
||||
// bytes in the read or write operation we need to delay.
|
||||
func (t *timedConn) delay(start time.Time, n int) {
|
||||
if t.rate > 0 {
|
||||
expected := time.Duration(n * int(time.Second) / t.rate.Int())
|
||||
if actual := time.Since(start); expected > actual {
|
||||
time.Sleep(expected - actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Read wraps the connection read and adds sleeping to ensure the rate.
|
||||
func (t *timedConn) Read(p []byte) (int, error) {
|
||||
start := t.now()
|
||||
n, err := t.ConnectorConn.Read(p)
|
||||
t.delay(start, n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Write wraps the connection write and adds sleeping to ensure the rate.
|
||||
func (t *timedConn) Write(p []byte) (int, error) {
|
||||
start := t.now()
|
||||
n, err := t.ConnectorConn.Write(p)
|
||||
t.delay(start, n)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// closeTrackingConn wraps a rpc.ConnectorConn and keeps track of if it was closed
|
||||
// or if it was leaked (and closes it if it was leaked).
|
||||
type closeTrackingConn struct {
|
||||
rpc.ConnectorConn
|
||||
}
|
||||
|
||||
// TrackClose wraps the conn and sets a finalizer on the returned value to
|
||||
// close the conn and monitor that it was leaked.
|
||||
func TrackClose(conn rpc.ConnectorConn) rpc.ConnectorConn {
|
||||
tracked := &closeTrackingConn{ConnectorConn: conn}
|
||||
runtime.SetFinalizer(tracked, (*closeTrackingConn).finalize)
|
||||
return tracked
|
||||
}
|
||||
|
||||
// Close clears the finalizer and closes the connection.
|
||||
func (c *closeTrackingConn) Close() error {
|
||||
runtime.SetFinalizer(c, nil)
|
||||
mon.Event("quic_connection_closed")
|
||||
return c.ConnectorConn.Close()
|
||||
}
|
||||
|
||||
// finalize monitors that a connection was leaked and closes the connection.
|
||||
func (c *closeTrackingConn) finalize() {
|
||||
mon.Event("quic_connection_leaked")
|
||||
_ = c.ConnectorConn.Close()
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
// Copyright (C) 2021 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package quic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/peertls/tlsopts"
|
||||
"storj.io/common/rpc"
|
||||
)
|
||||
|
||||
// Connector implements a dialer that creates a quic connection.
|
||||
type Connector struct {
|
||||
transferRate memory.Size
|
||||
|
||||
config *quic.Config
|
||||
}
|
||||
|
||||
// NewDefaultConnector instantiates a new instance of Connector.
|
||||
// If no quic configuration is provided, default value will be used.
|
||||
func NewDefaultConnector(quicConfig *quic.Config) Connector {
|
||||
if quicConfig == nil {
|
||||
quicConfig = &quic.Config{
|
||||
MaxIdleTimeout: 15 * time.Minute,
|
||||
KeepAlive: true,
|
||||
}
|
||||
}
|
||||
return Connector{
|
||||
config: quicConfig,
|
||||
}
|
||||
}
|
||||
|
||||
// DialContext creates a quic connection.
|
||||
func (c Connector) DialContext(ctx context.Context, tlsConfig *tls.Config, address string) (_ rpc.ConnectorConn, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if tlsConfig == nil {
|
||||
return nil, Error.New("tls config is not set")
|
||||
}
|
||||
tlsConfigCopy := tlsConfig.Clone()
|
||||
tlsConfigCopy.NextProtos = []string{tlsopts.StorjApplicationProtocol}
|
||||
|
||||
sess, err := quic.DialAddrContext(ctx, address, tlsConfigCopy, c.config)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
||||
stream, err := sess.OpenStreamSync(ctx)
|
||||
if err != nil {
|
||||
return nil, Error.Wrap(err)
|
||||
}
|
||||
|
||||
conn := &Conn{
|
||||
session: sess,
|
||||
stream: stream,
|
||||
}
|
||||
|
||||
return &timedConn{
|
||||
ConnectorConn: TrackClose(conn),
|
||||
rate: c.transferRate,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// SetTransferRate returns a QUIC connector with the given transfer rate.
|
||||
func (c Connector) SetTransferRate(rate memory.Size) Connector {
|
||||
c.transferRate = rate
|
||||
return c
|
||||
}
|
||||
|
||||
// TransferRate returns the transfer rate set on the connector.
|
||||
func (c Connector) TransferRate() memory.Size {
|
||||
return c.transferRate
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
// Copyright (C) 2021 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package quic
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"net"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/common/peertls/tlsopts"
|
||||
)
|
||||
|
||||
// Listener implements listener for QUIC.
|
||||
type Listener struct {
|
||||
listener quic.Listener
|
||||
conn *net.UDPConn
|
||||
}
|
||||
|
||||
// NewListener returns a new listener instance for QUIC.
|
||||
// The quic.Config may be nil, in that case the default values will be used.
|
||||
// if the provided context is closed, all existing or following Accept calls will return an error.
|
||||
func NewListener(conn *net.UDPConn, tlsConfig *tls.Config, quicConfig *quic.Config) (net.Listener, error) {
|
||||
if conn == nil {
|
||||
return nil, Error.New("underlying udp connection can't be nil")
|
||||
}
|
||||
if tlsConfig == nil {
|
||||
return nil, Error.New("tls config is not set")
|
||||
}
|
||||
tlsConfigCopy := tlsConfig.Clone()
|
||||
tlsConfigCopy.NextProtos = []string{tlsopts.StorjApplicationProtocol}
|
||||
|
||||
listener, err := quic.Listen(conn, tlsConfigCopy, quicConfig)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Listener{
|
||||
listener: listener,
|
||||
conn: conn,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Accept waits for and returns the next available quic session to the listener.
|
||||
func (l *Listener) Accept() (net.Conn, error) {
|
||||
ctx := context.Background()
|
||||
session, err := l.listener.Accept(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &Conn{
|
||||
session: session,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Close closes the QUIC listener.
|
||||
func (l *Listener) Close() (err error) {
|
||||
return errs.Combine(l.listener.Close(), l.conn.Close())
|
||||
}
|
||||
|
||||
// Addr returns the local network addr that the server is listening on.
|
||||
func (l *Listener) Addr() net.Addr {
|
||||
return l.listener.Addr()
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
// Copyright (C) 2021 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
// +build !go1.15
|
||||
|
||||
package qtls
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
|
||||
quicgo "github.com/lucas-clemente/quic-go"
|
||||
)
|
||||
|
||||
// ToTLSConnectionState converts a quic-go connection state to tls connection
|
||||
// state.
|
||||
func ToTLSConnectionState(state quicgo.ConnectionState) tls.ConnectionState {
|
||||
return tls.ConnectionState{
|
||||
Version: state.TLS.Version,
|
||||
HandshakeComplete: state.TLS.HandshakeComplete,
|
||||
DidResume: state.TLS.DidResume,
|
||||
CipherSuite: state.TLS.CipherSuite,
|
||||
NegotiatedProtocol: state.TLS.NegotiatedProtocol,
|
||||
ServerName: state.TLS.ServerName,
|
||||
PeerCertificates: state.TLS.PeerCertificates,
|
||||
VerifiedChains: state.TLS.VerifiedChains,
|
||||
SignedCertificateTimestamps: state.TLS.SignedCertificateTimestamps,
|
||||
OCSPResponse: state.TLS.OCSPResponse,
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
// Copyright (C) 2021 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
// +build go1.15
|
||||
|
||||
package qtls
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
|
||||
quicgo "github.com/lucas-clemente/quic-go"
|
||||
)
|
||||
|
||||
// ToTLSConnectionState converts a quic-go connection state to tls connection
|
||||
// state.
|
||||
func ToTLSConnectionState(state quicgo.ConnectionState) tls.ConnectionState {
|
||||
return state.TLS.ConnectionState
|
||||
}
|
@ -1,131 +0,0 @@
|
||||
// Copyright (C) 2021 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package server
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/common/memory"
|
||||
"storj.io/common/rpc"
|
||||
"storj.io/storj/private/quic"
|
||||
)
|
||||
|
||||
// HybridConnector implements a dialer that creates a connection using either
|
||||
// quic or tcp.
|
||||
type HybridConnector struct {
|
||||
quic *quic.Connector
|
||||
tcp *rpc.TCPConnector
|
||||
}
|
||||
|
||||
// NewDefaultHybridConnector instantiates a new instance of HybridConnector with
|
||||
// provided quic and tcp connectors.
|
||||
// If a nil value is provided for either connector, a default connector will be
|
||||
// created instead.
|
||||
// See func DialContext for more details.
|
||||
func NewDefaultHybridConnector(qc *quic.Connector, tc *rpc.TCPConnector) HybridConnector {
|
||||
if qc == nil {
|
||||
connector := quic.NewDefaultConnector(nil)
|
||||
qc = &connector
|
||||
}
|
||||
if tc == nil {
|
||||
connector := rpc.NewDefaultTCPConnector(nil)
|
||||
tc = &connector
|
||||
}
|
||||
|
||||
return HybridConnector{
|
||||
quic: qc,
|
||||
tcp: tc,
|
||||
}
|
||||
}
|
||||
|
||||
// DialContext creates a connection using either quic or tcp.
|
||||
// It tries to dial through both connector and returns the first established
|
||||
// connection. If both connections are established, it will return quic connection.
|
||||
// An error is returned if both connector failed.
|
||||
func (c HybridConnector) DialContext(ctx context.Context, tlsConfig *tls.Config, address string) (_ rpc.ConnectorConn, err error) {
|
||||
defer mon.Task()(&ctx)(&err)
|
||||
|
||||
if tlsConfig == nil {
|
||||
return nil, Error.New("tls config is not set")
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithCancel(ctx)
|
||||
defer cancel()
|
||||
|
||||
var tcpConn, quicConn rpc.ConnectorConn
|
||||
errChan := make(chan error)
|
||||
readyChan := make(chan struct{})
|
||||
|
||||
go func() {
|
||||
var err error
|
||||
quicConn, err = c.quic.DialContext(ctx, tlsConfig.Clone(), address)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
|
||||
readyChan <- struct{}{}
|
||||
}()
|
||||
go func() {
|
||||
var err error
|
||||
tcpConn, err = c.tcp.DialContext(ctx, tlsConfig.Clone(), address)
|
||||
if err != nil {
|
||||
errChan <- err
|
||||
return
|
||||
}
|
||||
|
||||
readyChan <- struct{}{}
|
||||
}()
|
||||
|
||||
var errors []error
|
||||
var numFinished int
|
||||
// makre sure both dial is finished either with an established connection or
|
||||
// an error. It allows us to appropriately close tcp connection if both
|
||||
// connections are ready around the same time
|
||||
for numFinished < 2 {
|
||||
select {
|
||||
case <-readyChan:
|
||||
numFinished++
|
||||
// if one connection is ready, we want to cancel the other dial if
|
||||
// the connection isn't ready
|
||||
cancel()
|
||||
case err := <-errChan:
|
||||
numFinished++
|
||||
errors = append(errors, err)
|
||||
}
|
||||
}
|
||||
|
||||
// we want to prioritize quic conn if both connections are available
|
||||
if quicConn != nil {
|
||||
if tcpConn != nil {
|
||||
_ = tcpConn.Close()
|
||||
}
|
||||
|
||||
mon.Event("hybrid_connector_established_quic_connection")
|
||||
return quicConn, nil
|
||||
}
|
||||
|
||||
if tcpConn != nil {
|
||||
mon.Event("hybrid_connector_established_tcp_connection")
|
||||
return tcpConn, nil
|
||||
}
|
||||
|
||||
mon.Event("hybrid_connector_established_no_connection")
|
||||
|
||||
return nil, errs.Combine(errors...)
|
||||
}
|
||||
|
||||
// SetQUICTransferRate returns a connector with the given transfer rate.
|
||||
func (c *HybridConnector) SetQUICTransferRate(rate memory.Size) {
|
||||
updated := c.quic.SetTransferRate(rate)
|
||||
c.quic = &updated
|
||||
}
|
||||
|
||||
// SetTCPTransferRate returns a connector with the given transfer rate.
|
||||
func (c *HybridConnector) SetTCPTransferRate(rate memory.Size) {
|
||||
c.tcp.TransferRate = rate
|
||||
}
|
@ -7,29 +7,16 @@ import (
|
||||
"net"
|
||||
"time"
|
||||
|
||||
quicgo "github.com/lucas-clemente/quic-go"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/common/netutil"
|
||||
"storj.io/common/rpc"
|
||||
"storj.io/storj/private/quic"
|
||||
"storj.io/common/rpc/quic"
|
||||
)
|
||||
|
||||
// defaultUserTimeout is the value we use for the TCP_USER_TIMEOUT setting.
|
||||
const defaultUserTimeout = 60 * time.Second
|
||||
|
||||
// defaultQUICConfig is the value we use for QUIC setting.
|
||||
func defaultQUICConfig() *quicgo.Config {
|
||||
return &quicgo.Config{
|
||||
MaxIdleTimeout: defaultUserTimeout,
|
||||
// disable address validation in QUIC (it costs an extra round-trip, and we believe
|
||||
// it to be unnecessary given the low potential for traffic amplification attacks).
|
||||
AcceptToken: func(clientAddr net.Addr, token *quicgo.Token) bool {
|
||||
return true
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// wrapListener wraps the provided net.Listener in one that sets timeouts
|
||||
// and monitors if the returned connections are closed or leaked.
|
||||
func wrapListener(lis net.Listener) net.Listener {
|
||||
|
@ -20,12 +20,12 @@ import (
|
||||
"storj.io/common/identity"
|
||||
"storj.io/common/peertls/tlsopts"
|
||||
"storj.io/common/rpc"
|
||||
"storj.io/common/rpc/quic"
|
||||
"storj.io/common/rpc/rpctracing"
|
||||
"storj.io/drpc/drpcmigrate"
|
||||
"storj.io/drpc/drpcmux"
|
||||
"storj.io/drpc/drpcserver"
|
||||
jaeger "storj.io/monkit-jaeger"
|
||||
"storj.io/storj/private/quic"
|
||||
)
|
||||
|
||||
// Config holds server specific configuration parameters.
|
||||
@ -169,7 +169,7 @@ func (p *Server) Run(ctx context.Context) (err error) {
|
||||
}
|
||||
|
||||
if p.public.udpConn != nil {
|
||||
p.public.quicListener, err = quic.NewListener(p.public.udpConn, p.tlsOptions.ServerTLSConfig(), defaultQUICConfig())
|
||||
p.public.quicListener, err = quic.NewListener(p.public.udpConn, p.tlsOptions.ServerTLSConfig(), nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -10,9 +10,10 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"storj.io/common/peertls/tlsopts"
|
||||
"storj.io/common/rpc"
|
||||
_ "storj.io/common/rpc/quic"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/storj/private/server"
|
||||
"storj.io/storj/private/testplanet"
|
||||
)
|
||||
|
||||
@ -25,7 +26,7 @@ func TestHybridConnector_Basic(t *testing.T) {
|
||||
sat := planet.Satellites[0]
|
||||
dialer := planet.Uplinks[0].Dialer
|
||||
|
||||
dialer.Connector = server.NewDefaultHybridConnector(nil, nil)
|
||||
dialer.Connector = rpc.NewHybridConnector()
|
||||
|
||||
conn, err := dialer.Connector.DialContext(ctx, dialer.TLSOptions.ClientTLSConfig(sat.ID()), sat.Addr())
|
||||
require.NoError(t, err)
|
||||
@ -49,7 +50,7 @@ func TestHybridConnector_QUICOnly(t *testing.T) {
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
connector := server.NewDefaultHybridConnector(nil, nil)
|
||||
connector := rpc.NewHybridConnector()
|
||||
|
||||
conn, err := connector.DialContext(ctx, tlsOptions.ClientTLSConfig(sat.ID()), sat.Addr())
|
||||
require.NoError(t, err)
|
||||
@ -74,7 +75,7 @@ func TestHybridConnector_TCPOnly(t *testing.T) {
|
||||
}, nil)
|
||||
require.NoError(t, err)
|
||||
|
||||
connector := server.NewDefaultHybridConnector(nil, nil)
|
||||
connector := rpc.NewHybridConnector()
|
||||
|
||||
conn, err := connector.DialContext(ctx, tlsOptions.ClientTLSConfig(sat.ID()), sat.Addr())
|
||||
require.NoError(t, err)
|
@ -16,9 +16,9 @@ import (
|
||||
"storj.io/common/identity/testidentity"
|
||||
"storj.io/common/peertls/tlsopts"
|
||||
"storj.io/common/rpc"
|
||||
"storj.io/common/rpc/quic"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/common/testcontext"
|
||||
"storj.io/storj/private/quic"
|
||||
"storj.io/storj/private/testplanet"
|
||||
"storj.io/storj/satellite"
|
||||
"storj.io/storj/storagenode"
|
||||
|
@ -14,9 +14,9 @@ import (
|
||||
|
||||
"storj.io/common/pb"
|
||||
"storj.io/common/rpc"
|
||||
"storj.io/common/rpc/quic"
|
||||
"storj.io/common/rpc/rpcstatus"
|
||||
"storj.io/common/storj"
|
||||
"storj.io/storj/private/quic"
|
||||
"storj.io/storj/satellite/overlay"
|
||||
)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user