How igniterealtime/openfire works
Project Type and Purpose
• Openfire is a Java‐based XMPP (Jabber) server implementing real‐time collaboration (RTC) services.
• Core functionality is in the xmppserver Maven module; other modules handle distribution, installers, internationalization, plugins, and startup wrappers.
High-Level Architectural Components
a. Clients & External Interfaces
• XMPP Clients (TCP port 5222, TLS 5223)
• Server-to-Server XMPP (S2S) connections (port 5269)
• HTTP-Bind (BOSH) endpoint (default port 7070)
• WebSocket endpoint (default port 7443)
• Admin Console (HTTP on 9090, HTTPS on 9091)
b. Transport & Connection Layer
• Netty‐based NIO (xmppserver/src/main/java/.../nio) for handling TCP, TLS, and WebSocket connections
• Traditional blocking I/O for older connectors (in net package)
c. XMPP Core
• Session management (ClientSession, ServerSession, ComponentSession)
• Packet routing: IQRouter, MessageRouter, PresenceRouter
• Handlers for stanzas (handler, http, websocket, bosh managers)
• Authentication/Authorization (pluggable providers in auth, user, group, crowd)
• Plugins system (dynamic loading via PluginManager in container)
d. Persistence & Database
• Database abstraction layer (database package) and upgrade scripts under distribution/src/database
• Offline message store, archiving, pubsub persistence providers
e. Supporting Services
• Clustering (cluster package) for multi-node deployments
• Audit and statistics (audit, stats)
• Security (keystore/truststore management under keystore)
• File transfer proxy, media proxy, message‐carbons, pubsub, MUC (chat rooms)
Data Flow & Interactions
1. XMPP Client opens a TCP/TLS or WebSocket/BOSH connection → Netty/HTTPBindManager
2. Connection goes to ConnectionManager → Session created (ClientSession or HttpSession)
3. Incoming stanzas (XML) parsed by XMPPParser (XMLLightweightParser/XMPPPacketReader)
4. Packet delivered to PacketRouter → directed to appropriate handler:
• IQ handlers (IQBindHandler, IQRegisterHandler, etc.)
• Presence handlers
• Message handlers → possible offline storage or direct deliver via PacketDeliverer
5. Authentication handled via AuthProvider → user credentials validated (JDBC, LDAP, native)
6. Authorization via AuthorizationManager (ACLs, group-based policies)
7. Messages routed to other sessions or remote servers via RemoteConnectionManager → S2S
8. Plugins may intercept or extend behavior via PacketInterceptor/InterceptorManager
9. All state changes and metrics persisted in DB via DbConnectionManager
Showing XMPP to “new URL” (HTTP/WebSocket) Connections
• HTTP/WebSocket endpoints feeding into the same ConnectionManager but via HttpBindManager and WebSocketClientConnectionHandler respectively.
• Conversion from HTTP payloads → XMPP stanzas, then follow the core packet routing path.
Architectural Patterns & Principles
• Modular Maven multi‐module layout (core, distribution, plugins, i18n, starter)
• SPI‐based extensibility for auth, user/group providers, persistence, cache strategies
• Event‐driven design: event listeners/dispatchers for clustering, session events, user events
• Pluggable protocol endpoints: raw TCP, BOSH (servlet), WebSocket (Netty)
• Dependency injection via provider mappers and factory classes