GNServer 0.0.0.0.33__py3-none-any.whl → 0.0.0.0.35__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/__init__.py +1 -1
- GNServer/_client.py +30 -11
- {gnserver-0.0.0.0.33.dist-info → gnserver-0.0.0.0.35.dist-info}/METADATA +1 -1
- gnserver-0.0.0.0.35.dist-info/RECORD +9 -0
- gnserver-0.0.0.0.33.dist-info/RECORD +0 -9
- {gnserver-0.0.0.0.33.dist-info → gnserver-0.0.0.0.35.dist-info}/WHEEL +0 -0
- {gnserver-0.0.0.0.33.dist-info → gnserver-0.0.0.0.35.dist-info}/licenses/LICENSE +0 -0
- {gnserver-0.0.0.0.33.dist-info → gnserver-0.0.0.0.35.dist-info}/top_level.txt +0 -0
GNServer/__init__.py
CHANGED
@@ -36,7 +36,7 @@ DEALINGS IN THE SOFTWARE.
|
|
36
36
|
from ._app import App
|
37
37
|
|
38
38
|
from gnobjects.net.objects import Url, GNRequest, GNResponse, CommandObject, CORSObject, FileObject, TemplateObject, GNProtocol
|
39
|
-
from gnobjects.net.objects import AllGNFastCommands as
|
39
|
+
from gnobjects.net.objects import AllGNFastCommands as responses
|
40
40
|
|
41
41
|
|
42
42
|
from ._client import AsyncClient
|
GNServer/_client.py
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
import os
|
1
2
|
import time
|
2
3
|
import httpx
|
3
4
|
import asyncio
|
@@ -75,13 +76,15 @@ class GNExceptions:
|
|
75
76
|
|
76
77
|
|
77
78
|
from KeyisBTools import TTLDict
|
78
|
-
from KeyisBTools.cryptography.sign import
|
79
|
+
from KeyisBTools.cryptography.sign import s2
|
80
|
+
from KeyisBTools.cryptography import m1
|
81
|
+
from KeyisBTools.cryptography.bytes import hash
|
82
|
+
from KeyisBTools.models.serialization import serialize, deserialize
|
79
83
|
from gnobjects.net.objects import GNRequest, GNResponse, Url
|
80
84
|
|
81
85
|
from ._crt import crt_client
|
82
86
|
|
83
87
|
|
84
|
-
s1 = S1()
|
85
88
|
|
86
89
|
|
87
90
|
async def chain_async(first_item, rest: AsyncIterable) -> AsyncGenerator:
|
@@ -92,7 +95,7 @@ async def chain_async(first_item, rest: AsyncIterable) -> AsyncGenerator:
|
|
92
95
|
|
93
96
|
|
94
97
|
class AsyncClient:
|
95
|
-
def __init__(self):
|
98
|
+
def __init__(self, server_key: Optional[Union[bytes, str]] = None):
|
96
99
|
self.__dns_core__ipv4 = '51.250.85.38:52943'
|
97
100
|
self.__dns_gn__ipv4: Optional[str] = None
|
98
101
|
|
@@ -105,11 +108,25 @@ class AsyncClient:
|
|
105
108
|
self.__dns_client: Optional[AsyncClient] = None
|
106
109
|
self._dns_cache: TTLDict = TTLDict()
|
107
110
|
|
108
|
-
|
111
|
+
if server_key:
|
112
|
+
if isinstance(server_key, bytes):
|
113
|
+
self.__server_key = server_key
|
114
|
+
else:
|
115
|
+
if not os.path.exists(server_key):
|
116
|
+
raise Exception(f'Path not found: {server_key}')
|
117
|
+
|
118
|
+
self.__server_key = open(server_key, 'rb').read()
|
119
|
+
else:
|
120
|
+
self.__server_key = None
|
121
|
+
|
122
|
+
async def getCoreDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
|
109
123
|
if use_cache:
|
110
124
|
resuilt = self._dns_cache.get(domain)
|
111
125
|
if resuilt is not None:
|
112
126
|
return resuilt
|
127
|
+
|
128
|
+
if domain == 'api.dns.core':
|
129
|
+
return self.__dns_core__ipv4
|
113
130
|
|
114
131
|
if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
|
115
132
|
return domain
|
@@ -118,8 +135,10 @@ class AsyncClient:
|
|
118
135
|
if self.__dns_client is None:
|
119
136
|
self.__dns_client = AsyncClient()
|
120
137
|
|
121
|
-
if
|
122
|
-
|
138
|
+
if self.__server_key is not None:
|
139
|
+
s = s2.sign(self.__server_key)
|
140
|
+
data = m1.encrypt(s, domain.encode(), serialize({'domain': domain}), hash(self.__server_key))
|
141
|
+
payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s}, 'data': data}
|
123
142
|
else:
|
124
143
|
payload = None
|
125
144
|
|
@@ -144,7 +163,7 @@ class AsyncClient:
|
|
144
163
|
except:
|
145
164
|
raise GNExceptions.ConnectionError.dns.connection
|
146
165
|
|
147
|
-
async def getGNDNS(self, domain: str,
|
166
|
+
async def getGNDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
|
148
167
|
if use_cache:
|
149
168
|
resuilt = self._dns_cache.get(domain)
|
150
169
|
if resuilt is not None:
|
@@ -160,8 +179,8 @@ class AsyncClient:
|
|
160
179
|
if self.__dns_client is None:
|
161
180
|
self.__dns_client = AsyncClient()
|
162
181
|
|
163
|
-
if
|
164
|
-
payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(
|
182
|
+
if self.__server_key is not None:
|
183
|
+
payload = {'sign': {'alg': 'KeyisB-c-s-m1', 'data': s1.sign(self.__server_key)}}
|
165
184
|
else:
|
166
185
|
payload = None
|
167
186
|
|
@@ -187,11 +206,11 @@ class AsyncClient:
|
|
187
206
|
except:
|
188
207
|
raise GNExceptions.ConnectionError.dns.connection
|
189
208
|
|
190
|
-
async def getDNS(self, domain: str,
|
209
|
+
async def getDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False):
|
191
210
|
if domain.endswith(('.core', '.gw', '.gn', '.cdn', '.sys', '.gwis', '.abs')):
|
192
211
|
return await self.getCoreDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
|
193
212
|
else:
|
194
|
-
return await self.getGNDNS(domain=domain,
|
213
|
+
return await self.getGNDNS(domain=domain, use_cache=use_cache, keep_alive=keep_alive)
|
195
214
|
|
196
215
|
def addRequestCallback(self, callback: Callable, name: str):
|
197
216
|
self.__request_callbacks[name] = callback
|
@@ -0,0 +1,9 @@
|
|
1
|
+
GNServer/__init__.py,sha256=RCYh6f0lwh-Xh-5fv0jZvbUE6x7l8xYJhbn-o8_ITlE,1551
|
2
|
+
GNServer/_app.py,sha256=77g8nGa1-5faslltJeffpU585T9xZKf7D7wm8EjBMyU,27610
|
3
|
+
GNServer/_client.py,sha256=wK5F_ilMX70tYEcWYRHvWyKGMaKA0ivvsUeg6PrEk9s,30249
|
4
|
+
GNServer/_crt.py,sha256=SOmyX7zBiCY9EhVSekksQtBHgTIZVvdqNZ8Ni-E5Zow,1390
|
5
|
+
gnserver-0.0.0.0.35.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
|
6
|
+
gnserver-0.0.0.0.35.dist-info/METADATA,sha256=YBj3hf0ii65K8jNA3rkCge3KMAalCOO9bWxYHSnXqmw,830
|
7
|
+
gnserver-0.0.0.0.35.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
+
gnserver-0.0.0.0.35.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
|
9
|
+
gnserver-0.0.0.0.35.dist-info/RECORD,,
|
@@ -1,9 +0,0 @@
|
|
1
|
-
GNServer/__init__.py,sha256=-iS5bld8zmaFjLCN5VW6T1CBbACHoGUPttdRdLPrUkw,1550
|
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.33.dist-info/licenses/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
|
6
|
-
gnserver-0.0.0.0.33.dist-info/METADATA,sha256=Iob6tpV7SrWMGAFv9Fhc3HhxURF2qt4zdLtnAoHqnqU,830
|
7
|
-
gnserver-0.0.0.0.33.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
8
|
-
gnserver-0.0.0.0.33.dist-info/top_level.txt,sha256=-UOUBuD4u7Qkb1o5PdcwyA3kx8xCH2lwy0tJHi26Wb4,9
|
9
|
-
gnserver-0.0.0.0.33.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|