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(
...
@@ -35,15 +35,19 @@ var BaseLibP2P = fx.Options(
)
)
func
LibP2P
(
cfg
*
BuildCfg
)
fx
.
Option
{
func
LibP2P
(
cfg
*
BuildCfg
)
fx
.
Option
{
return
fx
.
Options
(
opts
:=
fx
.
Options
(
BaseLibP2P
,
BaseLibP2P
,
maybeProvide
(
P2PNoSecurity
,
cfg
.
DisableEncryptedConnections
),
maybeProvide
(
P2PNoSecurity
,
cfg
.
DisableEncryptedConnections
),
maybeProvide
(
Pubsub
,
cfg
.
getOpt
(
"pubsub"
)
||
cfg
.
getOpt
(
"ipnsps"
)),
maybeProvide
(
Pubsub
,
cfg
.
getOpt
(
"pubsub"
)
||
cfg
.
getOpt
(
"ipnsps"
)),
fx
.
Provide
(
P2PSmuxTransport
(
cfg
.
getOpt
(
"mplex"
))),
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
{
func
Storage
(
cfg
*
BuildCfg
)
fx
.
Option
{
...
...
core/node/libp2p.go
View file @
bf380b87
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"fmt"
"fmt"
"io/ioutil"
"io/ioutil"
"os"
"os"
"sort"
"strings"
"strings"
"time"
"time"
...
@@ -398,10 +399,8 @@ type P2PHostOut struct {
...
@@ -398,10 +399,8 @@ type P2PHostOut struct {
Host
host
.
Host
Host
host
.
Host
Routing
BaseRouting
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
)
{
func
P2PHost
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
params
P2PHostIn
)
(
out
P2PHostOut
,
err
error
)
{
opts
:=
[]
libp2p
.
Option
{
libp2p
.
NoListenAddrs
}
opts
:=
[]
libp2p
.
Option
{
libp2p
.
NoListenAddrs
}
for
_
,
o
:=
range
params
.
Opts
{
for
_
,
o
:=
range
params
.
Opts
{
...
@@ -438,80 +437,95 @@ func P2PHost(mctx MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut
...
@@ -438,80 +437,95 @@ func P2PHost(mctx MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut
},
},
})
})
// TODO: break this up into more DI units
return
out
,
err
// TODO: I'm not a fan of type assertions like this but the
}
// `RoutingOption` system doesn't currently provide access to the
// IpfsNode.
type
Router
struct
{
//
routing
.
IpfsRouting
// Ideally, we'd do something like:
//
Priority
int
// less = more important
// 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).
type
p2pRouterOut
struct
{
// 2. Pass the IpfsNode into the RoutingOption (would also remove the
fx
.
Out
// PSRouter case below.
// 3. Introduce some kind of service manager? (my personal favorite but
Router
Router
`group:"routers"`
// that requires a fair amount of work).
}
if
dht
,
ok
:=
out
.
Routing
.
(
*
dht
.
IpfsDHT
);
ok
{
out
.
IpfsDHT
=
dht
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
{
lc
.
Append
(
fx
.
Hook
{
OnStop
:
func
(
ctx
context
.
Context
)
error
{
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
fx
.
In
R
epo
repo
.
Repo
R
outers
[]
Router
`group:"routers"`
Validator
record
.
Validator
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
{
type
p2p
PS
Routing
In
struct
{
fx
.
Out
fx
.
In
IpfsRouting
routing
.
IpfsRouting
BaseRouting
BaseRouting
PSRouter
*
namesys
.
PubsubValueStore
Repo
repo
.
Repo
}
Validator
record
.
Validator
Host
host
.
Host
func
P2POnlineRouting
(
ipnsps
bool
)
func
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pRoutingIn
)
(
out
p2pRoutingOut
)
{
PubSub
*
pubsub
.
PubSub
`optional:"true"`
return
func
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pRoutingIn
)
(
out
p2pRoutingOut
)
{
}
out
.
IpfsRouting
=
in
.
BaseRouting
func
P2PPubsubRouter
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
in
p2pPSRoutingIn
)
(
p2pRouterOut
,
*
namesys
.
PubsubValueStore
)
{
if
ipnsps
{
psRouter
:=
namesys
.
NewPubsubValueStore
(
out
.
PSRouter
=
namesys
.
NewPubsubValueStore
(
lifecycleCtx
(
mctx
,
lc
),
lifecycleCtx
(
mctx
,
lc
),
in
.
Host
,
in
.
Host
,
in
.
BaseRouting
,
in
.
BaseRouting
,
in
.
PubSub
,
in
.
PubSub
,
in
.
Validator
,
in
.
Validator
,
)
)
return
p2pRouterOut
{
out
.
IpfsRouting
=
routinghelpers
.
Tiered
{
Router
:
Router
{
Routers
:
[]
routing
.
IpfsRouting
{
IpfsRouting
:
&
routinghelpers
.
Compose
{
// Always check pubsub first.
ValueStore
:
&
routinghelpers
.
LimitedValueStore
{
&
routinghelpers
.
Compose
{
ValueStore
:
psRouter
,
ValueStore
:
&
routinghelpers
.
LimitedValueStore
{
Namespaces
:
[]
string
{
"ipns"
},
ValueStore
:
out
.
PSRouter
,
Namespaces
:
[]
string
{
"ipns"
},
},
},
in
.
BaseRouting
,
},
},
Validator
:
in
.
Validator
,
},
}
Priority
:
100
,
}
},
return
out
},
psRouter
}
}
}
func
AutoNATService
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
cfg
*
config
.
Config
,
host
host
.
Host
)
error
{
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