support adjusting listening options

This commit is contained in:
Alain Zscheile 2022-11-24 20:29:30 +01:00
parent 825b65f9ee
commit 47f4dadad7
3 changed files with 23 additions and 12 deletions

View file

@ -5,14 +5,17 @@ defmodule Floof do
require Logger
def accept(port) do
def accept(port, opts \\ []) do
{:ok, socket} =
:gen_tcp.listen(port, [
:binary,
packet: 4,
active: false,
reuseaddr: true
])
:gen_tcp.listen(
port,
[
:binary,
packet: 4,
active: false,
reuseaddr: true
] ++ opts
)
Logger.info("Accepting connections on #{port}")
loop_acceptor(socket)

View file

@ -8,7 +8,8 @@ defmodule Floof.Application do
@impl true
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)
markers = Application.fetch_env!(:floof, :markers)
attrs = Application.fetch_env!(:floof, :attrs)
@ -36,9 +37,13 @@ defmodule Floof.Application do
pubkey_mgr: pubkey_mgr,
pubkey_config: pubkey_config
), Floof.DistributorSeen}},
{Floof.SessionManager, %{}},
{Task, fn -> Floof.accept(port) end}
{Floof.SessionManager, %{}}
] ++
if listen_port != nil do
[{Task, fn -> Floof.accept(listen_port, listen_opts) end}]
else
[]
end ++
for upstream <- upstreams do
{host, port} =
case upstream do

View file

@ -20,8 +20,11 @@ defmodule Floof.MixProject do
extra_applications: [:asn1, :logger],
mod: {Floof.Application, []},
env: [
port: 2540,
# upstreams have structure {host, port} or {host} (port defaults to 2540)
# listen_port cam be set to `nil` to disable to server-socket listener
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: [],
# 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