Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 29aaf38

Browse files
committed
context option for simultaneous connect
1 parent 412dbb3 commit 29aaf38

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

network/context.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ type noDialCtxKey struct{}
1414
type dialPeerTimeoutCtxKey struct{}
1515
type forceDirectDialCtxKey struct{}
1616
type useTransientCtxKey struct{}
17+
type simConnectCtxKey struct{}
1718

1819
var noDial = noDialCtxKey{}
1920
var forceDirectDial = forceDirectDialCtxKey{}
2021
var useTransient = useTransientCtxKey{}
22+
var simConnect = simConnectCtxKey{}
2123

2224
// EXPERIMENTAL
2325
// 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) {
3739
return false, ""
3840
}
3941

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+
4060
// WithNoDial constructs a new context with an option that instructs the network
4161
// to not attempt a new dial when opening a stream.
4262
func WithNoDial(ctx context.Context, reason string) context.Context {

0 commit comments

Comments
 (0)