libp2p / go-libp2p

libp2p implementation in Go
MIT License
6.02k stars 1.06k forks source link

RoutedHost: Embed the underlying host instead of hiding it #2969

Open burdiyan opened 1 week ago

burdiyan commented 1 week ago

When using a libp2p host with routing, the underlying concrete type is RoutedHost. This type wraps the original Host type and hides it into a private field, which makes it hard to make interface type assertions on the host.

E.g. sometimes it's useful to have access to the underlying instance of the IDService, which is exposed by BasicHost as a method IDService() identityIDService, but is inaccessible for type assertions because RoutedHost hides the BasicHost in its private field.

This commit uses type embedding, instead of a private field, to fix it.