Skip to content

Commit 0cb45f3

Browse files
committed
solved issue with correct web socket router url returned in the API
1 parent c291623 commit 0cb45f3

File tree

4 files changed

+12
-13
lines changed

4 files changed

+12
-13
lines changed

bitdust/interface/api.py

-5
Original file line numberDiff line numberDiff line change
@@ -803,11 +803,6 @@ def device_remove(name):
803803
websocket.send('{"command": "api_call", "method": "device_remove", "kwargs": {"name": "my_iPhone_12"} }');
804804
"""
805805
from bitdust.interface import api_device
806-
if api_device.instances(name):
807-
try:
808-
api_device.stop_device(name)
809-
except Exception as exc:
810-
return ERROR(exc)
811806
try:
812807
api_device.remove_device(name)
813808
except Exception as exc:

bitdust/interface/api_device.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -269,16 +269,15 @@ def add_routed_device(device_name, key_size=4096):
269269
def remove_device(device_name):
270270
validate_device_name(device_name)
271271
device_key_object = devices(device_name)
272-
if not device_key_object:
273-
raise Exception('device %r does not exist' % device_name)
274272
if instances(device_name):
275273
stop_device(device_name)
276274
device_file_path = os.path.join(settings.DevicesDir(), device_name)
277-
if not os.path.isfile(device_file_path):
275+
if os.path.isfile(device_file_path):
276+
os.remove(device_file_path)
277+
else:
278278
lg.warn('device info file %s does not exist' % device_file_path)
279-
return True
280-
os.remove(device_file_path)
281-
devices().pop(device_name, None)
279+
if device_key_object:
280+
devices().pop(device_name, None)
282281
if _Debug:
283282
lg.args(_DebugLevel, device_name=device_name, device_file_path=device_file_path)
284283
return True

bitdust/interface/routed_web_socket.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,8 @@ def on_incoming_message(self, url, json_data):
459459
return True
460460
cmd = json_data.get('cmd')
461461
if cmd == 'api':
462+
if self.active_router_url and self.active_router_url != url:
463+
lg.warn('active web socket router %r switched to %r' % (self.active_router_url, url))
462464
self.active_router_url = url
463465
self.client_connected = True
464466
self.event('api-message', url=url, json_data=json_data)
@@ -477,6 +479,8 @@ def on_incoming_message(self, url, json_data):
477479
lg.exc()
478480
self.automat('auth-error')
479481
return False
482+
if self.active_router_url and self.active_router_url != url:
483+
lg.warn('active web socket router %r switched to %r' % (self.active_router_url, url))
480484
self.active_router_url = url
481485
self.automat('client-pub-key-received', client_key_object=client_key_object)
482486
return True
@@ -934,7 +938,8 @@ def _on_web_socket_handshake_accepted(self, url, route_url):
934938
if url in self.connecting_routers:
935939
self.connecting_routers.remove(url)
936940
if not self.active_router_url:
937-
self.active_router_url = route_url
941+
self.active_router_url = url
942+
lg.info('connected active web socket router %r' % self.active_router_url)
938943
self.handshaked_routers.append(route_url)
939944
handshaked_count = len(self.handshaked_routers)
940945
if _Debug:

bitdust_forks/Bismuth/connectionmanager.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,4 @@ def connection_manager(self):
7171
if not self.node.IS_STOPPING:
7272
time.sleep(1)
7373
except Exception as e:
74-
self.node.logger.app_log.warning(f'Error in connection manger ({e})')
74+
self.node.logger.app_log.warning(f'Error in connection manager ({e})')

0 commit comments

Comments
 (0)