@cryptotaxi247 / kubo / commits / 23f50ab03

Minor cleanups in libp2p construction

License: MIT Signed-off-by: Łukasz Magiera <magik6k@gmail.com>

Łukasz Magiera committed Apr 8, 2019 at 16:00 UTC 23f50ab03e3bfe9e8d669075050c743ad2cb619e
1 file changed +3 -7
core/node/libp2p.go
+3 -7
@@ -152,6 +152,8 @@ func P2PPNetChecker(repo repo.Repo, ph host.Host, lc fx.Lifecycle) error {
152 OnStart: func(_ context.Context) error {
153 go func() {
154 t := time.NewTicker(30 * time.Second)
155 + defer t.Stop()
156 +
157 <-t.C // swallow one tick
158 for {
159 select {
@@ -406,13 +408,7 @@ func P2PHost(mctx MetricsCtx, lc fx.Lifecycle, params P2PHostIn) (out P2PHostOut
408 opts = append(opts, o...)
409 }
410
409 - ctx, cancel := context.WithCancel(mctx)
410 - lc.Append(fx.Hook{
411 - OnStop: func(_ context.Context) error {
412 - cancel()
413 - return nil
414 - },
415 - })
411 + ctx := lifecycleCtx(mctx, lc)
412
413 opts = append(opts, libp2p.Routing(func(h host.Host) (routing.PeerRouting, error) {
414 r, err := params.RoutingOption(ctx, h, params.Repo.Datastore(), params.Validator)