dimples 1.1.0__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.1.0 → dimples-1.2.0}/PKG-INFO +1 -1
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/network/state.py +1 -1
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/terminal.py +3 -4
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/dbi/session.py +4 -2
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/flexible.py +1 -1
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/queue.py +1 -1
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/session.py +3 -1
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/ws.py +1 -1
- {dimples-1.1.0 → dimples-1.2.0}/dimples/edge/octopus.py +11 -3
- {dimples-1.1.0 → dimples-1.2.0}/dimples/edge/start.py +1 -2
- {dimples-1.1.0 → dimples-1.2.0}/dimples/group/helper.py +2 -1
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/dispatcher.py +11 -3
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/push.py +11 -3
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/session.py +2 -9
- {dimples-1.1.0 → dimples-1.2.0}/dimples/station/handler.py +5 -2
- {dimples-1.1.0 → dimples-1.2.0}/dimples/utils/__init__.py +4 -40
- {dimples-1.1.0 → dimples-1.2.0}/dimples/utils/cache.py +28 -33
- {dimples-1.1.0 → dimples-1.2.0}/dimples.egg-info/PKG-INFO +1 -1
- {dimples-1.1.0 → dimples-1.2.0}/dimples.egg-info/requires.txt +3 -3
- {dimples-1.1.0 → dimples-1.2.0}/setup.py +4 -4
- {dimples-1.1.0 → dimples-1.2.0}/README.md +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/archivist.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/checkpoint.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/commands.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/creator.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/group.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/grp_expel.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/grp_invite.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/grp_join.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/grp_query.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/grp_quit.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/grp_reset.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/grp_resign.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/cpu/handshake.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/facebook.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/messenger.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/network/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/network/session.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/network/transition.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/packer.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/client/processor.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/anonymous.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/ans.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/archivist.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/compat/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/compat/btc.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/compat/compatible.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/compat/entity.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/compat/meta.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/compat/network.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/dbi/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/dbi/account.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/dbi/message.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/facebook.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/messenger.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/packer.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/processer.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/protocol/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/protocol/ans.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/protocol/block.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/protocol/handshake.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/protocol/login.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/protocol/mute.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/protocol/report.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/register.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/common/session.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/gate.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/gatekeeper.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/mars.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/mtp.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/protocol/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/protocol/mars.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/protocol/ws.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/conn/seeker.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/account.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/base.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/document.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/group.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/group_history.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/group_keys.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/login.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/meta.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/private.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/station.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/dos/user.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/message.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/session.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_cipherkey.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_document.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_group.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_group_history.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_group_keys.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_login.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_message.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_meta.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_private.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_station.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/database/t_user.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/edge/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/edge/shared.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/group/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/group/admin.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/group/builder.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/group/delegate.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/group/emitter.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/group/manager.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/group/packer.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/register/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/register/base.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/register/ext.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/register/run.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/register/shared.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/archivist.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/cpu/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/cpu/ans.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/cpu/document.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/cpu/handshake.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/cpu/login.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/cpu/report.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/messenger.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/packer.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/processor.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/session_center.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/server/trace.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/station/__init__.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/station/shared.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/station/start.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/utils/config.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/utils/dos.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples/utils/log.py +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples.egg-info/SOURCES.txt +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples.egg-info/dependency_links.txt +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples.egg-info/entry_points.txt +0 -0
- {dimples-1.1.0 → dimples-1.2.0}/dimples.egg-info/top_level.txt +0 -0
- {dimples-1.1.0 → 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,7 +388,7 @@ 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
|
-
Runner.thread_run(terminal)
|
|
391
|
+
Runner.thread_run(runner=terminal)
|
|
384
392
|
return terminal
|
|
385
393
|
|
|
386
394
|
|
|
@@ -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
|
|
@@ -134,7 +134,7 @@ class Dispatcher(MessageDeliver, Logging):
|
|
|
134
134
|
runner = Roamer(database=db)
|
|
135
135
|
self.__roamer = runner
|
|
136
136
|
# Runner.async_run(coroutine=runner.start())
|
|
137
|
-
Runner.thread_run(runner)
|
|
137
|
+
Runner.thread_run(runner=runner)
|
|
138
138
|
return runner
|
|
139
139
|
|
|
140
140
|
def add_roaming(self, user: ID, station: ID) -> bool:
|
|
@@ -275,7 +275,7 @@ class RoamingInfo:
|
|
|
275
275
|
self.station = station
|
|
276
276
|
|
|
277
277
|
|
|
278
|
-
class Roamer(
|
|
278
|
+
class Roamer(Runner, Logging):
|
|
279
279
|
""" Delegate for redirect cached messages to roamed station """
|
|
280
280
|
|
|
281
281
|
def __init__(self, database: MessageDBI):
|
|
@@ -310,6 +310,14 @@ class Roamer(DaemonRunner, Logging):
|
|
|
310
310
|
self.__append(info=info)
|
|
311
311
|
return True
|
|
312
312
|
|
|
313
|
+
# Override
|
|
314
|
+
async def setup(self):
|
|
315
|
+
pass
|
|
316
|
+
|
|
317
|
+
# Override
|
|
318
|
+
async def finish(self):
|
|
319
|
+
pass
|
|
320
|
+
|
|
313
321
|
# Override
|
|
314
322
|
async def process(self) -> bool:
|
|
315
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,7 +117,7 @@ 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)
|
|
@@ -125,7 +125,7 @@ class PushCenter(DaemonRunner, Logging):
|
|
|
125
125
|
self.__keeper = BadgeKeeper()
|
|
126
126
|
self.__service: Optional[PushService] = None
|
|
127
127
|
# Runner.async_run(coroutine=self.start())
|
|
128
|
-
Runner.thread_run(self)
|
|
128
|
+
Runner.thread_run(runner=self)
|
|
129
129
|
|
|
130
130
|
@property
|
|
131
131
|
def service(self) -> Optional[PushService]:
|
|
@@ -149,6 +149,14 @@ class PushCenter(DaemonRunner, Logging):
|
|
|
149
149
|
queue = self.__queue
|
|
150
150
|
queue.add_message(msg=msg)
|
|
151
151
|
|
|
152
|
+
# Override
|
|
153
|
+
async def setup(self):
|
|
154
|
+
pass
|
|
155
|
+
|
|
156
|
+
# Override
|
|
157
|
+
async def finish(self):
|
|
158
|
+
pass
|
|
159
|
+
|
|
152
160
|
# Override
|
|
153
161
|
async def process(self) -> bool:
|
|
154
162
|
# 1. get waiting messages
|
|
@@ -96,8 +96,7 @@ class ServerSession(BaseSession):
|
|
|
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
|
-
|
|
100
|
-
Runner.thread_run(crt)
|
|
99
|
+
Runner.async_run(coroutine=crt)
|
|
101
100
|
return True
|
|
102
101
|
|
|
103
102
|
# Override
|
|
@@ -106,15 +105,9 @@ class ServerSession(BaseSession):
|
|
|
106
105
|
session_change_active(session=self, active=active)
|
|
107
106
|
# load cached message asynchronously
|
|
108
107
|
crt = load_cached_messages(session=self)
|
|
109
|
-
|
|
110
|
-
Runner.thread_run(crt)
|
|
108
|
+
Runner.async_run(coroutine=crt)
|
|
111
109
|
return True
|
|
112
110
|
|
|
113
|
-
# Override
|
|
114
|
-
async def start(self):
|
|
115
|
-
await super().start()
|
|
116
|
-
await self.run()
|
|
117
|
-
|
|
118
111
|
#
|
|
119
112
|
# Docker Delegate
|
|
120
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)
|
|
@@ -33,7 +33,6 @@
|
|
|
33
33
|
-- Albert Moky @ Jan. 23, 2019
|
|
34
34
|
"""
|
|
35
35
|
|
|
36
|
-
import threading
|
|
37
36
|
from typing import Optional, List, Dict
|
|
38
37
|
|
|
39
38
|
from dimsdk import md5, sha1, sha256, keccak256, ripemd160
|
|
@@ -51,11 +50,10 @@ from dimsdk import DocumentHelper
|
|
|
51
50
|
|
|
52
51
|
from dimplugins.crypto.aes import random_bytes
|
|
53
52
|
|
|
54
|
-
from startrek.
|
|
55
|
-
from startrek.
|
|
53
|
+
from startrek.skywalker import Singleton
|
|
54
|
+
from startrek.skywalker import Runnable, Runner, Daemon
|
|
56
55
|
from startrek.fsm import Delegate as StateDelegate
|
|
57
|
-
from startrek.net.
|
|
58
|
-
|
|
56
|
+
from startrek.net.socket import get_remote_address, get_local_address
|
|
59
57
|
|
|
60
58
|
from .log import Log, Logging
|
|
61
59
|
from .dos import Path, File, TextFile, JSONFile
|
|
@@ -123,7 +121,7 @@ __all__ = [
|
|
|
123
121
|
|
|
124
122
|
'Converter',
|
|
125
123
|
|
|
126
|
-
'Runnable', 'Runner', 'Daemon',
|
|
124
|
+
'Runnable', 'Runner', 'Daemon',
|
|
127
125
|
'StateDelegate',
|
|
128
126
|
|
|
129
127
|
'get_remote_address', 'get_local_address',
|
|
@@ -143,37 +141,3 @@ __all__ = [
|
|
|
143
141
|
'template_replace',
|
|
144
142
|
|
|
145
143
|
]
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
#
|
|
149
|
-
# Patch for Runner
|
|
150
|
-
#
|
|
151
|
-
async def _run_forever(runner: Runner):
|
|
152
|
-
await runner.start()
|
|
153
|
-
while True:
|
|
154
|
-
await Runner.sleep(seconds=2.0)
|
|
155
|
-
if not runner.running:
|
|
156
|
-
break
|
|
157
|
-
Log.warning(msg='runner stopped: %s' % runner)
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
def _start_runner(runner: Runner):
|
|
161
|
-
Runner.sync_run(main=_run_forever(runner=runner))
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
def _start_coroutine(coroutine):
|
|
165
|
-
Runner.sync_run(main=coroutine)
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
def _bg_run(target):
|
|
169
|
-
if isinstance(target, Runner):
|
|
170
|
-
fn = _start_runner
|
|
171
|
-
else:
|
|
172
|
-
fn = _start_coroutine
|
|
173
|
-
thr = threading.Thread(target=fn, args=(target,), daemon=True)
|
|
174
|
-
thr.start()
|
|
175
|
-
return thr
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
""" Run coroutine in background thread """
|
|
179
|
-
Runner.thread_run = _bg_run
|
|
@@ -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.
|
|
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
|