go-libp2p icon indicating copy to clipboard operation
go-libp2p copied to clipboard

The `closableBasicHost` type needs to be exported so users can access the underlying `BasicHost`

Open aarshkshah1992 opened this issue 1 year ago • 5 comments

  • Looks like the libp2p.New function was changed to replace the exported BasicHost type with an un-exported closableBasicHost type that wraps a BasicHost

https://github.com/libp2p/go-libp2p/blob/04b2096cb952142073df125a47087fb91eb6b8de/config/config.go#L438

  • However, there is code in Lotus that depends on being able to access the concrete BasicHost implementation from a libp2p Host and that breaks now.

Please can we export the closableBasicHost type ?

For reference, the Lotus code that breaks is at https://github.com/filecoin-project/lotus/blob/967524aa83852123206715d0f54fd552c7546d5b/node/impl/net/net.go#L138.

aarshkshah1992 avatar May 22 '24 06:05 aarshkshah1992

@aarshkshah1992 in the specific case you raised can't you get around this by doing an interface check for GetAutoNat rather than a type check?

Maybe the underlying type should be exported, but it seems more likely that it's just a symptom of the more important need of getting access to some of the optional (if common) components of the Host.

aschmahmann avatar May 22 '24 07:05 aschmahmann

@aschmahmann Yeah, you are right. We don't need this change for Lotus anymore. Please feel free to close the issue.

aarshkshah1992 avatar May 22 '24 08:05 aarshkshah1992

I'm definitely open to exporting this type, but I'd like to see a better use case. If other folks have use cases or things that broke, please let me know.

It's not as simple as just exporting the type and changing what this function returns because it can now return either a closableBasicHost or a closableRoutedHost.

And generally I want to move away from BasicHost actually being a KitchenSinkHost. I want to move towards services being more pluggable (https://github.com/libp2p/go-libp2p/issues/1993).

MarcoPolo avatar May 22 '24 17:05 MarcoPolo

After chatting with @sukunrt for a bit, we think (if needed) we could flip the current style and have basic host call app.Close when it closes. That way we wouldn't need to export a new type and could keep exporting basic host.

Writing this for posterity, but it seems like it may not be needed.

MarcoPolo avatar May 23 '24 00:05 MarcoPolo

@aarshkshah1992 can you use EvtLocalReachabilityChanged?

sukunrt avatar Sep 18 '24 08:09 sukunrt