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
dms3
go-dms3
Commits
bf380b87
Commit
bf380b87
authored
Apr 15, 2019
by
Łukasz Magiera
Committed by
Steven Allen
Apr 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup routing related units
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
23f50ab0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
79 additions
and
61 deletions
+79
-61
core/node/groups.go
core/node/groups.go
+6
-2
core/node/libp2p.go
core/node/libp2p.go
+73
-59
No files found.
core/node/groups.go
View file @
bf380b87
...
...
@@ -35,15 +35,19 @@ var BaseLibP2P = fx.Options(
)
func
LibP2P
(
cfg
*
BuildCfg
)
fx
.
Option
{
return
fx
.
Options
(
opts
:=
fx
.
Options
(
BaseLibP2P
,
maybeProvide
(
P2PNoSecurity
,
cfg
.
DisableEncryptedConnections
),
maybeProvide
(
Pubsub
,
cfg
.
getOpt
(
"pubsub"
)
||
cfg
.
getOpt
(
"ipnsps"
)),
fx
.
Provide
(
P2PSmuxTransport
(
cfg
.
getOpt
(
"mplex"
))),
fx
.
Provide
(
P2POnlineRouting
(
cfg
.
getOpt
(
"ipnsps"
))),
fx
.
Provide
(
P2PRouting
),
fx
.
Provide
(
P2PBaseRouting
),
maybeProvide
(
P2PPubsubRouter
,
cfg
.
getOpt
(
"ipnsps"
)),
)
return
opts
}
func
Storage
(
cfg
*
BuildCfg
)
fx
.
Option
{
...
...
core/node/libp2p.go
View file @
bf380b87
...
...
@@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"os"
"sort"
"strings"
"time"
...
...
@@ -398,10 +399,8 @@ type P2PHostOut struct {
Host
host
.
Host
Routing
BaseRouting
IpfsDHT
*
dht
.
IpfsDHT
}
// TODO: move some of this into params struct
func
P2PHost
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
params
P2PHostIn
)
(
out
P2PHostOut
,
err
error
)
{
opts
:=
[]
libp2p
.
Option
{
libp2p
.
NoListenAddrs
}
for
_
,
o
:=
range
params
.
Opts
{
...
...
@@ -438,80 +437,95 @@ func P2PHost(mctx MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut
},
})
// TODO: break this up into more DI units
// TODO: I'm not a fan of type assertions like this but the
// `RoutingOption` system doesn't currently provide access to the
// IpfsNode.
//
// Ideally, we'd do something like:
//
// 1. Add some fancy method to introspect into tiered routers to extract
// things like the pubsub router or the DHT (complicated, messy,
// probably not worth it).
// 2. Pass the IpfsNode into the RoutingOption (would also remove the
// PSRouter case below.
// 3. Introduce some kind of service manager? (my personal favorite but
// that requires a fair amount of work).
if
dht
,
ok
:=
out
.
Routing
.
(
*
dht
.
IpfsDHT
);
ok
{
out
.
IpfsDHT
=
dht
return
out
,
err
}
type
Router
struct
{
routing
.
IpfsRouting
Priority
int
// less = more important
}
type
p2pRouterOut
struct
{
fx
.
Out
Router
Router
`group:"routers"`
}
func
P2PBaseRouting
(
lc
fx
.
Lifecycle
,
in
BaseRouting
)
(
out
p2pRouterOut
,
dr
*
dht
.
IpfsDHT
)
{
if
dht
,
ok
:=
in
.
(
*
dht
.
IpfsDHT
);
ok
{
dr
=
dht
lc
.
Append
(
fx
.
Hook
{
OnStop
:
func
(
ctx
context
.
Context
)
error
{
return
out
.
IpfsDHT
.
Close
()
return
dr
.
Close
()
},
})
}
return
out
,
err
return
p2pRouterOut
{
Router
:
Router
{
Priority
:
1000
,
IpfsRouting
:
in
,
},
},
dr
}
type
p2pRoutingIn
struct
{
type
p2p
Online
RoutingIn
struct
{
fx
.
In
R
epo
repo
.
Repo
R
outers
[]
Router
`group:"routers"`
Validator
record
.
Validator
Host
host
.
Host
PubSub
*
pubsub
.
PubSub
`optional:"true"`
}
BaseRouting
BaseRouting
func
P2PRouting
(
in
p2pOnlineRoutingIn
)
routing
.
IpfsRouting
{
routers
:=
in
.
Routers
sort
.
SliceStable
(
routers
,
func
(
i
,
j
int
)
bool
{
return
routers
[
i
]
.
Priority
<
routers
[
j
]
.
Priority
})
irouters
:=
make
([]
routing
.
IpfsRouting
,
len
(
routers
))
for
i
,
v
:=
range
routers
{
irouters
[
i
]
=
v
.
IpfsRouting
}
return
routinghelpers
.
Tiered
{
Routers
:
irouters
,
Validator
:
in
.
Validator
,
}
}
type
p2pRouting
Out
struct
{
fx
.
Out
type
p2p
PS
Routing
In
struct
{
fx
.
In
IpfsRouting
routing
.
IpfsRouting
PSRouter
*
namesys
.
PubsubValueStore
}
func
P2POnlineRouting
(
ipnsps
bool
)
func
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pRoutingIn
)
(
out
p2pRoutingOut
)
{
return
func
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pRoutingIn
)
(
out
p2pRoutingOut
)
{
out
.
IpfsRouting
=
in
.
BaseRouting
if
ipnsps
{
out
.
PSRouter
=
namesys
.
NewPubsubValueStore
(
lifecycleCtx
(
mctx
,
lc
),
in
.
Host
,
in
.
BaseRouting
,
in
.
PubSub
,
in
.
Validator
,
)
out
.
IpfsRouting
=
routinghelpers
.
Tiered
{
Routers
:
[]
routing
.
IpfsRouting
{
// Always check pubsub first.
&
routinghelpers
.
Compose
{
ValueStore
:
&
routinghelpers
.
LimitedValueStore
{
ValueStore
:
out
.
PSRouter
,
Namespaces
:
[]
string
{
"ipns"
},
},
},
in
.
BaseRouting
,
BaseRouting
BaseRouting
Repo
repo
.
Repo
Validator
record
.
Validator
Host
host
.
Host
PubSub
*
pubsub
.
PubSub
`optional:"true"`
}
func
P2PPubsubRouter
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pPSRoutingIn
)
(
p2pRouterOut
,
*
namesys
.
PubsubValueStore
)
{
psRouter
:=
namesys
.
NewPubsubValueStore
(
lifecycleCtx
(
mctx
,
lc
),
in
.
Host
,
in
.
BaseRouting
,
in
.
PubSub
,
in
.
Validator
,
)
return
p2pRouterOut
{
Router
:
Router
{
IpfsRouting
:
&
routinghelpers
.
Compose
{
ValueStore
:
&
routinghelpers
.
LimitedValueStore
{
ValueStore
:
psRouter
,
Namespaces
:
[]
string
{
"ipns"
},
},
Validator
:
in
.
Validator
,
}
}
return
out
}
},
Priority
:
100
,
},
},
psRouter
}
func
AutoNATService
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
cfg
*
config
.
Config
,
host
host
.
Host
)
error
{
...
...
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