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