add ability to supply arbitrary filters
This commit is contained in:
parent
740bee0073
commit
7bbf59625a
|
@ -14,6 +14,7 @@ defmodule Floof.Application do
|
|||
markers = Application.fetch_env!(:floof, :markers)
|
||||
attrs = Application.fetch_env!(:floof, :attrs)
|
||||
set_markers = Application.fetch_env!(:floof, :set_markers)
|
||||
extra_filters = Application.fetch_env!(:floof, :extra_filters)
|
||||
spool_dir = Application.fetch_env!(:floof, :spool_dir)
|
||||
sessions_file = Application.fetch_env!(:floof, :sessions_file)
|
||||
|
||||
|
@ -28,7 +29,8 @@ defmodule Floof.Application do
|
|||
Floof.Distributor.fconfig(
|
||||
markers: markers,
|
||||
attrs: attrs,
|
||||
set_markers: set_markers
|
||||
set_markers: set_markers,
|
||||
extra_filters: extra_filters
|
||||
)},
|
||||
{Floof.SessionManager, {:sessions, [file: to_charlist(sessions_file)]}}
|
||||
] ++
|
||||
|
|
|
@ -12,7 +12,8 @@ defmodule Floof.Distributor do
|
|||
Record.defrecord(:fconfig,
|
||||
markers: [],
|
||||
attrs: [],
|
||||
set_markers: []
|
||||
set_markers: [],
|
||||
extra_filters: []
|
||||
)
|
||||
|
||||
Record.defrecord(:dstate, fconf: {}, trgs: MapSet.new())
|
||||
|
@ -72,13 +73,27 @@ defmodule Floof.Distributor do
|
|||
{:XferBlob, ttl, old_markers, signature, data} = dcd
|
||||
set_markers = fconfig(fconf, :set_markers)
|
||||
new_markers = Enum.uniq(set_markers ++ old_markers)
|
||||
dcd2 = {:XferBlob, ttl - 1, new_markers, signature, data}
|
||||
dcd = {:XferBlob, ttl - 1, new_markers, signature, data}
|
||||
|
||||
dcd =
|
||||
Enum.reduce(
|
||||
fconfig(fconf, :extra_filters),
|
||||
dcd,
|
||||
fn f, dcdx ->
|
||||
case dcdx do
|
||||
nil -> nil
|
||||
dcdx -> f.(dcdx)
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
for trg <- trgs do
|
||||
send(trg, {:fwdxfer, {dcdhash, dcd2}})
|
||||
send(trg, {:fwdxfer, {dcdhash, dcd}})
|
||||
end
|
||||
|
||||
Floof.SessionManager.set_for_all(dcdhash, dcd2, origin)
|
||||
if ttl > 1 do
|
||||
Floof.SessionManager.set_for_all(dcdhash, dcd, origin)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
|
3
mix.exs
3
mix.exs
|
@ -34,6 +34,9 @@ defmodule Floof.MixProject do
|
|||
# these are the markers of form {:RelativeDistinguishedName, oid-as-list(), value()}
|
||||
# which get added to all processed messages
|
||||
set_markers: [],
|
||||
# a list of functions which can be used to further filter packets
|
||||
# (by returning nil if unwanted) and modify them
|
||||
extra_filters: [],
|
||||
# file locations
|
||||
# the spool dir saves messages in-transit, and is used to prevent RAM OOM
|
||||
spool_dir: "mock_spool",
|
||||
|
|
Loading…
Reference in a new issue