dimples 1.0.3__tar.gz → 1.2.0__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.0.3 → dimples-1.2.0}/PKG-INFO +1 -1
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/network/state.py +1 -1
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/terminal.py +3 -4
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/dbi/session.py +4 -2
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/flexible.py +1 -1
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/queue.py +1 -1
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/session.py +3 -1
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/ws.py +1 -1
- {dimples-1.0.3 → dimples-1.2.0}/dimples/edge/octopus.py +11 -17
- {dimples-1.0.3 → dimples-1.2.0}/dimples/edge/start.py +1 -2
- {dimples-1.0.3 → dimples-1.2.0}/dimples/group/helper.py +2 -1
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/dispatcher.py +12 -3
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/push.py +12 -3
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/session.py +4 -7
- {dimples-1.0.3 → dimples-1.2.0}/dimples/station/handler.py +5 -2
- {dimples-1.0.3 → dimples-1.2.0}/dimples/utils/__init__.py +4 -5
- {dimples-1.0.3 → dimples-1.2.0}/dimples/utils/cache.py +28 -33
- {dimples-1.0.3 → dimples-1.2.0}/dimples.egg-info/PKG-INFO +1 -1
- {dimples-1.0.3 → dimples-1.2.0}/dimples.egg-info/requires.txt +3 -3
- {dimples-1.0.3 → dimples-1.2.0}/setup.py +4 -4
- {dimples-1.0.3 → dimples-1.2.0}/README.md +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/archivist.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/checkpoint.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/commands.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/creator.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/group.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/grp_expel.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/grp_invite.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/grp_join.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/grp_query.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/grp_quit.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/grp_reset.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/grp_resign.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/cpu/handshake.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/facebook.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/messenger.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/network/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/network/session.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/network/transition.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/packer.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/client/processor.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/anonymous.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/ans.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/archivist.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/compat/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/compat/btc.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/compat/compatible.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/compat/entity.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/compat/meta.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/compat/network.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/dbi/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/dbi/account.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/dbi/message.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/facebook.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/messenger.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/packer.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/processer.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/protocol/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/protocol/ans.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/protocol/block.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/protocol/handshake.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/protocol/login.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/protocol/mute.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/protocol/report.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/register.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/common/session.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/gate.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/gatekeeper.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/mars.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/mtp.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/protocol/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/protocol/mars.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/protocol/ws.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/conn/seeker.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/account.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/base.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/document.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/group.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/group_history.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/group_keys.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/login.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/meta.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/private.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/station.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/dos/user.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/message.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/session.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_cipherkey.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_document.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_group.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_group_history.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_group_keys.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_login.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_message.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_meta.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_private.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_station.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/database/t_user.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/edge/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/edge/shared.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/group/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/group/admin.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/group/builder.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/group/delegate.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/group/emitter.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/group/manager.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/group/packer.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/register/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/register/base.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/register/ext.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/register/run.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/register/shared.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/archivist.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/cpu/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/cpu/ans.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/cpu/document.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/cpu/handshake.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/cpu/login.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/cpu/report.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/messenger.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/packer.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/processor.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/session_center.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/server/trace.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/station/__init__.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/station/shared.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/station/start.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/utils/config.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/utils/dos.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples/utils/log.py +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples.egg-info/SOURCES.txt +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples.egg-info/dependency_links.txt +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples.egg-info/entry_points.txt +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/dimples.egg-info/top_level.txt +0 -0
- {dimples-1.0.3 → dimples-1.2.0}/setup.cfg +0 -0
|
@@ -31,7 +31,7 @@ from typing import Optional, Union
|
|
|
31
31
|
|
|
32
32
|
from dimsdk import ID
|
|
33
33
|
|
|
34
|
-
from startrek.
|
|
34
|
+
from startrek.skywalker import Runner
|
|
35
35
|
from startrek.fsm import Context, BaseTransition, BaseState, AutoMachine
|
|
36
36
|
from startrek import Docker, DockerStatus
|
|
37
37
|
|
|
@@ -34,7 +34,8 @@ import time
|
|
|
34
34
|
|
|
35
35
|
from dimples import EntityType
|
|
36
36
|
|
|
37
|
-
from ..utils import
|
|
37
|
+
from ..utils import Logging
|
|
38
|
+
from ..utils import Runner
|
|
38
39
|
from ..utils import StateDelegate
|
|
39
40
|
|
|
40
41
|
from .network import ClientSession
|
|
@@ -51,7 +52,7 @@ class DeviceMixin:
|
|
|
51
52
|
return 'DIMP/0.4 (Client; Linux; en-US) DIMCoreKit/0.9 (Terminal) DIM-by-GSP/1.0'
|
|
52
53
|
|
|
53
54
|
|
|
54
|
-
class Terminal(
|
|
55
|
+
class Terminal(Runner, DeviceMixin, Logging, StateDelegate):
|
|
55
56
|
|
|
56
57
|
def __init__(self, messenger: ClientMessenger):
|
|
57
58
|
super().__init__(interval=60)
|
|
@@ -74,7 +75,6 @@ class Terminal(DaemonRunner, DeviceMixin, Logging, StateDelegate):
|
|
|
74
75
|
|
|
75
76
|
# Override
|
|
76
77
|
async def setup(self):
|
|
77
|
-
await super().setup()
|
|
78
78
|
session = self.session
|
|
79
79
|
session.fsm.delegate = self
|
|
80
80
|
await session.start()
|
|
@@ -82,7 +82,6 @@ class Terminal(DaemonRunner, DeviceMixin, Logging, StateDelegate):
|
|
|
82
82
|
# Override
|
|
83
83
|
async def finish(self):
|
|
84
84
|
await self.session.stop()
|
|
85
|
-
await super().finish()
|
|
86
85
|
|
|
87
86
|
# Override
|
|
88
87
|
async def process(self) -> bool:
|
|
@@ -213,11 +213,13 @@ class StationDBI(ABC):
|
|
|
213
213
|
raise NotImplemented
|
|
214
214
|
|
|
215
215
|
@abstractmethod
|
|
216
|
-
async def add_station(self, identifier: Optional[ID], host: str, port: int, provider: ID,
|
|
216
|
+
async def add_station(self, identifier: Optional[ID], host: str, port: int, provider: ID,
|
|
217
|
+
chosen: int = 0) -> bool:
|
|
217
218
|
raise NotImplemented
|
|
218
219
|
|
|
219
220
|
@abstractmethod
|
|
220
|
-
async def update_station(self, identifier: Optional[ID], host: str, port: int, provider: ID,
|
|
221
|
+
async def update_station(self, identifier: Optional[ID], host: str, port: int, provider: ID,
|
|
222
|
+
chosen: int = None) -> bool:
|
|
221
223
|
raise NotImplemented
|
|
222
224
|
|
|
223
225
|
@abstractmethod
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
from typing import Optional, Union, List
|
|
32
32
|
|
|
33
33
|
from startrek.types import SocketAddress
|
|
34
|
-
from startrek.
|
|
34
|
+
from startrek.skywalker import Runner
|
|
35
35
|
from startrek import Connection
|
|
36
36
|
from startrek import Arrival, Departure
|
|
37
37
|
from startrek import StarDocker
|
|
@@ -112,10 +112,10 @@ class MessageQueue:
|
|
|
112
112
|
self.__insert(priority=priority)
|
|
113
113
|
else:
|
|
114
114
|
# 1.3. check duplicated
|
|
115
|
-
signature = msg.get('signature')
|
|
116
115
|
for wrapper in fleet:
|
|
117
116
|
item = wrapper.msg
|
|
118
117
|
if self.__is_duplicated(item, msg):
|
|
118
|
+
signature = msg.get('signature')
|
|
119
119
|
print('[QUEUE] duplicated message: %s' % signature)
|
|
120
120
|
return False
|
|
121
121
|
# 2. append with wrapper
|
|
@@ -87,7 +87,9 @@ class BaseSession(GateKeeper, Session, ABC):
|
|
|
87
87
|
# Override
|
|
88
88
|
async def queue_message_package(self, msg: ReliableMessage, data: bytes, priority: int = 0) -> bool:
|
|
89
89
|
ship = await self._docker_pack(payload=data, priority=priority)
|
|
90
|
-
if ship is
|
|
90
|
+
if ship is None:
|
|
91
|
+
self.error(msg='failed to pack msg: %s -> %s, %s' % (msg.sender, msg.receiver, msg.group))
|
|
92
|
+
else:
|
|
91
93
|
return self._queue_append(msg=msg, ship=ship)
|
|
92
94
|
|
|
93
95
|
#
|
|
@@ -33,7 +33,7 @@ import threading
|
|
|
33
33
|
from typing import Optional, List, Tuple
|
|
34
34
|
|
|
35
35
|
from startrek.types import SocketAddress
|
|
36
|
-
from startrek.
|
|
36
|
+
from startrek.skywalker import Runner
|
|
37
37
|
from startrek import Arrival, Departure
|
|
38
38
|
from startrek import ArrivalShip, DepartureShip, DeparturePriority
|
|
39
39
|
from startrek import BaseConnection, BaseChannel
|
|
@@ -41,7 +41,7 @@ from dimsdk import ReliableMessage
|
|
|
41
41
|
from dimsdk import Station
|
|
42
42
|
|
|
43
43
|
from ..utils import Log, Logging
|
|
44
|
-
from ..utils import Runner
|
|
44
|
+
from ..utils import Runner
|
|
45
45
|
from ..utils import get_msg_sig
|
|
46
46
|
from ..common import ProviderInfo
|
|
47
47
|
from ..common import MessageDBI, SessionDBI
|
|
@@ -58,7 +58,7 @@ from .shared import GlobalVariable
|
|
|
58
58
|
from .shared import create_session
|
|
59
59
|
|
|
60
60
|
|
|
61
|
-
class Octopus(
|
|
61
|
+
class Octopus(Runner, Logging):
|
|
62
62
|
|
|
63
63
|
def __init__(self, shared: GlobalVariable, local_host: str = '127.0.0.1', local_port: int = 9394):
|
|
64
64
|
super().__init__(interval=60)
|
|
@@ -142,6 +142,14 @@ class Octopus(DaemonRunner, Logging):
|
|
|
142
142
|
# 3. stop runner
|
|
143
143
|
await super().stop()
|
|
144
144
|
|
|
145
|
+
# Override
|
|
146
|
+
async def setup(self):
|
|
147
|
+
pass
|
|
148
|
+
|
|
149
|
+
# Override
|
|
150
|
+
async def finish(self):
|
|
151
|
+
pass
|
|
152
|
+
|
|
145
153
|
# Override
|
|
146
154
|
async def process(self) -> bool:
|
|
147
155
|
# get all neighbor stations
|
|
@@ -380,24 +388,10 @@ def create_messenger(facebook: ClientFacebook, database: MessageDBI,
|
|
|
380
388
|
def create_terminal(messenger: OctopusMessenger) -> Terminal:
|
|
381
389
|
terminal = Terminal(messenger=messenger)
|
|
382
390
|
messenger.terminal = terminal
|
|
383
|
-
|
|
384
|
-
thr.start()
|
|
391
|
+
Runner.thread_run(runner=terminal)
|
|
385
392
|
return terminal
|
|
386
393
|
|
|
387
394
|
|
|
388
|
-
def __start_terminal(terminal: Terminal):
|
|
389
|
-
Runner.sync_run(main=__run_terminal(terminal=terminal))
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
async def __run_terminal(terminal: Terminal):
|
|
393
|
-
await terminal.start()
|
|
394
|
-
while True:
|
|
395
|
-
await Runner.sleep(seconds=2.0)
|
|
396
|
-
if not terminal.running:
|
|
397
|
-
break
|
|
398
|
-
Log.warning(msg='terminal stopped: %s' % terminal)
|
|
399
|
-
|
|
400
|
-
|
|
401
395
|
async def update_station(station: Station, database: SessionDBI):
|
|
402
396
|
Log.info(msg='update station: %s' % station)
|
|
403
397
|
# SP ID
|
|
@@ -75,8 +75,7 @@ async def main():
|
|
|
75
75
|
assert host is not None and port > 0, 'station config error: %s' % config
|
|
76
76
|
octopus = Octopus(shared=shared, local_host=host, local_port=port)
|
|
77
77
|
await octopus.start()
|
|
78
|
-
|
|
79
|
-
await Runner.sleep(seconds=1.0)
|
|
78
|
+
await octopus.run()
|
|
80
79
|
Log.warning(msg='bot stopped: %s' % octopus)
|
|
81
80
|
|
|
82
81
|
|
|
@@ -61,7 +61,7 @@ class GroupCommandHelper(Logging):
|
|
|
61
61
|
#
|
|
62
62
|
|
|
63
63
|
async def save_group_history(self, group: ID, content: GroupCommand, message: ReliableMessage) -> bool:
|
|
64
|
-
if self.is_expired(content=content):
|
|
64
|
+
if await self.is_expired(content=content):
|
|
65
65
|
self.warning(msg='drop expired command: %s, %s => %s' % (content.cmd, message.sender, group))
|
|
66
66
|
return False
|
|
67
67
|
# check command time
|
|
@@ -114,6 +114,7 @@ class GroupCommandHelper(Logging):
|
|
|
114
114
|
# membership command, check with reset command
|
|
115
115
|
cmd, _ = await self.get_reset_command_message(group=group)
|
|
116
116
|
if cmd is None: # or msg is None:
|
|
117
|
+
self.error(msg='"reset" command not found: %s' % content)
|
|
117
118
|
return False
|
|
118
119
|
return is_before(old_time=cmd.time, new_time=content.time)
|
|
119
120
|
|
|
@@ -39,7 +39,7 @@ from dimsdk import Station
|
|
|
39
39
|
from dimsdk import Content, ReceiptCommand
|
|
40
40
|
from dimsdk import ReliableMessage
|
|
41
41
|
|
|
42
|
-
from ..utils import Singleton, Log, Logging, Runner
|
|
42
|
+
from ..utils import Singleton, Log, Logging, Runner
|
|
43
43
|
from ..common import CommonFacebook
|
|
44
44
|
from ..common import MessageDBI, SessionDBI
|
|
45
45
|
from ..common import ReliableMessageDBI
|
|
@@ -133,7 +133,8 @@ class Dispatcher(MessageDeliver, Logging):
|
|
|
133
133
|
assert db is not None, 'dispatcher not initialized'
|
|
134
134
|
runner = Roamer(database=db)
|
|
135
135
|
self.__roamer = runner
|
|
136
|
-
Runner.async_run(coroutine=runner.start())
|
|
136
|
+
# Runner.async_run(coroutine=runner.start())
|
|
137
|
+
Runner.thread_run(runner=runner)
|
|
137
138
|
return runner
|
|
138
139
|
|
|
139
140
|
def add_roaming(self, user: ID, station: ID) -> bool:
|
|
@@ -274,7 +275,7 @@ class RoamingInfo:
|
|
|
274
275
|
self.station = station
|
|
275
276
|
|
|
276
277
|
|
|
277
|
-
class Roamer(
|
|
278
|
+
class Roamer(Runner, Logging):
|
|
278
279
|
""" Delegate for redirect cached messages to roamed station """
|
|
279
280
|
|
|
280
281
|
def __init__(self, database: MessageDBI):
|
|
@@ -309,6 +310,14 @@ class Roamer(DaemonRunner, Logging):
|
|
|
309
310
|
self.__append(info=info)
|
|
310
311
|
return True
|
|
311
312
|
|
|
313
|
+
# Override
|
|
314
|
+
async def setup(self):
|
|
315
|
+
pass
|
|
316
|
+
|
|
317
|
+
# Override
|
|
318
|
+
async def finish(self):
|
|
319
|
+
pass
|
|
320
|
+
|
|
312
321
|
# Override
|
|
313
322
|
async def process(self) -> bool:
|
|
314
323
|
info = self.__next()
|
|
@@ -38,7 +38,7 @@ from typing import Optional, List, Dict
|
|
|
38
38
|
|
|
39
39
|
from dimsdk import ID, ReliableMessage
|
|
40
40
|
|
|
41
|
-
from ..utils import Runner
|
|
41
|
+
from ..utils import Runner
|
|
42
42
|
from ..utils import Singleton, Logging
|
|
43
43
|
|
|
44
44
|
|
|
@@ -117,14 +117,15 @@ class PushService(ABC):
|
|
|
117
117
|
|
|
118
118
|
|
|
119
119
|
@Singleton
|
|
120
|
-
class PushCenter(
|
|
120
|
+
class PushCenter(Runner, Logging):
|
|
121
121
|
|
|
122
122
|
def __init__(self):
|
|
123
123
|
super().__init__(interval=Runner.INTERVAL_SLOW)
|
|
124
124
|
self.__queue = MessageQueue()
|
|
125
125
|
self.__keeper = BadgeKeeper()
|
|
126
126
|
self.__service: Optional[PushService] = None
|
|
127
|
-
Runner.async_run(coroutine=self.start())
|
|
127
|
+
# Runner.async_run(coroutine=self.start())
|
|
128
|
+
Runner.thread_run(runner=self)
|
|
128
129
|
|
|
129
130
|
@property
|
|
130
131
|
def service(self) -> Optional[PushService]:
|
|
@@ -148,6 +149,14 @@ class PushCenter(DaemonRunner, Logging):
|
|
|
148
149
|
queue = self.__queue
|
|
149
150
|
queue.add_message(msg=msg)
|
|
150
151
|
|
|
152
|
+
# Override
|
|
153
|
+
async def setup(self):
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
# Override
|
|
157
|
+
async def finish(self):
|
|
158
|
+
pass
|
|
159
|
+
|
|
151
160
|
# Override
|
|
152
161
|
async def process(self) -> bool:
|
|
153
162
|
# 1. get waiting messages
|
|
@@ -95,7 +95,8 @@ class ServerSession(BaseSession):
|
|
|
95
95
|
if super().set_identifier(identifier=identifier):
|
|
96
96
|
session_change_id(session=self, new_id=identifier, old_id=old)
|
|
97
97
|
# load cached message asynchronously
|
|
98
|
-
|
|
98
|
+
crt = load_cached_messages(session=self)
|
|
99
|
+
Runner.async_run(coroutine=crt)
|
|
99
100
|
return True
|
|
100
101
|
|
|
101
102
|
# Override
|
|
@@ -103,14 +104,10 @@ class ServerSession(BaseSession):
|
|
|
103
104
|
if super().set_active(active=active, when=when):
|
|
104
105
|
session_change_active(session=self, active=active)
|
|
105
106
|
# load cached message asynchronously
|
|
106
|
-
|
|
107
|
+
crt = load_cached_messages(session=self)
|
|
108
|
+
Runner.async_run(coroutine=crt)
|
|
107
109
|
return True
|
|
108
110
|
|
|
109
|
-
# Override
|
|
110
|
-
async def start(self):
|
|
111
|
-
await super().start()
|
|
112
|
-
await self.run()
|
|
113
|
-
|
|
114
111
|
#
|
|
115
112
|
# Docker Delegate
|
|
116
113
|
#
|
|
@@ -64,14 +64,15 @@ class RequestHandler(StreamRequestHandler, Logging):
|
|
|
64
64
|
super().handle()
|
|
65
65
|
try:
|
|
66
66
|
self.info(msg='session started: %s' % str(self.client_address))
|
|
67
|
-
|
|
67
|
+
crt = _start_session(client_address=self.client_address, request=self.request)
|
|
68
|
+
Runner.sync_run(main=crt)
|
|
68
69
|
self.info(msg='session finished: %s' % str(self.client_address))
|
|
69
70
|
except Exception as error:
|
|
70
71
|
self.error(msg='request handler error: %s' % error)
|
|
71
72
|
traceback.print_exc()
|
|
72
73
|
|
|
73
74
|
|
|
74
|
-
async def
|
|
75
|
+
async def _start_session(client_address, request):
|
|
75
76
|
shared = GlobalVariable()
|
|
76
77
|
session = ServerSession(remote=client_address, sock=request, database=shared.sdb)
|
|
77
78
|
messenger = create_messenger(facebook=shared.facebook, database=shared.mdb, session=session)
|
|
@@ -81,6 +82,8 @@ async def start_session(client_address, request):
|
|
|
81
82
|
try:
|
|
82
83
|
# handle
|
|
83
84
|
await session.start()
|
|
85
|
+
await session.run()
|
|
86
|
+
# await session.stop()
|
|
84
87
|
finally:
|
|
85
88
|
# finish
|
|
86
89
|
center.remove_session(session=session)
|
|
@@ -50,11 +50,10 @@ from dimsdk import DocumentHelper
|
|
|
50
50
|
|
|
51
51
|
from dimplugins.crypto.aes import random_bytes
|
|
52
52
|
|
|
53
|
-
from startrek.
|
|
54
|
-
from startrek.
|
|
53
|
+
from startrek.skywalker import Singleton
|
|
54
|
+
from startrek.skywalker import Runnable, Runner, Daemon
|
|
55
55
|
from startrek.fsm import Delegate as StateDelegate
|
|
56
|
-
from startrek.net.
|
|
57
|
-
|
|
56
|
+
from startrek.net.socket import get_remote_address, get_local_address
|
|
58
57
|
|
|
59
58
|
from .log import Log, Logging
|
|
60
59
|
from .dos import Path, File, TextFile, JSONFile
|
|
@@ -122,7 +121,7 @@ __all__ = [
|
|
|
122
121
|
|
|
123
122
|
'Converter',
|
|
124
123
|
|
|
125
|
-
'Runnable', 'Runner', 'Daemon',
|
|
124
|
+
'Runnable', 'Runner', 'Daemon',
|
|
126
125
|
'StateDelegate',
|
|
127
126
|
|
|
128
127
|
'get_remote_address', 'get_local_address',
|
|
@@ -31,10 +31,12 @@
|
|
|
31
31
|
|
|
32
32
|
from typing import TypeVar, Generic, Optional, Dict, Set, Tuple
|
|
33
33
|
|
|
34
|
-
from startrek.
|
|
35
|
-
from startrek.
|
|
34
|
+
from startrek.skywalker import Singleton
|
|
35
|
+
from startrek.skywalker import Runner
|
|
36
36
|
from dimsdk import DateTime
|
|
37
37
|
|
|
38
|
+
from .log import Logging
|
|
39
|
+
|
|
38
40
|
|
|
39
41
|
K = TypeVar('K')
|
|
40
42
|
V = TypeVar('V')
|
|
@@ -133,44 +135,37 @@ class CachePool(Generic[K, V]):
|
|
|
133
135
|
|
|
134
136
|
|
|
135
137
|
@Singleton
|
|
136
|
-
class CacheManager(
|
|
138
|
+
class CacheManager(Runner, Logging):
|
|
137
139
|
|
|
138
140
|
def __init__(self):
|
|
141
|
+
super().__init__(interval=2.0)
|
|
139
142
|
self.__pools: Dict[str, CachePool] = {} # name -> pool
|
|
140
|
-
|
|
141
|
-
self.
|
|
142
|
-
|
|
143
|
-
self.__daemon.start()
|
|
143
|
+
self.__next_time = DateTime.now()
|
|
144
|
+
# Runner.async_run(coroutine=self.start())
|
|
145
|
+
Runner.thread_run(runner=self)
|
|
144
146
|
|
|
145
|
-
|
|
146
|
-
def
|
|
147
|
-
|
|
147
|
+
# Override
|
|
148
|
+
async def setup(self):
|
|
149
|
+
pass
|
|
148
150
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
# 2. waiting for the gate to stop
|
|
153
|
-
await Runner.sleep(seconds=5)
|
|
154
|
-
# 3. cancel the async task
|
|
155
|
-
self.__daemon.stop()
|
|
151
|
+
# Override
|
|
152
|
+
async def finish(self):
|
|
153
|
+
pass
|
|
156
154
|
|
|
157
155
|
# Override
|
|
158
|
-
async def
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
except Exception as error:
|
|
172
|
-
print('[MEM] failed to purge cache: %s' % error)
|
|
173
|
-
print('[MEM] stop %s' % self)
|
|
156
|
+
async def process(self) -> bool:
|
|
157
|
+
# try to purge each 5 minutes
|
|
158
|
+
now = DateTime.now()
|
|
159
|
+
if now < self.__next_time:
|
|
160
|
+
return False
|
|
161
|
+
else:
|
|
162
|
+
self.__next_time = DateTime(now.timestamp + 300)
|
|
163
|
+
# purge
|
|
164
|
+
try:
|
|
165
|
+
count = self.purge(now=now)
|
|
166
|
+
self.info(msg='[MEM] purge %d item(s) from cache pools' % count)
|
|
167
|
+
except Exception as error:
|
|
168
|
+
self.error(msg='[MEM] failed to purge cache: %s' % error)
|
|
174
169
|
|
|
175
170
|
def get_pool(self, name: str) -> CachePool[K, V]:
|
|
176
171
|
""" get pool with name """
|
|
@@ -14,7 +14,7 @@ import io
|
|
|
14
14
|
|
|
15
15
|
from setuptools import setup, find_packages
|
|
16
16
|
|
|
17
|
-
__version__ = '1.0
|
|
17
|
+
__version__ = '1.2.0'
|
|
18
18
|
__author__ = 'Albert Moky'
|
|
19
19
|
__contact__ = 'albert.moky@gmail.com'
|
|
20
20
|
|
|
@@ -58,8 +58,8 @@ setup(
|
|
|
58
58
|
'dkd>=2.0.0',
|
|
59
59
|
'mkm>=2.0.0',
|
|
60
60
|
|
|
61
|
-
'startrek>=2.
|
|
62
|
-
'tcp>=2.
|
|
63
|
-
'udp>=2.
|
|
61
|
+
'startrek>=2.1.0',
|
|
62
|
+
'tcp>=2.1.0',
|
|
63
|
+
'udp>=2.1.0',
|
|
64
64
|
]
|
|
65
65
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|