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

Require upnpc as external executable #1036

Merged
merged 1 commit into from
May 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ RUN apk add --no-cache --update \
wget \
openssl \
libsodium-dev \
gmp-dev
gmp-dev \
miniupnpc


# Install hex and rebar
Expand Down
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ compile_c_programs:
$(CC) src/c/crypto/stdio_helpers.c src/c/crypto/ed25519.c -o priv/c_dist/libsodium_port -I src/c/crypto/stdio_helpers.h -lsodium
$(CC) src/c/hypergeometric_distribution.c -o priv/c_dist/hypergeometric_distribution -lgmp

git submodule update --force --recursive --init --remote
$(MAKE) -C src/c/nat/miniupnp/miniupnpc
cp src/c/nat/miniupnp/miniupnpc/build/upnpc-static priv/c_dist/upnpc


ifeq ($(TPM_INSTALLED),0)
$(CC) src/c/crypto/stdio_helpers.c src/c/crypto/tpm/lib.c src/c/crypto/tpm/port.c -o priv/c_dist/tpm_port -I src/c/crypto/stdio_helpers.h -I src/c/crypto/tpm/lib.h $(TPMFLAGS)
$(CC) src/c/crypto/tpm/keygen.c src/c/crypto/tpm/lib.c -o priv/c_dist/tpm_keygen -I src/c/crypto/tpm/lib.h $(TPMFLAGS)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Requirements:
- Erlang OTP 25
- Elixir 1.14
- GMP (https://gmplib.org/)
- MiniUPnP used for port forwarding & IP lookup (https://miniupnp.tuxfamily.org/)

Platforms supported:

Expand Down
10 changes: 5 additions & 5 deletions lib/archethic/networking/ip_lookup/nat_discovery/miniupnp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ defmodule Archethic.Networking.IPLookup.NATDiscovery.MiniUPNP do

require Logger

@upnpc Application.app_dir(:archethic, "priv/c_dist/upnpc")
@upnp_command "upnpc"

@spec get_node_ip() :: {:ok, :inet.ip_address()} | {:error, any()}
def get_node_ip do
case System.cmd(@upnpc, ["-s"]) do
case System.cmd(@upnp_command, ["-s"]) do
{output, 0} ->
[[_, ip]] = Regex.scan(~r/ExternalIPAddress = ([0-9.]*)/, output, capture: :all)

Expand All @@ -29,7 +29,7 @@ defmodule Archethic.Networking.IPLookup.NATDiscovery.MiniUPNP do
end

defp get_local_ip do
case System.cmd(@upnpc, ["-s"]) do
case System.cmd(@upnp_command, ["-s"]) do
{output, 0} ->
[[_, ip]] = Regex.scan(~r/Local LAN ip address : ([0-9.]*)/, output, capture: :all)

Expand All @@ -49,7 +49,7 @@ defmodule Archethic.Networking.IPLookup.NATDiscovery.MiniUPNP do
defp do_open_port(_local_ip, _port, 0), do: :error

defp do_open_port(local_ip, port, retries) do
case System.cmd(@upnpc, map_query(local_ip, port)) do
case System.cmd(@upnp_command, map_query(local_ip, port)) do
{_, 0} ->
:ok

Expand Down Expand Up @@ -87,7 +87,7 @@ defmodule Archethic.Networking.IPLookup.NATDiscovery.MiniUPNP do
defp handle_error(reason, _local_ip, port) do
if Regex.scan(~r/ConflictInMappingEntry/, reason, capture: :all) != [] do
Logger.warning("Port is employed to another host.")
System.cmd(@upnpc, revoke_query(port))
System.cmd(@upnp_command, revoke_query(port))
end
end

Expand Down
1 change: 0 additions & 1 deletion src/c/nat/miniupnp
Submodule miniupnp deleted from 836fba
Loading