Skip to content

Commit 0ace9a6

Browse files
authored
Merge pull request #802 from vesellov/master
populate details about service_proxy_server() inf the api.network_status
2 parents 54296bd + 9cc915b commit 0ace9a6

19 files changed

+357
-241
lines changed

CHANGELOG.txt

+24
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,30 @@
11
Change Log
22
==========
33

4+
5+
2024-09-04 Veselin Penev [[email protected]](mailto:[email protected])
6+
7+
* bump pycryptodomex==3.20.0
8+
* solved another issue with removing old versions of the same file
9+
* calculate original file size before start the backup
10+
* able to populate web-socket stream data for specific files/locations
11+
* fix in bitdust/userid/id_url.py
12+
* fix bug in logging
13+
* fixed bug related to auto-removing oldest versions of the files
14+
15+
16+
17+
2024-07-29 Veselin Penev [[email protected]](mailto:[email protected])
18+
19+
* downgrade coincurve version
20+
* built supplier.storage_contract.scan_recent_storage_transactions() method
21+
* added caching of identities unique names
22+
* fix in supplier.storage_contract.verify_accept_storage_payment()
23+
* fix in bitdust/supplier/customer_space.py
24+
* fix in bitdust/blockchain/bismuth_wallet.py
25+
26+
27+
428
2024-07-12 Veselin Penev [[email protected]](mailto:[email protected])
529

630
* do not reject unpaid customers for now, storage contracts are still in progress

bitdust/access/key_ring.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -462,8 +462,11 @@ def on_key_received(newpacket, info, status, error_message):
462462
# but we already have a key with that ID
463463
if my_keys.is_key_private(key_id):
464464
# we should not overwrite existing private key
465-
# TODO: check other scenarios
466-
raise Exception('private key already registered with %r' % key_id)
465+
if my_keys.get_public_key_raw(key_id) != key_object.toPublicString():
466+
raise Exception('private key already registered : %r' % key_id)
467+
lg.warn('received public key, but matching private key is already registered %r' % key_id)
468+
p2p_service.SendAck(newpacket)
469+
return True
467470
if my_keys.get_public_key_raw(key_id) != key_object.toPublicString():
468471
my_keys.erase_key(key_id)
469472
if not my_keys.register_key(key_id, key_object, label=key_label):

bitdust/access/shared_access_coordinator.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def doConnectCustomerSuppliers(self, *args, **kwargs):
669669
self.suppliers_in_progress.clear()
670670
self.suppliers_succeed.clear()
671671
for supplier_idurl in self.known_suppliers_list:
672-
self.suppliers_in_progress.append(supplier_idurl)
672+
self.suppliers_in_progress.append(id_url.field(supplier_idurl))
673673
if id_url.is_cached(supplier_idurl):
674674
self._do_connect_with_supplier(supplier_idurl)
675675
else:
@@ -689,7 +689,7 @@ def doSupplierRequestListFiles(self, event, *args, **kwargs):
689689
"""
690690
Action method.
691691
"""
692-
supplier_idurl = kwargs['supplier_idurl']
692+
supplier_idurl = id_url.field(kwargs['supplier_idurl'])
693693
pkt_out = None
694694
if event == 'supplier-file-modified':
695695
remote_path = kwargs['remote_path']
@@ -797,8 +797,8 @@ def doRemember(self, event, *args, **kwargs):
797797
"""
798798
Action method.
799799
"""
800-
supplier_idurl = kwargs['supplier_idurl']
801-
if supplier_idurl in self.suppliers_in_progress:
800+
supplier_idurl = id_url.field(kwargs['supplier_idurl'])
801+
if id_url.is_in(supplier_idurl, self.suppliers_in_progress):
802802
self.suppliers_in_progress.remove(supplier_idurl)
803803
if event in ['index-sent', 'index-up-to-date']:
804804
if supplier_idurl not in self.suppliers_succeed:

bitdust/crypt/encrypted.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ def Unserialize(data, decrypt_key=None):
294294
exc,
295295
list(dct.keys()),
296296
(dct.get('c'), dct.get('b'), dct.get('i'), dct.get('r')),
297-
traceback.format_tb(),
297+
'\n'.join(traceback.format_stack()),
298298
))
299299
if _Debug:
300300
lg.out(_DebugLevel, repr(dct))

bitdust/interface/api.py

+35-36
Original file line numberDiff line numberDiff line change
@@ -515,13 +515,14 @@ def process_info():
515515
}
516516
if driver.is_on('service_backup_db'):
517517
from bitdust.storage import backup_fs
518+
v = backup_fs.total_stats()
518519
result['file'] = {
519-
'items': backup_fs.counter(),
520-
'files': backup_fs.numberfiles(),
521-
'files_size': backup_fs.sizefiles(),
522-
'folders': backup_fs.numberfolders(),
523-
'folders_size': backup_fs.sizefolders(),
524-
'backups_size': backup_fs.sizebackups(),
520+
'items': v['items'],
521+
'files': v['files'],
522+
'folders': v['folders'],
523+
'files_size': v['size_files'],
524+
'folders_size': v['size_folders'],
525+
'backups_size': v['size_backups'],
525526
'customers': len(backup_fs.known_customers()),
526527
}
527528
if driver.is_on('service_shared_data'):
@@ -693,6 +694,7 @@ def network_select(name):
693694

694695
def _on_network_disconnected(x):
695696
cur_base_dir = deploy.current_base_dir()
697+
# TODO: must wait shutdown and init to complete with defered
696698
shutdowner.shutdown_services()
697699
shutdowner.shutdown_local()
698700
shutdowner.shutdown_automats()
@@ -969,6 +971,20 @@ def network_status(suppliers=False, customers=False, cache=False, tcp=False, udp
969971
i['queue'] = len(s.pending_packets)
970972
sessions.append(i)
971973
r['proxy']['sessions'] = sessions
974+
if driver.is_on('service_proxy_server'):
975+
from bitdust.transport.proxy import proxy_router
976+
if proxy_router.A():
977+
r['proxy']['routes'] = []
978+
for v in proxy_router.A().routes.values():
979+
_r = v['connection_info'].copy()
980+
_r['contacts'] = ', '.join(['{}:{}'.format(c[0], c[1]) for c in v['contacts']])
981+
_r['address'] = ', '.join(['{}:{}'.format(a[0], a[1]) for a in v['address']])
982+
_r.pop('id', None)
983+
_r.pop('index', None)
984+
r['proxy']['routes'].append(_r)
985+
r['proxy']['closed_routes'] = [(strng.to_text(k), strng.to_text(v)) for k, v in proxy_router.A().closed_routes.items()]
986+
r['proxy']['acks'] = len(proxy_router.A().acks)
987+
r['proxy']['hosts'] = ', '.join([('{}://{}:{}'.format(strng.to_text(k), strng.to_text(v[0]), strng.to_text(v[1]))) for k, v in proxy_router.A().my_hosts.items()])
972988
if dht:
973989
from bitdust.dht import dht_service
974990
r['dht'] = {}
@@ -2292,7 +2308,7 @@ def file_delete(remote_path):
22922308
backup_fs.DeleteLocalDir(settings.getLocalBackupsDir(), pathIDfull)
22932309
backup_fs.DeleteByID(pathID, iter=backup_fs.fs(customer_idurl, key_alias), iterID=backup_fs.fsID(customer_idurl, key_alias))
22942310
backup_fs.Scan(customer_idurl=customer_idurl, key_alias=key_alias)
2295-
backup_fs.Calculate(iterID=backup_fs.fsID(customer_idurl, key_alias))
2311+
backup_fs.Calculate(customer_idurl=customer_idurl, key_alias=key_alias)
22962312
if key_alias != 'master':
22972313
if driver.is_on('service_shared_data'):
22982314
from bitdust.access import shared_access_coordinator
@@ -2428,33 +2444,17 @@ def file_upload_start(local_path, remote_path, wait_result=False, publish_events
24282444
if not pathID:
24292445
return ERROR('path %s was not registered yet' % remote_path)
24302446
keyID = my_keys.make_key_id(alias=key_alias, creator_glob_id=parts['customer'])
2431-
# customerID = global_id.MakeGlobalID(customer=parts['customer'], key_alias=key_alias)
24322447
pathIDfull = packetid.MakeBackupID(keyID, pathID)
24332448
if key_alias != 'master':
24342449
if not driver.is_on('service_shared_data'):
24352450
return ERROR('service_shared_data() is not started')
2436-
2437-
2438-
# def _restart_active_share(result):
2439-
# if _Debug:
2440-
# lg.args(_DebugLevel, result=result, key_id=keyID, path=path, pathID=pathID)
2441-
# if key_alias != 'master':
2442-
# from bitdust.access import shared_access_coordinator
2443-
# active_share = shared_access_coordinator.get_active_share(keyID)
2444-
# if not active_share:
2445-
# active_share = shared_access_coordinator.SharedAccessCoordinator(key_id=keyID, publish_events=publish_events)
2446-
# active_share.automat('restart')
2447-
# return result
2448-
24492451
if wait_result:
24502452
task_created_defer = Deferred()
24512453
tsk = backup_control.StartSingle(
24522454
pathID=pathIDfull,
24532455
localPath=local_path,
24542456
keyID=keyID,
24552457
)
2456-
# if key_alias != 'master':
2457-
# tsk.result_defer.addCallback(_restart_active_share)
24582458
tsk.result_defer.addCallback(
24592459
lambda result: task_created_defer.callback(
24602460
OK(
@@ -2470,15 +2470,16 @@ def file_upload_start(local_path, remote_path, wait_result=False, publish_events
24702470
)
24712471
)
24722472
)
2473-
tsk.result_defer.addErrback(lambda result: task_created_defer.callback(ERROR(
2474-
'uploading task %d for %s failed: %s' % (
2475-
tsk.number,
2476-
tsk.pathID,
2477-
result[1],
2478-
),
2479-
api_method='file_upload_start',
2480-
), ), )
2481-
backup_fs.Calculate(iterID=backup_fs.fsID(customer_idurl, key_alias))
2473+
tsk.result_defer.addErrback(lambda result: task_created_defer.callback(ERROR(result, api_method='file_upload_start')))
2474+
# tsk.result_defer.addErrback(lambda result: task_created_defer.callback(ERROR(
2475+
# 'uploading task %d for %s failed: %s' % (
2476+
# tsk.number,
2477+
# tsk.pathID,
2478+
# result,
2479+
# ),
2480+
# api_method='file_upload_start',
2481+
# ), ), )
2482+
backup_fs.Calculate(customer_idurl=customer_idurl, key_alias=key_alias)
24822483
backup_control.SaveFSIndex(customer_idurl, key_alias)
24832484
if _Debug:
24842485
lg.out(_DebugLevel, 'api.file_upload_start %s with %s, wait_result=True' % (remote_path, pathIDfull))
@@ -2489,10 +2490,8 @@ def file_upload_start(local_path, remote_path, wait_result=False, publish_events
24892490
localPath=local_path,
24902491
keyID=keyID,
24912492
)
2492-
# if key_alias != 'master':
2493-
# tsk.result_defer.addCallback(_restart_active_share)
2494-
tsk.result_defer.addErrback(lambda result: lg.err('errback from api.file_upload_start.task(%s) failed with %s' % (result[0], result[1])))
2495-
backup_fs.Calculate(iterID=backup_fs.fsID(customer_idurl, key_alias))
2493+
tsk.result_defer.addErrback(lambda result: lg.err('errback from api.file_upload_start.task() failed with %r' % result))
2494+
backup_fs.Calculate(customer_idurl=customer_idurl, key_alias=key_alias)
24962495
backup_control.SaveFSIndex(customer_idurl, key_alias)
24972496
if _Debug:
24982497
lg.out(_DebugLevel, 'api.file_upload_start %s with %s' % (remote_path, pathIDfull))

bitdust/p2p/p2p_service.py

+92
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@
5151

5252
#------------------------------------------------------------------------------
5353

54+
from twisted.internet.defer import Deferred
55+
56+
#------------------------------------------------------------------------------
57+
5458
from bitdust.logs import lg
5559

5660
from bitdust.contacts import contactsdb
@@ -66,8 +70,11 @@
6670
from bitdust.crypt import signed
6771
from bitdust.crypt import my_keys
6872

73+
from bitdust.services import driver
74+
6975
from bitdust.transport import gateway
7076
from bitdust.transport import callback
77+
from bitdust.transport import packet_out
7178

7279
from bitdust.userid import my_id
7380

@@ -195,6 +202,91 @@ def outbox(outpacket, wide, callbacks, target=None, route=None, response_timeout
195202
#------------------------------------------------------------------------------
196203

197204

205+
def on_request_service_received(newpacket, info):
206+
if len(newpacket.Payload) > 1024*10:
207+
lg.warn('too long payload')
208+
SendFail(newpacket, 'too long payload')
209+
return True
210+
try:
211+
json_payload = serialization.BytesToDict(newpacket.Payload, keys_to_text=True, values_to_text=True)
212+
json_payload['name']
213+
json_payload['payload']
214+
except:
215+
lg.warn('json payload invalid')
216+
SendFail(newpacket, 'json payload invalid')
217+
return True
218+
service_name = str(json_payload['name'])
219+
if _Debug:
220+
lg.out(_Debug, 'service_p2p_hookups.RequestService {%s} from %s' % (service_name, newpacket.OwnerID))
221+
if not driver.is_exist(service_name):
222+
lg.warn('got wrong payload in %s' % service_name)
223+
SendFail(newpacket, 'service %s not exist' % service_name)
224+
return True
225+
if not driver.is_on(service_name):
226+
SendFail(newpacket, 'service %s is off' % service_name)
227+
return True
228+
try:
229+
result = driver.request(service_name, json_payload['payload'], newpacket, info)
230+
except:
231+
lg.exc()
232+
SendFail(newpacket, 'request processing failed with exception')
233+
return True
234+
if not result:
235+
if _Debug:
236+
lg.out(_Debug, 'service_p2p_hookups._send_request_service SKIP request %s' % service_name)
237+
return False
238+
if isinstance(result, Deferred):
239+
if _Debug:
240+
lg.out(_Debug, 'service_p2p_hookups._send_request_service fired delayed execution')
241+
elif isinstance(result, packet_out.PacketOut):
242+
if _Debug:
243+
lg.out(_Debug, 'service_p2p_hookups._send_request_service outbox packet sent')
244+
return True
245+
246+
247+
def on_cancel_service_received(newpacket, info):
248+
if len(newpacket.Payload) > 1024*10:
249+
SendFail(newpacket, 'too long payload')
250+
return True
251+
try:
252+
json_payload = serialization.BytesToDict(newpacket.Payload, keys_to_text=True, values_to_text=True)
253+
json_payload['name']
254+
json_payload['payload']
255+
except:
256+
SendFail(newpacket, 'json payload invalid')
257+
return True
258+
service_name = json_payload['name']
259+
if _Debug:
260+
lg.out(_Debug, 'service_p2p_hookups.CancelService {%s} from %s' % (service_name, newpacket.OwnerID))
261+
if not driver.is_exist(service_name):
262+
lg.warn('got wrong payload in %s' % newpacket)
263+
SendFail(newpacket, 'service %s not exist' % service_name)
264+
return True
265+
if not driver.is_on(service_name):
266+
SendFail(newpacket, 'service %s is off' % service_name)
267+
return True
268+
try:
269+
result = driver.cancel(service_name, json_payload['payload'], newpacket, info)
270+
except:
271+
lg.exc()
272+
SendFail(newpacket, 'request processing failed with exception')
273+
return True
274+
if not result:
275+
if _Debug:
276+
lg.out(_Debug, 'service_p2p_hookups._send_cancel_service SKIP request %s' % service_name)
277+
return False
278+
if isinstance(result, Deferred):
279+
if _Debug:
280+
lg.out(_Debug, 'service_p2p_hookups._send_cancel_service fired delayed execution')
281+
elif isinstance(result, packet_out.PacketOut):
282+
if _Debug:
283+
lg.out(_Debug, 'service_p2p_hookups._send_cancel_service outbox packet sent')
284+
return True
285+
286+
287+
#------------------------------------------------------------------------------
288+
289+
198290
def Ack(newpacket, info):
199291
if _Debug:
200292
lg.out(_DebugLevel, 'p2p_service.Ack %s from [%s] at %s://%s with %d bytes payload' % (newpacket.PacketID, nameurl.GetName(newpacket.CreatorID), info.proto, info.host, len(newpacket.Payload)))

bitdust/services/driver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ def _on_started(start_result, stop_result, dependencies_results):
474474

475475
def _on_failed(err):
476476
lg.warn('failed service %s in driver.restart() : %r' % (service_name, err))
477-
restart_result.errback(str(err))
477+
restart_result.errback(Exception(str(err)))
478478
return None
479479

480480
def _do_start(stop_result=None, dependencies_results=None):

0 commit comments

Comments
 (0)