From 9369b598fa3ac8dad0d4725eda213d83298c42a1 Mon Sep 17 00:00:00 2001 From: Izalia Mae Date: Fri, 18 Nov 2022 14:10:39 -0500 Subject: [PATCH] add software name for inboxes --- relay/application.py | 11 ++++++----- relay/database.py | 14 +++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/relay/application.py b/relay/application.py index cc2815b..6c17d16 100644 --- a/relay/application.py +++ b/relay/application.py @@ -9,7 +9,7 @@ from datetime import datetime, timedelta from .config import RelayConfig from .database import RelayDatabase -from .misc import DotDict, check_open_port, set_app +from .misc import DotDict, check_open_port, fetch_nodeinfo, set_app from .views import routes @@ -25,15 +25,16 @@ class Application(web.Application): if not self['config'].load(): self['config'].save() - self['database'] = RelayDatabase(self['config']) - self['database'].load() - self['cache'] = DotDict({key: Cache(maxsize=self['config'][key]) for key in self['config'].cachekeys}) self['semaphore'] = asyncio.Semaphore(self['config'].push_limit) - self.set_signal_handler() set_app(self) + self['database'] = RelayDatabase(self['config']) + self['database'].load() + + self.set_signal_handler() + @property def cache(self): diff --git a/relay/database.py b/relay/database.py index 90b1473..b79c0aa 100644 --- a/relay/database.py +++ b/relay/database.py @@ -1,3 +1,4 @@ +import asyncio import json import logging import traceback @@ -5,6 +6,8 @@ import traceback from Crypto.PublicKey import RSA from urllib.parse import urlparse +from .misc import fetch_nodeinfo + class RelayDatabase(dict): def __init__(self, config): @@ -75,9 +78,18 @@ class RelayDatabase(dict): else: self['relay-list'] = data.get('relay-list', {}) - for domain in self['relay-list'].keys(): + for domain, instance in self['relay-list'].items(): if self.config.is_banned(domain) or (self.config.whitelist_enabled and not self.config.is_whitelisted(domain)): self.del_inbox(domain) + continue + + if not instance.get('software'): + nodeinfo = asyncio.run(fetch_nodeinfo(domain)) + + if not nodeinfo: + continue + + instance['software'] = nodeinfo.swname new_db = False