Просмотр исходного кода

Use refraction-networking/conjure v0.7.10-0.20231110193225-e4749a9dedc9

- Concurrent DTLS client->server and server->client dial attempts
Rod Hynes 2 лет назад
Родитель
Сommit
28909de443

+ 1 - 1
go.mod

@@ -33,7 +33,7 @@ require (
 	github.com/oschwald/maxminddb-golang v1.12.0
 	github.com/patrickmn/go-cache v2.1.0+incompatible
 	github.com/pion/sctp v1.8.8
-	github.com/refraction-networking/conjure v0.7.9
+	github.com/refraction-networking/conjure v0.7.10-0.20231110193225-e4749a9dedc9
 	github.com/refraction-networking/gotapdance v1.7.7
 	github.com/refraction-networking/utls v1.3.3
 	github.com/ryanuber/go-glob v0.0.0-20170128012129-256dc444b735

+ 4 - 0
go.sum

@@ -178,6 +178,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/refraction-networking/conjure v0.7.9 h1:ABEtW1treui43vP0LlCslfw274bIyFaoxDB59BzUrl4=
 github.com/refraction-networking/conjure v0.7.9/go.mod h1:O5u/Mpg5b3whLF8L701pTMQW23SviS+rDKdWbY/BM0Q=
+github.com/refraction-networking/conjure v0.7.10-0.20231110185258-440efbc194c2 h1:XAEn6rgTrzZrHYSWWvWVNzFyGADLv0n1SR2c2POZ2go=
+github.com/refraction-networking/conjure v0.7.10-0.20231110185258-440efbc194c2/go.mod h1:O5u/Mpg5b3whLF8L701pTMQW23SviS+rDKdWbY/BM0Q=
+github.com/refraction-networking/conjure v0.7.10-0.20231110193225-e4749a9dedc9 h1:46+z0lVJL5ynP09dtThex4GiowaANoBk7DsNF0+a+7Q=
+github.com/refraction-networking/conjure v0.7.10-0.20231110193225-e4749a9dedc9/go.mod h1:O5u/Mpg5b3whLF8L701pTMQW23SviS+rDKdWbY/BM0Q=
 github.com/refraction-networking/ed25519 v0.1.2 h1:08kJZUkAlY7a7cZGosl1teGytV+QEoNxPO7NnRvAB+g=
 github.com/refraction-networking/ed25519 v0.1.2/go.mod h1:nxYLUAYt/hmNpAh64PNSQ/tQ9gTIB89wCaGKJlRtZ9I=
 github.com/refraction-networking/gotapdance v1.7.7 h1:RSdDCA0v4n/iIxCnxLF6uCoJdlo000R+IKGvELfpc/A=

+ 33 - 17
vendor/github.com/refraction-networking/conjure/pkg/transports/connecting/dtls/client.go

@@ -5,6 +5,7 @@ import (
 	"fmt"
 	"io"
 	"net"
+	"strings"
 	"sync"
 	"time"
 
@@ -44,7 +45,6 @@ type ClientTransport struct {
 	psk                 []byte
 	stunServer          string
 	disableIRWorkaround bool
-	listenTimeout       *time.Duration
 }
 
 type ClientConfig struct {
@@ -132,7 +132,6 @@ func (t *ClientTransport) SetParams(p any) error {
 	case *ClientConfig:
 		t.stunServer = params.STUNServer
 		t.disableIRWorkaround = params.DisableIRWorkaround
-		t.listenTimeout = params.ListenTimeout
 	}
 
 	return nil
@@ -205,27 +204,44 @@ func (t *ClientTransport) GetDstPort(seed []byte) (uint16, error) {
 
 func (t *ClientTransport) WrapDial(dialer dialFunc) (dialFunc, error) {
 	dtlsDialer := func(ctx context.Context, network, localAddr, address string) (net.Conn, error) {
-		// Create a context that will automatically cancel after 5 seconds or when the existing context is cancelled, whichever comes first.
-		timeout := t.listenTimeout
-		if timeout == nil {
-			time := defaultListenTime
-			timeout = &time
-		}
-		ctxtimeout, cancel := context.WithTimeout(ctx, *timeout)
+
+		dialCtx, cancel := context.WithCancel(ctx)
 		defer cancel()
 
-		conn, errListen := t.listen(ctxtimeout, dialer, address)
-		if errListen != nil {
-			// fallback to dial
-			conn, errDial := t.dial(ctx, dialer, address)
-			if errDial != nil {
-				return nil, fmt.Errorf("error listening: %v, error dialing: %v", errListen, errDial)
+		type result struct {
+			conn net.Conn
+			err  error
+		}
+
+		results := make(chan result, 2)
+
+		go func() {
+			conn, err := t.listen(dialCtx, dialer, address)
+			results <- result{conn, err}
+		}()
+
+		go func() {
+			conn, err := t.dial(dialCtx, dialer, address)
+			results <- result{conn, err}
+		}()
+
+		first := <-results
+		if first.err == nil {
+			// Interrupt the other dial
+			cancel()
+			second := <-results
+			if second.conn != nil {
+				_ = second.conn.Close()
 			}
+			return first.conn, nil
+		}
 
-			return conn, nil
+		second := <-results
+		if second.err == nil {
+			return second.conn, nil
 		}
 
-		return conn, nil
+		return nil, fmt.Errorf(strings.Join([]string{first.err.Error(), second.err.Error()}, "; "))
 	}
 
 	return dtlsDialer, nil

+ 1 - 1
vendor/modules.txt

@@ -260,7 +260,7 @@ github.com/pmezard/go-difflib/difflib
 # github.com/quic-go/qpack v0.4.0
 ## explicit; go 1.18
 github.com/quic-go/qpack
-# github.com/refraction-networking/conjure v0.7.9
+# github.com/refraction-networking/conjure v0.7.10-0.20231110193225-e4749a9dedc9
 ## explicit; go 1.18
 github.com/refraction-networking/conjure/pkg/client/assets
 github.com/refraction-networking/conjure/pkg/core