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
7eee7c00
Commit
7eee7c00
authored
Feb 04, 2021
by
vyzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add support for transient connections
parent
410e6bdb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
0 deletions
+19
-0
network/context.go
network/context.go
+17
-0
network/network.go
network/network.go
+2
-0
No files found.
network/context.go
View file @
7eee7c00
...
@@ -13,9 +13,11 @@ var DialPeerTimeout = 60 * time.Second
...
@@ -13,9 +13,11 @@ var DialPeerTimeout = 60 * time.Second
type
noDialCtxKey
struct
{}
type
noDialCtxKey
struct
{}
type
dialPeerTimeoutCtxKey
struct
{}
type
dialPeerTimeoutCtxKey
struct
{}
type
forceDirectDialCtxKey
struct
{}
type
forceDirectDialCtxKey
struct
{}
type
useTransientCtxKey
struct
{}
var
noDial
=
noDialCtxKey
{}
var
noDial
=
noDialCtxKey
{}
var
forceDirectDial
=
forceDirectDialCtxKey
{}
var
forceDirectDial
=
forceDirectDialCtxKey
{}
var
useTransient
=
useTransientCtxKey
{}
// EXPERIMENTAL
// EXPERIMENTAL
// WithForceDirectDial constructs a new context with an option that instructs the network
// WithForceDirectDial constructs a new context with an option that instructs the network
...
@@ -66,3 +68,18 @@ func GetDialPeerTimeout(ctx context.Context) time.Duration {
...
@@ -66,3 +68,18 @@ func GetDialPeerTimeout(ctx context.Context) time.Duration {
func
WithDialPeerTimeout
(
ctx
context
.
Context
,
timeout
time
.
Duration
)
context
.
Context
{
func
WithDialPeerTimeout
(
ctx
context
.
Context
,
timeout
time
.
Duration
)
context
.
Context
{
return
context
.
WithValue
(
ctx
,
dialPeerTimeoutCtxKey
{},
timeout
)
return
context
.
WithValue
(
ctx
,
dialPeerTimeoutCtxKey
{},
timeout
)
}
}
// WithUseTransient constructs a new context with an option that instructs to network
// that it is acceptable to use a transient connection when opening a new stream.
func
WithUseTransient
(
ctx
context
.
Context
)
context
.
Context
{
return
context
.
WithValue
(
ctx
,
useTransient
,
true
)
}
// GetUseTransient returns true if the use transient option is set in the context.
func
GetUseTransient
(
ctx
context
.
Context
)
bool
{
v
:=
ctx
.
Value
(
useTransient
)
if
v
!=
nil
{
return
true
}
return
false
}
network/network.go
View file @
7eee7c00
...
@@ -103,6 +103,8 @@ type Stat struct {
...
@@ -103,6 +103,8 @@ type Stat struct {
Direction
Direction
Direction
Direction
// Opened is the timestamp when this connection was opened.
// Opened is the timestamp when this connection was opened.
Opened
time
.
Time
Opened
time
.
Time
// Transient indicates that this connection is transient and may be closed soon
Transient
bool
// Extra stores additional metadata about this connection.
// Extra stores additional metadata about this connection.
Extra
map
[
interface
{}]
interface
{}
Extra
map
[
interface
{}]
interface
{}
}
}
...
...
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