-
-
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
v0.15.0 / Bitswap v0.9.0 make it impossible to add Tracer #9256
Comments
@mrd0ll4r I see this indeed is an issue. I think it make sense to add more customization inside kubo. Line 28 in 3ae52a4
Then you could just provide thoses bitswap Options. Similar to how we do with libp2p. As a more adhoc way you could also use the fx plugin to override the exchange factory and just add your options. |
@mrd0ll4r : @ajnavarro is going to link to a sample code change you could make here. After he has done so, can you please make the PR |
I agree. It was racy and I didn't like it either :) I don't have a strong opinion on how this is exposed, I'm just interested in it being exposed at all.
I've been trying to achieve this for a few hours now, without luck. func constructModifiedBitswap() interface{} {
return func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt irouting.TieredRouter, blockStore blockstore.GCBlockstore) exchange.Interface {
...
}} But this is not allowed by fx:
I then tried to trick it by returning not just Digging through the fx issues, it seems like this should be possible using func reconstructModifiedBitswap() interface{} {
return func(bsImpl exchange.Interface, mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt irouting.TieredRouter, blockStore blockstore.GCBlockstore) exchange.Interface {
// Close old implementation
if err := bsImpl.Close(); err != nil {
panic(err) // Surely this will work
}
// Construct wiretap
bitswapNetwork := bsnet.NewFromIpfsHost(host, rt)
wiretap := NewWiretap(host.Network(), bitswapNetwork)
// Construct new Bitswap implementation
opts := []bs.Option{
bs.WithTracer(wiretap),
// ...
}
exch := bs.New(helpers.LifecycleCtx(mctx, lc), bitswapNetwork, blockStore, opts...)
lc.Append(fx.Hook{
OnStop: func(ctx context.Context) error {
return exch.Close()
},
})
return exch
}
} which, to my surprise, actually compiles, gets called, and causes Bitswap to panic. 😄 (see below) The panic:
Which reveals that a) |
we can do something similar as we did with routers here https://github.com/ipfs/kubo/blob/master/core/node/libp2p/routing.go#L58 and here https://github.com/ipfs/kubo/blob/master/core/node/libp2p/routing.go#L135 collect all |
@mrd0ll4r yeah the log message is wrong, thx 🎉 fixed it: |
@mrd0ll4r I actually messed up the type in go-bitswap. |
I fixed it in go-bitswap |
Hmm. I've been staring at this for a while, but not too sure how it applies. I don't know fx, or how IPFS is constructed, really... Do you want me to do something like this:
func Foo(cfg *config.Config, provide bool) interface{} {
return func() []bitswap.Option {
...
}}
...
fx.Provide(Foo(cfg,provideFlag))
func(mctx helpers.MetricsCtx, lc fx.Lifecycle, host host.Host, rt irouting.TieredRouter, bs blockstore.GCBlockstore, opts ...bitswap.Option) exchange.Interface And then I could |
@mrd0ll4r yeah, if we add |
Oops, seems like we needed more information for this issue, please comment with more details or this issue will be closed in 7 days. |
I remove the stale label since a PR was submitted: #9258 |
Checklist
Installation method
built from source
Version
Description
I'm maintaining the ipfs-metric-exporter plugin we use to analyze Bitswap traffic in real time.
For that, we implement
PluginDaemonInternal
and used to applybitswap.WithTracer
to the Bitswap instance of the running node.The rework in Bitswap v0.9.0 has encapsulated and unexported the function-type option and made it such that this can now only be supplied to and applied by
bitswap.New
.Logically, I tried to inject this option using the new
fx
type plugins, but to no avail.AFAI can see, Bitswap is initialized via
core.node.OnlineExchange
, which does not allow me to inject any options.What am I missing here? How can I, as a plugin author, apply the
WithTracer
option to the Bitswap implementation of a kubo node?The text was updated successfully, but these errors were encountered: