# P2P モジュール

## 概要

Diarkis P2P は、ユーザー・デバイスがサーバーを介さずに直接通信することを可能にします。

Diarkis サーバー・クラスターは、NAT トラバーサル技術を使用してクライアントのディスカバリーポイントとして機能します。

peer-to-peer 通信では、各パケット交換のためにサーバーが介在しないため、クライアント・デバイスはネットワーク遅延を最小限に抑えることができます。

Diarkis P2P は UDP ネットワーク・プロトコルのみをサポートし、RUDP（信頼性のある UDP）の独自実装を持ち、パケットの配送と順序を保証します。

接続されたデバイス間で交換されるパケットはすべて暗号化されており、暗号鍵は接続されたデバイス間の接続に固有のもので、安全な通信を確保します。

### 仕組み

peer-to-peer 通信には二つのステップが必要です。まず、クライアントは自分のアドレスを交換し、[ホールパンチング](https://en.wikipedia.org/wiki/Hole_punching_\(networking\))を行います。ホールパンチングが成功すると、クライアントはパケットを直接送受信することができます。

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

### NAT Types

Diarkis P2P では、クライアント SDK にホールパンチング、いわゆる NAT Traversal の機能が含まれています。NAT Traversal は、ゲーム機のシステムやその他多くのネットワーク・アプリケーションで一般的に使用されている技術ですが、Diarkis P2P の大きな特徴は、通常のホールパンチング手法では接続が難しい **Symmetric Cone 型のルーター** に接続された端末とも、必ずではないものの **通信の確立が可能となる点** にあります。これにより、**成功率の高い通信**が期待できます。

<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>

### サーバー・リレーへのフォールバック

Diarkis P2P のユニークなアーキテクチャにより、クライアント・デバイスは Diarkis サーバー・クラスターとの接続を維持することができます。これにより、ピアツーピア接続が確立できなかった場合でも、通信を peer-to-peer からサーバー・リレーにフォールバックすることができ、すべてのユーザーがネットワーク設定に関係なく通信を続けることができます。


---

# 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/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.
