Skip to content

Commit

Permalink
stun: Hand over more metadata to callback function
Browse files Browse the repository at this point in the history
Include the username and realm with the info map handed over to
callbacks for 'stun_query' events, analogous to TURN events.  Also,
include the STUN protocol version.
  • Loading branch information
weiss committed Aug 23, 2020
1 parent 26d7fa2 commit be1d2fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Log relay allocation refreshes at notice level.
* Log duration of TURN sessions.
* Hand over more metadata to STUN callback.

# Version 1.0.37

Expand Down
20 changes: 13 additions & 7 deletions src/stun.erl
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ process(State, #stun{class = request,
?LOG_INFO("Responding to STUN request"),
Resp#stun{class = response, 'XOR-MAPPED-ADDRESS' = AddrPort}
end,
run_hook(stun_query, State),
run_hook(stun_query, State, Msg),
send(State, R, Secret);
process(#state{use_turn = false} = State,
#stun{class = request} = Msg, Secret) ->
Expand Down Expand Up @@ -708,19 +708,25 @@ prepare_response(State, Msg) ->
trid = Msg#stun.trid,
'SOFTWARE' = State#state.server_name}.

run_hook(HookName, #state{session_id = ID,
peer = Client,
sock_mod = SockMod,
hook_fun = HookFun})
run_hook(HookName,
#state{session_id = ID,
peer = Client,
sock_mod = SockMod,
hook_fun = HookFun},
#stun{'USERNAME' = User,
'REALM' = Realm} = Msg)
when is_function(HookFun) ->
Info = #{id => ID,
user => User,
realm => Realm,
client => Client,
transport => stun_logger:encode_transport(SockMod)},
transport => stun_logger:encode_transport(SockMod),
version => stun_codec:version(Msg)},
?LOG_DEBUG("Running '~s' hook", [HookName]),
try HookFun(HookName, Info)
catch _:Err -> ?LOG_ERROR("Hook '~s' failed: ~p", [HookName, Err])
end;
run_hook(HookName, _State) ->
run_hook(HookName, _State, _Msg) ->
?LOG_DEBUG("No callback function specified for '~s' hook", [HookName]),
ok.

Expand Down

0 comments on commit be1d2fb

Please sign in to comment.