# P2P Module

## Overview

Diarkis P2P enables direct communication between user devices without using a server as an intermediary.

The Diarkis server cluster functions as a client discovery point by utilizing NAT traversal technology.

In peer-to-peer communication, the server does not intervene for each packet exchange, allowing client devices to minimize network latency.

Diarkis P2P supports only the UDP network protocol and features a proprietary implementation of RUDP (Reliable UDP) to ensure packet delivery and order.

All packets exchanged between connected devices are encrypted, with encryption keys unique to the connection between the connected devices, ensuring secure communication.

### How It Works

Peer-to-peer communication requires two steps. First, clients exchange their addresses and perform [hole punching](https://en.wikipedia.org/wiki/Hole_punching_\(networking\)). Once hole punching is successful, clients can send and receive packets directly.

<figure><img src="https://3799879693-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FryZ6XqKeHRZxcxMovWdn%2Fuploads%2Fgit-blob-4ef1e15b38c0cbf6436d6729a7dc05eac4669d3e%2Fimage%20(5).png?alt=media" alt=""><figcaption></figcaption></figure>

### NAT Types

In **Diarkis P2P**, the client SDK includes a hole punching feature, also known as **NAT traversal**. While NAT traversal is a common technology used in game console systems and many other networked applications, a key feature of **Diarkis P2P** is its ability to **establish connectivity even with devices connected to Symmetric Cone-type routers**, which typically cannot be reached using standard hole punching methods—though it is not guaranteed, Diarkis P2P increases the chances of successful communication.

<table><thead><tr><th width="187.25">NAT Type</th><th width="142.19921875">Other Solutions</th><th width="138.33984375">Diarkis</th></tr></thead><tbody><tr><td>Full</td><td>○</td><td>○</td></tr><tr><td>Restricted</td><td>○</td><td>○</td></tr><tr><td>Port Restricted</td><td>○</td><td>○</td></tr><tr><td>Symmetric</td><td>✖︎</td><td>△</td></tr></tbody></table>

### Fallback to Server Relay-Hybrid Connectivity Architecture in Diarkis P2P

**Diarkis P2P** is designed with a hybrid communication architecture that enables client devices to maintain a persistent connection to the **Diarkis server cluster** while simultaneously attempting to establish **direct peer-to-peer (P2P) communication**.

If a P2P connection cannot be established—due to NAT restrictions, firewall policies, or symmetric NAT configurations—Diarkis automatically triggers a **fallback to server-relay mode**, utilizing its built-in TURN-like functionality. This ensures **uninterrupted, bidirectional packet delivery** between clients, regardless of network topology.

By preserving both server and peer connectivity, Diarkis P2P guarantees **resilient communication continuity**, supports **dynamic fallback routing**, and maintains **session integrity** across varied client environments without manual intervention or custom NAT traversal logic.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.diarkis.io/en/diarkis-modules/p2p.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
