Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DI-based core.NewNode #6162

Merged
merged 27 commits into from
Apr 18, 2019
Merged

DI-based core.NewNode #6162

merged 27 commits into from
Apr 18, 2019

Conversation

magik6k
Copy link
Member

@magik6k magik6k commented Apr 1, 2019

TODO:

  • Fix Regressions
    • Fuse (probably works)
  • Remove old code
  • Organize DI Providers / Services
  • (Possibly separate PR) Expose DI /

@magik6k magik6k requested a review from Kubuxu as a code owner April 1, 2019 16:29
@ghost ghost assigned magik6k Apr 1, 2019
@ghost ghost added the status/in-progress In progress label Apr 1, 2019
@magik6k magik6k changed the title DI-based core.NewNode [WIP] DI-based core.NewNode Apr 1, 2019
@magik6k magik6k force-pushed the feat/dig branch 3 times, most recently from 3781a67 to f3f0962 Compare April 3, 2019 14:58
@magik6k
Copy link
Member Author

magik6k commented Apr 3, 2019

Should be ready for a review. Few notes:

  • I recommend starting with reading the DI library docs, mainly this part - https://godoc.org/go.uber.org/fx#ex-package.
  • This PR aims to not introduce too many breaking changes, and make the code less intimidating.
  • The main constructor flow starts in core/builder.NewNode.
  • core/node is a new package which contains DI-related node construction logic.
  • core/ package now only provides IpfsNode and wraps DI constructor (will change in constructor interface refactor, not sure how exactly yet).
  • core/node/groups.go groups providers into larger components for a few reasons:
    • It's easier to see what is related
    • Groups are exported, so if someone want's to assemble their own node with different components they don't have to pull everything manually
  • Diff might seem big, but most changes are just moving existing constructor code and wrapping it into smaller units.

@magik6k magik6k changed the title [WIP] DI-based core.NewNode DI-based core.NewNode Apr 3, 2019
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🕺

Awesome!

(now we just need to spread the love to libp2p so we can have a unified system)


The only comment there was to add some layer of abstraction so we aren't tied to fx but, well, seeing it in action, I'm not sure if it's worth it (although we likely will want a small library of helper functions).

cc @bigs & @raulk

core/bootstrap/bootstrap.go Outdated Show resolved Hide resolved
}
go func() {
// Note that some services use contexts to signal shutting down, which is
// very suboptimal. This needs to be here until that's addressed somehow
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hear hear!

core/node/core.go Show resolved Hide resolved
core/node/groups.go Outdated Show resolved Hide resolved
core/node/helpers.go Outdated Show resolved Hide resolved
core/node/libp2p.go Show resolved Hide resolved
core/node/libp2p.go Outdated Show resolved Hide resolved
// 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have different DI units provide different routers and then have a single unit collect them all? (then we can just drop the routing option system)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to run into a circular dependency - If we want to construct routing after the host, we'd also need to somehow defer enabling autorelay.

Autorelay construction depends on routing [1], which in that place can only be provided as libp2p.Option to libp2p.New. We can't get the full routing there as PubsubRouter requires PubSub, which requires Host..

We could try not passing the AutoRelay option to Libp2p constructor, and instead construct it manually here, but it feels hacky. Better ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sucks... we'll fix this when we add fx support to libp2p but I'd like to merge this first.

What if we had this option depend on IpfsDHT specifically and then constructed the real router after we construct the host?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we had this option depend on IpfsDHT specifically and then constructed the real router after we construct the host?

What about NilRouter? (used when --routing=none is set)

I'd say we'll clean this up in the second stage of the refactor (and remove RoutingOption)

core/node/libp2p.go Outdated Show resolved Hide resolved
@magik6k
Copy link
Member Author

magik6k commented Apr 8, 2019

add some layer of abstraction so we aren't tied to fx

There isn't really that much fx specific code here (DI systems likely won't differ that much), so if we'd really need to switch to something else, it shouldn't be too hard.

@Stebalien
Copy link
Member

There isn't really that much fx specific code here (DI systems likely won't differ that much), so if we'd really need to switch to something else, it shouldn't be too hard.

Really, my main concern is pluggability but we can probably punt on that.

core/node/libp2p.go Outdated Show resolved Hide resolved
// 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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sucks... we'll fix this when we add fx support to libp2p but I'd like to merge this first.

What if we had this option depend on IpfsDHT specifically and then constructed the real router after we construct the host?

License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
magik6k and others added 15 commits April 17, 2019 16:56
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Łukasz Magiera <magik6k@gmail.com>
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
Copy link
Member

@Stebalien Stebalien left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll have some cleanup work ahead of us but this looks good to merge. Let's do so before we start collecting conflicts.

"github.com/libp2p/go-libp2p-net"
"github.com/libp2p/go-libp2p-peer"
"github.com/libp2p/go-libp2p-peerstore"
"github.com/libp2p/go-libp2p-routing"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's leave the explicit names for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(meh, actually, I don't care much either way)


func P2PAddrFilters(cfg *config.Config) (opts Libp2pOpts, err error) {
for _, s := range cfg.Swarm.AddrFilters {
f, err := mask.NewMask(s)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mamask?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(fixed)

mplex "github.com/whyrusleeping/go-smux-multiplex"
yamux "github.com/whyrusleeping/go-smux-yamux"
"github.com/whyrusleeping/multiaddr-filter"
mamask "github.com/whyrusleeping/multiaddr-filter"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate imports.

if err != nil {
return nil, err
}
noAnnAddrs[maddr.String()] = true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIXME later: We shouldn't convert to strings here. We should just run string(maddr.Bytes()).

fx.Out

Opts []libp2p.Option `group:"libp2p"`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to get rid of this helper entirely (libp2p/go-libp2p#603). I'll file a followup PR after merging this.

@Stebalien Stebalien merged commit c3a7bc2 into master Apr 18, 2019
@ghost ghost removed the status/in-progress In progress label Apr 18, 2019
@Stebalien
Copy link
Member

🚀 🌕

@Stebalien Stebalien deleted the feat/dig branch April 18, 2019 00:06
@Stebalien
Copy link
Member

@magik6k,

Next up: all of these options need to be documented.

hacdias pushed a commit to ipfs/boxo that referenced this pull request Jan 27, 2023
DI-based core.NewNode

This commit was moved from ipfs/kubo@c3a7bc2
gammazero pushed a commit to ipfs/boxo that referenced this pull request Sep 29, 2023
DI-based core.NewNode

This commit was moved from ipfs/kubo@c3a7bc2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants