decode XferInner only when appropriate
That is, make sure that the signature is valid before decoding
This commit is contained in:
parent
025b4a826f
commit
bf46142dab
2 changed files with 7 additions and 7 deletions
|
@ -59,12 +59,12 @@ defmodule Floof.Distributor do
|
|||
end
|
||||
|
||||
@impl true
|
||||
def handle_cast({:xfer, {origin, dcdhash, dcd, attrs}}, state) do
|
||||
def handle_cast({:xfer, {origin, dcdhash, dcd}}, state) do
|
||||
# we split the state such that only the parts necessary get
|
||||
# copied into the spawned-off process
|
||||
fconf = dstate(state, :fconf)
|
||||
|
||||
if check_incoming(fconf, dcdhash, dcd, attrs) do
|
||||
if check_incoming(fconf, dcdhash, dcd) do
|
||||
trgs = MapSet.delete(dstate(state, :trgs), origin)
|
||||
Floof.DistributorSeen.mark_seen(dcdhash)
|
||||
|
||||
|
@ -92,7 +92,7 @@ defmodule Floof.Distributor do
|
|||
{:noreply, dstate(state, trgs: MapSet.delete(dstate(state, :trgs), pid))}
|
||||
end
|
||||
|
||||
defp check_incoming(fconf, dcdhash, dcd, attrs) do
|
||||
defp check_incoming(fconf, dcdhash, dcd) do
|
||||
{:XferBlob, source, ttl, _, {:Signature, sigalgo, sigval}, xfinner} = dcd
|
||||
|
||||
case sigalgo do
|
||||
|
@ -113,7 +113,7 @@ defmodule Floof.Distributor do
|
|||
Logger.warn("packet in processing expired (out of hops): #{inspect(xfinner)}")
|
||||
false
|
||||
|
||||
not check_filters(fconf, dcd, attrs) ->
|
||||
not check_filters(fconf, dcd) ->
|
||||
Logger.debug("packet discarded according to filters: #{inspect(xfinner)}")
|
||||
false
|
||||
|
||||
|
@ -138,8 +138,9 @@ defmodule Floof.Distributor do
|
|||
end
|
||||
end
|
||||
|
||||
defp check_filters(fconf, {:XferBlob, _, _, markers, _, _}, attrs) do
|
||||
defp check_filters(fconf, {:XferBlob, _, _, markers, _, xfinner}) do
|
||||
try do
|
||||
{:ok, {:XferInner, _, attrs, _, _}} = :FloofProtocol.decode(:XferInner, xfinner)
|
||||
cond do
|
||||
not check_filters_markers2(fconfig(fconf, :markers), markers) -> false
|
||||
not check_filters_markers2(fconfig(fconf, :attrs), attrs) -> false
|
||||
|
|
|
@ -5,9 +5,8 @@ defmodule Floof.Message do
|
|||
|
||||
def emit(xf) do
|
||||
{:XferBlob, _, _, _, _, xfinner} = xf
|
||||
{:ok, {:XferInner, _, attrs, _, _}} = :FloofProtocol.decode(:XferInner, xfinner)
|
||||
mhash = :crypto.hash(:blake2b, xfinner)
|
||||
GenServer.cast(Floof.Distributor, {:xfer, {self(), mhash, xf, attrs}})
|
||||
GenServer.cast(Floof.Distributor, {:xfer, {self(), mhash, xf}})
|
||||
mhash
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue