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

Resolves IP Lookups #270 #313

Merged
69 commits merged into from
May 27, 2022
Merged

Conversation

apoorv-2204
Copy link
Contributor

@apoorv-2204 apoorv-2204 commented May 11, 2022

Description

We must check the IP retrieved for given node, (in production) belongs to Public IP. It should not be static or NAT IP.

Type of change

Please delete options that are not relevant.

  • Bug fix (Fix static ip in archethic Snap)
  • New feature (In dev single node || dev docker mode we should not fallback to public Ip)

How Has This Been Tested?

  • Add unit Tests
  • Run node in mix prod , it must use nat and then fallback to Ipify

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules

@apoorv-2204 apoorv-2204 changed the title retrive public ip in prod Resolves Lookups #270 May 11, 2022
@apoorv-2204 apoorv-2204 changed the title Resolves Lookups #270 Resolves IP Lookups #270 May 11, 2022
@apoorv-2204 apoorv-2204 marked this pull request as ready for review May 11, 2022 15:16
@roychowdhuryrohit-dev roychowdhuryrohit-dev added the P2P Involve P2P networking label May 11, 2022
@roychowdhuryrohit-dev
Copy link
Contributor

roychowdhuryrohit-dev commented May 11, 2022

LGTM so far well done. Correct log message outputting as expected for private ip NAT.

2022-05-11 16:13:10.976 [warning] Cannot use NAT IP lookup - "NAT: Private IP "
2022-05-11 16:13:10.976 [info] Trying IPFY as fallback
2022-05-11 16:13:11.648 [info] Node IP discovered: HIDDEN
2022-05-11 16:13:11.649 [info] Not previous synchronization date
2022-05-11 16:13:11.649 [info] We are using the default one
2022-05-11 16:13:11.649 [info] Node bootstrapping...

@ghost
Copy link

ghost commented May 11, 2022

Function ending with ? should return a boolean , it's the convention in Elixir codebases.
So your function should check the validity of the public ip it's all. The fallback should be part of the rest of caller function

@apoorv-2204
Copy link
Contributor Author

apoorv-2204 commented May 11, 2022

Function ending with ? should return a boolean , it's the convention in Elixir codebases. So your function should check the validity of the public ip it's all. The fallback should be part of the rest of caller function

My bad . on it,

@ghost
Copy link

ghost commented May 11, 2022

The point is not to rename it but simplify it a bit.
You just have to check the validity of the ip otherwise call the existing fallback method with something like this:

with {:ok, ip} <- apply(provider, :get_node_ip, []),
        true <- Networking.valid_ip?(ip) do
    Logger.info("Node IP discovered: #{:inet.ntoa(ip)} by #{provider}")
    ip
else
  false ->
    fallback(provider, "NAT: Private IP")
  {:error, reason} ->
    fallback(provider, reason)
end

@apoorv-2204
Copy link
Contributor Author

The point is not to rename it but simplify it a bit. You just have to check the validity of the ip otherwise call the existing fallback method with something like this:

with {:ok, ip} <- apply(provider, :get_node_ip, []),
        true <- Networking.valid_ip?(ip) do
    Logger.info("Node IP discovered: #{:inet.ntoa(ip)} by #{provider}")
    ip
else
  false ->
    fallback(provider, "NAT: Private IP")
  {:error, reason} ->
    fallback(provider, reason)
end

I agree , my bad

@apoorv-2204 apoorv-2204 requested a review from a user May 12, 2022 04:39
@ghost
Copy link

ghost commented May 12, 2022

Can you update the PR description from the template described ?

Also it would be great to add some unit tests

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

There are still improvements to be done, and you should avoid removing stuff already present, as it can lead to regression

config/dev.exs Show resolved Hide resolved
lib/archethic/networking/ip_lookup.ex Outdated Show resolved Hide resolved
config/prod.exs Show resolved Hide resolved
@ghost ghost added the bug Something isn't working label May 12, 2022
@apoorv-2204
Copy link
Contributor Author

There are still improvements to be done, and you should avoid removing stuff already present, as it can lead to regression

Sure, I will do the required changes.
thx

@apoorv-2204 apoorv-2204 requested review from roychowdhuryrohit-dev and removed request for roychowdhuryrohit-dev May 25, 2022 15:54
@apoorv-2204 apoorv-2204 requested review from a user and blackode and removed request for roychowdhuryrohit-dev May 27, 2022 05:55
config/dev.exs Outdated Show resolved Hide resolved
lib/archethic/networking.ex Outdated Show resolved Hide resolved
@apoorv-2204
Copy link
Contributor Author

apoorv-2204 commented May 27, 2022

MIX_ENV=prod iex -S mix

image

config/prod.exs Outdated Show resolved Hide resolved
@apoorv-2204
Copy link
Contributor Author

apoorv-2204 commented May 27, 2022

As per req: node in :prod crashes when given ARCHETHIC_NETWORKING_IMPL=STATIC
image

@ghost
Copy link

ghost commented May 27, 2022

As per req: node in :prod crashes when given ARCHETHIC_NETWORKING_IMPL=STATIC image

For static, we should set env var ARCHETHIC_STATIC_IP

@apoorv-2204
Copy link
Contributor Author

As per req: node in :prod crashes when given ARCHETHIC_NETWORKING_IMPL=STATIC image

For static, we should set env var ARCHETHIC_STATIC_IP

There is no fallback for static, when ran in with NAT, gets public ip.
And it is accessible via 127.0.0.1
image
image

config/config.exs Show resolved Hide resolved
config/prod.exs Outdated Show resolved Hide resolved
lib/archethic/networking.ex Show resolved Hide resolved
@ghost
Copy link

ghost commented May 27, 2022

otherwise it seems good 👍

@ghost ghost merged commit 165fc8c into archethic-foundation:develop May 27, 2022
@apoorv-2204 apoorv-2204 deleted the IPLookups#270 branch May 28, 2022 08:14
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P2P Involve P2P networking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants