ejabberd Stanza Routing¶
Message Routing¶
In case of a message sent from User A to User B, both of whom are served by the same domain, the flow of the message through the system is as follows:
- User A's ejabberd_receiverreceives the stanza and passes it toejabberd_c2s.
- After some consistency check, user_send_packetis called if the stanza is correct.
- The stanza is matched against any privacy lists in use and, in case
   of being allowed, routed by ejabberd_router:route/3.
- ejabberd_router:route/3runs the- filter_packethook.- filter_packethook can drop of modify the stanza.
- 
ejabberd_routerwill then consult the routing table to know what do to next. It is easier to understand by looking at an example of actual routing table content:
In that case, user is local so we need to route to same domain (in
   our case localhost). We then can see that we have to call
   ejabberd_local:route to route the message to local user. As both
   user are local (no server-to-server involved), it matches our
   expectations.
- 
ejabberd_localroutes the stanza toejabberd_smgiven it's got at least a bare JID as the recipient.
- 
ejabberd_smdetermines the available resources of User B, takes into account their session priorities and whether the message is addressed to a particular resource or a bare JID and appropriately replicates (or not) the message and sends it to the recipient'sejabberd_c2sprocess(es).
In case no resources are available for delivery (hence no
   ejabberd_c2s processes to pass the message to),
   offline_message_hook is run to delegate offline message storage.
- ejabberd_c2sverifies the stanza against any relevant privacy lists and sends it on the user socket if it does exist. In the case of ejabberd Business Edition and ejabberd Saas, session can be detached and push notifications can be used as a fallback.- user_receive_packethook is run to notify the rest of the system about stanza delivery to User B.
Here is a broader diagram, including server-to-server routing:
