Skip to content

Commit

Permalink
New bondy_session_manager API and pool worker selection
Browse files Browse the repository at this point in the history
- Changed the `bondy_session_manager` pool worker selection to use the Session Id as opposed to the realm to distribute load evenly when a single realm is  used
- Renamed several functions to improve understanding
- Fixed sending a GOODBYE message only when session is close by the Router.

Signed-off-by: Alejandro M. Ramallo <[email protected]>
  • Loading branch information
aramallo committed Jan 15, 2025
1 parent 9188926 commit 3e82ba5
Show file tree
Hide file tree
Showing 6 changed files with 264 additions and 211 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 1.0.0-rc.29
## Changes
* Changed the `bondy_session_manager` pool worker selection to use the Session
Id as opposed to the realm to distribute load evenly when a single realm is
used

## Fixes
* Fixed sending a GOODBYE message only when session is close by the Router.


## 1.0.0-rc.28
## Fixes
* Upgraded `plum_db` with a fix to a bug causing a partition a crash when
Expand Down
2 changes: 1 addition & 1 deletion apps/bondy/src/bondy_rbac_user.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1728,5 +1728,5 @@ close_sessions(RealmUri, Username, Reason) ->

%% @private
close_sessions(RealmUri, Username, Reason, Opts) ->
ok = bondy_session_manager:close(RealmUri, Username, Reason, Opts).
ok = bondy_session_manager:close_all(RealmUri, Username, Reason, Opts).

49 changes: 40 additions & 9 deletions apps/bondy/src/bondy_session.erl
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
-include_lib("kernel/include/logger.hrl").
-include_lib("wamp/include/wamp.hrl").
-include("bondy.hrl").
-include("bondy_security.hrl").

-define(SESSION_SPACE, ?MODULE).

Expand Down Expand Up @@ -153,7 +154,7 @@
-export([authmethod_details/1]).
-export([authrole/1]).
-export([authroles/1]).
-export([close/1]).
-export([close/2]).
-export([created/1]).
-export([external_id/1]).
-export([features/2]).
Expand Down Expand Up @@ -329,31 +330,38 @@ update(#session{id = Id} = S) ->
%% @doc
%% @end
%% -----------------------------------------------------------------------------
-spec close(t()) -> ok.
-spec close(t(), Reason :: optional(uri())) -> ok.

close(#session{} = S) ->
close(#session{} = S, Reason)
when is_binary(Reason) orelse Reason == undefined ->
Id = S#session.id,
ExtId = S#session.external_id,
RealmUri = S#session.realm_uri,
Secs = erlang:system_time(second) - S#session.created,
ok = bondy_event_manager:notify({session_closed, S, Secs}),

%% Delete session
%% Cleanup session
Tab1 = tuplespace:locate_table(?SESSION_SPACE, Id),
true = ets:delete(Tab1, Id),

%% Delete index
%% Cleanup index
Tab2 = tuplespace:locate_table(?SESSION_SPACE, ExtId),
true = ets:delete(Tab2, ExtId),

%% Delete counters
%% Cleanup counters
ok = bondy_session_counter:delete_all(Id),

%% Revoke Tickets and Tokens
ok = maybe_revoke_tickets(S, Reason),

%% Notify internally
Secs = erlang:system_time(second) - S#session.created,
ok = bondy_event_manager:notify({session_closed, S, Secs}),

?LOG_DEBUG(#{
description => "Session closed",
realm => RealmUri,
session_id => Id,
protocol_session_id => ExtId
protocol_session_id => ExtId,
reason => Reason
}),

ok.
Expand Down Expand Up @@ -1214,6 +1222,29 @@ get_rbac_context(#session{authid = Authid, realm_uri = Uri}) ->
bondy_rbac:get_context(Uri, Authid).


%% @private
maybe_revoke_tickets(Session, ?WAMP_CLOSE_LOGOUT) ->
case authmethod(Session) of
?WAMP_TICKET_AUTH ->
Authid = authid(Session),
#{
authrealm := Authrealm,
scope := Scope
} = authmethod_details(Session),
bondy_ticket:revoke(Authrealm, Authid, Scope);

?WAMP_OAUTH2_AUTH ->
%% TODO remove token for sessionID
ok
end;

maybe_revoke_tickets(_, _) ->
%% No need to revoke tokens.
%% In case of ?BONDY_USER_DELETED, the delete action would have already
%% revoked all tokens for this user.
ok.




%% =============================================================================
Expand Down
Loading

0 comments on commit 3e82ba5

Please sign in to comment.