Skip to content
This repository has been archived by the owner on Dec 2, 2022. It is now read-only.

add and use public_ip as fallback #295

Merged
merged 1 commit into from
Sep 14, 2022
Merged

Conversation

shalzz
Copy link
Contributor

@shalzz shalzz commented Sep 13, 2022

Fixes #244

@CLAassistant
Copy link

CLAassistant commented Sep 13, 2022

CLA assistant check
All committers have signed the CLA.

debug!("Failed to get public IP: {}", e);
debug!("Failed to get public IP via UPNP: {}", e);
debug!("Trying with public_ip DNS/HTTP resolvers");
if let Some(v) = public_ip::addr().await {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any way to get and print specific error, not None?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, however the crate tries various resolvers to try and get the external IP address on a best effort basis. The error would be resolver specific and in worst case would be a collection of errors of all resolvers tried (connection/networking errors).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would look something like this

                                let mut errors = vec![];
                                let ip = public_ip::resolve(public_ip::ALL, public_ip::Version::Any)
                                    .filter_map(|result| std::future::ready( result.map_err(|e| errors.push(e)).ok() ))
                                    .next()
                                    .await
                                    .map(|(addr, _)| addr);

                                if let Some(v) = ip {
                                    debug!("Discovered public IP: {}", v);
                                    node_endpoint.write().address = Ip(v);
                                } else {
                                    debug!("Failed to get public IP via DNS/HTTP resolvers: {:?}", errors);
                                }

Copy link
Member

@vorot93 vorot93 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

@vorot93 vorot93 merged commit 5938dad into akula-bft:master Sep 14, 2022
@vorot93 vorot93 mentioned this pull request Sep 14, 2022
@shalzz shalzz deleted the patch-1 branch September 15, 2022 02:53
brilliant-lx pushed a commit to bnb-chain/akula that referenced this pull request Sep 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reliably bind to/discover public IP
3 participants