mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
network: Fix selection when no networks are specified.
This commit is contained in:
@@ -76,6 +76,7 @@ class BaseApp(DBMethods):
|
|||||||
|
|
||||||
self._enabled_log_categories = set()
|
self._enabled_log_categories = set()
|
||||||
for category in self.settings.get("enabled_log_categories", []):
|
for category in self.settings.get("enabled_log_categories", []):
|
||||||
|
category = category.lower()
|
||||||
if category == "net":
|
if category == "net":
|
||||||
self._enabled_log_categories.add(LC.NET)
|
self._enabled_log_categories.add(LC.NET)
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -2336,6 +2336,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
|
|||||||
security_token=security_token,
|
security_token=security_token,
|
||||||
from_feerate=msg_buf.fee_rate_from,
|
from_feerate=msg_buf.fee_rate_from,
|
||||||
to_feerate=msg_buf.fee_rate_to,
|
to_feerate=msg_buf.fee_rate_to,
|
||||||
|
pk_from=self.getPubkeyForAddress(cursor, offer_addr),
|
||||||
auto_accept_type=msg_buf.auto_accept_type,
|
auto_accept_type=msg_buf.auto_accept_type,
|
||||||
message_nets=msg_buf.message_nets,
|
message_nets=msg_buf.message_nets,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
import base64
|
import base64
|
||||||
import json
|
import json
|
||||||
import random
|
|
||||||
import zmq
|
import zmq
|
||||||
|
|
||||||
from basicswap.basicswap_util import (
|
from basicswap.basicswap_util import (
|
||||||
@@ -134,12 +133,22 @@ class BSXNetwork:
|
|||||||
and self.coin_clients[Coins.PART]["core_version"] > 23020700
|
and self.coin_clients[Coins.PART]["core_version"] > 23020700
|
||||||
):
|
):
|
||||||
self._can_use_smsg_payload2 = True
|
self._can_use_smsg_payload2 = True
|
||||||
|
|
||||||
|
self.log.debug(f'"can_use_smsg_payload2": {self._can_use_smsg_payload2}')
|
||||||
# Set smsg_payload_version automatically if it's unset
|
# Set smsg_payload_version automatically if it's unset
|
||||||
|
was_set: bool = False
|
||||||
|
if self._smsg_payload_version == 0:
|
||||||
self._smsg_payload_version = int(
|
self._smsg_payload_version = int(
|
||||||
self.settings.get(
|
self.settings.get(
|
||||||
"smsg_payload_version", 2 if self._can_use_smsg_payload2 else 1
|
"smsg_payload_version", 2 if self._can_use_smsg_payload2 else 1
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
was_set = True
|
||||||
|
self.log.debug(
|
||||||
|
'{}"smsg_payload_version": {}'.format(
|
||||||
|
"Set " if was_set else "", self._smsg_payload_version
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
have_smsg: bool = False
|
have_smsg: bool = False
|
||||||
for network in network_config_list:
|
for network in network_config_list:
|
||||||
@@ -382,14 +391,12 @@ class BSXNetwork:
|
|||||||
remote_active_network_ids, remote_bridged_network_ids = self.expandMessageNets(
|
remote_active_network_ids, remote_bridged_network_ids = self.expandMessageNets(
|
||||||
remote_message_nets
|
remote_message_nets
|
||||||
)
|
)
|
||||||
|
if len(received_on_network_ids) < 1:
|
||||||
|
self.log.debug("selectMessageNetString: received_on_network_ids is empty.")
|
||||||
|
received_on_network_ids.append(MessageNetworks.SMSG)
|
||||||
# If no data was sent it must be from an old version
|
# If no data was sent it must be from an old version
|
||||||
if (
|
if len(remote_active_network_ids) < 1 and len(remote_bridged_network_ids) < 1:
|
||||||
len(remote_active_network_ids) < 1
|
return networkIDToType(received_on_network_ids[0])
|
||||||
and len(remote_bridged_network_ids) < 1
|
|
||||||
and len(received_on_network_ids) < 1
|
|
||||||
):
|
|
||||||
return networkIDToType(random.choice(tuple(active_networks_set)))
|
|
||||||
|
|
||||||
# Choose which network to respond on
|
# Choose which network to respond on
|
||||||
# Pick the received on network if it's in the local node's active networks and the list of remote node's active networks
|
# Pick the received on network if it's in the local node's active networks and the list of remote node's active networks
|
||||||
@@ -433,10 +440,11 @@ class BSXNetwork:
|
|||||||
)
|
)
|
||||||
for row in rows:
|
for row in rows:
|
||||||
# TODO: rank networks
|
# TODO: rank networks
|
||||||
network_id = row
|
network_id = row[0]
|
||||||
received_on_network_ids.add(network_id)
|
received_on_network_ids.add(network_id)
|
||||||
|
return self.selectMessageNetString(
|
||||||
return self.selectMessageNetString(received_on_network_ids, remote_message_nets)
|
list(received_on_network_ids), remote_message_nets
|
||||||
|
)
|
||||||
|
|
||||||
def expandMessageNets(self, message_nets: str) -> (list, list):
|
def expandMessageNets(self, message_nets: str) -> (list, list):
|
||||||
if message_nets is None or len(message_nets) < 1:
|
if message_nets is None or len(message_nets) < 1:
|
||||||
|
|||||||
Reference in New Issue
Block a user