Skip to content
This repository has been archived by the owner on Jun 12, 2023. It is now read-only.

Commit

Permalink
Merge pull request #1479 from helium/jg/config_ports_from_radio_device
Browse files Browse the repository at this point in the history
Consolidate udp listener port config under radio_device
  • Loading branch information
Vagabond authored Mar 11, 2022
2 parents aebcdd8 + 82421b0 commit 7f78cf2
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 26 deletions.
4 changes: 2 additions & 2 deletions config/docker.config
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
[
{gateway_and_mux_enable, false},
{jsonrpc_ip, {0,0,0,0}}, %% bind jsonrpc to host when in docker container
{radio_device, { {0,0,0,0}, 1680, %% change to 1681 when activating mux+gateway-rs
{0,0,0,0}, 31341} },
{radio_device, { {0,0,0,0}, 1680,
{0,0,0,0}, 31341} },
{use_ebus, false}
]}
].
2 changes: 1 addition & 1 deletion config/sys.config
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
{update_dir, "/opt/miner/update"},
{api_base_url, "https://api.helium.io/v1"},
{election_interval, 30},
{radio_device, { {127,0,0,1}, 1680, %% change to 1681 when activating mux+gateway-rs
{radio_device, { {127,0,0,1}, 1680,
{127,0,0,1}, 31341} },
{default_routers, ["/p2p/11w77YQLhgUt8HUJrMtntGGr97RyXmot1ofs5Ct2ELTmbFoYsQa","/p2p/11afuQSrmk52mgxLu91AdtDXbJ9wmqWBUxC3hvjejoXkxEZfPvY"]},
{mark_mods, [miner_hbbft_handler]},
Expand Down
3 changes: 0 additions & 3 deletions priv/gateway_rs/settings.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
## semtech listening address override
listen = "127.0.0.1:1682"

## api listening port override
api = 4468

Expand Down
4 changes: 2 additions & 2 deletions src/miner_gateway_ecc_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ start_link(Options) when is_list(Options) ->

init([Options]) ->
Transport = proplists:get_value(transport, Options, tcp),
Host = proplists:get_value(host, Options, "localhost"),
Port = proplists:get_value(port, Options, 4468),
Host = proplists:get_value(host, Options, "127.0.0.1"),
Port = proplists:get_value(api_port, Options, 4468),
{ok, #{http_connection := ConnPid} = Connection} = grpc_connect(Transport, Host, Port),
MonRef = erlang:monitor(process, ConnPid),
{ok, #state{
Expand Down
32 changes: 23 additions & 9 deletions src/miner_gateway_port.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
keypair,
transport=tcp,
host="localhost",
port=4468,
port,
monitor,
os_pid,
tcp_port
tcp_port=4468,
udp_port
}).

-define(CONNECT_RETRY_WAIT, 100).
Expand All @@ -35,13 +36,14 @@ start_link(Options) when is_list(Options) ->

init([Options]) ->
Keypair = proplists:get_value(keypair, Options),
TcpPort = proplists:get_value(port, Options, 4468),
Host = proplists:get_value(host, Options, "localhost"),
TcpPort = proplists:get_value(api_port, Options, 4468),
UdpPort = proplists:get_value(radio_port, Options, 1682),
Host = proplists:get_value(host, Options, "127.0.0.1"),
Transport = proplists:get_value(transport, Options, tcp),

process_flag(trap_exit, true),

State = open_gateway_port(Keypair, Transport, Host, TcpPort),
State = open_gateway_port(Keypair, Transport, Host, UdpPort, TcpPort),
{ok, State}.

handle_call(_Msg, _From, State) ->
Expand All @@ -55,7 +57,12 @@ handle_cast(_Msg, State) ->
handle_info({Port, {exit_status, Status}}, #state{port = Port} = State) ->
lager:warning("gateway-rs process ~p exited with status ~p, restarting", [Port, Status]),
ok = cleanup_port(State),
NewState = open_gateway_port(State#state.keypair, State#state.transport, State#state.host, State#state.tcp_port),
NewState = open_gateway_port(
State#state.keypair,
State#state.transport,
State#state.host,
State#state.udp_port,
State#state.tcp_port),
ok = miner_gateway_ecc_worker:reconnect(),
{noreply, NewState};
handle_info({Port, {data, LogMsg}}, #state{port = Port} = State) ->
Expand All @@ -65,7 +72,12 @@ handle_info({Port, {data, LogMsg}}, #state{port = Port} = State) ->
handle_info({'DOWN', Ref, port, _Pid, Reason}, #state{port = Port, monitor = Ref} = State) ->
lager:warning("gateway-rs port ~p down with reason ~p, restarting", [Port, Reason]),
ok = cleanup_port(State),
NewState = open_gateway_port(State#state.keypair, State#state.transport, State#state.host, State#state.tcp_port),
NewState = open_gateway_port(
State#state.keypair,
State#state.transport,
State#state.host,
State#state.udp_port,
State#state.tcp_port),
ok = miner_gateway_ecc_worker:reconnect(),
{noreply, NewState};
handle_info(_Msg, State) ->
Expand All @@ -75,9 +87,11 @@ handle_info(_Msg, State) ->
terminate(_, State) ->
ok = cleanup_port(State).

open_gateway_port(KeyPair, Transport, Host, TcpPort) ->
open_gateway_port(KeyPair, Transport, Host, UdpPort, TcpPort) ->
Args = ["-c", gateway_config_dir(), "--stdin", "server"],
GatewayEnv0 = [{"GW_API", erlang:integer_to_list(TcpPort)}, {"GW_KEYPAIR", KeyPair}],
GatewayEnv0 = [{"GW_API", erlang:integer_to_list(TcpPort)},
{"GW_KEYPAIR", KeyPair},
{"GW_LISTEN", lists:flatten(io_lib:format("~s:~p", [Host, UdpPort]))}],
GatewayEnv =
case application:get_env(miner, gateway_env) of
undefined ->
Expand Down
19 changes: 12 additions & 7 deletions src/miner_port_services_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ init(_Opts) ->
period => 1
},

GatewayTcpPort = application:get_env(miner, gateway_api_port, 4468),

KeyPair =
case application:get_env(blockchain, key, undefined) of
undefined ->
Expand Down Expand Up @@ -74,17 +72,24 @@ init(_Opts) ->
end
end,

{ListenAddr, UdpListenPort} =
case application:get_env(miner, radio_device, undefined) of
{{Oct1, Oct2, Oct3, Oct4}, ListenPort, _, _} ->
{lists:flatten(io_lib:format("~p.~p.~p.~p", [Oct1, Oct2, Oct3, Oct4])), ListenPort};
_ -> {"127.0.0.1", 1680}
end,

GatewayECCWorkerOpts = [
{transport, application:get_env(miner, gateway_transport, tcp)},
{host, application:get_env(miner, gateway_host, "localhost")},
{port, GatewayTcpPort}
{host, ListenAddr},
{api_port, application:get_env(miner, gateway_api_port, 4468)}
],

GatewayPortOpts = [{keypair, KeyPair}] ++ GatewayECCWorkerOpts,
GatewayPortOpts = [{keypair, KeyPair}, {radio_port, UdpListenPort + 2}] ++ GatewayECCWorkerOpts,

MuxOpts = [
{host_port, application:get_env(miner, mux_host_port, 1680)},
{client_ports, application:get_env(miner, mux_client_ports, [1681, 1682])}
{host_port, UdpListenPort},
{client_ports, [UdpListenPort + 1, UdpListenPort + 2]}
],

ChildSpecs =
Expand Down
7 changes: 6 additions & 1 deletion src/miner_restart_sup.erl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ init(_Opts) ->

OnionServer =
case application:get_env(miner, radio_device, undefined) of
{RadioBindIP, RadioBindPort, RadioSendIP, RadioSendPort} ->
{RadioBindIP, RadioBindPort0, RadioSendIP, RadioSendPort} ->
RadioBindPort =
case application:get_env(miner, gateway_and_mux_enable, false) of
false -> RadioBindPort0;
true -> RadioBindPort0 + 1
end,
%% check if we are overriding/forcing the region ( for lora )
RegionOverRide = check_for_region_override(),
OnionOpts = #{
Expand Down
2 changes: 1 addition & 1 deletion test/miner_gateway_mux_integration_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ all() ->
init_per_suite(Config) ->
ok = application:load(miner),
ok = application:set_env(miner, gateway_and_mux_enable, true),
ok = application:set_env(miner, radio_device, {{127, 0, 0, 1}, 1681, {127, 0, 0, 1}, 31341}),
ok = application:set_env(miner, radio_device, {{127, 0, 0, 1}, 1680, deprecated, deprecated}),
application:ensure_all_started(miner),
Config.

Expand Down

0 comments on commit 7f78cf2

Please sign in to comment.