make TTL hop-based

this avoid dozens of issues regarding time warps, and also solves the issue
of infinitely cycling packets when the system is under saturation, as now
packets expire after passing the set amount of hops
This commit is contained in:
Alain Zscheile 2022-11-26 12:55:48 +01:00
parent ecf27c1f01
commit 025b4a826f
4 changed files with 7 additions and 9 deletions

View file

@ -82,7 +82,6 @@ source = [
{:ok, secret} = File.read("test01.ed25519k")
msg_topic = [{:RelativeDistinguishedName, {2, 5, 4, 41}, "test topic"}]
msg_inner = Floof.Message.pack_inner(msg_topic, [], :info, <<0, 0>>)
ttl = :erlang.convert_time_unit(:erlang.system_time(), :native, :second) + 60
msg_outer = Floof.Message.build_outer(source, ttl, [], secret, msg_inner)
msg_outer = Floof.Message.build_outer(source, 255, [], secret, msg_inner)
Floof.Message.emit(msg_outer)
```

View file

@ -41,8 +41,8 @@ XferBlob ::= SEQUENCE {
-- source system name --
source RDNSequence,
-- message time-to-live eol timestamp in seconds since epoch
ttl INTEGER (0..MAX),
-- message max remaining hops
ttl INTEGER (0..255),
-- message markers (e.g. review data and such)
markers SET OF RelativeDistinguishedName,

View file

@ -74,7 +74,7 @@ defmodule Floof.Distributor do
{:XferBlob, source, ttl, old_markers, signature, data} = dcd
set_markers = fconfig(fconf, :set_markers)
new_markers = Enum.uniq(set_markers ++ old_markers)
dcd2 = {:XferBlob, source, ttl, new_markers, signature, data}
dcd2 = {:XferBlob, source, ttl - 1, new_markers, signature, data}
for trg <- trgs do
send(trg, {:fwdxfer, {dcdhash, dcd2}})
@ -109,8 +109,8 @@ defmodule Floof.Distributor do
Logger.error("packet signature invalid for #{inspect(xfinner)}")
false
:erlang.convert_time_unit(:erlang.system_time(), :native, :second) >= ttl ->
Logger.warn("packet in processing expired at #{ttl}: #{inspect(xfinner)}")
ttl == 0 ->
Logger.warn("packet in processing expired (out of hops): #{inspect(xfinner)}")
false
not check_filters(fconf, dcd, attrs) ->

View file

@ -51,8 +51,7 @@ defmodule FloofTest do
source = [{:RelativeDistinguishedName, {0, 9, 2342, 19_200_300, 100, 1, 25}, "test"}]
msg_topic = [{:RelativeDistinguishedName, {2, 5, 4, 41}, "test topic"}]
msg_inner = Floof.Message.pack_inner(msg_topic, [], :info, <<0, 0>>)
ttl = :erlang.convert_time_unit(:erlang.system_time(), :native, :second) + 60
msg_outer = Floof.Message.build_outer(source, ttl, [], secret_key, msg_inner)
msg_outer = Floof.Message.build_outer(source, 10, [], secret_key, msg_inner)
{:ok, msg_encd} = :FloofProtocol.encode(:ProtoMessage, {:xfer, msg_outer})
Floof.Distributor.register(self())