Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorv-2204 committed May 23, 2022
1 parent 4b8e28f commit 7828c4e
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,13 @@ config :archethic,
Archethic.Networking.IPLookup,
(case(System.get_env("ARCHETHIC_NETWORKING_IMPL", "NAT") |> String.upcase()) do
"NAT" ->
Archethic.Networking.IPLookup.NAT
Archethic.Networking.IPLookup.LocalDiscovery

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

"IPFY" ->
Archethic.Networking.IPLookup.IPIFY
Archethic.Networking.IPLookup.PublicGateway
end)

config :archethic, Archethic.Networking.PortForwarding,
Expand Down
4 changes: 2 additions & 2 deletions config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ config :archethic, Archethic.Networking, validate_node_ip: false
config :archethic, Archethic.Networking.IPLookup, MockIPLookup

config :archethic, Archethic.Networking.IPLookup.Static, MockStatic
config :archethic, Archethic.Networking.IPLookup.LocalDiscovery, MockLocalDiscovery
config :archethic, Archethic.Networking.IPLookup.PublicGateway, MockPublicGateway
config :archethic, Archethic.Networking.IPLookup.NAT, MockNAT
config :archethic, Archethic.Networking.IPLookup.IPIFY, MockIPIFY

config :archethic, Archethic.Networking.PortForwarding, MockPortForwarding
config :archethic, Archethic.Networking.Scheduler, enabled: false
Expand Down
2 changes: 1 addition & 1 deletion lib/archethic/networking/ip_lookup.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ defmodule Archethic.Networking.IPLookup do
Logger.info("Node IP discovered by #{provider}")
ip
else
{:error, reason} when provider == Archethic.Networking.IPLookup.NAT ->
{:error, reason} when provider == LocalDiscovery ->
fallback(LocalDiscovery, reason)

{:error, reason} ->
Expand Down
2 changes: 2 additions & 0 deletions lib/archethic/networking/ip_lookup/ipify.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ defmodule Archethic.Networking.IPLookup.IPIFY do
"""

alias Archethic.Networking.IPLookup.PublicGateway
alias Archethic.Networking.IPLookup.Impl

@behaviour Impl
@behaviour PublicGateway

@impl PublicGateway
Expand Down
2 changes: 2 additions & 0 deletions lib/archethic/networking/ip_lookup/nat.ex
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ defmodule Archethic.Networking.IPLookup.NAT do
"""

alias Archethic.Networking.IPLookup.LocalDiscovery
alias Archethic.Networking.IPLookup.Impl

@behaviour Impl
@behaviour LocalDiscovery

@impl LocalDiscovery
Expand Down
14 changes: 8 additions & 6 deletions test/archethic/networking/ip_lookup_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule Archethic.Networking.IPLookupTest do
use ExUnit.Case, async: false
import Mox
import Archethic.Networking.IPLookup, only: [get_node_ip: 0]
alias Archethic.Networking.IPLookup.LocalDiscovery
alias Archethic.Networking.IPLookup.PublicGateway

def put_conf(validate_node_ip: validate_node_ip, mock_module: mock_module) do
Application.put_env(
Expand Down Expand Up @@ -36,30 +38,30 @@ defmodule Archethic.Networking.IPLookupTest do
MockStatic
|> stub(:get_node_ip, fn -> {:ok, {127, 0, 0, 1}} end)

MockPublicGateway
MockIPIFY
|> stub(:get_node_ip, fn -> {:ok, {17, 5, 7, 8}} end)

assert {17, 5, 7, 8} == get_node_ip()
end

test "Prod-mode: Private IP(NAT), it must fallback to IPIFY to get public IP" do
# set prod mode configuration values
put_conf(validate_node_ip: true, mock_module: MockLocalDiscovery)
put_conf(validate_node_ip: true, mock_module: LocalDiscovery)

MockLocalDiscovery
MockNAT
|> stub(:get_node_ip, fn -> {:ok, {0, 0, 0, 0}} end)

MockPublicGateway
MockIPIFY
|> stub(:get_node_ip, fn -> {:ok, {17, 5, 7, 8}} end)

assert {17, 5, 7, 8} == get_node_ip()
end

test "IPIFIY IP: returns public IP" do
# set prod mode configuration values
put_conf(validate_node_ip: true, mock_module: MockPublicGateway)
put_conf(validate_node_ip: true, mock_module: PublicGateway)

MockPublicGateway
MockIPIFY
|> stub(:get_node_ip, fn -> {:ok, {17, 5, 7, 8}} end)

assert {17, 5, 7, 8} == get_node_ip()
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ Mox.defmock(MockMetricsCollector, for: Archethic.Metrics.Collector)
# -----Start-of-Networking-Mocks-----

Mox.defmock(MockStatic, for: Archethic.Networking.IPLookup.Impl)
Mox.defmock(MockLocalDiscovery, for: Archethic.Networking.IPLookup.LocalDiscovery)
Mox.defmock(MockPublicGateway, for: Archethic.Networking.IPLookup.PublicGateway)
Mox.defmock(MockNAT, for: Archethic.Networking.IPLookup.Impl)
Mox.defmock(MockIPIFY, for: Archethic.Networking.IPLookup.Impl)

Mox.defmock(MockIPLookup, for: Archethic.Networking.IPLookup.Impl)

Expand Down

0 comments on commit 7828c4e

Please sign in to comment.