Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Free joins #1000

Merged
merged 4 commits into from
Aug 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env-template
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@ ROUTER_METRICS_PORT=3000
# The integer represents the first 7-bits of a DevAddr. NOT the Network ID.
# Change at your own discretion, this may lead to instability in assigning DevAddrs to devices.
ROUTER_DEVADDR_PREFIX=72

# Charge an Organization for join requests (default: true)
ROUTER_CHARGE_JOINS=true
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
27 changes: 21 additions & 6 deletions src/device/router_device_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1278,12 +1278,27 @@ validate_join(
true ->
{error, bad_nonce};
false ->
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} ->
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),
michaeldjeffrey marked this conversation as resolved.
Show resolved Hide resolved
{ok, UpdatedDevice, JoinAcceptArgs} = handle_join(
Packet,
PubKeyBin,
Expand Down
12 changes: 9 additions & 3 deletions src/router_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@ event_join_request(ID, Timestamp, Device, PubKeyBin, Packet, Region, {Balance, N
DevEUI = router_device:dev_eui(Device),
AppEUI = router_device:app_eui(Device),

Payload = blockchain_helium_packet_v1:payload(Packet),
PayloadSize = erlang:byte_size(Payload),
Used = router_blockchain:calculate_dc_amount(PayloadSize),
Used =
case router_utils:get_env_bool(charge_joins, true) of
false ->
0;
true ->
Payload = blockchain_helium_packet_v1:payload(Packet),
PayloadSize = erlang:byte_size(Payload),
router_blockchain:calculate_dc_amount(PayloadSize)
end,

Map = #{
id => ID,
Expand Down
Loading