Skip to content

Commit

Permalink
Fix issue in HTTP roaming as well
Browse files Browse the repository at this point in the history
  • Loading branch information
macpie committed Oct 7, 2024
1 parent 4dcf958 commit 3cfb50b
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 11 deletions.
15 changes: 15 additions & 0 deletions src/protocols/hpr_protocol_http_roaming.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@
GatewayLocation :: hpr_gateway_location:loc()
) -> ok | {error, any()}.
send(PacketUp, Route, Timestamp, GatewayLocation) ->
send(PacketUp, Route, Timestamp, GatewayLocation, 3).

-spec send(
PacketUp :: hpr_packet_up:packet(),
Route :: hpr_route:route(),
Timestamp :: non_neg_integer(),
GatewayLocation :: hpr_gateway_location:loc(),
Retry :: non_neg_integer()
) -> ok | {error, any()}.
send(_PacketUp, _Route, _Timestamp, _GatewayLocation, 0) ->
{error, {gwmp_sup_err, max_retries}};
send(PacketUp, Route, Timestamp, GatewayLocation, Retry) ->
Protocol = protocol_from(Route),
WorkerKey = worker_key_from(PacketUp, Protocol),
PubKeyBin = hpr_packet_up:gateway(PacketUp),
Expand All @@ -29,6 +41,9 @@ send(PacketUp, Route, Timestamp, GatewayLocation) ->
key => WorkerKey, protocol => Protocol, net_id => hpr_route:net_id(Route)
})
of
{error, already_registered} ->
timer:sleep(2),
send(PacketUp, Route, Timestamp, GatewayLocation, Retry - 1);
{error, Reason} = Err ->
lager:error(
"failed to start http connector for ~s: ~p",
Expand Down
28 changes: 17 additions & 11 deletions src/protocols/http/hpr_http_roaming_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,23 @@ init(Args) ->
key := Key
} = Args,
lager:debug("~p init with ~p", [?MODULE, Args]),
true = gproc:add_local_name(Key),
{ok, #state{
net_id = NetID,
route_id = RouteID,
address = Address,
transaction_id = next_transaction_id(),
send_data_timer = DedupeTimeout,
flow_type = FlowType,
auth_header = Auth,
receiver_nsid = ReceiverNSID
}}.
try gproc:add_local_name(Key) of
true ->
{ok, #state{
net_id = NetID,
route_id = RouteID,
address = Address,
transaction_id = next_transaction_id(),
send_data_timer = DedupeTimeout,
flow_type = FlowType,
auth_header = Auth,
receiver_nsid = ReceiverNSID
}}
catch
% This will only catch a bad registration
error:badarg ->
{stop, already_registered}
end.

handle_call(_Msg, _From, State) ->
lager:warning("rcvd unknown call msg: ~p from: ~p", [_Msg, _From]),
Expand Down

0 comments on commit 3cfb50b

Please sign in to comment.