GNServer 0.0.0.0.25__py3-none-any.whl → 0.0.0.0.27__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 +22 -22
- {gnserver-0.0.0.0.25.dist-info → gnserver-0.0.0.0.27.dist-info}/METADATA +2 -1
- gnserver-0.0.0.0.27.dist-info/RECORD +9 -0
- GNServer/tools/__init__.py +0 -1
- GNServer/tools/_models.py +0 -74
- gnserver-0.0.0.0.25.dist-info/RECORD +0 -11
- {gnserver-0.0.0.0.25.dist-info → gnserver-0.0.0.0.27.dist-info}/WHEEL +0 -0
- {gnserver-0.0.0.0.25.dist-info → gnserver-0.0.0.0.27.dist-info}/licenses/LICENSE +0 -0
- {gnserver-0.0.0.0.25.dist-info → gnserver-0.0.0.0.27.dist-info}/top_level.txt +0 -0
GNServer/_client.py
CHANGED
@@ -101,7 +101,11 @@ class GNExceptions:
|
|
101
101
|
|
102
102
|
|
103
103
|
from KeyisBClient.gn import GNRequest, GNResponse
|
104
|
-
from
|
104
|
+
from KeyisBTools import TTLDict
|
105
|
+
|
106
|
+
from KeyisBTools.cryptography.sign import M1
|
107
|
+
|
108
|
+
m1 = M1()
|
105
109
|
|
106
110
|
|
107
111
|
|
@@ -119,16 +123,12 @@ class AsyncClient:
|
|
119
123
|
self.__dns_client: Optional[AsyncClient] = None
|
120
124
|
self._dns_cache: TTLDict = TTLDict()
|
121
125
|
|
122
|
-
|
123
|
-
async def getCoreDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
|
124
|
-
|
126
|
+
async def getCoreDNS(self, domain: str, token: Optional[bytes] = None, use_cache: bool = True, keep_alive: bool = False) -> str:
|
125
127
|
if use_cache:
|
126
128
|
resuilt = self._dns_cache.get(domain)
|
127
129
|
if resuilt is not None:
|
128
130
|
return resuilt
|
129
131
|
|
130
|
-
|
131
|
-
|
132
132
|
if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
|
133
133
|
return domain
|
134
134
|
|
@@ -136,7 +136,12 @@ class AsyncClient:
|
|
136
136
|
if self.__dns_client is None:
|
137
137
|
self.__dns_client = AsyncClient()
|
138
138
|
|
139
|
-
|
139
|
+
if token is not None:
|
140
|
+
payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': m1.sign(token)}}
|
141
|
+
else:
|
142
|
+
payload = None
|
143
|
+
|
144
|
+
r1 = await self.__dns_client.request(GNRequest('GET', Url(f'gn://{self.__dns_core__ipv4}/getIp?d={domain}'), payload=payload), keep_alive=keep_alive)
|
140
145
|
|
141
146
|
if r1.command != 'ok':
|
142
147
|
raise GNExceptions.ConnectionError.dns.data
|
@@ -154,32 +159,24 @@ class AsyncClient:
|
|
154
159
|
except:
|
155
160
|
raise GNExceptions.ConnectionError.dns.connection
|
156
161
|
|
157
|
-
|
158
|
-
|
159
|
-
async def getGNDNS(self, domain: str, token: Optional[str] = None, use_cache: bool = True, keep_alive: bool = False) -> str:
|
160
|
-
|
161
|
-
|
162
|
+
async def getGNDNS(self, domain: str, token: Optional[bytes] = None, use_cache: bool = True, keep_alive: bool = False) -> str:
|
162
163
|
if use_cache:
|
163
164
|
resuilt = self._dns_cache.get(domain)
|
164
165
|
if resuilt is not None:
|
165
166
|
return resuilt
|
166
167
|
|
167
|
-
|
168
|
-
|
169
168
|
if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
|
170
169
|
return domain
|
171
170
|
|
172
|
-
|
173
171
|
if self.__dns_gn__ipv4 is None:
|
174
172
|
self.__dns_gn__ipv4 = await self.getCoreDNS('dns.gn')
|
175
173
|
|
176
|
-
|
177
174
|
try:
|
178
175
|
if self.__dns_client is None:
|
179
176
|
self.__dns_client = AsyncClient()
|
180
177
|
|
181
178
|
if token is not None:
|
182
|
-
payload = {'
|
179
|
+
payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': m1.sign(token)}}
|
183
180
|
else:
|
184
181
|
payload = None
|
185
182
|
|
@@ -201,8 +198,11 @@ class AsyncClient:
|
|
201
198
|
except:
|
202
199
|
raise GNExceptions.ConnectionError.dns.connection
|
203
200
|
|
204
|
-
|
205
|
-
|
201
|
+
async def getDNS(self, domain: str, token: Optional[str] = None, use_cache: bool = True, keep_alive: bool = False):
|
202
|
+
if domain.endswith(('.core', '.gw', '.gn', '.cdn', '.sys', '.gwis', '.abs')):
|
203
|
+
return await self.getCoreDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
|
204
|
+
else:
|
205
|
+
return await self.getGNDNS(domain=domain, token=token, use_cache=use_cache, keep_alive=keep_alive)
|
206
206
|
|
207
207
|
def addRequestCallback(self, callback: Callable, name: str):
|
208
208
|
self.__request_callbacks[name] = callback
|
@@ -223,7 +223,7 @@ class AsyncClient:
|
|
223
223
|
print('дождались')
|
224
224
|
if c.status == 'active':
|
225
225
|
return c
|
226
|
-
elif c.status == 'connecting': # если очень
|
226
|
+
elif c.status == 'connecting': # если очень долго подключаемся, то кидаем ошибку
|
227
227
|
await self.disconnect(domain)
|
228
228
|
raise GNExceptions.ConnectionError.client.timeout
|
229
229
|
elif c.status == 'disconnect':
|
@@ -239,7 +239,7 @@ class AsyncClient:
|
|
239
239
|
c.status = 'connecting'
|
240
240
|
self._active_connections[domain] = c
|
241
241
|
|
242
|
-
data = await self.
|
242
|
+
data = await self.getDNS(domain)
|
243
243
|
|
244
244
|
data = data.split(':')
|
245
245
|
|
@@ -251,7 +251,7 @@ class AsyncClient:
|
|
251
251
|
c._disconnect_signal = f
|
252
252
|
c._domain = domain
|
253
253
|
|
254
|
-
await c.connect(data[
|
254
|
+
await c.connect(data[0], data[1], keep_alive=keep_alive)
|
255
255
|
await c.connect_future
|
256
256
|
|
257
257
|
return c
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: GNServer
|
3
|
-
Version: 0.0.0.0.
|
3
|
+
Version: 0.0.0.0.27
|
4
4
|
Summary: GNServer
|
5
5
|
Home-page: https://github.com/KeyisB/libs/tree/main/GNServer
|
6
6
|
Author: KeyisB
|
@@ -14,6 +14,7 @@ License-File: LICENSE
|
|
14
14
|
Requires-Dist: aioquic
|
15
15
|
Requires-Dist: anyio
|
16
16
|
Requires-Dist: KeyisBClient
|
17
|
+
Requires-Dist: KeyisBTools
|
17
18
|
Requires-Dist: aiofiles
|
18
19
|
Requires-Dist: uvloop
|
19
20
|
Dynamic: author
|
@@ -0,0 +1,9 @@
|
|
1
|
+
GNServer/___client.py,sha256=hmeUL2Vqp-BnwJeRcLZAaIfRNVxBrRRB_AFk9ofkei4,25459
|
2
|
+
GNServer/__init__.py,sha256=V50sMYrrPdOGuI1iJm-SW7izhX-eggDH16AHvtIKjmM,1480
|
3
|
+
GNServer/_app.py,sha256=WYK16u-G6TDEMBa3MVaJP3-HzTh4NIcmzsyOdxaSsm0,30664
|
4
|
+
GNServer/_client.py,sha256=uF5h5pu0noJ1uNWSdC-kxGvBUwUUmyyAQTt_altNJ_g,29861
|
5
|
+
gnserver-0.0.0.0.27.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
|
6
|
+
gnserver-0.0.0.0.27.dist-info/METADATA,sha256=8pB4A-duYiWVMfoKmSEE7zUs1rfo8gaF5fe1yszZfXE,833
|
7
|
+
gnserver-0.0.0.0.27.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
+
gnserver-0.0.0.0.27.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
|
9
|
+
gnserver-0.0.0.0.27.dist-info/RECORD,,
|
GNServer/tools/__init__.py
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
from ._models import TTLDict
|
GNServer/tools/_models.py
DELETED
@@ -1,74 +0,0 @@
|
|
1
|
-
import time
|
2
|
-
import asyncio
|
3
|
-
from typing import Optional
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
class TTLDict:
|
8
|
-
def __init__(self, default_ttl: int = 60, cleanup_interval: int = 300):
|
9
|
-
"""
|
10
|
-
:param default_ttl: TTL по умолчанию (сек), если при записи не указан
|
11
|
-
:param cleanup_interval: периодическая очистка от просроченных ключей (сек), по умолчанию 5 мин
|
12
|
-
"""
|
13
|
-
|
14
|
-
self._store = {}
|
15
|
-
self._default_ttl = default_ttl
|
16
|
-
self._cleanup_interval = cleanup_interval
|
17
|
-
self._task = None
|
18
|
-
|
19
|
-
def set(self, key, value, ttl: Optional[int] = None):
|
20
|
-
if ttl is None:
|
21
|
-
ttl = self._default_ttl
|
22
|
-
expire_at = time.monotonic() + ttl
|
23
|
-
self._store[key] = (value, expire_at)
|
24
|
-
|
25
|
-
if self._task is None:
|
26
|
-
loop = asyncio.get_running_loop()
|
27
|
-
self._task = loop.create_task(self._cleanup_worker())
|
28
|
-
|
29
|
-
def get(self, key):
|
30
|
-
now = time.monotonic()
|
31
|
-
item = self._store.get(key)
|
32
|
-
if not item:
|
33
|
-
return None
|
34
|
-
|
35
|
-
value, expire_at = item
|
36
|
-
if expire_at < now:
|
37
|
-
del self._store[key]
|
38
|
-
return None
|
39
|
-
return value
|
40
|
-
|
41
|
-
def __setitem__(self, key, value):
|
42
|
-
self.set(key, value, self._default_ttl)
|
43
|
-
|
44
|
-
def __getitem__(self, key):
|
45
|
-
return self.get(key)
|
46
|
-
|
47
|
-
def __contains__(self, key):
|
48
|
-
return self.get(key) is not None
|
49
|
-
|
50
|
-
def __len__(self):
|
51
|
-
return len(self._store)
|
52
|
-
|
53
|
-
def __repr__(self):
|
54
|
-
return f"<TTLDict size={len(self._store)}>"
|
55
|
-
|
56
|
-
async def _cleanup_worker(self):
|
57
|
-
while True:
|
58
|
-
await asyncio.sleep(self._cleanup_interval)
|
59
|
-
self.cleanup()
|
60
|
-
|
61
|
-
def cleanup(self):
|
62
|
-
"""Удалить все просроченные ключи"""
|
63
|
-
now = time.monotonic()
|
64
|
-
expired = [k for k, (_, exp) in self._store.items() if exp < now]
|
65
|
-
for k in expired:
|
66
|
-
self._store.pop(k, None)
|
67
|
-
|
68
|
-
async def stop(self):
|
69
|
-
"""Остановить фон очистки"""
|
70
|
-
self._task.cancel()
|
71
|
-
try:
|
72
|
-
await self._task
|
73
|
-
except asyncio.CancelledError:
|
74
|
-
pass
|
@@ -1,11 +0,0 @@
|
|
1
|
-
GNServer/___client.py,sha256=hmeUL2Vqp-BnwJeRcLZAaIfRNVxBrRRB_AFk9ofkei4,25459
|
2
|
-
GNServer/__init__.py,sha256=V50sMYrrPdOGuI1iJm-SW7izhX-eggDH16AHvtIKjmM,1480
|
3
|
-
GNServer/_app.py,sha256=WYK16u-G6TDEMBa3MVaJP3-HzTh4NIcmzsyOdxaSsm0,30664
|
4
|
-
GNServer/_client.py,sha256=0Dy2n5FN6_nKm8n5XLCXkimKkKdIrhQpIY0Sk1UkNMk,29163
|
5
|
-
GNServer/tools/__init__.py,sha256=itqkS5iBB2GEHqz8H-htqgd55rUi6utnuKVAzBBByCM,28
|
6
|
-
GNServer/tools/_models.py,sha256=1V94cbNHQGAl5l9DJbGvvkm1gmsgTEMgkjzlnZk8ymw,2264
|
7
|
-
gnserver-0.0.0.0.25.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
|
8
|
-
gnserver-0.0.0.0.25.dist-info/METADATA,sha256=A_iTQQjqw9z2p3UrvkiqvYnRceT7nqpjT0EzQj6RezA,805
|
9
|
-
gnserver-0.0.0.0.25.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
10
|
-
gnserver-0.0.0.0.25.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
|
11
|
-
gnserver-0.0.0.0.25.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|