GNServer 0.0.0.0.41__py3-none-any.whl → 0.0.0.0.43__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- GNServer/_client.py +73 -97
- {gnserver-0.0.0.0.41.dist-info → gnserver-0.0.0.0.43.dist-info}/METADATA +1 -1
- {gnserver-0.0.0.0.41.dist-info → gnserver-0.0.0.0.43.dist-info}/RECORD +6 -6
- gnserver-0.0.0.0.43.dist-info/licenses/LICENSE +29 -0
- gnserver-0.0.0.0.41.dist-info/licenses/LICENSE +0 -21
- {gnserver-0.0.0.0.41.dist-info → gnserver-0.0.0.0.43.dist-info}/WHEEL +0 -0
- {gnserver-0.0.0.0.41.dist-info → gnserver-0.0.0.0.43.dist-info}/top_level.txt +0 -0
GNServer/_client.py
CHANGED
@@ -5,7 +5,7 @@ import asyncio
|
|
5
5
|
import datetime
|
6
6
|
from itertools import count
|
7
7
|
from collections import deque
|
8
|
-
from typing import Any, Dict, Deque, Tuple, Union, Optional, AsyncGenerator, Callable, Literal, AsyncIterable
|
8
|
+
from typing import Any, Dict, Deque, Tuple, Union, Optional, AsyncGenerator, Callable, Literal, AsyncIterable, overload
|
9
9
|
from aioquic.quic.events import QuicEvent, StreamDataReceived, StreamReset, ConnectionTerminated
|
10
10
|
from aioquic.quic.configuration import QuicConfiguration
|
11
11
|
from aioquic.asyncio.client import connect
|
@@ -162,98 +162,6 @@ class AsyncClient:
|
|
162
162
|
else:
|
163
163
|
self.__server_key = None
|
164
164
|
|
165
|
-
async def getCoreDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
|
166
|
-
if use_cache:
|
167
|
-
resuilt = self._dns_cache.get(domain)
|
168
|
-
if resuilt is not None:
|
169
|
-
return resuilt
|
170
|
-
|
171
|
-
if domain == 'api.dns.core':
|
172
|
-
return self.__dns_core__ipv4
|
173
|
-
|
174
|
-
if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
|
175
|
-
return domain
|
176
|
-
|
177
|
-
try:
|
178
|
-
if self.__dns_client is None:
|
179
|
-
self.__dns_client = AsyncClient()
|
180
|
-
|
181
|
-
if self.__server_key is not None:
|
182
|
-
s = s2.sign(self.__server_key)
|
183
|
-
data = m1.encrypt(s, domain.encode(), serialize({'domain': domain}), hash(self.__server_key))
|
184
|
-
payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s, 'domain': self.__domain}, 'data': data}
|
185
|
-
else:
|
186
|
-
payload = None
|
187
|
-
|
188
|
-
r1 = await self.__dns_client.request(GNRequest('GET', Url(f'gn://{self.__dns_core__ipv4}/getIp?d={domain}'), payload=payload), keep_alive=keep_alive)
|
189
|
-
|
190
|
-
if not r1.command:
|
191
|
-
raise r1
|
192
|
-
|
193
|
-
if r1.payload is None:
|
194
|
-
raise GNExceptions.ConnectionError.dns.data
|
195
|
-
|
196
|
-
r1_data = r1.payload
|
197
|
-
|
198
|
-
result = r1_data['ip'] + ':' + str(r1_data['port']) # type: ignore
|
199
|
-
|
200
|
-
self._dns_cache.set(domain, result, r1_data.get('ttl')) # type: ignore
|
201
|
-
|
202
|
-
return result
|
203
|
-
|
204
|
-
except httpx.TimeoutException:
|
205
|
-
raise GNExceptions.ConnectionError.dns.timeout
|
206
|
-
except:
|
207
|
-
raise GNExceptions.ConnectionError.dns.connection
|
208
|
-
|
209
|
-
async def getGNDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
|
210
|
-
if use_cache:
|
211
|
-
resuilt = self._dns_cache.get(domain)
|
212
|
-
if resuilt is not None:
|
213
|
-
return resuilt
|
214
|
-
|
215
|
-
if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
|
216
|
-
return domain
|
217
|
-
|
218
|
-
if self.__dns_gn__ipv4 is None:
|
219
|
-
self.__dns_gn__ipv4 = await self.getCoreDNS('dns.gn')
|
220
|
-
|
221
|
-
try:
|
222
|
-
if self.__dns_client is None:
|
223
|
-
self.__dns_client = AsyncClient()
|
224
|
-
|
225
|
-
if self.__server_key is not None:
|
226
|
-
payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(self.__server_key)}}
|
227
|
-
else:
|
228
|
-
payload = None
|
229
|
-
|
230
|
-
r1 = await self.__dns_client.request(GNRequest('GET', Url(f'gn://{self.__dns_gn__ipv4}/getIp?d={domain}'), payload=payload), keep_alive=keep_alive)
|
231
|
-
|
232
|
-
if r1.command != 'ok':
|
233
|
-
raise GNExceptions.ConnectionError.dns.data
|
234
|
-
|
235
|
-
|
236
|
-
if r1.payload is None:
|
237
|
-
raise GNExceptions.ConnectionError.dns.data
|
238
|
-
|
239
|
-
r1_data = r1.payload
|
240
|
-
|
241
|
-
result = r1_data['ip'] + ':' + str(r1_data['port']) # type: ignore
|
242
|
-
|
243
|
-
self._dns_cache.set(domain, result, r1_data.get('ttl')) # type: ignore
|
244
|
-
|
245
|
-
return result
|
246
|
-
|
247
|
-
except httpx.TimeoutException:
|
248
|
-
raise GNExceptions.ConnectionError.dns.timeout
|
249
|
-
except:
|
250
|
-
raise GNExceptions.ConnectionError.dns.connection
|
251
|
-
|
252
|
-
async def getDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False):
|
253
|
-
if domain.endswith(('.core', '.gw', '.gn', '.cdn', '.sys', '.gwis', '.abs')):
|
254
|
-
return await self.getCoreDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
|
255
|
-
else:
|
256
|
-
return await self.getGNDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
|
257
165
|
|
258
166
|
def addRequestCallback(self, callback: Callable, name: str):
|
259
167
|
self.__request_callbacks[name] = callback
|
@@ -292,7 +200,7 @@ class AsyncClient:
|
|
292
200
|
self._active_connections[domain] = c
|
293
201
|
|
294
202
|
devLog(request, '1.2.6', 10, f'Connecting to {domain}...')
|
295
|
-
data = await self.getDNS(domain)
|
203
|
+
data = await self.getDNS(domain, raise_errors=True)
|
296
204
|
devLog(request, '1.2.7', 10, f'Got DNS for {domain}: {data}')
|
297
205
|
|
298
206
|
data = data.split(':')
|
@@ -390,6 +298,76 @@ class AsyncClient:
|
|
390
298
|
return r
|
391
299
|
|
392
300
|
|
301
|
+
|
302
|
+
def isDNSCore(self, domain: str) -> bool:
|
303
|
+
return domain.endswith(('.core', '.gw', '.gn', '.cdn', '.sys', '.gwis', '.abs'))
|
304
|
+
|
305
|
+
@overload
|
306
|
+
async def getDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False, raise_errors: Literal[False] = False) -> GNResponse: ...
|
307
|
+
@overload
|
308
|
+
async def getDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False, raise_errors: Literal[True] = True) -> str: ...
|
309
|
+
|
310
|
+
async def getDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False, raise_errors: bool = False) -> Union[str, GNResponse]:
|
311
|
+
if use_cache:
|
312
|
+
resuilt = self._dns_cache.get(domain)
|
313
|
+
if resuilt is not None:
|
314
|
+
if raise_errors:
|
315
|
+
r1_data = resuilt.payload
|
316
|
+
result = r1_data['ip'] + ':' + str(r1_data['port']) # type: ignore
|
317
|
+
else:
|
318
|
+
result = resuilt
|
319
|
+
return result
|
320
|
+
|
321
|
+
|
322
|
+
if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
|
323
|
+
return domain
|
324
|
+
|
325
|
+
if domain == 'api.dns.core':
|
326
|
+
return self.__dns_core__ipv4
|
327
|
+
|
328
|
+
is_dns_core = self.isDNSCore(domain)
|
329
|
+
if not is_dns_core:
|
330
|
+
if self.__dns_gn__ipv4 is None:
|
331
|
+
self.__dns_gn__ipv4 = await self.getDNS('api.dns.gn', raise_errors=True)
|
332
|
+
|
333
|
+
if self.__dns_client is None:
|
334
|
+
self.__dns_client = AsyncClient()
|
335
|
+
|
336
|
+
if self.__server_key is not None:
|
337
|
+
s = s2.sign(self.__server_key)
|
338
|
+
data = m1.encrypt(s, domain.encode(), serialize({'domain': domain}), hash(self.__server_key))
|
339
|
+
payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s, 'domain': self.__domain}, 'data': data}
|
340
|
+
else:
|
341
|
+
payload = None
|
342
|
+
|
343
|
+
if is_dns_core:
|
344
|
+
ip_dns = self.__dns_core__ipv4
|
345
|
+
else:
|
346
|
+
ip_dns = self.__dns_gn__ipv4
|
347
|
+
|
348
|
+
r1 = await self.__dns_client.request(GNRequest('GET', Url(f'gn://{ip_dns}/getIp?d={domain}'), payload=payload), keep_alive=keep_alive)
|
349
|
+
|
350
|
+
if not r1.command:
|
351
|
+
if raise_errors:
|
352
|
+
raise r1
|
353
|
+
else:
|
354
|
+
return r1
|
355
|
+
|
356
|
+
self._dns_cache.set(domain, r1, r1.payload.get('ttl', 60)) # type: ignore
|
357
|
+
|
358
|
+
if raise_errors:
|
359
|
+
r1_data = r1.payload
|
360
|
+
result = r1_data['ip'] + ':' + str(r1_data['port']) # type: ignore
|
361
|
+
else:
|
362
|
+
result = r1
|
363
|
+
return result
|
364
|
+
|
365
|
+
|
366
|
+
|
367
|
+
|
368
|
+
|
369
|
+
|
370
|
+
|
393
371
|
# async def requestStream(self, request: Union[GNRequest, AsyncGenerator[GNRequest, Any]]) -> AsyncGenerator[GNResponse, None]:
|
394
372
|
# """
|
395
373
|
# Build and send a async request.
|
@@ -800,6 +778,4 @@ class QuicClient:
|
|
800
778
|
chunk = await queue.get()
|
801
779
|
if chunk is None or chunk.command == 'gn:end-stream':
|
802
780
|
break
|
803
|
-
yield chunk
|
804
|
-
|
805
|
-
|
781
|
+
yield chunk
|
@@ -1,13 +1,13 @@
|
|
1
1
|
GNServer/__init__.py,sha256=6CMCZlkBO74PW8i8DAri5xz2fYM9EyPH8vdsLYBMmOo,1560
|
2
2
|
GNServer/_app.py,sha256=nvK_9w1YtZfE-Xh0K-ebkvVINAx4Fir3NSw7Lbwyaz4,18874
|
3
|
-
GNServer/_client.py,sha256=
|
3
|
+
GNServer/_client.py,sha256=jABXjnNJ9o6Mo3jRTW5Qyb-yhgjdH4VnIexwOplJcyg,31867
|
4
4
|
GNServer/_cors_resolver.py,sha256=U9IFGN7vpVsEM2smhuf5QGj8vYgs7HeFQwDdzWVVy9c,4832
|
5
5
|
GNServer/_crt.py,sha256=SOmyX7zBiCY9EhVSekksQtBHgTIZVvdqNZ8Ni-E5Zow,1390
|
6
6
|
GNServer/_func_params_validation.py,sha256=pDXRzPVTdPnDHFMMmKd014SConBjFOuaLeJTY0vldlM,11412
|
7
7
|
GNServer/_routes.py,sha256=bJnmQ8uEhPVQgy2tTqE5TEIM8aFXV-lVI7c2nG0rQwk,3384
|
8
8
|
GNServer/_template_resolver.py,sha256=vdJYb_7PjIeTWq-Clr7jyj7QIvPBxplU7EqeOuMJ64c,1409
|
9
|
-
gnserver-0.0.0.0.
|
10
|
-
gnserver-0.0.0.0.
|
11
|
-
gnserver-0.0.0.0.
|
12
|
-
gnserver-0.0.0.0.
|
13
|
-
gnserver-0.0.0.0.
|
9
|
+
gnserver-0.0.0.0.43.dist-info/licenses/LICENSE,sha256=_rN-sb3LemR3cKsEqjJRdXkdt7mME1mkW1BwWEn-zAw,1309
|
10
|
+
gnserver-0.0.0.0.43.dist-info/METADATA,sha256=24T_ROdMsk676KmLYK89nDqS5HxLMEs-lhn2xOcfRTs,830
|
11
|
+
gnserver-0.0.0.0.43.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
12
|
+
gnserver-0.0.0.0.43.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
|
13
|
+
gnserver-0.0.0.0.43.dist-info/RECORD,,
|
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
Copyright (C) 2024 KeyisB. All rights reserved.
|
3
|
+
|
4
|
+
Permission is hereby granted, free of charge, to any person
|
5
|
+
obtaining a copy of this software and associated documentation
|
6
|
+
files (the "Software"), to use the Software exclusively for
|
7
|
+
projects related to the MMB or GW systems, including personal,
|
8
|
+
educational, and commercial purposes, subject to the following
|
9
|
+
conditions:
|
10
|
+
|
11
|
+
1. Copying, modification, merging, publishing, distribution,
|
12
|
+
sublicensing, and/or selling copies of the Software are
|
13
|
+
strictly prohibited.
|
14
|
+
2. The licensee may use the Software only in its original,
|
15
|
+
unmodified form.
|
16
|
+
3. All copies or substantial portions of the Software must
|
17
|
+
remain unaltered and include this copyright notice and these terms of use.
|
18
|
+
4. Use of the Software for projects not related to GW or
|
19
|
+
MMB systems is strictly prohibited.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
22
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
23
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
24
|
+
A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT
|
25
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
26
|
+
CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION
|
27
|
+
OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR
|
28
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
29
|
+
DEALINGS IN THE SOFTWARE.
|
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2024 KeyisB
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
File without changes
|
File without changes
|