mirror of
https://git.wownero.com/wowlet/wowlet-backend.git
synced 2024-08-15 01:03:13 +00:00
Load nodes from cache
This commit is contained in:
parent
19bb05a581
commit
fe8c6ba241
2 changed files with 25 additions and 9 deletions
|
@ -15,7 +15,6 @@ app = None
|
|||
cache = None
|
||||
connected_websockets = set()
|
||||
api_data = {}
|
||||
nodes = {}
|
||||
user_agents = None
|
||||
txfiatdb = None
|
||||
|
||||
|
@ -53,17 +52,16 @@ def create_app():
|
|||
|
||||
@app.before_serving
|
||||
async def startup():
|
||||
global nodes, txfiatdb, user_agents
|
||||
global txfiatdb, user_agents
|
||||
await _setup_cache(app)
|
||||
loop = asyncio.get_event_loop()
|
||||
|
||||
f = open("data/nodes.json", "r")
|
||||
nodes = json.loads(f.read())
|
||||
f.close()
|
||||
with open('data/nodes.json', 'r') as f:
|
||||
nodes = json.loads(f.read())
|
||||
cache.execute('JSON.SET', 'nodes', '.', json.dumps(nodes))
|
||||
|
||||
f = open("data/user_agents.txt", "r")
|
||||
user_agents = [l.strip() for l in f.readlines() if l.strip()]
|
||||
f.close()
|
||||
with open('data/user_agents.txt', 'r') as f:
|
||||
user_agents = [l.strip() for l in f.readlines() if l.strip()]
|
||||
|
||||
from fapi.fapi import FeatherApi
|
||||
from fapi.utils import loopyloop, TxFiatDb, XmrRig
|
||||
|
|
20
fapi/fapi.py
20
fapi/fapi.py
|
@ -23,6 +23,16 @@ class FeatherApi:
|
|||
except Exception as ex:
|
||||
app.logger.error(f"Redis error: {ex}")
|
||||
|
||||
@staticmethod
|
||||
async def redis_json_get(key, path="."):
|
||||
from fapi.factory import app, cache
|
||||
try:
|
||||
data = await cache.execute('JSON.GET', key, path)
|
||||
if data:
|
||||
return json.loads(data)
|
||||
except Exception as ex:
|
||||
app.logger.error(f"Redis error: {ex}")
|
||||
|
||||
@staticmethod
|
||||
async def xmrto_rates():
|
||||
from fapi.factory import app, cache
|
||||
|
@ -338,7 +348,10 @@ class FeatherApi:
|
|||
|
||||
@staticmethod
|
||||
async def check_nodes():
|
||||
from fapi.factory import nodes, app
|
||||
from fapi.factory import app
|
||||
|
||||
nodes = await FeatherApi.redis_json_get("nodes")
|
||||
|
||||
data = []
|
||||
for network_type, network_name in nodes.items():
|
||||
for k, _nodes in nodes[network_type].items():
|
||||
|
@ -362,6 +375,11 @@ class FeatherApi:
|
|||
"nettype": blob["nettype"],
|
||||
"type": k
|
||||
}
|
||||
|
||||
# Filter out nodes affected by < v0.17.1.3 sybil attack
|
||||
if _node['target_height'] > _node["height"]:
|
||||
continue
|
||||
|
||||
except Exception as ex:
|
||||
app.logger.warning(f"node {node} not reachable")
|
||||
_node = {
|
||||
|
|
Loading…
Reference in a new issue