Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
adam.huang
go-libp2p
Commits
9183b8af
Commit
9183b8af
authored
Nov 10, 2016
by
Jeromy Johnson
Committed by
GitHub
Nov 10, 2016
Browse files
Merge pull request #150 from libp2p/feat/negotiate-timeouts
add negotiate timeout option to basichost
parents
6bccc8c1
4f17a651
Changes
2
Show whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
9183b8af
...
...
@@ -23,6 +23,8 @@ import (
var
log
=
logging
.
Logger
(
"basichost"
)
var
NegotiateTimeout
=
time
.
Second
*
60
// Option is a type used to pass in options to the host.
type
Option
int
...
...
@@ -48,6 +50,8 @@ type BasicHost struct {
relay
*
relay
.
RelayService
natmgr
*
natManager
NegotiateTimeout
time
.
Duration
proc
goprocess
.
Process
bwc
metrics
.
Reporter
...
...
@@ -58,6 +62,7 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
h
:=
&
BasicHost
{
network
:
net
,
mux
:
msmux
.
NewMultistreamMuxer
(),
NegotiateTimeout
:
NegotiateTimeout
,
}
h
.
proc
=
goprocess
.
WithTeardown
(
func
()
error
{
...
...
@@ -106,6 +111,15 @@ func (h *BasicHost) newConnHandler(c inet.Conn) {
// TODO: this feels a bit wonky
func
(
h
*
BasicHost
)
newStreamHandler
(
s
inet
.
Stream
)
{
before
:=
time
.
Now
()
if
h
.
NegotiateTimeout
!=
0
{
if
err
:=
s
.
SetDeadline
(
time
.
Now
()
.
Add
(
h
.
NegotiateTimeout
));
err
!=
nil
{
log
.
Error
(
"setting stream deadline: "
,
err
)
s
.
Close
()
return
}
}
protoID
,
handle
,
err
:=
h
.
Mux
()
.
Negotiate
(
s
)
took
:=
time
.
Now
()
.
Sub
(
before
)
if
err
!=
nil
{
...
...
@@ -121,6 +135,15 @@ func (h *BasicHost) newStreamHandler(s inet.Stream) {
s
.
Close
()
return
}
if
h
.
NegotiateTimeout
!=
0
{
if
err
:=
s
.
SetDeadline
(
time
.
Time
{});
err
!=
nil
{
log
.
Error
(
"resetting stream deadline: "
,
err
)
s
.
Close
()
return
}
}
s
.
SetProtocol
(
protocol
.
ID
(
protoID
))
if
h
.
bwc
!=
nil
{
...
...
p2p/net/mock/mock_net.go
View file @
9183b8af
...
...
@@ -85,6 +85,7 @@ func (mn *mocknet) AddPeerWithPeerstore(p peer.ID, ps pstore.Peerstore) (host.Ho
}
h
:=
bhost
.
New
(
n
)
h
.
NegotiateTimeout
=
0
mn
.
proc
.
AddChild
(
n
.
proc
)
...
...
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