diff --git a/app/library/cache.py b/app/library/cache.py index ea130af..a576f45 100644 --- a/app/library/cache.py +++ b/app/library/cache.py @@ -22,6 +22,24 @@ class Cache(object): value=data ) + def get_tor_url(self, codename): + key_name = f'node_{codename}_tor_url' + data = self.redis.get(key_name) + if data: + current_app.logger.info(f'HIT - {key_name}') + return data + else: + current_app.logger.info(f'MISS - {key_name}') + try: + dns = f'{codename}.node.{config.DO_DOMAIN}' + url = f'https://{dns}/tor/' + r = r_get(url, timeout=6) + data = r.text.strip() + self.store_data(key_name, 86400, data) + return data + except: + return {'error': 'true'} + def get_info(self, codename): key_name = f'node_{codename}_info' data = self.redis.get(key_name) diff --git a/app/models.py b/app/models.py index 8e033bc..24a4d12 100644 --- a/app/models.py +++ b/app/models.py @@ -29,6 +29,10 @@ class Operation(db.Model): record_v4_id = db.Column(db.Integer, unique=True, nullable=True) record_v6_id = db.Column(db.Integer, unique=True, nullable=True) + def get_node_tor_url(self): + u = cache.get_tor_url(self.codename) + return u.decode() + def get_node_url(self): return f'{self.codename}.node.{config.DO_DOMAIN}' diff --git a/app/templates/index.html b/app/templates/index.html index 4a7b4bb..45db43f 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -37,7 +37,11 @@