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

Websocket transport (with tokio) doesn't work on Android #5672

Open
jsamol opened this issue Nov 11, 2024 · 1 comment
Open

Websocket transport (with tokio) doesn't work on Android #5672

jsamol opened this issue Nov 11, 2024 · 1 comment

Comments

@jsamol
Copy link

jsamol commented Nov 11, 2024

Summary

Since the websocket transport relies on the DNS transport, it's affected by the same issue as its dependency (#2064) and fails to work on Android. For DNS, the issue can be mitigated by providing custom libp2p_dns::ResolverConfig and libp2p_dns::ResolverOpts instead of trying to read the system configuration, but this is not currently possible for websockets, since the websocket builder (for tokio) creates a DNS transport instance internally and doesn't allow any customization:

impl_websocket_builder!(
"tokio",
super::provider::Tokio,
// Note this is an unnecessary await for Tokio Websocket (i.e. tokio dns) in order to be consistent
// with above AsyncStd construction.
futures::future::ready(libp2p_dns::tokio::Transport::system(
libp2p_tcp::tokio::Transport::new(libp2p_tcp::Config::default())
)),
rw_stream_sink::RwStreamSink<libp2p_websocket::BytesConnection<libp2p_tcp::tokio::TcpStream>>
);

Expected behavior

SwarmBuilder::with_websocket successfully configures the websocket transport on Android.

Actual behavior

SwarmBuilder::with_websocket returns an error due to an internal DNS issue where /etc/resolv.conf can't be found.

Relevant log output

No response

Possible Solution

I'm not very familiar with the library’s internals, but the most straightforward solution appears to be to allow custom configuration for the internal DNS transport so the builder doesn’t attempt to read the system config. This could be achieved by introducing a libp2p_websocket::Config structure, similar to those used by other transports (e.g., TCP), with optional DNS configuration for creating the DNS transport instance. However, the DNS configuration should probably be only included when applicable, such as when using the tokio runtime, to avoid cluttering the interface.

Version

0.54.1

Would you like to work on fixing this bug ?

Maybe

@dariusc93
Copy link
Member

Thank you for the report. A workaround would probably be to use Swarm::new and supply a transport that way with your option. Long term, we should probably pass a configuration option from the builder or maybe just use TokioDnsConfig::custom by default.

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

2 participants