support adjusting listening options
This commit is contained in:
parent
825b65f9ee
commit
47f4dadad7
3 changed files with 23 additions and 12 deletions
17
lib/floof.ex
17
lib/floof.ex
|
@ -5,14 +5,17 @@ defmodule Floof do
|
||||||
|
|
||||||
require Logger
|
require Logger
|
||||||
|
|
||||||
def accept(port) do
|
def accept(port, opts \\ []) do
|
||||||
{:ok, socket} =
|
{:ok, socket} =
|
||||||
:gen_tcp.listen(port, [
|
:gen_tcp.listen(
|
||||||
:binary,
|
port,
|
||||||
packet: 4,
|
[
|
||||||
active: false,
|
:binary,
|
||||||
reuseaddr: true
|
packet: 4,
|
||||||
])
|
active: false,
|
||||||
|
reuseaddr: true
|
||||||
|
] ++ opts
|
||||||
|
)
|
||||||
|
|
||||||
Logger.info("Accepting connections on #{port}")
|
Logger.info("Accepting connections on #{port}")
|
||||||
loop_acceptor(socket)
|
loop_acceptor(socket)
|
||||||
|
|
|
@ -8,7 +8,8 @@ defmodule Floof.Application do
|
||||||
|
|
||||||
@impl true
|
@impl true
|
||||||
def start(_type, _args) do
|
def start(_type, _args) do
|
||||||
port = Application.fetch_env!(:floof, :port)
|
listen_port = Application.fetch_env!(:floof, :listen_port)
|
||||||
|
listen_opts = Application.fetch_env!(:floof, :listen_opts)
|
||||||
upstreams = Application.fetch_env!(:floof, :upstreams)
|
upstreams = Application.fetch_env!(:floof, :upstreams)
|
||||||
markers = Application.fetch_env!(:floof, :markers)
|
markers = Application.fetch_env!(:floof, :markers)
|
||||||
attrs = Application.fetch_env!(:floof, :attrs)
|
attrs = Application.fetch_env!(:floof, :attrs)
|
||||||
|
@ -36,9 +37,13 @@ defmodule Floof.Application do
|
||||||
pubkey_mgr: pubkey_mgr,
|
pubkey_mgr: pubkey_mgr,
|
||||||
pubkey_config: pubkey_config
|
pubkey_config: pubkey_config
|
||||||
), Floof.DistributorSeen}},
|
), Floof.DistributorSeen}},
|
||||||
{Floof.SessionManager, %{}},
|
{Floof.SessionManager, %{}}
|
||||||
{Task, fn -> Floof.accept(port) end}
|
|
||||||
] ++
|
] ++
|
||||||
|
if listen_port != nil do
|
||||||
|
[{Task, fn -> Floof.accept(listen_port, listen_opts) end}]
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
end ++
|
||||||
for upstream <- upstreams do
|
for upstream <- upstreams do
|
||||||
{host, port} =
|
{host, port} =
|
||||||
case upstream do
|
case upstream do
|
||||||
|
|
7
mix.exs
7
mix.exs
|
@ -20,8 +20,11 @@ defmodule Floof.MixProject do
|
||||||
extra_applications: [:asn1, :logger],
|
extra_applications: [:asn1, :logger],
|
||||||
mod: {Floof.Application, []},
|
mod: {Floof.Application, []},
|
||||||
env: [
|
env: [
|
||||||
port: 2540,
|
# listen_port cam be set to `nil` to disable to server-socket listener
|
||||||
# upstreams have structure {host, port} or {host} (port defaults to 2540)
|
listen_port: 2540,
|
||||||
|
# listen_opts can be used to specify e.g. `[ip: {192,168,0,133}]` a specific interface IP
|
||||||
|
listen_opts: [],
|
||||||
|
# upstreams have structure `{host, port}` or `{host}` (port defaults to 2540)
|
||||||
upstreams: [],
|
upstreams: [],
|
||||||
# markers have the structure {bool(), {:RelativeDistinguishedName, oid-as-list(), value()}}
|
# markers have the structure {bool(), {:RelativeDistinguishedName, oid-as-list(), value()}}
|
||||||
# all of the markers marked with 'true' should be included in each message to-be-processed
|
# all of the markers marked with 'true' should be included in each message to-be-processed
|
||||||
|
|
Loading…
Reference in a new issue