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
7f1ffcbd
Commit
7f1ffcbd
authored
Jul 25, 2017
by
vyzo
Browse files
basic_host: NewHost: don't panic on relay errors, return an error instead
The legacy interface stays unchanged with a panic though.
parent
3b6d6112
Changes
2
Hide whitespace changes
Inline
Side-by-side
p2p/host/basic/basic_host.go
View file @
7f1ffcbd
...
...
@@ -107,7 +107,7 @@ type HostOpts struct {
}
// NewHost constructs a new *BasicHost and activates it by attaching its stream and connection handlers to the given inet.Network.
func
NewHost
(
net
inet
.
Network
,
opts
*
HostOpts
)
*
BasicHost
{
func
NewHost
(
net
inet
.
Network
,
opts
*
HostOpts
)
(
*
BasicHost
,
error
)
{
h
:=
&
BasicHost
{
network
:
net
,
mux
:
msmux
.
NewMultistreamMuxer
(),
...
...
@@ -156,9 +156,7 @@ func NewHost(net inet.Network, opts *HostOpts) *BasicHost {
relayCtx
,
relayCancel
=
context
.
WithCancel
(
context
.
Background
())
err
:=
circuit
.
AddRelayTransport
(
relayCtx
,
h
,
opts
.
RelayOpts
...
)
if
err
!=
nil
{
// perhaps inappropriate, but otherwise we have to change the interface
// to return an error, which will nost likely lead to a fatality anyway
panic
(
err
)
return
nil
,
err
}
}
...
...
@@ -175,7 +173,7 @@ func NewHost(net inet.Network, opts *HostOpts) *BasicHost {
net
.
SetConnHandler
(
h
.
newConnHandler
)
net
.
SetStreamHandler
(
h
.
newStreamHandler
)
return
h
return
h
,
nil
}
// New constructs and sets up a new *BasicHost with given Network and options.
...
...
@@ -200,7 +198,14 @@ func New(net inet.Network, opts ...interface{}) *BasicHost {
}
}
return
NewHost
(
net
,
hostopts
)
h
,
err
:=
NewHost
(
net
,
hostopts
)
if
err
!=
nil
{
// this cannot happen with legacy options
// plus we want to keep the (deprecated) legacy interface unchanged
panic
(
err
)
}
return
h
}
// newConnHandler is the remote-opened conn handler for inet.Network
...
...
p2p/net/mock/mock_net.go
View file @
7f1ffcbd
...
...
@@ -87,7 +87,11 @@ func (mn *mocknet) AddPeerWithPeerstore(p peer.ID, ps pstore.Peerstore) (host.Ho
opts
:=
&
bhost
.
HostOpts
{
NegotiationTimeout
:
-
1
,
}
h
:=
bhost
.
NewHost
(
n
,
opts
)
h
,
err
:=
bhost
.
NewHost
(
n
,
opts
)
if
err
!=
nil
{
return
nil
,
err
}
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