start ipc server

pull/2791/head
Ayrat Badykov 5 years ago
parent 10fcd5800c
commit f03ead074c
No known key found for this signature in database
GPG Key ID: B44668E265E9396F
  1. 5
      apps/ethereum_jsonrpc/config/config.exs
  2. 10
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/application.ex
  3. 15
      apps/ethereum_jsonrpc/lib/ethereum_jsonrpc/ipc.ex

@ -9,6 +9,11 @@ config :ethereum_jsonrpc, EthereumJSONRPC.RequestCoordinator,
wait_per_timeout: :timer.seconds(20), wait_per_timeout: :timer.seconds(20),
max_jitter: :timer.seconds(2) max_jitter: :timer.seconds(2)
config :ethereum_jsonrpc,
rpc_transport: if(System.get_env("ETHEREUM_JSONRPC_JSON_RPC_TRANSPORT", "http") == "http", do: :http, else: :ipc),
ipc_path: System.get_env("IPC_PATH")
# Add this configuration to add global RPC request throttling. # Add this configuration to add global RPC request throttling.
# throttle_rate_limit: 250, # throttle_rate_limit: 250,
# throttle_rolling_window_opts: [ # throttle_rolling_window_opts: [

@ -5,7 +5,7 @@ defmodule EthereumJSONRPC.Application do
use Application use Application
alias EthereumJSONRPC.{RequestCoordinator, RollingWindow} alias EthereumJSONRPC.{IPC, RequestCoordinator, RollingWindow}
@impl Application @impl Application
def start(_type, _args) do def start(_type, _args) do
@ -17,6 +17,7 @@ defmodule EthereumJSONRPC.Application do
:hackney_pool.child_spec(:ethereum_jsonrpc, recv_timeout: 60_000, timeout: 60_000, max_connections: 1000), :hackney_pool.child_spec(:ethereum_jsonrpc, recv_timeout: 60_000, timeout: 60_000, max_connections: 1000),
Supervisor.child_spec({RollingWindow, [rolling_window_opts]}, id: RollingWindow.ErrorThrottle) Supervisor.child_spec({RollingWindow, [rolling_window_opts]}, id: RollingWindow.ErrorThrottle)
] ]
|> add_ipc_client()
|> add_throttle_rolling_window(config) |> add_throttle_rolling_window(config)
|> Supervisor.start_link(strategy: :one_for_one, name: EthereumJSONRPC.Supervisor) |> Supervisor.start_link(strategy: :one_for_one, name: EthereumJSONRPC.Supervisor)
end end
@ -37,4 +38,11 @@ defmodule EthereumJSONRPC.Application do
children children
end end
end end
defp add_ipc_client(children) do
case Application.get_env(:ethereum_jsonrpc, :rpc_transport) do
:ipc -> [IPC.child_spec([path: Application.get_env(:ethereum_jsonrpc, :ipc_path)]) | children]
_ -> children
end
end
end end

@ -4,8 +4,19 @@ defmodule EthereumJSONRPC.IPC do
# Server # Server
def start_link(state \\ []) do def child_spec(opts) do
GenServer.start_link(__MODULE__, Keyword.merge(state, socket: nil)) IO.inspect(opts)
default = %{
id: __MODULE__,
start: {__MODULE__, :start_link, opts},
type: :worker
}
Supervisor.child_spec(default, [])
end
def start_link({:path, path}) do
GenServer.start_link(__MODULE__, [path: path, socket: nil])
end end
def init(state) do def init(state) do

Loading…
Cancel
Save