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
7b324b14
Commit
7b324b14
authored
Oct 26, 2018
by
vyzo
Browse files
remove BasicRouting interface; use PeerRouting and upcast for discovery
parent
c2d846a7
Changes
3
Hide whitespace changes
Inline
Side-by-side
config/config.go
View file @
7b324b14
...
...
@@ -35,12 +35,7 @@ type AddrsFactory = bhost.AddrsFactory
// NATManagerC is a NATManager constructor.
type
NATManagerC
func
(
inet
.
Network
)
bhost
.
NATManager
type
BasicRouting
interface
{
routing
.
ContentRouting
routing
.
PeerRouting
}
type
RoutingC
func
(
host
.
Host
)
(
BasicRouting
,
error
)
type
RoutingC
func
(
host
.
Host
)
(
routing
.
PeerRouting
,
error
)
// Config describes a set of settings for a libp2p node
//
...
...
@@ -178,21 +173,24 @@ func (cfg *Config) NewNode(ctx context.Context) (host.Host, error) {
return
nil
,
err
}
if
cfg
.
Relay
{
discovery
:=
discovery
.
NewRoutingDiscovery
(
router
)
hop
:=
false
for
_
,
opt
:=
range
cfg
.
RelayOpts
{
if
opt
==
circuit
.
OptHop
{
hop
=
true
break
crouter
,
ok
:=
router
.
(
routing
.
ContentRouting
)
if
ok
{
if
cfg
.
Relay
{
discovery
:=
discovery
.
NewRoutingDiscovery
(
crouter
)
hop
:=
false
for
_
,
opt
:=
range
cfg
.
RelayOpts
{
if
opt
==
circuit
.
OptHop
{
hop
=
true
break
}
}
}
if
hop
{
h
=
relay
.
NewRelayHost
(
swrm
.
Context
(),
h
.
(
*
bhost
.
BasicHost
),
discovery
)
}
else
{
h
=
relay
.
NewAutoRelayHost
(
swrm
.
Context
(),
h
.
(
*
bhost
.
BasicHost
),
discovery
)
if
hop
{
h
=
relay
.
NewRelayHost
(
swrm
.
Context
(),
h
.
(
*
bhost
.
BasicHost
),
discovery
)
}
else
{
h
=
relay
.
NewAutoRelayHost
(
swrm
.
Context
(),
h
.
(
*
bhost
.
BasicHost
),
discovery
)
}
}
}
...
...
libp2p.go
View file @
7b324b14
...
...
@@ -15,9 +15,6 @@ type Config = config.Config
// (`libp2p.New`).
type
Option
=
config
.
Option
// BasicRouting is the combination of PeerRouting and ContentRouting
type
BasicRouting
=
config
.
BasicRouting
// ChainOptions chains multiple options into a single option.
func
ChainOptions
(
opts
...
Option
)
Option
{
return
func
(
cfg
*
Config
)
error
{
...
...
p2p/host/relay/autorelay_test.go
View file @
7b324b14
...
...
@@ -136,7 +136,7 @@ func TestAutoRelay(t *testing.T) {
defer
cancel
()
mtab
:=
newMockRoutingTable
()
makeRouting
:=
func
(
h
host
.
Host
)
(
libp2p
.
Basic
Routing
,
error
)
{
makeRouting
:=
func
(
h
host
.
Host
)
(
routing
.
Peer
Routing
,
error
)
{
mr
:=
newMockRouting
(
h
,
mtab
)
return
mr
,
nil
}
...
...
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