Skip to content

Commit

Permalink
new approach to run BitDust on mobile devices
Browse files Browse the repository at this point in the history
  • Loading branch information
vesellov committed Dec 30, 2024
1 parent de3a101 commit 2f19332
Show file tree
Hide file tree
Showing 163 changed files with 8,655 additions and 755 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
Change Log
==========

2024-12-30 Veselin Penev [penev.veselin@gmail.com](mailto:penev.veselin@gmail.com)

* new approach to run BitDust on mobile devices
* built api.device_* methods for secure remote web socket connections
* added command line interface to manipulate paired devices
* save&load connected routers
* handling situations when web socket server or client are disconnected
* bug fix in group_participant()



2024-10-07 Veselin Penev [penev.veselin@gmail.com](mailto:penev.veselin@gmail.com)

* add uniqueness to Request()/Data() packets for index files
Expand Down
1 change: 1 addition & 0 deletions bitdust/access/group_access_donor.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@


class GroupAccessDonor(automat.Automat):

"""
This class implements all the functionality of ``group_access_donor()`` state machine.
"""
Expand Down
23 changes: 13 additions & 10 deletions bitdust/access/group_participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,16 @@ def start_group_participants():

def _start():
started = 0
for group_key_id, group_info in groups.active_groups().items():
for group_key_id, _ in groups.active_groups().items():
if not group_key_id:
continue
if not my_keys.is_key_registered(group_key_id):
lg.err('can not start GroupParticipant because key %r is not registered' % group_key_id)
continue
if group_key_id.startswith('person'):
# TODO: temporarily disabled
continue
if not group_info['active']:
if not groups.is_group_active(group_key_id):
continue
if not my_keys.is_key_registered(group_key_id):
lg.err('can not start GroupParticipant because key %r is not registered' % group_key_id)
continue
if not id_url.is_cached(global_id.glob2idurl(group_key_id, as_field=False)):
continue
Expand All @@ -269,11 +269,13 @@ def _on_cached(result):
for group_key_id, _ in groups.active_groups().items():
if not group_key_id:
continue
if not my_keys.is_key_registered(group_key_id):
continue
if group_key_id.startswith('person'):
# TODO: temporarily disabled
continue
if not groups.is_group_active(group_key_id):
continue
if not my_keys.is_key_registered(group_key_id):
continue
creator_idurl = global_id.glob2idurl(group_key_id)
if id_url.is_the_same(creator_idurl, my_id.getIDURL()):
continue
Expand Down Expand Up @@ -342,6 +344,9 @@ def __init__(self, group_key_id, participant_idurl=None, debug_level=_DebugLevel
), state='AT_STARTUP', debug_level=debug_level, log_events=log_events, log_transitions=log_transitions, publish_events=publish_events, **kwargs
)

def state_changed(self, oldstate, newstate, event, *args, **kwargs):
groups.run_group_state_callbacks(oldstate, newstate, self.to_json())

def update_group_key_id(self, new_group_key_id):
if _Debug:
lg.args(_DebugLevel, old=self.group_key_id, new=new_group_key_id)
Expand All @@ -359,7 +364,7 @@ def to_json(self):
'active': groups.is_group_active(self.group_key_id),
'participant_id': self.participant_id,
'group_key_id': self.group_key_id,
'alias': self.group_glob_id['key_alias'],
'alias': self.group_glob_id['key_alias'] if self.group_glob_id else '',
'label': my_keys.get_label(self.group_key_id) or '',
'creator': self.group_creator_id,
'active_supplier_pos': self.active_supplier_pos,
Expand Down Expand Up @@ -1184,7 +1189,6 @@ def _do_push_messages_to_another_participant(self, remote_id, sequence_head, seq
},
recipient_global_id=remote_id,
packet_id=packet_id,
# message_ack_timeout=config.conf().getInt('services/message-broker/message-ack-timeout'),
# skip_handshake=True,
fire_callbacks=False,
)
Expand Down Expand Up @@ -1212,7 +1216,6 @@ def _do_pull_messages_from_another_participant(self, remote_id, sequence_head, s
},
recipient_global_id=remote_id,
packet_id=packet_id,
# message_ack_timeout=config.conf().getInt('services/message-broker/message-ack-timeout'),
# skip_handshake=True,
fire_callbacks=False,
)
Expand Down
27 changes: 26 additions & 1 deletion bitdust/access/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@

_ActiveGroups = {}

_GroupStateCallbacks = []

#------------------------------------------------------------------------------


Expand Down Expand Up @@ -353,7 +355,7 @@ def is_group_active(group_key_id):
group_key_id = my_keys.latest_key_id(group_key_id)
if not is_group_exist(group_key_id):
return False
return active_groups()[group_key_id]['active']
return active_groups()[group_key_id].get('active', False)


def set_group_active(group_key_id, value):
Expand All @@ -371,6 +373,29 @@ def set_group_active(group_key_id, value):
#------------------------------------------------------------------------------


def add_group_state_callback(cb):
global _GroupStateCallbacks
_GroupStateCallbacks.append(cb)


def remove_group_state_callback(cb):
"""
Set callback to fire when any contact were changed.
"""
global _GroupStateCallbacks
if cb in _GroupStateCallbacks:
_GroupStateCallbacks.remove(cb)


def run_group_state_callbacks(oldstate, newstate, group_json_info):
global _GroupStateCallbacks
for cb in _GroupStateCallbacks:
cb(oldstate, newstate, group_json_info)


#------------------------------------------------------------------------------


def on_identity_url_changed(evt):
from bitdust.access import group_participant
service_dir = settings.ServiceDir('service_private_groups')
Expand Down
2 changes: 2 additions & 0 deletions bitdust/access/shared_access_donor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@


class SharedAccessDonor(automat.Automat):

"""
This class implements all the functionality of the ``shared_access_donor()`` state machine.
"""
Expand Down Expand Up @@ -235,6 +236,7 @@ def doSendMyIdentityToUser(self, *args, **kwargs):
"""
Action method.
"""

def _on_ack(response):
self.ping_response = time.time()
self.automat('ack', response)
Expand Down
2 changes: 2 additions & 0 deletions bitdust/automats/automat.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ def SetGlobalLogTransitions(value=False):


class Automat(object):

"""
Base class of the State Machine Object.
Expand Down Expand Up @@ -393,6 +394,7 @@ class Automat(object):
You also must set that flag in the MS Visio document and rebuild the code:
put ``[post]`` string into the last line of the LABEL shape.
"""

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):
self.id, self.index = create_index(name)
self.name = name
Expand Down
2 changes: 2 additions & 0 deletions bitdust/broadcast/broadcast_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ def A(event=None, *args, **kwargs):


class BroadcastListener(automat.Automat):

"""
This class implements all the functionality of the ``broadcast_listener()``
state machine.
"""

def init(self):
"""
Method to initialize additional variables and flags at creation phase
Expand Down
1 change: 1 addition & 0 deletions bitdust/broadcast/broadcaster_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ def A(event=None, *args, **kwargs):


class BroadcasterNode(automat.Automat):

"""
This class implements all the functionality of the ``broadcaster_node()``
state machine.
Expand Down
1 change: 1 addition & 0 deletions bitdust/broadcast/broadcasters_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def A(event=None, *args, **kwargs):


class BroadcastersFinder(automat.Automat):

"""
This class implements all the functionality of the
``broadcasters_finder()`` state machine.
Expand Down
36 changes: 26 additions & 10 deletions bitdust/chat/message_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,7 @@ def convert_json(blob):
#------------------------------------------------------------------------------


def get_conversation_id(
sender_local_key_id,
recipient_local_key_id,
payload_type,
):
def get_conversation_id(sender_local_key_id, recipient_local_key_id, payload_type):
conversation_id = None
if payload_type in [3, 4]:
conversation_id = '{}&{}'.format(recipient_local_key_id, recipient_local_key_id)
Expand Down Expand Up @@ -625,10 +621,7 @@ def update_conversations_with_new_local_key_id(old_id, new_id):
lg.args(_DebugLevel, modifications=modifications)
for old_conv_id, new_conv_id in modifications.items():
sql = 'UPDATE conversations SET conversation_id=? WHERE conversation_id=?'
params = [
new_conv_id,
old_conv_id,
]
params = [new_conv_id, old_conv_id]
cur().execute(sql, params)
db().commit()
if _Debug:
Expand Down Expand Up @@ -683,7 +676,7 @@ def check_create_keys():
else:
to_be_opened.append(key_id)
if to_be_cached:
lg.warn('still see %d not cached identities, not able to process those customers: %r' (len(to_be_cached), to_be_cached))
lg.warn('still see %d not cached identities, not able to process those customers: %r' % (len(to_be_cached), to_be_cached))
if _Debug:
lg.args(_DebugLevel, to_be_opened=to_be_opened, to_be_cached=to_be_cached)
for key_id in to_be_opened:
Expand Down Expand Up @@ -861,6 +854,29 @@ def populate_messages(recipient_id=None, sender_id=None, message_types=[], offse
#------------------------------------------------------------------------------


def notify_group_conversation(oldstate, newstate, group_json_info):
sender_recipient_local_key_id = my_keys.get_local_key_id(group_json_info['group_key_id'])
if sender_recipient_local_key_id is None:
return
conversation_id = get_conversation_id(sender_recipient_local_key_id, sender_recipient_local_key_id, 3)
if conversation_id is None:
return
snapshot = dict(
conversation_id=conversation_id,
type=MESSAGE_TYPE_CODES[3],
started=None,
last_updated=None,
last_message_id=group_json_info['sequence_tail'],
key_id=group_json_info['group_key_id'],
old_state=oldstate,
)
snapshot.update(group_json_info)
listeners.push_snapshot('conversation', snap_id=conversation_id, data=snapshot)


#------------------------------------------------------------------------------


def main():
import pprint
my_keys.init()
Expand Down
2 changes: 2 additions & 0 deletions bitdust/chat/message_keeper.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
from bitdust.logs import lg

from bitdust.interface import api_web_socket
from bitdust.interface import api_device

from bitdust.crypt import my_keys

Expand Down Expand Up @@ -155,6 +156,7 @@ def store_message(data, message_id, sender_id, recipient_id, message_type=None,
lg.warn('message %r was not stored' % message_id)
return message_json
api_web_socket.on_stream_message(message_json)
api_device.on_stream_message(message_json)
if _Debug:
lg.out(_DebugLevel, 'message_keeper.store_message [%s]:%s from %r to %r' % (message_type, message_id, sender_id, recipient_id))
return message_json
1 change: 1 addition & 0 deletions bitdust/chat/nickname_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ def Destroy():


class NicknameHolder(automat.Automat):

"""
This class implements all the functionality of the ``nickname_holder()``
state machine.
Expand Down
2 changes: 2 additions & 0 deletions bitdust/chat/nickname_observer.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,12 @@ def stop_all():


class NicknameObserver(automat.Automat):

"""
This class implements all the functionality of the ``nickname_observer()``
state machine.
"""

def init(self):
"""
Method to initialize additional variables and flags at creation of the
Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/accountant_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def A(event=None, *args, **kwargs):


class AccountantNode(automat.Automat):

"""
This class implements all the functionality of the ``accountant_node()``
state machine.
Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/accountants_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def A(event=None, *args, **kwargs):


class AccountantsFinder(automat.Automat):

"""
This class implements all the functionality of the ``accountants_finder()``
state machine.
Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/coins_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ def make_key(self, key):


class BaseMD5Index(BaseHashIndex):

def transform_key(self, key):
return md5(key).digest()

Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/coins_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def A(event=None, *args, **kwargs):


class CoinsMiner(automat.Automat):

"""
This class implements all the functionality of the ``coins_miner()`` state
machine.
Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/contract_chain_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def A(event=None, *args, **kwargs):


class ContractChainConsumer(automat.Automat):

"""
This class implements all the functionality of the ``contract_chain_consumer()`` state machine.
"""
Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/contract_chain_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def send_to_miner(coins):


class Query(object):

def __init__(self, query_dict):
"""
"""
Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/customer_contract_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ def recheck_contract(supplier_idurl):


class CustomerContractExecutor(automat.Automat):

"""
This class implements all the functionality of the ``customer_contract_executor()`` state machine.
"""
Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/mine_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def work_from_known_hash(coin_json, prev_hash, simplification=2, starter_length=


class MininigCounter(object):

def __init__(self, max_counts, max_seconds):
self.max_counts = max_counts
self.max_seconds = max_seconds
Expand Down
2 changes: 2 additions & 0 deletions bitdust/coins/miner_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ def finish_contract(typ, partner, **kwargs):


class Contract(object):

def __init__(self, **kwargs):
for key, value in kwargs.items():
setattr(self, key, value)
Expand All @@ -178,6 +179,7 @@ def __init__(self, **kwargs):


class CoinsMinerNode(object):

def inbox_packet(self, newpacket, info):
return False

Expand Down
1 change: 1 addition & 0 deletions bitdust/coins/supplier_contract_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ def recheck_contract(customer_idurl):


class SupplierContractExecutor(automat.Automat):

"""
This class implements all the functionality of the ``supplier_contract_executor()`` state machine.
"""
Expand Down
Loading

0 comments on commit 2f19332

Please sign in to comment.