GitHub Action commited on
Commit
cc036f3
·
1 Parent(s): 0867205

Sync from GitHub with Git LFS

Browse files
docs/dht_protocol.md CHANGED
@@ -99,11 +99,12 @@ pow_input_string = DID + " -- " + addr + " -- " + datetime + " -- " + nonce_stri
99
 
100
  ### 4.1 DISCOVERY
101
 
102
- Используется для объявления себя в локальной сети.
103
 
104
  ```json
105
  {
106
  "type": "DISCOVERY",
 
107
  "id": "did:example:123",
108
  "name": "Agent_X",
109
  "pubkey": "base58...",
@@ -120,17 +121,29 @@ pow_input_string = DID + " -- " + addr + " -- " + datetime + " -- " + nonce_stri
120
  "signature": "BASE64URL(...)",
121
  "sig_algo": "ed25519"
122
  }
123
- ````
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  ---
126
 
127
- ### 4.2 PEER\_EXCHANGE\_REQUEST / RESPONSE
128
 
129
- Запрос известных пиров:
130
 
131
  ```json
132
  {
133
  "type": "PEER_EXCHANGE_REQUEST",
 
134
  "id": "did:example:123",
135
  "name": "Agent_X",
136
  "addresses": [
@@ -148,11 +161,13 @@ pow_input_string = DID + " -- " + addr + " -- " + datetime + " -- " + nonce_stri
148
  }
149
  ```
150
 
151
- Ответ содержит список пиров (каждый с DID, pubkey и адресами, у которых тоже должен быть валидный PoW):
 
152
 
153
  ```json
154
  [
155
  {
 
156
  "id": "did:example:456",
157
  "name": "Agent_Y",
158
  "pubkey": "base58...",
@@ -172,6 +187,32 @@ pow_input_string = DID + " -- " + addr + " -- " + datetime + " -- " + nonce_stri
172
  ]
173
  ```
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  ---
176
 
177
  ## 5. Правила валидации адресов и пиров
 
99
 
100
  ### 4.1 DISCOVERY
101
 
102
+ Используется для объявления себя в локальной сети и публикации своих сетевых интерфейсов.
103
 
104
  ```json
105
  {
106
  "type": "DISCOVERY",
107
+ "version": "1.0",
108
  "id": "did:example:123",
109
  "name": "Agent_X",
110
  "pubkey": "base58...",
 
121
  "signature": "BASE64URL(...)",
122
  "sig_algo": "ed25519"
123
  }
124
+ ```
125
+
126
+ **Поля:**
127
+
128
+ * `type` — тип сообщения (`DISCOVERY`).
129
+ * `version` — версия формата сообщения.
130
+ * `id` — децентрализованный идентификатор агента (DID).
131
+ * `name` — человекочитаемое имя агента.
132
+ * `pubkey` — публичный ключ агента (Base58, Ed25519).
133
+ * `addresses` — список адресов, подписанных PoW.
134
+ * `signature` — подпись агента над всем сообщением.
135
+ * `sig_algo` — алгоритм подписи (в текущей версии — только `ed25519`).
136
 
137
  ---
138
 
139
+ ### 4.2 PEER_EXCHANGE_REQUEST / RESPONSE
140
 
141
+ **Запрос известных пиров:**
142
 
143
  ```json
144
  {
145
  "type": "PEER_EXCHANGE_REQUEST",
146
+ "version": "1.0",
147
  "id": "did:example:123",
148
  "name": "Agent_X",
149
  "addresses": [
 
161
  }
162
  ```
163
 
164
+ **Ответ:**
165
+ содержит список пиров (каждый с DID, pubkey и адресами, у которых тоже должен быть валидный PoW):
166
 
167
  ```json
168
  [
169
  {
170
+ "version": "1.0",
171
  "id": "did:example:456",
172
  "name": "Agent_Y",
173
  "pubkey": "base58...",
 
187
  ]
188
  ```
189
 
190
+ **Поля ответа аналогичны DISCOVERY, но**:
191
+
192
+ * каждый объект в массиве описывает отдельного агента,
193
+ * поле `version` относится к формату объекта пира, а не всего сообщения.
194
+
195
+ ---
196
+
197
+ 💡 *Для валидации структуры сообщений см. актуальную схему:*
198
+ [`schemas/dht_protocol.json`](https://github.com/kagvi13/HMP/blob/main/schemas/dht_protocol.json)
199
+
200
+ ---
201
+
202
+ ### 4.3 Особенности передачи и хранения записей
203
+
204
+ 1. **Каждое сообщение `DISCOVERY` или `PEER_EXCHANGE_REQUEST` содержит один активный адрес агента.**
205
+ Если у агента несколько интерфейсов (например, интернет и локальная сеть), он публикует отдельные сообщения для каждого адреса,
206
+ при этом для каждого адреса вычисляется собственный PoW (`nonce`, `pow_hash`, `difficulty`).
207
+
208
+ 2. **Подпись (`signature`) создаётся самим агентом и охватывает всё содержимое сообщения.**
209
+ Это гарантирует неизменность данных — при любом изменении (например, IP или параметров PoW)
210
+ агент формирует новую запись с актуальной меткой времени (`datetime`) и новой подписью.
211
+
212
+ 3. **Узел DHT хранит неизменяемый JSON-блок**, подписанный владельцем и содержащий последнюю известную дату (`datetime`).
213
+ Такие блоки могут кэшироваться и передаваться другим пирам для верификации,
214
+ но не должны изменяться или перезаписываться другими участниками сети.
215
+
216
  ---
217
 
218
  ## 5. Правила валидации адресов и пиров
docs/schemas/dht_protocol.json CHANGED
@@ -1,72 +1,143 @@
1
  {
2
  "$schema": "http://json-schema.org/draft-07/schema#",
 
3
  "title": "DHT Protocol Schema",
 
 
4
  "type": "object",
 
5
  "oneOf": [
6
  { "$ref": "#/definitions/discovery" },
7
  { "$ref": "#/definitions/peerExchangeRequest" },
8
  { "$ref": "#/definitions/peerExchangeResponse" }
9
  ],
 
10
  "definitions": {
11
  "interface": {
12
  "type": "object",
13
- "required": ["addr", "nonce", "pow_hash", "difficulty", "datetime"],
14
  "properties": {
15
- "addr": { "type": "string", "pattern": "^(tcp|udp)://.+" },
16
- "nonce": { "type": "integer", "minimum": 0 },
17
- "pow_hash": { "type": "string" },
18
- "difficulty": { "type": "integer", "minimum": 1 },
19
- "datetime": { "type": "string", "format": "date-time" },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  "type": {
21
  "type": "string",
22
- "enum": ["localhost", "internet", "yggdrasil", "i2p"],
23
- "pattern": "^(lan:[0-9]{1,3}(\\.[0-9]{1,3}){3})$"
24
  }
25
- }
 
26
  },
 
27
  "peer": {
28
  "type": "object",
29
- "required": ["id", "name", "pubkey", "addresses"],
30
  "properties": {
31
- "id": { "type": "string" },
32
- "name": { "type": "string" },
33
- "pubkey": { "type": "string" },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  "addresses": {
35
  "type": "array",
36
- "items": { "$ref": "#/definitions/interface" }
 
 
 
 
 
 
 
 
 
 
37
  }
38
- }
 
39
  },
 
40
  "discovery": {
41
  "type": "object",
42
- "required": ["type", "id", "name", "pubkey", "addresses"],
43
  "properties": {
44
  "type": { "const": "DISCOVERY" },
 
 
 
 
 
45
  "id": { "type": "string" },
46
  "name": { "type": "string" },
47
  "pubkey": { "type": "string" },
48
  "addresses": {
49
  "type": "array",
50
  "items": { "$ref": "#/definitions/interface" }
51
- }
52
- }
 
 
 
53
  },
 
54
  "peerExchangeRequest": {
55
  "type": "object",
56
- "required": ["type", "id", "name", "addresses"],
57
  "properties": {
58
  "type": { "const": "PEER_EXCHANGE_REQUEST" },
 
 
 
 
 
59
  "id": { "type": "string" },
60
  "name": { "type": "string" },
61
  "addresses": {
62
  "type": "array",
63
  "items": { "$ref": "#/definitions/interface" }
64
- }
65
- }
 
 
 
66
  },
 
67
  "peerExchangeResponse": {
68
  "type": "array",
69
- "items": { "$ref": "#/definitions/peer" }
 
70
  }
71
  }
72
  }
 
1
  {
2
  "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://hypercortex.org/schemas/dht_protocol.json",
4
  "title": "DHT Protocol Schema",
5
+ "description": "Schema for DISCOVERY and PEER_EXCHANGE messages in the HyperCortex Mesh DHT layer.",
6
+ "schema_version": "4.2",
7
  "type": "object",
8
+
9
  "oneOf": [
10
  { "$ref": "#/definitions/discovery" },
11
  { "$ref": "#/definitions/peerExchangeRequest" },
12
  { "$ref": "#/definitions/peerExchangeResponse" }
13
  ],
14
+
15
  "definitions": {
16
  "interface": {
17
  "type": "object",
18
+ "required": ["addr", "nonce", "pow_hash", "difficulty", "datetime", "type"],
19
  "properties": {
20
+ "addr": {
21
+ "type": "string",
22
+ "pattern": "^(tcp|udp)://.+",
23
+ "description": "Full address of the peer (transport://host:port)."
24
+ },
25
+ "nonce": {
26
+ "type": "integer",
27
+ "minimum": 0,
28
+ "description": "Proof-of-Work nonce."
29
+ },
30
+ "pow_hash": {
31
+ "type": "string",
32
+ "description": "Proof-of-Work SHA256 hash result."
33
+ },
34
+ "difficulty": {
35
+ "type": "integer",
36
+ "minimum": 1,
37
+ "description": "Difficulty level of the Proof-of-Work."
38
+ },
39
+ "datetime": {
40
+ "type": "string",
41
+ "format": "date-time",
42
+ "description": "Timestamp of when the address was last validated."
43
+ },
44
  "type": {
45
  "type": "string",
46
+ "description": "Interface type: internet, localhost, or private network.",
47
+ "pattern": "^(localhost|internet|yggdrasil|i2p|lan:[0-9]{1,3}(\\.[0-9]{1,3}){3})$"
48
  }
49
+ },
50
+ "additionalProperties": false
51
  },
52
+
53
  "peer": {
54
  "type": "object",
55
+ "required": ["id", "name", "pubkey", "addresses", "signature", "sig_algo", "version"],
56
  "properties": {
57
+ "version": {
58
+ "type": "string",
59
+ "description": "Version of this peer record format.",
60
+ "default": "1.0"
61
+ },
62
+ "id": {
63
+ "type": "string",
64
+ "description": "Peer's decentralized identifier (DID)."
65
+ },
66
+ "name": {
67
+ "type": "string",
68
+ "description": "Human-readable name of the peer."
69
+ },
70
+ "pubkey": {
71
+ "type": "string",
72
+ "description": "Base58-encoded Ed25519 public key."
73
+ },
74
  "addresses": {
75
  "type": "array",
76
+ "items": { "$ref": "#/definitions/interface" },
77
+ "description": "List of network interfaces associated with this peer."
78
+ },
79
+ "signature": {
80
+ "type": "string",
81
+ "description": "Base64URL-encoded Ed25519 signature of this record."
82
+ },
83
+ "sig_algo": {
84
+ "type": "string",
85
+ "enum": ["ed25519"],
86
+ "description": "Signature algorithm used for signing the record."
87
  }
88
+ },
89
+ "additionalProperties": false
90
  },
91
+
92
  "discovery": {
93
  "type": "object",
94
+ "required": ["type", "version", "id", "name", "pubkey", "addresses", "signature", "sig_algo"],
95
  "properties": {
96
  "type": { "const": "DISCOVERY" },
97
+ "version": {
98
+ "type": "string",
99
+ "description": "Version of the DISCOVERY message format.",
100
+ "default": "1.0"
101
+ },
102
  "id": { "type": "string" },
103
  "name": { "type": "string" },
104
  "pubkey": { "type": "string" },
105
  "addresses": {
106
  "type": "array",
107
  "items": { "$ref": "#/definitions/interface" }
108
+ },
109
+ "signature": { "type": "string" },
110
+ "sig_algo": { "type": "string", "enum": ["ed25519"] }
111
+ },
112
+ "additionalProperties": false
113
  },
114
+
115
  "peerExchangeRequest": {
116
  "type": "object",
117
+ "required": ["type", "version", "id", "name", "addresses", "signature", "sig_algo"],
118
  "properties": {
119
  "type": { "const": "PEER_EXCHANGE_REQUEST" },
120
+ "version": {
121
+ "type": "string",
122
+ "description": "Version of the PEER_EXCHANGE_REQUEST format.",
123
+ "default": "1.0"
124
+ },
125
  "id": { "type": "string" },
126
  "name": { "type": "string" },
127
  "addresses": {
128
  "type": "array",
129
  "items": { "$ref": "#/definitions/interface" }
130
+ },
131
+ "signature": { "type": "string" },
132
+ "sig_algo": { "type": "string", "enum": ["ed25519"] }
133
+ },
134
+ "additionalProperties": false
135
  },
136
+
137
  "peerExchangeResponse": {
138
  "type": "array",
139
+ "items": { "$ref": "#/definitions/peer" },
140
+ "description": "List of peers known to the responding agent."
141
  }
142
  }
143
  }