config: activate discovery_method

parent b53075de
......@@ -39,7 +39,6 @@ DEFAULTS = {
'DATA_DIR': '/var/lib/beiran',
'CACHE_DIR': '/var/cache/beiran',
'RUN_DIR': '/var/run',
'DISCOVERY_METHOD': 'zeroconf',
'KNOWN_NODES': [],
}
......@@ -233,7 +232,7 @@ class Config(metaclass=ConfigMeta):
def discovery_method(self):
"""
Service discovery method for beiran daemons to find each
others. The default value is ``zeroconf``. It can be eighter
others. The default value is ``None``. It can be eighter
``zeroconf``, ``dns`` or any other discovery plugins name.
config.toml: section ``beiran``, key ``discovery_method``
......
......@@ -286,7 +286,7 @@ class BeiranDaemon(EventEmitter):
})
# Only one discovery plugin at a time is supported (for now)
if plugin['type'] == 'discovery':
if plugin['type'] == 'discovery' and plugin['name'] == config.discovery_method:
Services.plugins['discovery'] = _plugin_obj
else:
Services.plugins['%s:%s' % (plugin['type'], plugin['name'])] = _plugin_obj
......
......@@ -27,6 +27,7 @@ from urllib.parse import urlparse
import re
from datetime import datetime
from peewee import IntegerField, CharField, UUIDField
from beiran.config import config
from beiran.models.base import BaseModel, JSONStringField
from beiran.log import build_logger
......@@ -189,7 +190,7 @@ class PeerAddress(BaseModel): # pylint: disable=too-many-instance-attributes
@classmethod
def add_or_update(cls, uuid: str, address: str,
discovery: str = None, config: dict = None) -> None:
discovery: str = None, paconfig: dict = None) -> None:
"""
Update with or create a new peer_address object from provided information.
......@@ -197,7 +198,7 @@ class PeerAddress(BaseModel): # pylint: disable=too-many-instance-attributes
uuid (str): uuid
address (str): address
discovery (str): discovery channel
config (dict): config dict
paconfig (dict): paconfig dict
Returns:
......@@ -209,10 +210,9 @@ class PeerAddress(BaseModel): # pylint: disable=too-many-instance-attributes
_self = cls(uuid=uuid, address=address)
_self.last_seen_at = int(datetime.now().timestamp())
if config:
_self.config = config
if discovery:
_self.discovery_method = discovery
if paconfig:
_self.config = paconfig
_self.discovery_method = discovery if discovery else config.discovery_method
_self.save()
@staticmethod
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment