Skip to content

Commit

Permalink
Do not report joins
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed Aug 15, 2023
1 parent 441e1b1 commit 795fa05
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/hpr_routing.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ handle_packet(PacketUp, Opts) ->
{ok, RoutesETS} ->
{Routed, IsFree} = maybe_deliver_packet_to_routes(PacketUp, RoutesETS),
ok = maybe_report_packet(
PacketUpType,
[hpr_route_ets:route(RouteETS) || {RouteETS, _} <- RoutesETS],
Routed,
IsFree,
Expand Down Expand Up @@ -340,24 +341,28 @@ deliver_packet(_OtherProtocol, _PacketUp, _Route) ->
lager:warning([{protocol, _OtherProtocol}], "protocol unimplemented").

-spec maybe_report_packet(
PacketUpType :: hpr_packet_up:packet_type(),
Routes :: [hpr_route:route()],
Routed :: non_neg_integer(),
IsFree :: boolean(),
PacketUp :: hpr_packet_up:packet(),
ReceivedTime :: non_neg_integer()
) -> ok.
maybe_report_packet(_Routes, 0, _IsFree, _PacketUp, _ReceivedTime) ->
lager:debug("not reporting packet");
maybe_report_packet([Route | _] = Routes, Routed, IsFree, PacketUp, ReceivedTime) when Routed > 0 ->
maybe_report_packet(_PacketUpType, _Routes, 0, _IsFree, _PacketUp, _ReceivedTime) ->
lager:debug("not reporting packet, no routed");
maybe_report_packet({uplink, _}, Routes, Routed, IsFree, PacketUp, ReceivedTime) when Routed > 0 ->
UniqueOUINetID = lists:usort([{hpr_route:oui(R), hpr_route:net_id(R)} || R <- Routes]),
case erlang:length(UniqueOUINetID) of
1 ->
[Route | _] = Routes,
ok = hpr_packet_reporter:report_packet(PacketUp, Route, IsFree, ReceivedTime);
_ ->
lager:error("routed packet to non unique OUI/Net ID ~p", [
[{hpr_route:id(R), hpr_route:oui(R), hpr_route:net_id(R)} || R <- Routes]
])
end.
end;
maybe_report_packet({Type, _}, _Routes, _Routed, _IsFree, _PacketUp, _ReceivedTime) ->
lager:debug("not reporting ~p packet", [Type]).

-spec packet_type_check(PacketUp :: hpr_packet_up:packet()) ->
boolean().
Expand Down

0 comments on commit 795fa05

Please sign in to comment.