Skip to content

Commit 34bb6d5

Browse files
committed
feat: add --listen-address flag
1 parent 327559c commit 34bb6d5

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

config/runtime.exs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ switches = [
1818
log_file: :string,
1919
beacon_api: :boolean,
2020
beacon_api_port: :integer,
21+
listen_address: :string,
2122
discovery_port: :integer,
2223
boot_nodes: :string,
2324
keystore_file: :string,
@@ -46,6 +47,7 @@ enable_metrics = Keyword.get(args, :metrics, false)
4647
metrics_port = Keyword.get(args, :metrics_port, if(enable_metrics, do: 9568, else: nil))
4748
beacon_api_port = Keyword.get(args, :beacon_api_port, nil)
4849
enable_beacon_api = Keyword.get(args, :beacon_api, not is_nil(beacon_api_port))
50+
listen_address = Keyword.get(args, :listen_address)
4951
discovery_port = Keyword.get(args, :discovery_port, 9000)
5052
cli_bootnodes = Keyword.get(args, :boot_nodes, "")
5153
keystore = Keyword.get(args, :keystore_file)
@@ -118,7 +120,10 @@ bootnodes =
118120
|> Enum.reject(&(&1 == ""))
119121
|> Enum.concat(bootnodes)
120122

121-
config :lambda_ethereum_consensus, :discovery, port: discovery_port, bootnodes: bootnodes
123+
config :lambda_ethereum_consensus, :libp2p,
124+
port: discovery_port,
125+
bootnodes: bootnodes,
126+
listen_addr: listen_address
122127

123128
# Engine API
124129

lib/lambda_ethereum_consensus/beacon/beacon_node.ex

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,34 @@ defmodule LambdaEthereumConsensus.Beacon.BeaconNode do
7979
end
8080

8181
defp get_libp2p_args() do
82-
config = Application.fetch_env!(:lambda_ethereum_consensus, :discovery)
82+
config = Application.fetch_env!(:lambda_ethereum_consensus, :libp2p)
8383
port = Keyword.fetch!(config, :port)
8484
bootnodes = Keyword.fetch!(config, :bootnodes)
8585

86+
listen_addr = Keyword.fetch!(config, :listen_addr) |> parse_listen_addr()
87+
8688
if Enum.empty?(bootnodes) do
8789
Logger.warning("No bootnodes configured.")
8890
end
8991

9092
[
91-
listen_addr: [],
93+
listen_addr: listen_addr,
9294
enable_discovery: true,
9395
discovery_addr: "0.0.0.0:#{port}",
9496
bootnodes: bootnodes
9597
]
9698
end
99+
100+
defp parse_listen_addr([]), do: []
101+
102+
defp parse_listen_addr(addr) do
103+
case String.split(addr, ":") do
104+
[ip, port] ->
105+
["/ip4/#{ip}/tcp/#{port}"]
106+
107+
_ ->
108+
Logger.error("Invalid listen address: #{addr}")
109+
System.halt(2)
110+
end
111+
end
97112
end

lib/libp2p_port.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ defmodule LambdaEthereumConsensus.Libp2pPort do
4848
]
4949

5050
@type init_arg ::
51-
{:listen_addr, String.t()}
51+
{:listen_addr, [String.t()]}
5252
| {:enable_discovery, boolean()}
5353
| {:discovery_addr, String.t()}
5454
| {:bootnodes, [String.t()]}
@@ -67,7 +67,7 @@ defmodule LambdaEthereumConsensus.Libp2pPort do
6767
* `:opts` - a Keyword list of options to pass onto the GenServer.
6868
Defaults to `[name: __MODULE__]`.
6969
70-
* `:listen_addr` - the address to listen on.
70+
* `:listen_addr` - the addresses to listen on.
7171
* `:enable_discovery` - boolean that specifies if the discovery service
7272
should be started.
7373
* `:discovery_addr` - the address used by the discovery service.

0 commit comments

Comments
 (0)