-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes #270 Improve handling of IP lookup providers and fallbacks
- Loading branch information
1 parent
cbff7e7
commit 165fc8c
Showing
17 changed files
with
350 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
defmodule Archethic.Networking.IPLookup.NATDiscovery do | ||
@moduledoc """ | ||
Provide abstraction over :natupnp_v1, :natupnp_v2, :natpmp | ||
""" | ||
|
||
alias Archethic.Networking.IPLookup.Impl | ||
|
||
alias __MODULE__.UPnPv1 | ||
alias __MODULE__.UPnPv2 | ||
alias __MODULE__.PMP | ||
|
||
require Logger | ||
|
||
@behaviour Impl | ||
def get_node_ip() do | ||
provider = provider() | ||
do_get_node_ip(provider) | ||
end | ||
|
||
defp do_get_node_ip(provider) do | ||
case provider.get_node_ip() do | ||
{:ok, ip} -> | ||
{:ok, ip} | ||
|
||
{:error, reason} -> | ||
Logger.error( | ||
"Cannot use the provider #{provider} for IP Lookup - reason: #{inspect(reason)}" | ||
) | ||
|
||
fallback(provider, reason) | ||
end | ||
end | ||
|
||
defp fallback(UPnPv1, _reason) do | ||
do_get_node_ip(UPnPv2) | ||
end | ||
|
||
defp fallback(UPnPv2, _reason) do | ||
do_get_node_ip(PMP) | ||
end | ||
|
||
defp fallback(PMP, reason) do | ||
{:error, reason} | ||
end | ||
|
||
defp fallback(_provider, reason) do | ||
{:error, reason} | ||
end | ||
|
||
defp provider() do | ||
:archethic | ||
|> Application.get_env(__MODULE__, []) | ||
|> Keyword.get(:provider, UPnPv1) | ||
end | ||
end |
Oops, something went wrong.