@@ -14,10 +14,12 @@ type noDialCtxKey struct{}
14
14
type dialPeerTimeoutCtxKey struct {}
15
15
type forceDirectDialCtxKey struct {}
16
16
type useTransientCtxKey struct {}
17
+ type simConnectCtxKey struct {}
17
18
18
19
var noDial = noDialCtxKey {}
19
20
var forceDirectDial = forceDirectDialCtxKey {}
20
21
var useTransient = useTransientCtxKey {}
22
+ var simConnect = simConnectCtxKey {}
21
23
22
24
// EXPERIMENTAL
23
25
// WithForceDirectDial constructs a new context with an option that instructs the network
@@ -37,6 +39,24 @@ func GetForceDirectDial(ctx context.Context) (forceDirect bool, reason string) {
37
39
return false , ""
38
40
}
39
41
42
+ // EXPERIMENTAL
43
+ // WithSimultaneousConnect constructs a new context with an option that instructs the transport
44
+ // to apply hole punching logic where applicable.
45
+ func WithSimultaneousConnect (ctx context.Context , reason string ) context.Context {
46
+ return context .WithValue (ctx , simConnect , reason )
47
+ }
48
+
49
+ // EXPERIMENTAL
50
+ // GetSimultaneousConnect returns true if the simultaneous connect option is set in the context
51
+ func GetSimultaneousConnect (ctx context.Context ) (simconnect bool , reason string ) {
52
+ v := ctx .Value (simConnect )
53
+ if v != nil {
54
+ return true , v .(string )
55
+ }
56
+
57
+ return false , ""
58
+ }
59
+
40
60
// WithNoDial constructs a new context with an option that instructs the network
41
61
// to not attempt a new dial when opening a stream.
42
62
func WithNoDial (ctx context.Context , reason string ) context.Context {
0 commit comments