# 2. Messaging Solution

## 2. Messaging Solution

**2.1 Overview**

ONLY NETWORK implements an entirely private and censorship-resistant messaging service, enabling users to enhance their control over their data. We have set up a three-layer secure communication mechanism for each user.

* **Layer 1**: Compared to the traditional client-server model, all messages are forwarded by many decentralized routing nodes in the network, enhancing privacy and censorship resistance.
* **Layer 2**: We use a state-of-the-art key distribution protocol based on the X3DH protocol and bidirectional ratchet to protect users' peer-to-peer communications, where no third party can intercept, eavesdrop, or modify the content of the communications.
* **Layer 3**: We protect metadata privacy through a secure routing protocol, which means no one can know the user's social relations and historical behavior. Then users can communicate on the network using an anonymous identity with confidence.

**2.2 Private Messaging**

Like any existing messaging application such as WhatsApp or Facebook Messenger, ONLY NETWORK enables users to communicate one-on-one or one-to-many with other network members. ONLY NETWORK enables developers to provide a messaging solution that, in terms of its UI, looks indistinguishable from other consumer messaging solutions but provides exceptional security, anonymity and privacy benefits that those solutions can’t provide.

**2.3 Group Messaging**

ONLY NETWORK extends the Private Chat service to large group communication through the topic subscription mechanism, providing users with an efficient private group messaging service. We divide different chat groups by topic. After subscribing to the topic, users can use the Pub-Sub method to send and receive messages in the group. Through this mechanism, users can quickly communicate with peers in the network who are interested in the same topic, such as players in the same gaming guild or holders of the same cryptocurrency.Users can get the same security guarantees as Private Chat using the improved Group Encryption policy to protect communication privacy. Only users granted the appropriate permissions can decrypt group chat messages. Users can also speed up the forwarding of group messages through the efficient Fast Routing Protocol so that even in the P2P environment, users can enjoy the high-performance experience under Web 2.0.

**2.4 Rich Messages**

ONLY NETWORK provides efficient and reliable transmission of rich messages, including texts, files, images, voices, videos, and customized messages. Meanwhile, it’s cross-platform, running on mainstream operating systems such as Windows, Mac OS, Linux, Android, etc.For audio and video, ONLY NETWORK supports real-time voice calls or video chats in web browsers, allows full-duplex communication between two browsers, and uses UDP protocol to achieve lightweight transmission and reduce transmission delay.For common files, ONLY NETWORK provides reliable encrypted file transmission service. It uses IPFS as the middleware for transit, which guarantees reliability. And it also uses the AES-CTR encryption method, which is simple and efficient but secure enough for privacy in the P2P network.

**2.5 Offline Caching and Notification**

ONLY NETWORK provides message notification service so that offline users can be acknowledged and retrieve missed messages from the network. We provide the notification module for edge nodes. When the user is offline, ONLY NETWORK will cache the messages received by the user during the period. Meanwhile, users will receive notifications from relevant push providers, so they can pull messages back online or process them offline through proxy gateways.Users can also set push rules on edge nodes for a more personalized user experience. For private chat messages that need to be protected from privacy leakage, users can configure the relevant parameters so that the entire push process takes place in the trusted execution environment (TEE). Also, after the user pulls the message, the edge nodes will remove the relevant information from the TEE.
