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
d0670f22
Commit
d0670f22
authored
Apr 01, 2019
by
Łukasz Magiera
Committed by
Steven Allen
Apr 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rewire teardown routines to lifecycles
License: MIT Signed-off-by:
Łukasz Magiera
<
magik6k@gmail.com
>
parent
0ba7661d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
44 additions
and
6 deletions
+44
-6
core/builder.go
core/builder.go
+1
-1
core/core.go
core/core.go
+2
-2
core/ncore.go
core/ncore.go
+41
-3
No files found.
core/builder.go
View file @
d0670f22
...
...
@@ -216,7 +216,7 @@ func NewNode(ctx context.Context, cfg *BuildCfg) (*IpfsNode, error) {
}
core
:=
fx
.
Options
(
fx
.
Provide
(
b
serv
.
New
),
fx
.
Provide
(
b
lockServiceCtor
),
fx
.
Provide
(
dagCtor
),
fx
.
Provide
(
resolver
.
NewBasicResolver
),
fx
.
Provide
(
pinning
),
...
...
core/core.go
View file @
d0670f22
...
...
@@ -684,10 +684,10 @@ func (n *IpfsNode) teardown() error {
closers
=
append
(
closers
,
n
.
Exchange
)
}
if
n
.
Mounts
.
Ipfs
!=
nil
&&
!
n
.
Mounts
.
Ipfs
.
IsActive
()
{
if
n
.
Mounts
.
Ipfs
!=
nil
&&
!
n
.
Mounts
.
Ipfs
.
IsActive
()
{
//TODO
closers
=
append
(
closers
,
mount
.
Closer
(
n
.
Mounts
.
Ipfs
))
}
if
n
.
Mounts
.
Ipns
!=
nil
&&
!
n
.
Mounts
.
Ipns
.
IsActive
()
{
if
n
.
Mounts
.
Ipns
!=
nil
&&
!
n
.
Mounts
.
Ipns
.
IsActive
()
{
// TODO
closers
=
append
(
closers
,
mount
.
Closer
(
n
.
Mounts
.
Ipns
))
}
...
...
core/ncore.go
View file @
d0670f22
...
...
@@ -159,7 +159,7 @@ func baseBlockstoreCtor(mctx MetricsCtx, repo repo.Repo, cfg *iconfig.Config, bc
return
}
func
gcBlockstoreCtor
(
repo
repo
.
Repo
,
bb
BaseBlocks
,
cfg
*
iconfig
.
Config
)
(
gclocker
bstore
.
GCLocker
,
gcbs
bstore
.
GCBlockstore
,
bs
bstore
.
Blockstore
,
fstore
*
filestore
.
Filestore
)
{
func
gcBlockstoreCtor
(
lc
fx
.
Lifecycle
,
repo
repo
.
Repo
,
bb
BaseBlocks
,
cfg
*
iconfig
.
Config
)
(
gclocker
bstore
.
GCLocker
,
gcbs
bstore
.
GCBlockstore
,
bs
bstore
.
Blockstore
,
fstore
*
filestore
.
Filestore
)
{
gclocker
=
bstore
.
NewGCLocker
()
gcbs
=
bstore
.
NewGCBlockstore
(
bb
,
gclocker
)
...
...
@@ -173,6 +173,18 @@ func gcBlockstoreCtor(repo repo.Repo, bb BaseBlocks, cfg *iconfig.Config) (gcloc
return
}
func
blockServiceCtor
(
lc
fx
.
Lifecycle
,
bs
bstore
.
Blockstore
,
rem
exchange
.
Interface
)
bserv
.
BlockService
{
bsvc
:=
bserv
.
New
(
bs
,
rem
)
lc
.
Append
(
fx
.
Hook
{
OnStop
:
func
(
ctx
context
.
Context
)
error
{
return
bsvc
.
Close
()
},
})
return
bsvc
}
func
recordValidator
(
ps
pstore
.
Peerstore
)
record
.
Validator
{
return
record
.
NamespacedValidator
{
"pk"
:
record
.
PublicKeyValidator
{},
...
...
@@ -431,6 +443,12 @@ func p2pHost(mctx MetricsCtx, lc fx.Lifecycle, params p2pHostIn) (out p2pHostOut
out
.
Host
=
rhost
.
Wrap
(
out
.
Host
,
out
.
Routing
)
}
lc
.
Append
(
fx
.
Hook
{
OnStop
:
func
(
ctx
context
.
Context
)
error
{
return
out
.
Host
.
Close
()
},
})
// 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
...
...
@@ -447,6 +465,12 @@ func p2pHost(mctx MetricsCtx, lc fx.Lifecycle, params p2pHostIn) (out p2pHostOut
// that requires a fair amount of work).
if
dht
,
ok
:=
out
.
Routing
.
(
*
dht
.
IpfsDHT
);
ok
{
out
.
IpfsDHT
=
dht
lc
.
Append
(
fx
.
Hook
{
OnStop
:
func
(
ctx
context
.
Context
)
error
{
return
out
.
IpfsDHT
.
Close
()
},
})
}
return
out
,
err
...
...
@@ -579,7 +603,13 @@ func dagCtor(bs bserv.BlockService) format.DAGService {
func
onlineExchangeCtor
(
mctx
MetricsCtx
,
lc
fx
.
Lifecycle
,
host
p2phost
.
Host
,
rt
routing
.
IpfsRouting
,
bs
bstore
.
GCBlockstore
)
exchange
.
Interface
{
bitswapNetwork
:=
bsnet
.
NewFromIpfsHost
(
host
,
rt
)
return
bitswap
.
New
(
lifecycleCtx
(
mctx
,
lc
),
bitswapNetwork
,
bs
)
exch
:=
bitswap
.
New
(
lifecycleCtx
(
mctx
,
lc
),
bitswapNetwork
,
bs
)
lc
.
Append
(
fx
.
Hook
{
OnStop
:
func
(
ctx
context
.
Context
)
error
{
return
exch
.
Close
()
},
})
return
exch
}
func
onlineNamesysCtor
(
rt
routing
.
IpfsRouting
,
repo
repo
.
Repo
,
cfg
*
iconfig
.
Config
)
(
namesys
.
NameSystem
,
error
)
{
...
...
@@ -738,7 +768,15 @@ func files(mctx MetricsCtx, lc fx.Lifecycle, repo repo.Repo, dag format.DAGServi
return
nil
,
err
}
return
mfs
.
NewRoot
(
ctx
,
dag
,
nd
,
pf
)
root
,
err
:=
mfs
.
NewRoot
(
ctx
,
dag
,
nd
,
pf
)
lc
.
Append
(
fx
.
Hook
{
OnStop
:
func
(
ctx
context
.
Context
)
error
{
return
root
.
Close
()
},
})
return
root
,
err
}
////////////
...
...
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