GNServer 0.0.0.0.24__py3-none-any.whl → 0.0.0.0.25__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 +31 -7
- {gnserver-0.0.0.0.24.dist-info → gnserver-0.0.0.0.25.dist-info}/METADATA +1 -1
- {gnserver-0.0.0.0.24.dist-info → gnserver-0.0.0.0.25.dist-info}/RECORD +6 -6
- {gnserver-0.0.0.0.24.dist-info → gnserver-0.0.0.0.25.dist-info}/WHEEL +0 -0
- {gnserver-0.0.0.0.24.dist-info → gnserver-0.0.0.0.25.dist-info}/licenses/LICENSE +0 -0
- {gnserver-0.0.0.0.24.dist-info → gnserver-0.0.0.0.25.dist-info}/top_level.txt +0 -0
GNServer/_client.py
CHANGED
@@ -101,7 +101,7 @@ class GNExceptions:
|
|
101
101
|
|
102
102
|
|
103
103
|
from KeyisBClient.gn import GNRequest, GNResponse
|
104
|
-
|
104
|
+
from .tools import TTLDict
|
105
105
|
|
106
106
|
|
107
107
|
|
@@ -117,9 +117,17 @@ class AsyncClient:
|
|
117
117
|
self._active_connections: Dict[str, QuicClient] = {}
|
118
118
|
|
119
119
|
self.__dns_client: Optional[AsyncClient] = None
|
120
|
+
self._dns_cache: TTLDict = TTLDict()
|
120
121
|
|
121
122
|
|
122
|
-
async def getCoreDNS(self, domain: str) -> str:
|
123
|
+
async def getCoreDNS(self, domain: str, use_cache: bool = True, keep_alive: bool = False) -> str:
|
124
|
+
|
125
|
+
if use_cache:
|
126
|
+
resuilt = self._dns_cache.get(domain)
|
127
|
+
if resuilt is not None:
|
128
|
+
return resuilt
|
129
|
+
|
130
|
+
|
123
131
|
|
124
132
|
if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
|
125
133
|
return domain
|
@@ -128,14 +136,18 @@ class AsyncClient:
|
|
128
136
|
if self.__dns_client is None:
|
129
137
|
self.__dns_client = AsyncClient()
|
130
138
|
|
131
|
-
r1 = await self.__dns_client.request(GNRequest('GET', Url(f'gn://{self.__dns_core__ipv4}/getIp?d={domain}')), keep_alive=
|
139
|
+
r1 = await self.__dns_client.request(GNRequest('GET', Url(f'gn://{self.__dns_core__ipv4}/getIp?d={domain}')), keep_alive=keep_alive)
|
132
140
|
|
133
141
|
if r1.command != 'ok':
|
134
142
|
raise GNExceptions.ConnectionError.dns.data
|
135
143
|
|
136
144
|
r1_data = r1.payload
|
137
145
|
|
138
|
-
|
146
|
+
result = r1_data['ip'] + ':' + str(r1_data['port'])
|
147
|
+
|
148
|
+
self._dns_cache.set(domain, result, r1_data.get('ttl'))
|
149
|
+
|
150
|
+
return result
|
139
151
|
|
140
152
|
except httpx.TimeoutException:
|
141
153
|
raise GNExceptions.ConnectionError.dns.timeout
|
@@ -144,7 +156,15 @@ class AsyncClient:
|
|
144
156
|
|
145
157
|
|
146
158
|
|
147
|
-
async def getGNDNS(self, domain: str, token: Optional[str] = None) -> str:
|
159
|
+
async def getGNDNS(self, domain: str, token: Optional[str] = None, use_cache: bool = True, keep_alive: bool = False) -> str:
|
160
|
+
|
161
|
+
|
162
|
+
if use_cache:
|
163
|
+
resuilt = self._dns_cache.get(domain)
|
164
|
+
if resuilt is not None:
|
165
|
+
return resuilt
|
166
|
+
|
167
|
+
|
148
168
|
|
149
169
|
if ':' in domain and domain.split('.')[-1].split(':')[0].isdigit() and domain.split(':')[-1].isdigit():
|
150
170
|
return domain
|
@@ -163,14 +183,18 @@ class AsyncClient:
|
|
163
183
|
else:
|
164
184
|
payload = None
|
165
185
|
|
166
|
-
r1 = await self.__dns_client.request(GNRequest('GET', Url(f'gn://{self.__dns_gn__ipv4}/getIp?d={domain}'), payload=payload))
|
186
|
+
r1 = await self.__dns_client.request(GNRequest('GET', Url(f'gn://{self.__dns_gn__ipv4}/getIp?d={domain}'), payload=payload), keep_alive=keep_alive)
|
167
187
|
|
168
188
|
if r1.command != 'ok':
|
169
189
|
raise GNExceptions.ConnectionError.dns.data
|
170
190
|
|
171
191
|
r1_data = r1.payload
|
172
192
|
|
173
|
-
|
193
|
+
result = r1_data['ip'] + ':' + str(r1_data['port'])
|
194
|
+
|
195
|
+
self._dns_cache.set(domain, result, r1_data.get('ttl'))
|
196
|
+
|
197
|
+
return result
|
174
198
|
|
175
199
|
except httpx.TimeoutException:
|
176
200
|
raise GNExceptions.ConnectionError.dns.timeout
|
@@ -1,11 +1,11 @@
|
|
1
1
|
GNServer/___client.py,sha256=hmeUL2Vqp-BnwJeRcLZAaIfRNVxBrRRB_AFk9ofkei4,25459
|
2
2
|
GNServer/__init__.py,sha256=V50sMYrrPdOGuI1iJm-SW7izhX-eggDH16AHvtIKjmM,1480
|
3
3
|
GNServer/_app.py,sha256=WYK16u-G6TDEMBa3MVaJP3-HzTh4NIcmzsyOdxaSsm0,30664
|
4
|
-
GNServer/_client.py,sha256=
|
4
|
+
GNServer/_client.py,sha256=0Dy2n5FN6_nKm8n5XLCXkimKkKdIrhQpIY0Sk1UkNMk,29163
|
5
5
|
GNServer/tools/__init__.py,sha256=itqkS5iBB2GEHqz8H-htqgd55rUi6utnuKVAzBBByCM,28
|
6
6
|
GNServer/tools/_models.py,sha256=1V94cbNHQGAl5l9DJbGvvkm1gmsgTEMgkjzlnZk8ymw,2264
|
7
|
-
gnserver-0.0.0.0.
|
8
|
-
gnserver-0.0.0.0.
|
9
|
-
gnserver-0.0.0.0.
|
10
|
-
gnserver-0.0.0.0.
|
11
|
-
gnserver-0.0.0.0.
|
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
|