Skip to content

Commit c291623

Browse files
authored
Merge pull request #809 from vesellov/master
more progress with routed web socket connctions
2 parents 1101c01 + bf5c52b commit c291623

File tree

97 files changed

+531
-260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+531
-260
lines changed

bitdust/access/group_access_donor.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767

6868

6969
class GroupAccessDonor(automat.Automat):
70+
7071
"""
7172
This class implements all the functionality of ``group_access_donor()`` state machine.
7273
"""

bitdust/access/shared_access_donor.py

+2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989

9090

9191
class SharedAccessDonor(automat.Automat):
92+
9293
"""
9394
This class implements all the functionality of the ``shared_access_donor()`` state machine.
9495
"""
@@ -235,6 +236,7 @@ def doSendMyIdentityToUser(self, *args, **kwargs):
235236
"""
236237
Action method.
237238
"""
239+
238240
def _on_ack(response):
239241
self.ping_response = time.time()
240242
self.automat('ack', response)

bitdust/automats/automat.py

+2
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ def SetGlobalLogTransitions(value=False):
342342

343343

344344
class Automat(object):
345+
345346
"""
346347
Base class of the State Machine Object.
347348
@@ -393,6 +394,7 @@ class Automat(object):
393394
You also must set that flag in the MS Visio document and rebuild the code:
394395
put ``[post]`` string into the last line of the LABEL shape.
395396
"""
397+
396398
def __init__(self, name, state, debug_level=_DebugLevel, log_events=_Debug, log_transitions=_Debug, publish_events=False, publish_event_state_not_changed=False, publish_fast=True, **kwargs):
397399
self.id, self.index = create_index(name)
398400
self.name = name

bitdust/broadcast/broadcast_listener.py

+2
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ def A(event=None, *args, **kwargs):
8888

8989

9090
class BroadcastListener(automat.Automat):
91+
9192
"""
9293
This class implements all the functionality of the ``broadcast_listener()``
9394
state machine.
9495
"""
96+
9597
def init(self):
9698
"""
9799
Method to initialize additional variables and flags at creation phase

bitdust/broadcast/broadcaster_node.py

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def A(event=None, *args, **kwargs):
9494

9595

9696
class BroadcasterNode(automat.Automat):
97+
9798
"""
9899
This class implements all the functionality of the ``broadcaster_node()``
99100
state machine.

bitdust/broadcast/broadcasters_finder.py

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def A(event=None, *args, **kwargs):
9292

9393

9494
class BroadcastersFinder(automat.Automat):
95+
9596
"""
9697
This class implements all the functionality of the
9798
``broadcasters_finder()`` state machine.

bitdust/chat/message_keeper.py

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
from bitdust.logs import lg
4343

4444
from bitdust.interface import api_web_socket
45+
from bitdust.interface import api_device
4546

4647
from bitdust.crypt import my_keys
4748

@@ -155,6 +156,7 @@ def store_message(data, message_id, sender_id, recipient_id, message_type=None,
155156
lg.warn('message %r was not stored' % message_id)
156157
return message_json
157158
api_web_socket.on_stream_message(message_json)
159+
api_device.on_stream_message(message_json)
158160
if _Debug:
159161
lg.out(_DebugLevel, 'message_keeper.store_message [%s]:%s from %r to %r' % (message_type, message_id, sender_id, recipient_id))
160162
return message_json

bitdust/chat/nickname_holder.py

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def Destroy():
113113

114114

115115
class NicknameHolder(automat.Automat):
116+
116117
"""
117118
This class implements all the functionality of the ``nickname_holder()``
118119
state machine.

bitdust/chat/nickname_observer.py

+2
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ def stop_all():
110110

111111

112112
class NicknameObserver(automat.Automat):
113+
113114
"""
114115
This class implements all the functionality of the ``nickname_observer()``
115116
state machine.
116117
"""
118+
117119
def init(self):
118120
"""
119121
Method to initialize additional variables and flags at creation of the

bitdust/coins/accountant_node.py

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ def A(event=None, *args, **kwargs):
103103

104104

105105
class AccountantNode(automat.Automat):
106+
106107
"""
107108
This class implements all the functionality of the ``accountant_node()``
108109
state machine.

bitdust/coins/accountants_finder.py

+1
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ def A(event=None, *args, **kwargs):
9292

9393

9494
class AccountantsFinder(automat.Automat):
95+
9596
"""
9697
This class implements all the functionality of the ``accountants_finder()``
9798
state machine.

bitdust/coins/coins_index.py

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def make_key(self, key):
162162

163163

164164
class BaseMD5Index(BaseHashIndex):
165+
165166
def transform_key(self, key):
166167
return md5(key).digest()
167168

bitdust/coins/coins_miner.py

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ def A(event=None, *args, **kwargs):
111111

112112

113113
class CoinsMiner(automat.Automat):
114+
114115
"""
115116
This class implements all the functionality of the ``coins_miner()`` state
116117
machine.

bitdust/coins/contract_chain_consumer.py

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ def A(event=None, *args, **kwargs):
8787

8888

8989
class ContractChainConsumer(automat.Automat):
90+
9091
"""
9192
This class implements all the functionality of the ``contract_chain_consumer()`` state machine.
9293
"""

bitdust/coins/contract_chain_node.py

+1
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def send_to_miner(coins):
105105

106106

107107
class Query(object):
108+
108109
def __init__(self, query_dict):
109110
"""
110111
"""

bitdust/coins/customer_contract_executor.py

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ def recheck_contract(supplier_idurl):
119119

120120

121121
class CustomerContractExecutor(automat.Automat):
122+
122123
"""
123124
This class implements all the functionality of the ``customer_contract_executor()`` state machine.
124125
"""

bitdust/coins/mine_old.py

+1
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ def work_from_known_hash(coin_json, prev_hash, simplification=2, starter_length=
150150

151151

152152
class MininigCounter(object):
153+
153154
def __init__(self, max_counts, max_seconds):
154155
self.max_counts = max_counts
155156
self.max_seconds = max_seconds

bitdust/coins/miner_old.py

+2
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ def finish_contract(typ, partner, **kwargs):
169169

170170

171171
class Contract(object):
172+
172173
def __init__(self, **kwargs):
173174
for key, value in kwargs.items():
174175
setattr(self, key, value)
@@ -178,6 +179,7 @@ def __init__(self, **kwargs):
178179

179180

180181
class CoinsMinerNode(object):
182+
181183
def inbox_packet(self, newpacket, info):
182184
return False
183185

bitdust/coins/supplier_contract_executor.py

+1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def recheck_contract(customer_idurl):
129129

130130

131131
class SupplierContractExecutor(automat.Automat):
132+
132133
"""
133134
This class implements all the functionality of the ``supplier_contract_executor()`` state machine.
134135
"""

bitdust/contacts/contactsdb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
#------------------------------------------------------------------------------
3737

3838
_Debug = False
39-
_DebugLevel = 10
39+
_DebugLevel = 24
4040

4141
#------------------------------------------------------------------------------
4242

bitdust/contacts/identitycache.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#------------------------------------------------------------------------------
4040

4141
_Debug = False
42-
_DebugLevel = 10
42+
_DebugLevel = 24
4343

4444
#------------------------------------------------------------------------------
4545

bitdust/contacts/identitydb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#------------------------------------------------------------------------------
4040

4141
_Debug = False
42-
_DebugLevel = 10
42+
_DebugLevel = 24
4343

4444
#------------------------------------------------------------------------------
4545

bitdust/crypt/encrypted.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
#------------------------------------------------------------------------------
6262

6363
_Debug = False
64-
_DebugLevel = 10
64+
_DebugLevel = 20
6565

6666
#------------------------------------------------------------------------------
6767

bitdust/crypt/signed.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
#------------------------------------------------------------------------------
5050

5151
_Debug = False
52-
_DebugLevel = 10
52+
_DebugLevel = 20
5353

5454
#------------------------------------------------------------------------------
5555

bitdust/currency/geth_service.py

+2
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def make(callback=None):
130130

131131

132132
def deploy(callback=None):
133+
133134
def _clone(out, retcode):
134135
make(callback=callback)
135136

@@ -196,6 +197,7 @@ def fake_createprocess(_appName, _commandLine, _processAttributes, _threadAttrib
196197

197198

198199
class GethProcessProtocol(protocol.ProcessProtocol):
200+
199201
def __init__(self, callback):
200202
"""
201203
"""

bitdust/customer/supplier_finder.py

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ def A(event=None, *args, **kwargs):
113113

114114

115115
class SupplierFinder(automat.Automat):
116+
116117
"""
117118
This class implements all the functionality of the ``supplier_finder()``
118119
state machine.

bitdust/dht/dht_service.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#------------------------------------------------------------------------------
3535

3636
_Debug = False
37-
_DebugLevel = 10
37+
_DebugLevel = 24
3838

3939
#------------------------------------------------------------------------------
4040

@@ -1244,6 +1244,7 @@ def get_cached_json_value(key, layer_id=0, cache_ttl=DEFAULT_CACHE_TTL):
12441244

12451245

12461246
class DHTNode(MultiLayerNode):
1247+
12471248
def __init__(self, udpPort=4000, dataStores=None, routingTables=None, networkProtocol=None, nodeID=None):
12481249
super(DHTNode, self).__init__(
12491250
udpPort=udpPort,
@@ -1392,6 +1393,7 @@ def reconnect(self, knownNodeAddresses=None):
13921393

13931394

13941395
class DHTProtocol(KademliaMultiLayerProtocol):
1396+
13951397
def __init__(self, node, msgEncoder=encoding.Bencode(), msgTranslator=msgformat.MultiLayerFormat()):
13961398
KademliaMultiLayerProtocol.__init__(self, node, msgEncoder=msgEncoder, msgTranslator=msgTranslator)
13971399
self._counter = count

bitdust/interface/api.py

+40-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ def enable_model_listener(model_name, request_all=False):
240240
lg.args(_DebugLevel, m=model_name, request_all=request_all)
241241
from bitdust.main import listeners
242242
from bitdust.interface import api_web_socket
243+
from bitdust.interface import api_device
243244
listeners.add_listener(api_web_socket.on_model_changed, model_name)
245+
listeners.add_listener(api_device.on_model_changed, model_name)
244246
if request_all:
245247
return request_model_data(model_name)
246248
return OK()
@@ -257,6 +259,7 @@ def disable_model_listener(model_name):
257259
lg.args(_DebugLevel, m=model_name)
258260
from bitdust.main import listeners
259261
from bitdust.interface import api_web_socket
262+
from bitdust.interface import api_device
260263
if model_name == 'key':
261264
listeners.populate_later('key', stop=True)
262265
elif model_name == 'conversation':
@@ -276,6 +279,7 @@ def disable_model_listener(model_name):
276279
elif model_name == 'shared_location':
277280
listeners.populate_later('shared_location', stop=True)
278281
listeners.remove_listener(api_web_socket.on_model_changed, model_name)
282+
listeners.remove_listener(api_device.on_model_changed, model_name)
279283
return OK()
280284

281285

@@ -603,11 +607,14 @@ def devices_list(sort=False):
603607
result = device_object.toDict()
604608
result['name'] = result.pop('label')
605609
result['instance'] = None
610+
result['url'] = None
606611
result.pop('body', None)
607612
result.pop('local_key_id', None)
608613
device_instance = api_device.instances(device_name)
609614
if device_instance:
610-
result.update({'instance': device_instance.to_json()})
615+
result['instance'] = device_instance.to_json()
616+
result['instance'].pop('device_name')
617+
result['url'] = result['instance'].pop('url', None)
611618
results.append(result)
612619
if sort:
613620
results = sorted(results, key=lambda i: i['label'])
@@ -631,12 +638,15 @@ def device_info(name):
631638
device_instance = api_device.instances(name)
632639
result = device_object.toDict()
633640
result['name'] = result.pop('label')
641+
result['url'] = None
634642
result['instance'] = None
635643
result.pop('body', None)
636644
result.pop('local_key_id', None)
637645
if not device_instance:
638646
return OK(result)
639-
result.update({'instance': device_instance.to_json()})
647+
result['instance'] = device_instance.to_json()
648+
result['instance'].pop('device_name')
649+
result['url'] = result['instance'].pop('url', None)
640650
return OK(result)
641651

642652

@@ -728,6 +738,34 @@ def _on_listening_started(success):
728738
return ret
729739

730740

741+
def device_authorization_reset(name, start=True, wait_listening=False):
742+
"""
743+
"""
744+
from bitdust.interface import api_device
745+
if _Debug:
746+
lg.args(_DebugLevel, name=name)
747+
try:
748+
api_device.reset_authorization(device_name=name)
749+
except Exception as exc:
750+
return ERROR(exc)
751+
if not start:
752+
return OK()
753+
return device_start(name, wait_listening=wait_listening)
754+
755+
756+
def device_client_code_input(name, client_code):
757+
"""
758+
"""
759+
from bitdust.interface import api_device
760+
if _Debug:
761+
lg.args(_DebugLevel, name=name, client_code=client_code)
762+
try:
763+
api_device.on_device_client_code_input_received(device_name=name, client_code=client_code)
764+
except Exception as exc:
765+
return ERROR(exc)
766+
return OK()
767+
768+
731769
def device_stop(name):
732770
"""
733771
This will stop accepting incoming connections from given API device and deactivate it.

0 commit comments

Comments
 (0)