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

Dynamic domains support in mod_disco #3151

Merged
merged 34 commits into from
Jun 15, 2021
Merged

Conversation

chrzaszcz
Copy link
Member

@chrzaszcz chrzaszcz commented Jun 9, 2021

Make mod_disco and all disco hooks/handlers compatible with dynamic domains.

The new mongoose_disco module is responsible for:

  • Calling the disco hooks and converting the results to XML.
  • Providing helpers to hooks handlers to add new identities, features, items and info.
  • Providing helpers for construction of XML for the cases when hooks are not used.

This way all the code handling the discovered features is more consistent across the modules and easier to maintain.

All disco hooks are run for host types and for MUC (Light) features there is simply a new hook introduced. Disco hooks are now run for specific functional entity (e.g. disco_local_* for the local server, disco_sm_* for a local client, disco_muc_* for the MUC service) rather than for specific XMPP (sub)domains.

@codecov
Copy link

codecov bot commented Jun 9, 2021

Codecov Report

Merging #3151 (836d2ad) into master (b094384) will decrease coverage by 0.02%.
The diff coverage is 94.20%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3151      +/-   ##
==========================================
- Coverage   79.83%   79.80%   -0.03%     
==========================================
  Files         396      396              
  Lines       32305    32340      +35     
==========================================
+ Hits        25790    25809      +19     
- Misses       6515     6531      +16     
Impacted Files Coverage Δ
src/http_upload/mod_http_upload.erl 94.56% <ø> (ø)
src/inbox/mod_inbox.erl 89.70% <ø> (ø)
src/mod_amp.erl 95.55% <ø> (ø)
src/mod_auth_token.erl 81.45% <ø> (ø)
src/mod_version.erl 93.75% <ø> (+3.27%) ⬆️
src/offline/mod_offline.erl 77.77% <0.00%> (ø)
src/mod_disco.erl 87.03% <88.73%> (+3.70%) ⬆️
src/mod_adhoc.erl 80.00% <90.00%> (+0.75%) ⬆️
src/mongoose_disco.erl 96.55% <96.22%> (-3.45%) ⬇️
src/config/mongoose_config_validator.erl 97.97% <100.00%> (+0.02%) ⬆️
... and 35 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b094384...836d2ad. Read the comment docs.

@chrzaszcz chrzaszcz force-pushed the disco-with-dynamic-domains branch 5 times, most recently from ceb9b75 to 9276d08 Compare June 11, 2021 12:47
Use exported functions for easier debugging.
- Argument list got long, converted item_acc to a map
- These hooks are executed only for domains,
    so there is no need to check if the IQ was addressed to a subdomain
- Unify handler names to match hook hames
Features are already added by ejabberd_local because of the iq handler.
Features are already added by ejabberd_local because of the iq handler.
- Rework feature_acc like item_acc
- Share common parts of item_acc and feature_acc (types and logic)
- Run the hooks for host types

NOTE: This commit breaks tests as all modules using disco features
      need to be changed.
Run the hooks for host types.
Motivation: instead of overloading one hook (disco_local_features)
  and running it both for the local domain and for the MUC domain,
  the logic can be split.
This eliminates the need to pattern-match on domains for all handlers.
The code is simpler and it is harder to make a mistake,
  e.g. by forgetting to pattern-match.
This way MUC features would never leak to local features and vice versa.

NOTE: This commit fixes the tests, they should pass from now on.
Make identity hooks return the acc like the feature and item hooks.
Update the handlers in modules.
Make the hook handler return the info as a map (like for other disco hooks).
Add a helper for calling the hook and converting the results to XML.
Also:
  - use the helpers from mongoose_disco in mod_muc and mod_muc_room
  - do not convert server info from binaries to strings and back
This way the accumulator is used only inside the handlers
  and XML is returned to the caller, which is more convenient.
No module other than mongoose_disco should call disco hooks.

Also: unify acc handling for all disco calls.

NOTE: This change breaks tests as modules need to be updated next.
Before: the handlers were running the hooks for an empty node
  and discarded previous results.

Now: the handlers are running first and they just set the node
  to empty and remaining hanflers are using that node.
  There is no need to nest hook calls in handlers anymore.
Also:
  - reorganize the handlers to follow the order from mongoose_disco
  - do not preprocess the config, this extra step was unnecessary
NOTE: This commit fixes the tests, are modules are consistent now.
The old code is still used for external components.
It is not a performance issue as there is no entry per domain.

The final solution would be to make external components
  use the domain API to regisyter components of type 'subdomain'.
This should be done in a separate PR.
Regarding mod_mam backends, the configuration for some options
is read per domain, not per host type.

This is a bug and needs to be addressed in the near future.
@chrzaszcz chrzaszcz marked this pull request as ready for review June 15, 2021 09:44
Copy link
Contributor

@arcusfelis arcusfelis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added some comments, the rest is good :)

{result, Items} ->
case mongoose_disco:get_local_items(HostType, From, To, Node, Lang) of
empty ->
Error = mongoose_xmpp_errors:item_not_found(),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe adding a text like mongoose_xmpp_errors:item_not_found(<<"en">>, <<"Local disco items not found">>).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if we need en as we have Lang here... anyway, there are more such errors in mod_disco, let's address it in a separate PR.

src/mod_disco.erl Outdated Show resolved Hide resolved
src/mod_disco.erl Outdated Show resolved Hide resolved
src/mod_disco.erl Outdated Show resolved Hide resolved
-spec process_sm_iq_items(mongoose_acc:t(), jid:jid(), jid:jid(), jlib:iq(), map()) ->
{mongoose_acc:t(), jlib:iq()}.
process_sm_iq_items(Acc, _From, _To, #iq{type = set, sub_el = SubEl} = IQ, _Extra) ->
{Acc, IQ#iq{type = error, sub_el = [SubEl, mongoose_xmpp_errors:not_allowed()]}};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice to have some text for the error.

children = ItemsXML}]}}
end;
false ->
{Acc, IQ#iq{type = error, sub_el = [SubEl, mongoose_xmpp_errors:service_unavailable()]}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here text for sure, 503 errors are evil :D

children = IdentityXML ++ FeaturesXML}]}}
end;
false ->
{Acc, IQ#iq{type = error, sub_el = [SubEl, mongoose_xmpp_errors:service_unavailable()]}}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

src/mod_muc.erl Outdated Show resolved Hide resolved
@arcusfelis arcusfelis merged commit b2ccb15 into master Jun 15, 2021
@arcusfelis arcusfelis deleted the disco-with-dynamic-domains branch June 15, 2021 16:28
@Premwoik Premwoik added this to the 5.0.0 milestone Oct 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants