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
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
00cd561
retrive public ip in prod
apoorv-2204 May 11, 2022
776a0f2
Amend method name publicip to is_public_ip
apoorv-2204 May 11, 2022
6e0a771
improve method is_public_ip
apoorv-2204 May 11, 2022
9a4b541
Simplify logic
apoorv-2204 May 11, 2022
7450cb9
remove private ip from production
apoorv-2204 May 12, 2022
71cb2f6
remove static alias
apoorv-2204 May 12, 2022
e10dba3
add validate_ip ? modify logic
apoorv-2204 May 12, 2022
725087b
restore defaults
apoorv-2204 May 13, 2022
71ed0a9
add simple solution
apoorv-2204 May 13, 2022
5e13cb6
remove mining_pending_txn Module parameters || add validate ip in Net…
apoorv-2204 May 13, 2022
8f99f76
add mock tests
apoorv-2204 May 13, 2022
49a61aa
redo add mock tests for iplookup
apoorv-2204 May 13, 2022
a44a77e
remove unused aliases|| modify config/test.exs
apoorv-2204 May 13, 2022
46d7e68
improve code
apoorv-2204 May 16, 2022
19be245
mix format
apoorv-2204 May 16, 2022
5593675
rollback config file changes
apoorv-2204 May 17, 2022
337ba4f
trying to add default_impl
apoorv-2204 May 18, 2022
a8a896c
refactor to improve code feasiblity
apoorv-2204 May 18, 2022
b76fb61
add changes related to refactor
apoorv-2204 May 18, 2022
8b94f45
correct typos || refactor Iplookuptests.ex
apoorv-2204 May 18, 2022
ec896da
Archethic.Networking.IPLookup.NAT is not a behaviour
apoorv-2204 May 18, 2022
6d6028b
use knigge to refactor for test feasiblity
apoorv-2204 May 18, 2022
c00bc82
remove unused import mox from trasaction_controller_test
apoorv-2204 May 18, 2022
373ed33
add kenige.verify
apoorv-2204 May 23, 2022
ea1527d
add mix knigge
apoorv-2204 May 23, 2022
5621518
simplify iplookuptest.exs
apoorv-2204 May 23, 2022
5361ba1
modify production.exs for Lookup And PublicGateway modules
apoorv-2204 May 23, 2022
e801908
add mix prod alias
apoorv-2204 May 23, 2022
3a7b5fd
revert prod.exs
apoorv-2204 May 23, 2022
25c27d8
simplifiy fallback
apoorv-2204 May 23, 2022
190d7ac
add prod alias with no tpm
apoorv-2204 May 23, 2022
4b8e28f
add localdiscovery in iplookup
apoorv-2204 May 23, 2022
7828c4e
temp
apoorv-2204 May 23, 2022
8103a06
Revert "temp"
apoorv-2204 May 23, 2022
23e7ff3
mess complete mess
apoorv-2204 May 23, 2022
914e9db
revert to "temp"
apoorv-2204 May 23, 2022
546bf0b
Revert "add localdiscovery in iplookup"
apoorv-2204 May 23, 2022
4c40458
any another way to address module patter mathching
apoorv-2204 May 24, 2022
5dcf619
simplifiy tests
apoorv-2204 May 24, 2022
724f7e3
improve test naming
apoorv-2204 May 24, 2022
f9ab92b
add guidlines
apoorv-2204 May 24, 2022
3fb49bc
format dev-guidlines
apoorv-2204 May 24, 2022
2fbe208
correct dev.exs
apoorv-2204 May 24, 2022
2251603
format dev.exs
apoorv-2204 May 24, 2022
a5732fd
modify params
apoorv-2204 May 24, 2022
eb90f96
provide new abstraction
apoorv-2204 May 25, 2022
f7f9697
remove patch , kept for history
apoorv-2204 May 25, 2022
41f6748
refactor code for mock test feasibility
apoorv-2204 May 25, 2022
fcc466e
resolve git hooks
apoorv-2204 May 25, 2022
d0550af
change LocalDiscovery TO NATDiscovery
apoorv-2204 May 25, 2022
9f7a725
correct prod.exs
apoorv-2204 May 25, 2022
de87425
request change p1
apoorv-2204 May 25, 2022
eee1f96
revert the handler
apoorv-2204 May 25, 2022
27f2688
correct tests
apoorv-2204 May 25, 2022
6faabf0
add spec
apoorv-2204 May 25, 2022
bf03e23
correct specs
apoorv-2204 May 25, 2022
d4cced7
remove specs causing dialyzer issues
apoorv-2204 May 25, 2022
389cf53
add {:error, error} return from remote discovery
apoorv-2204 May 25, 2022
a9ac434
resolve fallback in remote discovery
apoorv-2204 May 25, 2022
a53693c
Revert "resolve fallback in remote discovery"
apoorv-2204 May 25, 2022
62d6b04
adopt suggested changes in remote dicovery
apoorv-2204 May 25, 2022
e495db3
resolve {}
apoorv-2204 May 25, 2022
b3de554
requested changes
apoorv-2204 May 27, 2022
90feb3a
correct ipfy to ipify in prod.exs
apoorv-2204 May 27, 2022
3360f8a
amend if else clause instead of case in networking.exs
apoorv-2204 May 27, 2022
904a023
change in sys_env: ipify to remote discovery in prod.exs
apoorv-2204 May 27, 2022
1da9df9
change module_args() to provider()
apoorv-2204 May 27, 2022
d63fa9f
add remote
apoorv-2204 May 27, 2022
1a5c30d
add @type specs and docs
apoorv-2204 May 27, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ config :archethic, Archethic.OracleChain.Scheduler,
# Aggregate chain at the 50th second
summary_interval: "0 * * * * *"

config :archethic, Archethic.Networking.IPLookup, Archethic.Networking.IPLookup.Static

config :archethic, Archethic.Networking.IPLookup.Static,
apoorv-2204 marked this conversation as resolved.
Show resolved Hide resolved
hostname: System.get_env("ARCHETHIC_STATIC_IP", "127.0.0.1")
config :archethic, Archethic.Networking.IPLookup, provider: Archethic.Networking.IPLookup.Static

config :archethic, Archethic.Networking.Scheduler, interval: "0 * * * * * *"

Expand Down
36 changes: 22 additions & 14 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,29 @@ config :archethic, Archethic.Mining.PendingTransactionValidation,
:software
end)

config :archethic,
Archethic.Networking.IPLookup,
(case(System.get_env("ARCHETHIC_NETWORKING_IMPL", "NAT") |> String.upcase()) do
"NAT" ->
Archethic.Networking.IPLookup.NAT
config(
:archethic,
Archethic.Networking.IPLookup,
provider:
case(System.get_env("ARCHETHIC_NETWORKING_IMPL", "NAT") |> String.upcase()) do
"NAT" ->
Archethic.Networking.IPLookup.NAT

"STATIC" ->
Archethic.Networking.IPLookup.Static

"IPFY" ->
Archethic.Networking.IPLookup.IPIFY
end,
validate_node_ip:
case(System.get_env("ARCHETHIC_NODE_IP_VALIDATION", "true")) do
"true" ->
true

"STATIC" ->
Archethic.Networking.IPLookup.Static

"IPFY" ->
Archethic.Networking.IPLookup.IPIFY
end)
_ ->
false
end
)

config :archethic, Archethic.Networking.PortForwarding,
enabled:
Expand All @@ -166,9 +177,6 @@ config :archethic, Archethic.Networking.PortForwarding,
false
end)

config :archethic, Archethic.Networking.IPLookup.Static,
apoorv-2204 marked this conversation as resolved.
Show resolved Hide resolved
hostname: System.get_env("ARCHETHIC_STATIC_IP")

config :archethic, Archethic.Networking.Scheduler,
interval: System.get_env("ARCHETHIC_NETWORKING_UPDATE_SCHEDULER", "0 0 * * * * *")

Expand Down
33 changes: 26 additions & 7 deletions lib/archethic/networking/ip_lookup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ defmodule Archethic.Networking.IPLookup do

alias __MODULE__.IPIFY
alias __MODULE__.NAT
alias Archethic.Networking

require Logger

Expand All @@ -16,23 +17,29 @@ defmodule Archethic.Networking.IPLookup do
provider = get_provider()

ip =
case apply(provider, :get_node_ip, []) do
{:ok, ip} ->
case {apply(provider, :get_node_ip, []), should_validate_node_ip?()} do
apoorv-2204 marked this conversation as resolved.
Show resolved Hide resolved
{{:ok, ip}, true} ->
case Networking.valid_ip?(ip) do
true ->
Logger.info("Node IP discovered by #{provider}")
ip

false ->
fallback(provider, "NAT: Private IP ")
end

{{:ok, ip}, false} ->
Logger.info("Node IP discovered by #{provider}")
ip

{:error, reason} ->
{{:error, reason}, _} ->
fallback(provider, reason)
end

Logger.info("Node IP discovered: #{:inet.ntoa(ip)}")
ip
end

defp get_provider do
Application.get_env(:archethic, __MODULE__)
end

defp fallback(NAT, reason) do
Logger.warning("Cannot use NAT IP lookup - #{inspect(reason)}")
Logger.info("Trying IPFY as fallback")
Expand All @@ -49,4 +56,16 @@ defmodule Archethic.Networking.IPLookup do
defp fallback(provider, reason) do
raise "Cannot use #{provider} IP lookup - #{inspect(reason)}"
end

defp get_provider() do
:archethic
|> Application.get_env(__MODULE__, [])
|> Keyword.get(:provider)
end

def should_validate_node_ip?() do
:archethic
|> Application.get_env(__MODULE__, [])
|> Keyword.get(:validate_node_ip, false)
end
end