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

Export closeableBasicHost and closeableRoutedHost #3015

Closed
dennis-tra opened this issue Oct 22, 2024 · 4 comments
Closed

Export closeableBasicHost and closeableRoutedHost #3015

dennis-tra opened this issue Oct 22, 2024 · 4 comments

Comments

@dennis-tra
Copy link
Contributor

dennis-tra commented Oct 22, 2024

In some of our tooling I want to have access to the IDService. What I've done until recently is:

  • get a host via libp2p.New
  • type cast/assert it to a *basichost.BasicHost
  • access the exported .IDService() method

A few months ago the host that libp2p.New returns is wrapped inside a closeableBasicHost. Since this type isn't exported I cannot do the above anymore.

Maybe there's a more elegant way to do what I want?

If not, would you have any objections to export that type? Increasing the API surface needs to be carefully considered so I'd totally understand if you have reservations. However, if it's ok from your side, I'm happy to do the tiny change.

@aschmahmann
Copy link
Collaborator

Related issue #2809

@MarcoPolo
Copy link
Collaborator

I think using Fx's options for this is cleaner than having to type check against specific type or having to expose a new getter method in the Interface.

This PR would let you do it: #2956. Here's a test that demonstrates it: https://github.com/libp2p/go-libp2p/pull/2956/files#diff-f7fee66901d4e06c6566ce6e9859d0b89364d4ba13ad9edd24534bfecdb443cbR54

This would work even if the host itself doesn't use the ID service. As long as something is providing it in the dependency graph.

I'm leaning towards merging that PR so we can start using it since it has already come up a couple of times.

@MarcoPolo
Copy link
Collaborator

You'll be able to get the ID service in the next release. Refer to this test for an example:

func TestGetIDService(t *testing.T) {
var id identify.IDService
host, err := New(
NoTransports,
WithFxOption(fx.Populate(&id)),
)
require.NoError(t, err)
defer host.Close()
require.NotNil(t, id)
}

@dennis-tra
Copy link
Contributor Author

Thanks everyone, and apologies for not searching for a related issue! Great that 0.37 is already released!

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

No branches or pull requests

3 participants