Skip to content

Commit

Permalink
Make it optional
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed Aug 18, 2023
1 parent e9db12f commit f35e57b
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
3 changes: 2 additions & 1 deletion config/sys.config.src
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@
{devaddr_allocate_resolution, "${ROUTER_DEVADDR_ALLOCATE_RESOLUTION}"},
{metrics_port, "${ROUTER_METRICS_PORT}"},
{denylist_keys, ["1SbEYKju337P6aYsRd9DT2k4qgK5ZK62kXbSvnJgqeaxK3hqQrYURZjL"]},
{denylist_url, "https://api.github.com/repos/helium/denylist/releases/latest"}
{denylist_url, "https://api.github.com/repos/helium/denylist/releases/latest"},
{charge_joins, "${ROUTER_CHARGE_JOINS}"}
]},
{grpcbox, [
{client, #{
Expand Down
46 changes: 33 additions & 13 deletions src/device/router_device_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1265,30 +1265,50 @@ validate_join(
#packet_pb{
payload =
<<MType:3, _MHDRRFU:3, _Major:2, _AppEUI0:8/binary, _DevEUI0:8/binary,
DevNonce:2/binary, _MIC:4/binary>>
DevNonce:2/binary, _MIC:4/binary>> = Payload
} = Packet,
PubKeyBin,
Region,
APIDevice,
AppKey,
Device,
_OfferCache
OfferCache
) when MType == ?JOIN_REQ ->
case lists:member(DevNonce, router_device:dev_nonces(Device)) of
true ->
{error, bad_nonce};
false ->
OrgID = maps:get(organization_id, router_device:metadata(Device), undefined),
{Balance, Nonce} = router_console_dc_tracker:current_balance(OrgID),
{ok, UpdatedDevice, JoinAcceptArgs} = handle_join(
Packet,
PubKeyBin,
Region,
APIDevice,
AppKey,
Device
),
{ok, UpdatedDevice, DevNonce, JoinAcceptArgs, {Balance, Nonce}}
case router_utils:get_env_bool(charge_joins, true) of
true ->
PayloadSize = erlang:byte_size(Payload),
PHash = blockchain_helium_packet_v1:packet_hash(Packet),
case maybe_charge(Device, PayloadSize, PubKeyBin, PHash, OfferCache) of
{error, _} = Error ->
Error;
{ok, Balance, Nonce} ->
{ok, UpdatedDevice, JoinAcceptArgs} = handle_join(
Packet,
PubKeyBin,
Region,
APIDevice,
AppKey,
Device
),
{ok, UpdatedDevice, DevNonce, JoinAcceptArgs, {Balance, Nonce}}
end;
false ->
OrgID = maps:get(organization_id, router_device:metadata(Device), undefined),
{Balance, Nonce} = router_console_dc_tracker:current_balance(OrgID),
{ok, UpdatedDevice, JoinAcceptArgs} = handle_join(
Packet,
PubKeyBin,
Region,
APIDevice,
AppKey,
Device
),
{ok, UpdatedDevice, DevNonce, JoinAcceptArgs, {Balance, Nonce}}
end
end;
validate_join(
_Packet,
Expand Down

0 comments on commit f35e57b

Please sign in to comment.