GNServer 0.0.0.0.30__py3-none-any.whl → 0.0.0.0.31__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/_app.py +83 -200
- GNServer/_client.py +45 -71
- GNServer/_crt.py +26 -0
- {gnserver-0.0.0.0.30.dist-info → gnserver-0.0.0.0.31.dist-info}/METADATA +1 -1
- gnserver-0.0.0.0.31.dist-info/RECORD +9 -0
- GNServer/___client.py +0 -628
- gnserver-0.0.0.0.30.dist-info/RECORD +0 -9
- {gnserver-0.0.0.0.30.dist-info → gnserver-0.0.0.0.31.dist-info}/WHEEL +0 -0
- {gnserver-0.0.0.0.30.dist-info → gnserver-0.0.0.0.31.dist-info}/licenses/LICENSE +0 -0
- {gnserver-0.0.0.0.30.dist-info → gnserver-0.0.0.0.31.dist-info}/top_level.txt +0 -0
GNServer/_client.py
CHANGED
@@ -1,42 +1,16 @@
|
|
1
|
+
import time
|
1
2
|
import httpx
|
2
3
|
import asyncio
|
3
|
-
import logging as logging2
|
4
|
-
from typing import Union, List, Dict, Tuple, Optional
|
5
4
|
import datetime
|
6
|
-
logging2.basicConfig(level=logging2.INFO)
|
7
|
-
from KeyisBLogging import logging
|
8
|
-
from typing import Dict, List, Tuple, Optional, AsyncGenerator, Callable, Literal, AsyncIterable
|
9
5
|
from itertools import count
|
10
|
-
from aioquic.asyncio.client import connect
|
11
|
-
from aioquic.asyncio.protocol import QuicConnectionProtocol
|
12
|
-
from aioquic.quic.configuration import QuicConfiguration
|
13
|
-
from aioquic.quic.events import QuicEvent
|
14
|
-
from aioquic.asyncio.protocol import QuicConnectionProtocol
|
15
|
-
from aioquic.quic.events import QuicEvent, StreamDataReceived, StreamReset
|
16
|
-
import asyncio
|
17
|
-
from collections import deque
|
18
|
-
from typing import Dict, Deque, Tuple, Optional
|
19
|
-
|
20
|
-
import asyncio
|
21
|
-
import time
|
22
6
|
from collections import deque
|
23
|
-
from
|
24
|
-
from typing import Deque, Dict, Optional, Tuple, Union
|
25
|
-
|
26
|
-
from aioquic.quic.configuration import QuicConfiguration
|
7
|
+
from typing import Any, Dict, Deque, Tuple, Union, Optional, AsyncGenerator, Callable, Literal, AsyncIterable
|
27
8
|
from aioquic.quic.events import QuicEvent, StreamDataReceived, StreamReset, ConnectionTerminated
|
9
|
+
from aioquic.quic.configuration import QuicConfiguration
|
10
|
+
from aioquic.asyncio.client import connect
|
11
|
+
from aioquic.asyncio.protocol import QuicConnectionProtocol
|
28
12
|
|
29
13
|
|
30
|
-
import time
|
31
|
-
from typing import Any, Dict, Optional
|
32
|
-
|
33
|
-
import logging
|
34
|
-
logging.basicConfig(level=logging.DEBUG)
|
35
|
-
logging.getLogger("websockets").setLevel(logging.DEBUG)
|
36
|
-
|
37
|
-
import KeyisBClient
|
38
|
-
from KeyisBClient import Url
|
39
|
-
httpxAsyncClient = httpx.AsyncClient(verify=KeyisBClient.ssl_gw_crt_path, timeout=200)
|
40
14
|
|
41
15
|
class GNExceptions:
|
42
16
|
class ConnectionError:
|
@@ -100,12 +74,12 @@ class GNExceptions:
|
|
100
74
|
super().__init__(message)
|
101
75
|
|
102
76
|
|
103
|
-
|
104
|
-
|
105
|
-
from KeyisBClient.gn import GNRequest, GNResponse
|
106
77
|
from KeyisBTools import TTLDict
|
107
|
-
|
108
78
|
from KeyisBTools.cryptography.sign import S1
|
79
|
+
from gnobjects.net.objects import GNRequest, GNResponse, Url
|
80
|
+
|
81
|
+
from ._crt import crt_client
|
82
|
+
|
109
83
|
|
110
84
|
s1 = S1()
|
111
85
|
|
@@ -159,9 +133,9 @@ class AsyncClient:
|
|
159
133
|
|
160
134
|
r1_data = r1.payload
|
161
135
|
|
162
|
-
result = r1_data['ip'] + ':' + str(r1_data['port'])
|
136
|
+
result = r1_data['ip'] + ':' + str(r1_data['port']) # type: ignore
|
163
137
|
|
164
|
-
self._dns_cache.set(domain, result, r1_data.get('ttl'))
|
138
|
+
self._dns_cache.set(domain, result, r1_data.get('ttl')) # type: ignore
|
165
139
|
|
166
140
|
return result
|
167
141
|
|
@@ -202,9 +176,9 @@ class AsyncClient:
|
|
202
176
|
|
203
177
|
r1_data = r1.payload
|
204
178
|
|
205
|
-
result = r1_data['ip'] + ':' + str(r1_data['port'])
|
179
|
+
result = r1_data['ip'] + ':' + str(r1_data['port']) # type: ignore
|
206
180
|
|
207
|
-
self._dns_cache.set(domain, result, r1_data.get('ttl'))
|
181
|
+
self._dns_cache.set(domain, result, r1_data.get('ttl')) # type: ignore
|
208
182
|
|
209
183
|
return result
|
210
184
|
|
@@ -332,40 +306,40 @@ class AsyncClient:
|
|
332
306
|
return r
|
333
307
|
|
334
308
|
|
335
|
-
async def requestStream(self, request: Union[GNRequest, AsyncGenerator[GNRequest, Any]]) -> AsyncGenerator[GNResponse, None]:
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
309
|
+
# async def requestStream(self, request: Union[GNRequest, AsyncGenerator[GNRequest, Any]]) -> AsyncGenerator[GNResponse, None]:
|
310
|
+
# """
|
311
|
+
# Build and send a async request.
|
312
|
+
# """
|
313
|
+
# if isinstance(request, GNRequest):
|
314
|
+
# if request.gn_protocol is None:
|
315
|
+
# request.setGNProtocol(self.__current_session['protocols'][0])
|
342
316
|
|
343
|
-
|
344
|
-
|
317
|
+
# for f in self.__request_callbacks.values():
|
318
|
+
# asyncio.create_task(f(request))
|
345
319
|
|
346
|
-
|
320
|
+
# async for response in self.client.asyncRequestStream(request):
|
347
321
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
322
|
+
# for f in self.__response_callbacks.values():
|
323
|
+
# asyncio.create_task(f(response))
|
324
|
+
|
325
|
+
# yield response
|
326
|
+
# else:
|
327
|
+
# async def wrapped(request) -> AsyncGenerator[GNRequest, None]:
|
328
|
+
# async for req in request:
|
329
|
+
# if req.gn_protocol is None:
|
330
|
+
# req.setGNProtocol(self.__current_session['protocols'][0])
|
357
331
|
|
358
|
-
|
359
|
-
|
332
|
+
# for f in self.__request_callbacks.values():
|
333
|
+
# asyncio.create_task(f(req))
|
360
334
|
|
361
|
-
|
362
|
-
|
363
|
-
|
335
|
+
# req._stream = True
|
336
|
+
# yield req
|
337
|
+
# async for response in self.client.asyncRequestStream(wrapped(request)):
|
364
338
|
|
365
|
-
|
366
|
-
|
339
|
+
# for f in self.__response_callbacks.values():
|
340
|
+
# asyncio.create_task(f(response))
|
367
341
|
|
368
|
-
|
342
|
+
# yield response
|
369
343
|
|
370
344
|
class RawQuicClient(QuicConnectionProtocol):
|
371
345
|
|
@@ -378,9 +352,9 @@ class RawQuicClient(QuicConnectionProtocol):
|
|
378
352
|
def __init__(self, *args, **kwargs):
|
379
353
|
super().__init__(*args, **kwargs)
|
380
354
|
|
381
|
-
self.quicClient: QuicClient = None
|
355
|
+
self.quicClient: QuicClient = None # type: ignore
|
382
356
|
|
383
|
-
self._sys_stream_id:
|
357
|
+
self._sys_stream_id: int = None # type: ignore
|
384
358
|
self._queue_sys: Deque[Tuple[int, bytes, bool]] = deque()
|
385
359
|
self._queue_user: Deque[Tuple[int, bytes, bool]] = deque()
|
386
360
|
|
@@ -659,13 +633,13 @@ class QuicClient:
|
|
659
633
|
self.status: Literal['active', 'connecting', 'disconnect']
|
660
634
|
|
661
635
|
self.connect_future = asyncio.get_event_loop().create_future()
|
662
|
-
self.connection_time: datetime.datetime = None
|
636
|
+
self.connection_time: datetime.datetime = None # type: ignore
|
663
637
|
|
664
638
|
async def connect(self, ip: str, port: int, keep_alive: bool = True):
|
665
639
|
self.status = 'connecting'
|
666
640
|
self.connection_time = datetime.datetime.now()
|
667
641
|
cfg = QuicConfiguration(is_client=True, alpn_protocols=["gn:backend"])
|
668
|
-
cfg.load_verify_locations(
|
642
|
+
cfg.load_verify_locations(cadata=crt_client)
|
669
643
|
cfg.idle_timeout = 40
|
670
644
|
|
671
645
|
self._client_cm = connect(
|
@@ -678,7 +652,7 @@ class QuicClient:
|
|
678
652
|
|
679
653
|
|
680
654
|
try:
|
681
|
-
self._quik_core = await self._client_cm.__aenter__()
|
655
|
+
self._quik_core = await self._client_cm.__aenter__() # type: ignore
|
682
656
|
self._quik_core.quicClient = self
|
683
657
|
|
684
658
|
if keep_alive:
|
GNServer/_crt.py
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
crt_client = b"""
|
4
|
+
-----BEGIN CERTIFICATE-----
|
5
|
+
MIIDszCCApugAwIBAgIUIEUvi2bdBH5yNb2Qi75IqGqMd7wwDQYJKoZIhvcNAQEL
|
6
|
+
BQAwYTELMAkGA1UEBhMCVVMxDjAMBgNVBAgMBVN0YXRlMQ0wCwYDVQQHDARDaXR5
|
7
|
+
MRUwEwYDVQQKDAxPcmdhbml6YXRpb24xDTALBgNVBAsMBFVuaXQxDTALBgNVBAMM
|
8
|
+
BE15Q0EwHhcNMjUwNTA1MDEwMTExWhcNMzUwNTAzMDEwMTExWjBhMQswCQYDVQQG
|
9
|
+
EwJVUzEOMAwGA1UECAwFU3RhdGUxDTALBgNVBAcMBENpdHkxFTATBgNVBAoMDE9y
|
10
|
+
Z2FuaXphdGlvbjENMAsGA1UECwwEVW5pdDENMAsGA1UEAwwETXlDQTCCASIwDQYJ
|
11
|
+
KoZIhvcNAQEBBQADggEPADCCAQoCggEBAMbDdWyR5n3qKaYkZvkiXtVJ7DekJn6Q
|
12
|
+
eJA+kvje4KzxBlD+SkdkYMQxuTVU2yuNYXX88LhSbPygrzFSU7q3HG9dNwonWwP6
|
13
|
+
05XFAvYZ5LDNI7DrjRecE/+JvpgXaAwcv3IJRpuJU1e+JL2K3Z9wwhxYEJM+N/aN
|
14
|
+
pP8Zyr5ktXJgEKhWOVtpj2LSXno33SI04B0LWVlbiZX/yWtK3X/BJPlXaMn+r76n
|
15
|
+
6L3JDNSjtuBGqSI7FHDQEPd3dcsdK6SbP6ORndp72EZfLcJbyXLtYdHgjJS9DrD4
|
16
|
+
0f5Laq2SQ2oo/B3MKNNF/Y8e1USX1tIe+lePmqzjJJk2oB1GSBiaX00CAwEAAaNj
|
17
|
+
MGEwDwYDVR0TAQH/BAUwAwEB/zAOBgNVHQ8BAf8EBAMCAQYwHQYDVR0OBBYEFM8O
|
18
|
+
S2OUe3Xkh7XkQ95s+MZTCtsuMB8GA1UdIwQYMBaAFM8OS2OUe3Xkh7XkQ95s+MZT
|
19
|
+
CtsuMA0GCSqGSIb3DQEBCwUAA4IBAQA3OwR0e9rPAgQ3nIHJrs+Tm7xr5DFAigd0
|
20
|
+
V13Klncrl7SPD0HrqQ88qNhHZcXJqy8Y6y3sUIknisud+9cnzYo/rNgpSG702ZAo
|
21
|
+
D/+ILHV51D8OZssoBaAWTfMA/NchPRXGDGJ5vBG/nXgvdpVdRnDepspKY1rYYTV0
|
22
|
+
JYZ99+nSa3eyDQxyMmYSzK0hQmKHdJEMkb8Es2/hRlAktL31irlXW15Fr3li5pmj
|
23
|
+
jRIER3q1T4WNyIuBRdNKYi03Eh342RWgl6C5Yjs1WBXsSXMhKpEw3Hlkc973CWb0
|
24
|
+
oKCo/cPl0mNfdrj5ER3njUOvItIpPAOajqVN9RsALSc0jC9M8pWJ
|
25
|
+
-----END CERTIFICATE-----
|
26
|
+
"""
|
@@ -0,0 +1,9 @@
|
|
1
|
+
GNServer/__init__.py,sha256=V50sMYrrPdOGuI1iJm-SW7izhX-eggDH16AHvtIKjmM,1480
|
2
|
+
GNServer/_app.py,sha256=77g8nGa1-5faslltJeffpU585T9xZKf7D7wm8EjBMyU,27610
|
3
|
+
GNServer/_client.py,sha256=5kPQF1M6YriCKaCsleoasAaoZrf9YI428iG1RhCoufY,29474
|
4
|
+
GNServer/_crt.py,sha256=SOmyX7zBiCY9EhVSekksQtBHgTIZVvdqNZ8Ni-E5Zow,1390
|
5
|
+
gnserver-0.0.0.0.31.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
|
6
|
+
gnserver-0.0.0.0.31.dist-info/METADATA,sha256=WVL7KBS8pzeXrDxZhSLQBuNR9eri_UJCKcD7bISB3pE,833
|
7
|
+
gnserver-0.0.0.0.31.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
+
gnserver-0.0.0.0.31.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
|
9
|
+
gnserver-0.0.0.0.31.dist-info/RECORD,,
|