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-swarm
Commits
46f34ff8
Commit
46f34ff8
authored
Aug 18, 2016
by
Jeromy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
swarm: add deadline for connection setup
parent
9da803ca
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
swarm_dial.go
swarm_dial.go
+16
-0
No files found.
swarm_dial.go
View file @
46f34ff8
...
...
@@ -372,10 +372,21 @@ func (s *Swarm) dialAddr(ctx context.Context, p peer.ID, addr ma.Multiaddr) (con
return
connC
,
nil
}
var
ConnSetupTimeout
=
time
.
Minute
*
5
// dialConnSetup is the setup logic for a connection from the dial side. it
// needs to add the Conn to the StreamSwarm, then run newConnSetup
func
dialConnSetup
(
ctx
context
.
Context
,
s
*
Swarm
,
connC
conn
.
Conn
)
(
*
Conn
,
error
)
{
deadline
,
ok
:=
ctx
.
Deadline
()
if
!
ok
{
deadline
=
time
.
Now
()
.
Add
(
ConnSetupTimeout
)
}
if
err
:=
connC
.
SetDeadline
(
deadline
);
err
!=
nil
{
return
nil
,
err
}
psC
,
err
:=
s
.
swarm
.
AddConn
(
connC
)
if
err
!=
nil
{
// connC is closed by caller if we fail.
...
...
@@ -389,5 +400,10 @@ func dialConnSetup(ctx context.Context, s *Swarm, connC conn.Conn) (*Conn, error
return
nil
,
err
}
if
err
:=
connC
.
SetDeadline
(
time
.
Time
{});
err
!=
nil
{
log
.
Error
(
"failed to reset connection deadline after setup: "
,
err
)
return
nil
,
err
}
return
swarmC
,
err
}
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