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
6cea7341
Unverified
Commit
6cea7341
authored
Feb 15, 2021
by
Aarsh Shah
Committed by
GitHub
Feb 15, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
context to force direct dial (#181)
parent
a7d9ced9
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 @
6cea7341
...
@@ -12,8 +12,28 @@ var DialPeerTimeout = 60 * time.Second
...
@@ -12,8 +12,28 @@ var DialPeerTimeout = 60 * time.Second
type
noDialCtxKey
struct
{}
type
noDialCtxKey
struct
{}
type
dialPeerTimeoutCtxKey
struct
{}
type
dialPeerTimeoutCtxKey
struct
{}
type
forceDirectDialCtxKey
struct
{}
var
noDial
=
noDialCtxKey
{}
var
noDial
=
noDialCtxKey
{}
var
forceDirectDial
=
forceDirectDialCtxKey
{}
// EXPERIMENTAL
// WithForceDirectDial constructs a new context with an option that instructs the network
// to attempt to force a direct connection to a peer via a dial even if a proxied connection to it already exists.
func
WithForceDirectDial
(
ctx
context
.
Context
,
reason
string
)
context
.
Context
{
return
context
.
WithValue
(
ctx
,
forceDirectDial
,
reason
)
}
// EXPERIMENTAL
// GetForceDirectDial returns true if the force direct dial option is set in the context.
func
GetForceDirectDial
(
ctx
context
.
Context
)
(
forceDirect
bool
,
reason
string
)
{
v
:=
ctx
.
Value
(
forceDirectDial
)
if
v
!=
nil
{
return
true
,
v
.
(
string
)
}
return
false
,
""
}
// WithNoDial constructs a new context with an option that instructs the network
// WithNoDial constructs a new context with an option that instructs the network
// to not attempt a new dial when opening a stream.
// to not attempt a new dial when opening a stream.
...
...
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