Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-core
Commits
29aaf384
Commit
29aaf384
authored
Feb 19, 2021
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
context option for simultaneous connect
parent
412dbb35
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
0 deletions
+20
-0
network/context.go
network/context.go
+20
-0
No files found.
network/context.go
View file @
29aaf384
...
...
@@ -14,10 +14,12 @@ type noDialCtxKey struct{}
type
dialPeerTimeoutCtxKey
struct
{}
type
forceDirectDialCtxKey
struct
{}
type
useTransientCtxKey
struct
{}
type
simConnectCtxKey
struct
{}
var
noDial
=
noDialCtxKey
{}
var
forceDirectDial
=
forceDirectDialCtxKey
{}
var
useTransient
=
useTransientCtxKey
{}
var
simConnect
=
simConnectCtxKey
{}
// EXPERIMENTAL
// 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) {
return
false
,
""
}
// EXPERIMENTAL
// WithSimultaneousConnect constructs a new context with an option that instructs the transport
// to apply hole punching logic where applicable.
func
WithSimultaneousConnect
(
ctx
context
.
Context
,
reason
string
)
context
.
Context
{
return
context
.
WithValue
(
ctx
,
simConnect
,
reason
)
}
// EXPERIMENTAL
// GetSimultaneousConnect returns true if the simultaneous connect option is set in the context
func
GetSimultaneousConnect
(
ctx
context
.
Context
)
(
simconnect
bool
,
reason
string
)
{
v
:=
ctx
.
Value
(
simConnect
)
if
v
!=
nil
{
return
true
,
v
.
(
string
)
}
return
false
,
""
}
// WithNoDial constructs a new context with an option that instructs the network
// to not attempt a new dial when opening a stream.
func
WithNoDial
(
ctx
context
.
Context
,
reason
string
)
context
.
Context
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment