Debian Codegraph @

debian/patches/backport/07-Chore-bump-github.com-lucas-clemente-quic-go.patch

raw
1 From: =?utf-8?b?56eL44Gu44GL44GI44Gn?= <[email protected]>
2 Date: Wed, 6 Apr 2022 12:29:11 +0800
3 Subject: Chore: bump github.com/lucas-clemente/quic-go from 0.26.0 to 0.27.0
4
5 (cherry picked from commit 23816b25645365bd33bdcba022dd6f368b3cc3a2)
6
7 Closes: #1019844
8 ---
9 app/dns/nameserver_quic.go | 42 +++++++--------
10 transport/internet/quic/dialer.go | 104 +++++++++++++++++++-------------------
11 transport/internet/quic/hub.go | 16 +++---
12 3 files changed, 81 insertions(+), 81 deletions(-)
13
14 diff --git a/app/dns/nameserver_quic.go b/app/dns/nameserver_quic.go
15 index 049705e..7acfc24 100644
16 --- a/app/dns/nameserver_quic.go
17 +++ b/app/dns/nameserver_quic.go
18 @@ -38,7 +38,7 @@ type QUICNameServer struct {
19 reqID uint32
20 name string
21 destination net.Destination
22 - session quic.Session
23 + connection quic.Connection
24 }
25
26 // NewQUICNameServer creates DNS-over-QUIC client object for local resolving
27 @@ -192,7 +192,7 @@ func (s *QUICNameServer) sendQuery(ctx context.Context, domain string, clientIP
28
29 conn, err := s.openStream(dnsCtx)
30 if err != nil {
31 - newError("failed to open quic session").Base(err).AtError().WriteToLog()
32 + newError("failed to open quic connection").Base(err).AtError().WriteToLog()
33 return
34 }
35
36 @@ -316,7 +316,7 @@ func (s *QUICNameServer) QueryIP(ctx context.Context, domain string, clientIP ne
37 }
38 }
39
40 -func isActive(s quic.Session) bool {
41 +func isActive(s quic.Connection) bool {
42 select {
43 case <-s.Context().Done():
44 return false
45 @@ -325,17 +325,17 @@ func isActive(s quic.Session) bool {
46 }
47 }
48
49 -func (s *QUICNameServer) getSession() (quic.Session, error) {
50 - var session quic.Session
51 +func (s *QUICNameServer) getConnection() (quic.Connection, error) {
52 + var conn quic.Connection
53 s.RLock()
54 - session = s.session
55 - if session != nil && isActive(session) {
56 + conn = s.connection
57 + if conn != nil && isActive(conn) {
58 s.RUnlock()
59 - return session, nil
60 + return conn, nil
61 }
62 - if session != nil {
63 - // we're recreating the session, let's create a new one
64 - _ = session.CloseWithError(0, "")
65 + if conn != nil {
66 + // we're recreating the connection, let's create a new one
67 + _ = conn.CloseWithError(0, "")
68 }
69 s.RUnlock()
70
71 @@ -343,42 +343,42 @@ func (s *QUICNameServer) getSession() (quic.Session, error) {
72 defer s.Unlock()
73
74 var err error
75 - session, err = s.openSession()
76 + conn, err = s.openConnection()
77 if err != nil {
78 // This does not look too nice, but QUIC (or maybe quic-go)
79 // doesn't seem stable enough.
80 // Maybe retransmissions aren't fully implemented in quic-go?
81 // Anyways, the simple solution is to make a second try when
82 - // it fails to open the QUIC session.
83 - session, err = s.openSession()
84 + // it fails to open the QUIC connection.
85 + conn, err = s.openConnection()
86 if err != nil {
87 return nil, err
88 }
89 }
90 - s.session = session
91 - return session, nil
92 + s.connection = conn
93 + return conn, nil
94 }
95
96 -func (s *QUICNameServer) openSession() (quic.Session, error) {
97 +func (s *QUICNameServer) openConnection() (quic.Connection, error) {
98 tlsConfig := tls.Config{}
99 quicConfig := &quic.Config{
100 HandshakeIdleTimeout: handshakeIdleTimeout,
101 }
102
103 - session, err := quic.DialAddrContext(context.Background(), s.destination.NetAddr(), tlsConfig.GetTLSConfig(tls.WithNextProto("http/1.1", http2.NextProtoTLS, NextProtoDQ)), quicConfig)
104 + conn, err := quic.DialAddrContext(context.Background(), s.destination.NetAddr(), tlsConfig.GetTLSConfig(tls.WithNextProto("http/1.1", http2.NextProtoTLS, NextProtoDQ)), quicConfig)
105 if err != nil {
106 return nil, err
107 }
108
109 - return session, nil
110 + return conn, nil
111 }
112
113 func (s *QUICNameServer) openStream(ctx context.Context) (quic.Stream, error) {
114 - session, err := s.getSession()
115 + conn, err := s.getConnection()
116 if err != nil {
117 return nil, err
118 }
119
120 // open a new stream
121 - return session.OpenStreamSync(ctx)
122 + return conn.OpenStreamSync(ctx)
123 }
124 diff --git a/transport/internet/quic/dialer.go b/transport/internet/quic/dialer.go
125 index a44af58..7dc891b 100644
126 --- a/transport/internet/quic/dialer.go
127 +++ b/transport/internet/quic/dialer.go
128 @@ -15,39 +15,39 @@ import (
129 "v2ray.com/core/transport/internet/tls"
130 )
131
132 -type sessionContext struct {
133 +type connectionContext struct {
134 rawConn *sysConn
135 - session quic.Session
136 + conn quic.Connection
137 }
138
139 -var errSessionClosed = newError("session closed")
140 +var errConnectionClosed = newError("connection closed")
141
142 -func (c *sessionContext) openStream(destAddr net.Addr) (*interConn, error) {
143 - if !isActive(c.session) {
144 - return nil, errSessionClosed
145 +func (c *connectionContext) openStream(destAddr net.Addr) (*interConn, error) {
146 + if !isActive(c.conn) {
147 + return nil, errConnectionClosed
148 }
149
150 - stream, err := c.session.OpenStream()
151 + stream, err := c.conn.OpenStream()
152 if err != nil {
153 return nil, err
154 }
155
156 conn := &interConn{
157 stream: stream,
158 - local: c.session.LocalAddr(),
159 + local: c.conn.LocalAddr(),
160 remote: destAddr,
161 }
162
163 return conn, nil
164 }
165
166 -type clientSessions struct {
167 - access sync.Mutex
168 - sessions map[net.Destination][]*sessionContext
169 - cleanup *task.Periodic
170 +type clientConnections struct {
171 + access sync.Mutex
172 + conns map[net.Destination][]*connectionContext
173 + cleanup *task.Periodic
174 }
175
176 -func isActive(s quic.Session) bool {
177 +func isActive(s quic.Connection) bool {
178 select {
179 case <-s.Context().Done():
180 return false
181 @@ -56,31 +56,31 @@ func isActive(s quic.Session) bool {
182 }
183 }
184
185 -func removeInactiveSessions(sessions []*sessionContext) []*sessionContext {
186 - activeSessions := make([]*sessionContext, 0, len(sessions))
187 - for _, s := range sessions {
188 - if isActive(s.session) {
189 - activeSessions = append(activeSessions, s)
190 +func removeInactiveConnections(conns []*connectionContext) []*connectionContext {
191 + activeConnections := make([]*connectionContext, 0, len(conns))
192 + for _, s := range conns {
193 + if isActive(s.conn) {
194 + activeConnections = append(activeConnections, s)
195 continue
196 }
197 - if err := s.session.CloseWithError(0, ""); err != nil {
198 - newError("failed to close session").Base(err).WriteToLog()
199 + if err := s.conn.CloseWithError(0, ""); err != nil {
200 + newError("failed to close connection").Base(err).WriteToLog()
201 }
202 if err := s.rawConn.Close(); err != nil {
203 newError("failed to close raw connection").Base(err).WriteToLog()
204 }
205 }
206
207 - if len(activeSessions) < len(sessions) {
208 - return activeSessions
209 + if len(activeConnections) < len(conns) {
210 + return activeConnections
211 }
212
213 - return sessions
214 + return conns
215 }
216
217 -func openStream(sessions []*sessionContext, destAddr net.Addr) *interConn {
218 - for _, s := range sessions {
219 - if !isActive(s.session) {
220 +func openStream(conns []*connectionContext, destAddr net.Addr) *interConn {
221 + for _, s := range conns {
222 + if !isActive(s.conn) {
223 continue
224 }
225
226 @@ -95,50 +95,50 @@ func openStream(sessions []*sessionContext, destAddr net.Addr) *interConn {
227 return nil
228 }
229
230 -func (s *clientSessions) cleanSessions() error {
231 +func (s *clientConnections) cleanConnections() error {
232 s.access.Lock()
233 defer s.access.Unlock()
234
235 - if len(s.sessions) == 0 {
236 + if len(s.conns) == 0 {
237 return nil
238 }
239
240 - newSessionMap := make(map[net.Destination][]*sessionContext)
241 + newConnMap := make(map[net.Destination][]*connectionContext)
242
243 - for dest, sessions := range s.sessions {
244 - sessions = removeInactiveSessions(sessions)
245 - if len(sessions) > 0 {
246 - newSessionMap[dest] = sessions
247 + for dest, conns := range s.conns {
248 + conns = removeInactiveConnections(conns)
249 + if len(conns) > 0 {
250 + newConnMap[dest] = conns
251 }
252 }
253
254 - s.sessions = newSessionMap
255 + s.conns = newConnMap
256 return nil
257 }
258
259 -func (s *clientSessions) openConnection(destAddr net.Addr, config *Config, tlsConfig *tls.Config, sockopt *internet.SocketConfig) (internet.Connection, error) {
260 +func (s *clientConnections) openConnection(destAddr net.Addr, config *Config, tlsConfig *tls.Config, sockopt *internet.SocketConfig) (internet.Connection, error) {
261 s.access.Lock()
262 defer s.access.Unlock()
263
264 - if s.sessions == nil {
265 - s.sessions = make(map[net.Destination][]*sessionContext)
266 + if s.conns == nil {
267 + s.conns = make(map[net.Destination][]*connectionContext)
268 }
269
270 dest := net.DestinationFromAddr(destAddr)
271
272 - var sessions []*sessionContext
273 - if s, found := s.sessions[dest]; found {
274 - sessions = s
275 + var conns []*connectionContext
276 + if s, found := s.conns[dest]; found {
277 + conns = s
278 }
279
280 if true {
281 - conn := openStream(sessions, destAddr)
282 + conn := openStream(conns, destAddr)
283 if conn != nil {
284 return conn, nil
285 }
286 }
287
288 - sessions = removeInactiveSessions(sessions)
289 + conns = removeInactiveConnections(conns)
290
291 rawConn, err := internet.ListenSystemPacket(context.Background(), &net.UDPAddr{
292 IP: []byte{0, 0, 0, 0},
293 @@ -154,33 +154,33 @@ func (s *clientSessions) openConnection(destAddr net.Addr, config *Config, tlsCo
294 MaxIdleTimeout: time.Second * 30,
295 }
296
297 - conn, err := wrapSysConn(rawConn, config)
298 + sysConn, err := wrapSysConn(rawConn, config)
299 if err != nil {
300 rawConn.Close()
301 return nil, err
302 }
303
304 - session, err := quic.DialContext(context.Background(), conn, destAddr, "", tlsConfig.GetTLSConfig(tls.WithDestination(dest)), quicConfig)
305 + conn, err := quic.DialContext(context.Background(), sysConn, destAddr, "", tlsConfig.GetTLSConfig(tls.WithDestination(dest)), quicConfig)
306 if err != nil {
307 - conn.Close()
308 + sysConn.Close()
309 return nil, err
310 }
311
312 - context := &sessionContext{
313 - session: session,
314 - rawConn: conn,
315 + context := &connectionContext{
316 + conn: conn,
317 + rawConn: sysConn,
318 }
319 - s.sessions[dest] = append(sessions, context)
320 + s.conns[dest] = append(conns, context)
321 return context.openStream(destAddr)
322 }
323
324 -var client clientSessions
325 +var client clientConnections
326
327 func init() {
328 - client.sessions = make(map[net.Destination][]*sessionContext)
329 + client.conns = make(map[net.Destination][]*connectionContext)
330 client.cleanup = &task.Periodic{
331 Interval: time.Minute,
332 - Execute: client.cleanSessions,
333 + Execute: client.cleanConnections,
334 }
335 common.Must(client.cleanup.Start())
336 }
337 diff --git a/transport/internet/quic/hub.go b/transport/internet/quic/hub.go
338 index dda8ce7..d3e0622 100644
339 --- a/transport/internet/quic/hub.go
340 +++ b/transport/internet/quic/hub.go
341 @@ -23,17 +23,17 @@ type Listener struct {
342 addConn internet.ConnHandler
343 }
344
345 -func (l *Listener) acceptStreams(session quic.Session) {
346 +func (l *Listener) acceptStreams(conn quic.Connection) {
347 for {
348 - stream, err := session.AcceptStream(context.Background())
349 + stream, err := conn.AcceptStream(context.Background())
350 if err != nil {
351 newError("failed to accept stream").Base(err).WriteToLog()
352 select {
353 - case <-session.Context().Done():
354 + case <-conn.Context().Done():
355 return
356 case <-l.done.Wait():
357 - if err := session.CloseWithError(0, ""); err != nil {
358 - newError("failed to close session").Base(err).WriteToLog()
359 + if err := conn.CloseWithError(0, ""); err != nil {
360 + newError("failed to close connection").Base(err).WriteToLog()
361 }
362 return
363 default:
364 @@ -44,8 +44,8 @@ func (l *Listener) acceptStreams(session quic.Session) {
365
366 conn := &interConn{
367 stream: stream,
368 - local: session.LocalAddr(),
369 - remote: session.RemoteAddr(),
370 + local: conn.LocalAddr(),
371 + remote: conn.RemoteAddr(),
372 }
373
374 l.addConn(conn)
375 @@ -56,7 +56,7 @@ func (l *Listener) keepAccepting() {
376 for {
377 conn, err := l.listener.Accept(context.Background())
378 if err != nil {
379 - newError("failed to accept QUIC sessions").Base(err).WriteToLog()
380 + newError("failed to accept QUIC connections").Base(err).WriteToLog()
381 if l.done.Done() {
382 break
383 }