# Internal Networking Guide

## Introduction

This guide aims to give developers an overview of the low-level Netty-based networking in Openfire. It is not necessary for administrators of Openfire to read or understand this. It includes detailed information for developers that wish to understand, or make changes to, the Openfire source code.

For additional developer resources please see the Netty 4 user guide and the Netty 4 JavaDoc.

Topics that are covered in this document:

## Netty Architecture

The following diagram shows the generic architecture of Netty. There is nothing specific to Openfire shown in the diagram, but it is hoped that this will be a useful model for developers to picture when working with Netty in Openfire.

The generic Netty architecture.

## Netty in Openfire

In the diagram below we can start to understand how Netty is used in Openfire.

We see that Openfire's ConnectionManagerImpl creates various Connection Listeners that handle connections for the various connection types in Openfire, differentiated by port number, for example Server to Server (S2S) using STARTTLS, Client to Server (C2S) using STARTTLS, S2S using Direct TLS,C2S using Direct TLS, etc.

These Connection Listeners each create new NettyConnectionAcceptors which bootstraps networking connection listeners using Netty.

How Netty fits into Openfire.

Zooming in on the above diagram to the S2S and C2S child-group channel pipelines we can see specific ChannelHandler implementations that handle TLS, XMPP stanza decoding, stalled session logic, and the core Openfire "business logic", with a different business logic connection handler depending on whether this is a Server to Server connection or a Client to Server connection.

A close-up view of Netty child-channel pipelines in Openfire.

## Server Bootstrapping in Openfire

The following sequence diagram shows how Netty is bootstrapped as part of the XMPPServer bootstrapping process. It aims to add enough detail, on top of the information presented above, to enable developers to orientate themselves in the codebase and discover the finer details of the Netty-based connection and channel handling system within Openfire.

Netty bootstrapping in Openfire.

Note that the source for this diagram is available in the Openfire source repository.

## Message Handling with Netty in Openfire

The final sequence diagram shows how Openfire handles network messages using Netty. It aims to add enough detail, on top of the information presented above, to enable developers to orientate themselves in the codebase and discover the finer details of the network message processing and stanza parsing systems within Openfire.

How Openfire handles messages with Netty.

Note that the source for this diagram is available in the Openfire source repository.