dimples 1.2.5__tar.gz → 1.2.7__tar.gz
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.
- dimples-1.2.7/LICENSE +21 -0
- dimples-1.2.7/PKG-INFO +31 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/network/session.py +11 -11
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/network/state.py +16 -16
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/network/transition.py +12 -12
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/__init__.py +18 -18
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/flexible.py +41 -46
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/gate.py +46 -85
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/gatekeeper.py +13 -13
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/mars.py +2 -2
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/mtp.py +2 -2
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/session.py +1 -1
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/ws.py +2 -2
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/document.py +1 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/meta.py +4 -1
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/private.py +8 -2
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/document.py +2 -1
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/grp_history.py +2 -2
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/login.py +2 -2
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/station.py +14 -6
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_document.py +6 -10
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_group.py +18 -30
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_group_history.py +11 -21
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_group_keys.py +10 -9
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_login.py +7 -14
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_station.py +16 -21
- {dimples-1.2.5 → dimples-1.2.7}/dimples/register/run.py +3 -1
- {dimples-1.2.5 → dimples-1.2.7}/dimples/register/shared.py +23 -6
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/__init__.py +4 -2
- dimples-1.2.7/dimples/server/deliver.py +172 -0
- dimples-1.2.7/dimples/server/dis_roamer.py +115 -0
- dimples-1.2.7/dimples/server/dispatcher.py +247 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/session.py +53 -28
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/session_center.py +3 -3
- {dimples-1.2.5 → dimples-1.2.7}/dimples/station/handler.py +4 -16
- {dimples-1.2.5 → dimples-1.2.7}/dimples/station/shared.py +14 -4
- dimples-1.2.7/dimples.egg-info/PKG-INFO +31 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples.egg-info/SOURCES.txt +3 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples.egg-info/entry_points.txt +0 -1
- {dimples-1.2.5 → dimples-1.2.7}/dimples.egg-info/requires.txt +3 -3
- {dimples-1.2.5 → dimples-1.2.7}/setup.py +4 -4
- dimples-1.2.5/PKG-INFO +0 -22
- dimples-1.2.5/dimples/server/dispatcher.py +0 -464
- dimples-1.2.5/dimples.egg-info/PKG-INFO +0 -22
- {dimples-1.2.5 → dimples-1.2.7}/README.md +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/archivist.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/checkpoint.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/commands.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/creator.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/group.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/grp_expel.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/grp_invite.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/grp_join.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/grp_query.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/grp_quit.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/grp_reset.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/grp_resign.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/cpu/handshake.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/facebook.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/messenger.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/network/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/packer.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/processor.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/client/terminal.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/anonymous.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/ans.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/archivist.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/compat/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/compat/btc.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/compat/compatible.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/compat/entity.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/compat/meta.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/compat/network.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/dbi/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/dbi/account.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/dbi/message.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/dbi/session.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/facebook.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/messenger.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/packer.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/processer.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/protocol/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/protocol/ans.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/protocol/block.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/protocol/handshake.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/protocol/login.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/protocol/mute.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/protocol/report.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/register.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/common/session.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/protocol/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/protocol/mars.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/protocol/ws.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/queue.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/conn/seeker.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/account.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/base.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/group.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/group_history.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/group_keys.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/login.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/station.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/dos/user.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/message.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/base.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/group.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/grp_keys.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/message.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/meta.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/redis/user.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/session.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_base.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_cipherkey.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_message.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_meta.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_private.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/database/t_user.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/edge/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/edge/octopus.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/edge/shared.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/edge/start.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/group/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/group/admin.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/group/builder.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/group/delegate.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/group/emitter.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/group/helper.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/group/manager.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/group/packer.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/register/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/register/base.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/register/ext.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/archivist.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/cpu/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/cpu/ans.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/cpu/document.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/cpu/handshake.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/cpu/login.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/cpu/report.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/messenger.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/packer.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/processor.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/push.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/server/trace.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/station/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/station/start.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/utils/__init__.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/utils/cache.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/utils/config.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/utils/log.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples/utils/runner.py +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples.egg-info/dependency_links.txt +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/dimples.egg-info/top_level.txt +0 -0
- {dimples-1.2.5 → dimples-1.2.7}/setup.cfg +0 -0
dimples-1.2.7/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Albert Moky
|
|
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.
|
dimples-1.2.7/PKG-INFO
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: dimples
|
|
3
|
+
Version: 1.2.7
|
|
4
|
+
Summary: DIMP Library for Edges and Stations
|
|
5
|
+
Home-page: https://github.com/dimchat/demo-py
|
|
6
|
+
Author: Albert Moky
|
|
7
|
+
Author-email: albert.moky@gmail.com
|
|
8
|
+
License: MIT
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: dimplugins>=2.0.0
|
|
15
|
+
Requires-Dist: dimsdk>=2.0.0
|
|
16
|
+
Requires-Dist: dimp>=2.0.0
|
|
17
|
+
Requires-Dist: dkd>=2.0.0
|
|
18
|
+
Requires-Dist: mkm>=2.0.0
|
|
19
|
+
Requires-Dist: startrek>=2.2.0
|
|
20
|
+
Requires-Dist: tcp>=2.2.0
|
|
21
|
+
Requires-Dist: udp>=2.2.0
|
|
22
|
+
Requires-Dist: aiou>=0.3.0
|
|
23
|
+
|
|
24
|
+
# DIMP Library for Edges and Stations (Python version)
|
|
25
|
+
|
|
26
|
+
[](https://github.com/dimchat/demo-py/blob/master/LICENSE)
|
|
27
|
+
[](https://github.com/dimchat/demo-py/wiki)
|
|
28
|
+
[](https://github.com/dimchat/demo-py/pulls)
|
|
29
|
+
[](https://github.com/dimchat/demo-py/wiki)
|
|
30
|
+
|
|
31
|
+
Copyright © 2018-2022 Albert Moky
|
|
@@ -40,7 +40,7 @@ from typing import Optional, List
|
|
|
40
40
|
|
|
41
41
|
from dimsdk import Station
|
|
42
42
|
|
|
43
|
-
from startrek import
|
|
43
|
+
from startrek import Porter, PorterStatus
|
|
44
44
|
from startrek import Arrival
|
|
45
45
|
|
|
46
46
|
from ...utils import Daemon, Runner
|
|
@@ -146,20 +146,20 @@ class ClientSession(BaseSession):
|
|
|
146
146
|
#
|
|
147
147
|
|
|
148
148
|
# Override
|
|
149
|
-
async def
|
|
150
|
-
# await super().
|
|
151
|
-
if current is None or current ==
|
|
149
|
+
async def porter_status_changed(self, previous: PorterStatus, current: PorterStatus, porter: Porter):
|
|
150
|
+
# await super().porter_status_changed(previous=previous, current=current, porter=porter)
|
|
151
|
+
if current is None or current == PorterStatus.ERROR:
|
|
152
152
|
# connection error or session finished
|
|
153
153
|
self.set_active(active=False)
|
|
154
|
-
self.warning(msg='connection lost, waiting for reconnecting: %s' %
|
|
154
|
+
self.warning(msg='connection lost, waiting for reconnecting: %s' % porter)
|
|
155
155
|
# TODO: clear session ID and handshake again
|
|
156
|
-
elif current ==
|
|
156
|
+
elif current == PorterStatus.READY:
|
|
157
157
|
# connected/reconnected
|
|
158
158
|
self.set_active(active=True)
|
|
159
159
|
|
|
160
160
|
# Override
|
|
161
|
-
async def
|
|
162
|
-
# await super().
|
|
161
|
+
async def porter_received(self, ship: Arrival, porter: Porter):
|
|
162
|
+
# await super().porter_received(ship=ship, porter=porter)
|
|
163
163
|
all_responses = []
|
|
164
164
|
messenger = self.messenger
|
|
165
165
|
# 1. get data packages from arrival ship's payload
|
|
@@ -174,14 +174,14 @@ class ClientSession(BaseSession):
|
|
|
174
174
|
continue
|
|
175
175
|
all_responses.append(res)
|
|
176
176
|
except Exception as error:
|
|
177
|
-
source =
|
|
177
|
+
source = porter.remote_address
|
|
178
178
|
self.error(msg='parse message failed (%s): %s, %s' % (source, error, pack))
|
|
179
179
|
traceback.print_exc()
|
|
180
180
|
# from dimsdk import TextContent
|
|
181
181
|
# return TextContent.new(text='parse message failed: %s' % error)
|
|
182
182
|
gate = self.gate
|
|
183
|
-
source =
|
|
184
|
-
destination =
|
|
183
|
+
source = porter.remote_address
|
|
184
|
+
destination = porter.local_address
|
|
185
185
|
# 3. send responses separately
|
|
186
186
|
for res in all_responses:
|
|
187
187
|
await gate.send_response(payload=res, ship=ship, remote=source, local=destination)
|
|
@@ -33,7 +33,7 @@ from dimsdk import ID
|
|
|
33
33
|
|
|
34
34
|
from startrek.skywalker import Runner
|
|
35
35
|
from startrek.fsm import Context, BaseTransition, BaseState, AutoMachine
|
|
36
|
-
from startrek import
|
|
36
|
+
from startrek import Porter, PorterStatus
|
|
37
37
|
|
|
38
38
|
# from .session import ClientSession
|
|
39
39
|
|
|
@@ -43,7 +43,7 @@ class StateMachine(AutoMachine, Context):
|
|
|
43
43
|
def __init__(self, session):
|
|
44
44
|
super().__init__()
|
|
45
45
|
self.__session = weakref.ref(session)
|
|
46
|
-
self.
|
|
46
|
+
self.__porter_ref = None
|
|
47
47
|
# init states
|
|
48
48
|
builder = self._create_state_builder()
|
|
49
49
|
self.add_state(state=builder.get_default_state())
|
|
@@ -58,17 +58,17 @@ class StateMachine(AutoMachine, Context):
|
|
|
58
58
|
return self.__session()
|
|
59
59
|
|
|
60
60
|
@property
|
|
61
|
-
def
|
|
62
|
-
ref = self.
|
|
61
|
+
def porter(self) -> Optional[Porter]:
|
|
62
|
+
ref = self.__porter_ref
|
|
63
63
|
if ref is not None:
|
|
64
64
|
return ref()
|
|
65
65
|
|
|
66
|
-
@
|
|
67
|
-
def
|
|
68
|
-
if
|
|
69
|
-
self.
|
|
66
|
+
@porter.setter
|
|
67
|
+
def porter(self, docker: Porter):
|
|
68
|
+
if docker is None:
|
|
69
|
+
self.__porter_ref = None
|
|
70
70
|
else:
|
|
71
|
-
self.
|
|
71
|
+
self.__porter_ref = weakref.ref(docker)
|
|
72
72
|
|
|
73
73
|
# noinspection PyMethodMayBeStatic
|
|
74
74
|
def _create_state_builder(self):
|
|
@@ -90,21 +90,21 @@ class StateMachine(AutoMachine, Context):
|
|
|
90
90
|
return session.identifier
|
|
91
91
|
|
|
92
92
|
@property
|
|
93
|
-
def status(self) ->
|
|
94
|
-
docker = self.
|
|
93
|
+
def status(self) -> PorterStatus:
|
|
94
|
+
docker = self.porter
|
|
95
95
|
if docker is not None:
|
|
96
96
|
return docker.status
|
|
97
97
|
else:
|
|
98
98
|
session = self.session
|
|
99
99
|
gate = session.gate
|
|
100
|
-
coro = gate.
|
|
100
|
+
coro = gate.fetch_porter(remote=session.remote_address, local=None)
|
|
101
101
|
task = Runner.async_task(coro=coro)
|
|
102
|
-
task.add_done_callback(self.
|
|
102
|
+
task.add_done_callback(self._fetch_porter_callback)
|
|
103
103
|
# waiting for callback
|
|
104
|
-
return
|
|
104
|
+
return PorterStatus.ERROR
|
|
105
105
|
|
|
106
|
-
def
|
|
107
|
-
self.
|
|
106
|
+
def _fetch_porter_callback(self, t: asyncio.Task):
|
|
107
|
+
self.porter = t.result()
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
class StateOrder(IntEnum):
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
# SOFTWARE.
|
|
24
24
|
# ==============================================================================
|
|
25
25
|
|
|
26
|
-
from startrek import
|
|
26
|
+
from startrek import PorterStatus
|
|
27
27
|
|
|
28
28
|
from .state import StateMachine, StateTransition
|
|
29
29
|
from .state import StateOrder
|
|
@@ -106,7 +106,7 @@ class DefaultConnectingTransition(StateTransition):
|
|
|
106
106
|
if ctx.session_id is None:
|
|
107
107
|
# current user not set yet
|
|
108
108
|
return False
|
|
109
|
-
return ctx.status in [
|
|
109
|
+
return ctx.status in [PorterStatus.PREPARING, PorterStatus.READY]
|
|
110
110
|
|
|
111
111
|
|
|
112
112
|
class ConnectingConnectedTransition(StateTransition):
|
|
@@ -122,7 +122,7 @@ class ConnectingConnectedTransition(StateTransition):
|
|
|
122
122
|
def evaluate(self, ctx: StateMachine, now: float) -> bool:
|
|
123
123
|
# assert ctx.session_key is None, 'session key must be empty before handshaking'
|
|
124
124
|
# assert ctx.session_id is not None, 'current user lost?'
|
|
125
|
-
return ctx.status ==
|
|
125
|
+
return ctx.status == PorterStatus.READY
|
|
126
126
|
|
|
127
127
|
|
|
128
128
|
class ConnectingErrorTransition(StateTransition):
|
|
@@ -141,7 +141,7 @@ class ConnectingErrorTransition(StateTransition):
|
|
|
141
141
|
if self.is_expired(state=ctx.current_state, now=now):
|
|
142
142
|
# connecting expired, do it again
|
|
143
143
|
return True
|
|
144
|
-
return ctx.status not in [
|
|
144
|
+
return ctx.status not in [PorterStatus.PREPARING, PorterStatus.READY]
|
|
145
145
|
|
|
146
146
|
|
|
147
147
|
class ConnectedHandshakingTransition(StateTransition):
|
|
@@ -159,7 +159,7 @@ class ConnectedHandshakingTransition(StateTransition):
|
|
|
159
159
|
# FIXME: current user lost?
|
|
160
160
|
# state will be changed to 'error'
|
|
161
161
|
return False
|
|
162
|
-
return ctx.status ==
|
|
162
|
+
return ctx.status == PorterStatus.READY
|
|
163
163
|
|
|
164
164
|
|
|
165
165
|
class ConnectedErrorTransition(StateTransition):
|
|
@@ -176,7 +176,7 @@ class ConnectedErrorTransition(StateTransition):
|
|
|
176
176
|
if ctx.session_id is None:
|
|
177
177
|
# FIXME: current user lost?
|
|
178
178
|
return True
|
|
179
|
-
return ctx.status !=
|
|
179
|
+
return ctx.status != PorterStatus.READY
|
|
180
180
|
|
|
181
181
|
|
|
182
182
|
class HandshakingRunningTransition(StateTransition):
|
|
@@ -194,7 +194,7 @@ class HandshakingRunningTransition(StateTransition):
|
|
|
194
194
|
# FIXME: current user lost?
|
|
195
195
|
# state will be changed to 'error'
|
|
196
196
|
return False
|
|
197
|
-
if ctx.status !=
|
|
197
|
+
if ctx.status != PorterStatus.READY:
|
|
198
198
|
# connection lost, state will be changed to 'error'
|
|
199
199
|
return False
|
|
200
200
|
# when current user changed, the session key will cleared, so
|
|
@@ -217,7 +217,7 @@ class HandshakingConnectedTransition(StateTransition):
|
|
|
217
217
|
# FIXME: current user lost?
|
|
218
218
|
# state will be changed to 'error'
|
|
219
219
|
return False
|
|
220
|
-
if ctx.status !=
|
|
220
|
+
if ctx.status != PorterStatus.READY:
|
|
221
221
|
# connection lost, state will be changed to 'error'
|
|
222
222
|
return False
|
|
223
223
|
if ctx.session_key is not None:
|
|
@@ -241,7 +241,7 @@ class HandshakingErrorTransition(StateTransition):
|
|
|
241
241
|
if ctx.session_id is None:
|
|
242
242
|
# FIXME: current user lost?
|
|
243
243
|
return True
|
|
244
|
-
return ctx.status !=
|
|
244
|
+
return ctx.status != PorterStatus.READY
|
|
245
245
|
|
|
246
246
|
|
|
247
247
|
class RunningDefaultTransition(StateTransition):
|
|
@@ -258,7 +258,7 @@ class RunningDefaultTransition(StateTransition):
|
|
|
258
258
|
|
|
259
259
|
# Override
|
|
260
260
|
def evaluate(self, ctx: StateMachine, now: float) -> bool:
|
|
261
|
-
if ctx.status !=
|
|
261
|
+
if ctx.status != PorterStatus.READY:
|
|
262
262
|
# connection lost, state will be changed to 'error'
|
|
263
263
|
return False
|
|
264
264
|
if ctx.session_id is None:
|
|
@@ -277,7 +277,7 @@ class RunningErrorTransition(StateTransition):
|
|
|
277
277
|
|
|
278
278
|
# Override
|
|
279
279
|
def evaluate(self, ctx: StateMachine, now: float) -> bool:
|
|
280
|
-
return ctx.status !=
|
|
280
|
+
return ctx.status != PorterStatus.READY
|
|
281
281
|
|
|
282
282
|
|
|
283
283
|
class ErrorDefaultTransition(StateTransition):
|
|
@@ -289,4 +289,4 @@ class ErrorDefaultTransition(StateTransition):
|
|
|
289
289
|
|
|
290
290
|
# Override
|
|
291
291
|
def evaluate(self, ctx: StateMachine, now: float) -> bool:
|
|
292
|
-
return ctx.status !=
|
|
292
|
+
return ctx.status != PorterStatus.ERROR
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
|
|
30
30
|
+--------------+
|
|
31
31
|
| Facebook |
|
|
32
|
-
+--------------+
|
|
32
|
+
+--------------+ PorterDelegate ConnectionDelegate
|
|
33
33
|
: AccountDB +--------------+ +----------+
|
|
34
34
|
: | GateKeeper | . . . >| Gate |
|
|
35
35
|
+--------------+ +--------------+ +----------+
|
|
36
36
|
| Messenger | . . . >| Session | Hub (Connection)
|
|
37
|
-
+--------------+ +--------------+
|
|
37
|
+
+--------------+ +--------------+ Porter
|
|
38
38
|
MessageDB SessionDB
|
|
39
39
|
Filter
|
|
40
40
|
Dispatcher
|
|
@@ -46,24 +46,24 @@ from startrek import BaseChannel, ChannelReader, ChannelWriter
|
|
|
46
46
|
from startrek import BaseHub, BaseConnection, ActiveConnection
|
|
47
47
|
|
|
48
48
|
from startrek import Ship, Arrival, Departure, DeparturePriority
|
|
49
|
-
from startrek import
|
|
49
|
+
from startrek import Porter, PorterStatus, PorterDelegate, Gate
|
|
50
50
|
from startrek import ArrivalShip, ArrivalHall, DepartureShip, DepartureHall
|
|
51
|
-
from startrek import Dock, LockedDock,
|
|
51
|
+
from startrek import Dock, LockedDock, StarPorter, StarGate
|
|
52
52
|
|
|
53
|
-
from tcp import PlainArrival, PlainDeparture,
|
|
53
|
+
from tcp import PlainArrival, PlainDeparture, PlainPorter
|
|
54
54
|
from tcp import StreamChannel, StreamHub
|
|
55
55
|
from tcp import ServerHub as TCPServerHub, ClientHub as TCPClientHub
|
|
56
56
|
|
|
57
|
-
from udp import PackageArrival, PackageDeparture,
|
|
57
|
+
from udp import PackageArrival, PackageDeparture, PackagePorter
|
|
58
58
|
from udp import PacketChannel, PacketHub
|
|
59
59
|
from udp import ServerHub as UDPServerHub, ClientHub as UDPClientHub
|
|
60
60
|
|
|
61
61
|
from .protocol import WebSocket, NetMsg, NetMsgHead, NetMsgSeq
|
|
62
62
|
|
|
63
|
-
from .ws import WSArrival, WSDeparture,
|
|
64
|
-
from .mars import MarsStreamArrival, MarsStreamDeparture,
|
|
65
|
-
from .mtp import MTPStreamArrival, MTPStreamDeparture,
|
|
66
|
-
from .flexible import
|
|
63
|
+
from .ws import WSArrival, WSDeparture, WSPorter
|
|
64
|
+
from .mars import MarsStreamArrival, MarsStreamDeparture, MarsStreamPorter
|
|
65
|
+
from .mtp import MTPStreamArrival, MTPStreamDeparture, MTPStreamPorter
|
|
66
|
+
from .flexible import FlexiblePorter
|
|
67
67
|
from .gate import CommonGate, TCPServerGate, TCPClientGate, UDPServerGate, UDPClientGate
|
|
68
68
|
# from .gatekeeper import GateKeeper
|
|
69
69
|
from .queue import MessageWrapper, MessageQueue
|
|
@@ -81,20 +81,20 @@ __all__ = [
|
|
|
81
81
|
'BaseHub', 'BaseConnection', 'ActiveConnection',
|
|
82
82
|
|
|
83
83
|
'Ship', 'Arrival', 'Departure', 'DeparturePriority',
|
|
84
|
-
'
|
|
84
|
+
'Porter', 'PorterStatus', 'PorterDelegate', 'Gate',
|
|
85
85
|
'ArrivalShip', 'ArrivalHall', 'DepartureShip', 'DepartureHall',
|
|
86
|
-
'Dock', 'LockedDock', '
|
|
86
|
+
'Dock', 'LockedDock', 'StarPorter', 'StarGate',
|
|
87
87
|
|
|
88
88
|
#
|
|
89
89
|
# TCP
|
|
90
90
|
#
|
|
91
|
-
'PlainArrival', 'PlainDeparture', '
|
|
91
|
+
'PlainArrival', 'PlainDeparture', 'PlainPorter',
|
|
92
92
|
'StreamChannel', 'StreamHub', 'TCPServerHub', 'TCPClientHub',
|
|
93
93
|
|
|
94
94
|
#
|
|
95
95
|
# UDP
|
|
96
96
|
#
|
|
97
|
-
'PackageArrival', 'PackageDeparture', '
|
|
97
|
+
'PackageArrival', 'PackageDeparture', 'PackagePorter',
|
|
98
98
|
'PacketChannel', 'PacketHub', 'UDPServerHub', 'UDPClientHub',
|
|
99
99
|
|
|
100
100
|
#
|
|
@@ -105,10 +105,10 @@ __all__ = [
|
|
|
105
105
|
#
|
|
106
106
|
# Network
|
|
107
107
|
#
|
|
108
|
-
'WSArrival', 'WSDeparture', '
|
|
109
|
-
'MarsStreamArrival', 'MarsStreamDeparture', '
|
|
110
|
-
'MTPStreamArrival', 'MTPStreamDeparture', '
|
|
111
|
-
'
|
|
108
|
+
'WSArrival', 'WSDeparture', 'WSPorter',
|
|
109
|
+
'MarsStreamArrival', 'MarsStreamDeparture', 'MarsStreamPorter',
|
|
110
|
+
'MTPStreamArrival', 'MTPStreamDeparture', 'MTPStreamPorter',
|
|
111
|
+
'FlexiblePorter',
|
|
112
112
|
'CommonGate', 'TCPServerGate', 'TCPClientGate', 'UDPServerGate', 'UDPClientGate',
|
|
113
113
|
# 'GateKeeper',
|
|
114
114
|
'MessageWrapper', 'MessageQueue',
|
|
@@ -34,47 +34,26 @@ from startrek.types import SocketAddress
|
|
|
34
34
|
from startrek.skywalker import Runner
|
|
35
35
|
from startrek import Connection
|
|
36
36
|
from startrek import Arrival, Departure
|
|
37
|
-
from startrek import
|
|
37
|
+
from startrek import StarPorter
|
|
38
38
|
|
|
39
39
|
from ..utils import Logging
|
|
40
40
|
from .protocol import DeparturePacker
|
|
41
41
|
|
|
42
|
-
from .ws import
|
|
43
|
-
from .mtp import
|
|
44
|
-
from .mars import
|
|
42
|
+
from .ws import WSPorter
|
|
43
|
+
from .mtp import MTPStreamPorter, TransactionID, MTPHelper
|
|
44
|
+
from .mars import MarsStreamPorter, MarsHelper
|
|
45
45
|
|
|
46
46
|
|
|
47
|
-
class
|
|
47
|
+
class FlexiblePorter(StarPorter, DeparturePacker, Logging):
|
|
48
48
|
|
|
49
49
|
def __init__(self, remote: SocketAddress, local: Optional[SocketAddress]):
|
|
50
50
|
super().__init__(remote=remote, local=local)
|
|
51
|
-
self.
|
|
52
|
-
|
|
53
|
-
def _get_docker(self, data: bytes) -> Optional[StarDocker]:
|
|
54
|
-
docker = self.__docker
|
|
55
|
-
if docker is not None or len(data) == 0:
|
|
56
|
-
return docker
|
|
57
|
-
# check data for packer
|
|
58
|
-
if WSDocker.check(data=data):
|
|
59
|
-
docker = WSDocker(remote=self.remote_address, local=self.local_address)
|
|
60
|
-
elif MTPStreamDocker.check(data=data):
|
|
61
|
-
docker = MTPStreamDocker(remote=self.remote_address, local=self.local_address)
|
|
62
|
-
elif MarsStreamDocker.check(data=data):
|
|
63
|
-
docker = MarsStreamDocker(remote=self.remote_address, local=self.local_address)
|
|
64
|
-
else:
|
|
65
|
-
self.error(msg='unsupported data format: %s' % data)
|
|
66
|
-
return None
|
|
67
|
-
# OK
|
|
68
|
-
docker.delegate = self.delegate
|
|
69
|
-
coro = docker.set_connection(conn=self.connection)
|
|
70
|
-
Runner.async_task(coro=coro)
|
|
71
|
-
self.__docker = docker
|
|
72
|
-
return docker
|
|
51
|
+
self.__porter: Optional[StarPorter] = None
|
|
73
52
|
|
|
74
53
|
# Override
|
|
75
54
|
async def set_connection(self, conn: Optional[Connection]):
|
|
76
55
|
await super().set_connection(conn=conn)
|
|
77
|
-
docker = self.
|
|
56
|
+
docker = self.__porter
|
|
78
57
|
if docker is None:
|
|
79
58
|
self.error(msg='docker not ready, failed to set connection: %s' % conn)
|
|
80
59
|
else:
|
|
@@ -82,7 +61,7 @@ class FlexibleDocker(StarDocker, DeparturePacker, Logging):
|
|
|
82
61
|
|
|
83
62
|
# Override
|
|
84
63
|
async def send_ship(self, ship: Departure) -> bool:
|
|
85
|
-
docker = self.
|
|
64
|
+
docker = self.__porter
|
|
86
65
|
if docker is None:
|
|
87
66
|
self.error(msg='docker not ready, failed to send ship: %s' % ship)
|
|
88
67
|
return False
|
|
@@ -91,11 +70,25 @@ class FlexibleDocker(StarDocker, DeparturePacker, Logging):
|
|
|
91
70
|
|
|
92
71
|
# Override
|
|
93
72
|
async def process_received(self, data: bytes):
|
|
94
|
-
docker = self.
|
|
73
|
+
docker = self.__porter
|
|
95
74
|
if docker is None:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
75
|
+
# check data for packer
|
|
76
|
+
if WSPorter.check(data=data):
|
|
77
|
+
docker = WSPorter(remote=self.remote_address, local=self.local_address)
|
|
78
|
+
elif MTPStreamPorter.check(data=data):
|
|
79
|
+
docker = MTPStreamPorter(remote=self.remote_address, local=self.local_address)
|
|
80
|
+
elif MarsStreamPorter.check(data=data):
|
|
81
|
+
docker = MarsStreamPorter(remote=self.remote_address, local=self.local_address)
|
|
82
|
+
else:
|
|
83
|
+
self.error(msg='unsupported data format: %s' % data)
|
|
84
|
+
return None
|
|
85
|
+
# initialize
|
|
86
|
+
docker.delegate = self.delegate
|
|
87
|
+
coro = docker.set_connection(conn=self.connection)
|
|
88
|
+
Runner.async_task(coro=coro)
|
|
89
|
+
self.__porter = docker
|
|
90
|
+
# OK
|
|
91
|
+
return await docker.process_received(data=data)
|
|
99
92
|
|
|
100
93
|
# Override
|
|
101
94
|
def _get_arrivals(self, data: bytes) -> List[Arrival]:
|
|
@@ -120,7 +113,7 @@ class FlexibleDocker(StarDocker, DeparturePacker, Logging):
|
|
|
120
113
|
# Override
|
|
121
114
|
def purge(self, now: float = 0) -> int:
|
|
122
115
|
cnt = super().purge(now=now)
|
|
123
|
-
docker = self.
|
|
116
|
+
docker = self.__porter
|
|
124
117
|
if docker is None:
|
|
125
118
|
self.debug(msg='docker not ready, failed to purge')
|
|
126
119
|
else:
|
|
@@ -129,15 +122,17 @@ class FlexibleDocker(StarDocker, DeparturePacker, Logging):
|
|
|
129
122
|
|
|
130
123
|
# Override
|
|
131
124
|
async def close(self):
|
|
132
|
-
await
|
|
133
|
-
docker = self.
|
|
134
|
-
if docker is
|
|
135
|
-
self.
|
|
125
|
+
await super().set_connection(conn=None)
|
|
126
|
+
docker = self.__porter
|
|
127
|
+
if docker is None:
|
|
128
|
+
self.warning(msg='docker not ready, failed to close')
|
|
129
|
+
else:
|
|
130
|
+
self.__porter = None
|
|
136
131
|
await docker.close()
|
|
137
132
|
|
|
138
133
|
# Override
|
|
139
134
|
async def process(self) -> bool:
|
|
140
|
-
docker = self.
|
|
135
|
+
docker = self.__porter
|
|
141
136
|
if docker is None:
|
|
142
137
|
self.debug(msg='docker not ready, failed to process')
|
|
143
138
|
return False
|
|
@@ -146,21 +141,21 @@ class FlexibleDocker(StarDocker, DeparturePacker, Logging):
|
|
|
146
141
|
|
|
147
142
|
# Override
|
|
148
143
|
async def send_data(self, payload: Union[bytes, bytearray]) -> bool:
|
|
149
|
-
docker = self.
|
|
144
|
+
docker = self.__porter
|
|
150
145
|
if docker is None:
|
|
151
146
|
self.error(msg='docker not ready, failed to send payload: %s' % payload)
|
|
152
147
|
return False
|
|
153
|
-
elif isinstance(docker,
|
|
148
|
+
elif isinstance(docker, WSPorter):
|
|
154
149
|
ship = docker.pack(payload=payload)
|
|
155
150
|
return await docker.send_ship(ship=ship)
|
|
156
|
-
elif isinstance(docker,
|
|
151
|
+
elif isinstance(docker, MTPStreamPorter):
|
|
157
152
|
# sn = TransactionID.from_data(data=ship.sn)
|
|
158
153
|
sn = TransactionID.generate()
|
|
159
154
|
pack = MTPHelper.create_message(body=payload, sn=sn)
|
|
160
155
|
return await docker.send_package(pack=pack)
|
|
161
|
-
elif isinstance(docker,
|
|
156
|
+
elif isinstance(docker, MarsStreamPorter):
|
|
162
157
|
mars = MarsHelper.create_push(payload=payload)
|
|
163
|
-
ship =
|
|
158
|
+
ship = MarsStreamPorter.create_departure(mars=mars)
|
|
164
159
|
return await docker.send_ship(ship=ship)
|
|
165
160
|
else:
|
|
166
161
|
# error
|
|
@@ -168,7 +163,7 @@ class FlexibleDocker(StarDocker, DeparturePacker, Logging):
|
|
|
168
163
|
|
|
169
164
|
# Override
|
|
170
165
|
async def heartbeat(self):
|
|
171
|
-
docker = self.
|
|
166
|
+
docker = self.__porter
|
|
172
167
|
if docker is None:
|
|
173
168
|
self.warning(msg='docker not ready, failed to heart bet')
|
|
174
169
|
else:
|
|
@@ -176,7 +171,7 @@ class FlexibleDocker(StarDocker, DeparturePacker, Logging):
|
|
|
176
171
|
|
|
177
172
|
# Override
|
|
178
173
|
def pack(self, payload: bytes, priority: int = 0) -> Optional[Departure]:
|
|
179
|
-
docker = self.
|
|
174
|
+
docker = self.__porter
|
|
180
175
|
if docker is None:
|
|
181
176
|
self.error(msg='docker not ready, failed to pack: %s' % payload)
|
|
182
177
|
return None
|