-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
DI-based core.NewNode #6162
Conversation
3781a67
to
f3f0962
Compare
Should be ready for a review. Few notes:
|
There was a problem hiding this 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).
} | ||
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hear hear!
core/node/libp2p.go
Outdated
// 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 { |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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)
There isn't really that much |
Really, my main concern is pluggability but we can probably punt on that. |
core/node/libp2p.go
Outdated
// 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 { |
There was a problem hiding this comment.
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>
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>
There was a problem hiding this 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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
core/node/libp2p.go
Outdated
|
||
func P2PAddrFilters(cfg *config.Config) (opts Libp2pOpts, err error) { | ||
for _, s := range cfg.Swarm.AddrFilters { | ||
f, err := mask.NewMask(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mamask
?
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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"` | ||
} |
There was a problem hiding this comment.
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.
🚀 🌕 |
Next up: all of these options need to be documented. |
DI-based core.NewNode This commit was moved from ipfs/kubo@c3a7bc2
DI-based core.NewNode This commit was moved from ipfs/kubo@c3a7bc2
TODO: