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
|
cache = None
|
||||||
connected_websockets = set()
|
connected_websockets = set()
|
||||||
api_data = {}
|
api_data = {}
|
||||||
nodes = {}
|
|
||||||
user_agents = None
|
user_agents = None
|
||||||
txfiatdb = None
|
txfiatdb = None
|
||||||
|
|
||||||
|
@ -53,17 +52,16 @@ def create_app():
|
||||||
|
|
||||||
@app.before_serving
|
@app.before_serving
|
||||||
async def startup():
|
async def startup():
|
||||||
global nodes, txfiatdb, user_agents
|
global txfiatdb, user_agents
|
||||||
await _setup_cache(app)
|
await _setup_cache(app)
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
f = open("data/nodes.json", "r")
|
with open('data/nodes.json', 'r') as f:
|
||||||
nodes = json.loads(f.read())
|
nodes = json.loads(f.read())
|
||||||
f.close()
|
cache.execute('JSON.SET', 'nodes', '.', json.dumps(nodes))
|
||||||
|
|
||||||
f = open("data/user_agents.txt", "r")
|
with open('data/user_agents.txt', 'r') as f:
|
||||||
user_agents = [l.strip() for l in f.readlines() if l.strip()]
|
user_agents = [l.strip() for l in f.readlines() if l.strip()]
|
||||||
f.close()
|
|
||||||
|
|
||||||
from fapi.fapi import FeatherApi
|
from fapi.fapi import FeatherApi
|
||||||
from fapi.utils import loopyloop, TxFiatDb, XmrRig
|
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:
|
except Exception as ex:
|
||||||
app.logger.error(f"Redis error: {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
|
@staticmethod
|
||||||
async def xmrto_rates():
|
async def xmrto_rates():
|
||||||
from fapi.factory import app, cache
|
from fapi.factory import app, cache
|
||||||
|
@ -338,7 +348,10 @@ class FeatherApi:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def check_nodes():
|
async def check_nodes():
|
||||||
from fapi.factory import nodes, app
|
from fapi.factory import app
|
||||||
|
|
||||||
|
nodes = await FeatherApi.redis_json_get("nodes")
|
||||||
|
|
||||||
data = []
|
data = []
|
||||||
for network_type, network_name in nodes.items():
|
for network_type, network_name in nodes.items():
|
||||||
for k, _nodes in nodes[network_type].items():
|
for k, _nodes in nodes[network_type].items():
|
||||||
|
@ -362,6 +375,11 @@ class FeatherApi:
|
||||||
"nettype": blob["nettype"],
|
"nettype": blob["nettype"],
|
||||||
"type": k
|
"type": k
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Filter out nodes affected by < v0.17.1.3 sybil attack
|
||||||
|
if _node['target_height'] > _node["height"]:
|
||||||
|
continue
|
||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
app.logger.warning(f"node {node} not reachable")
|
app.logger.warning(f"node {node} not reachable")
|
||||||
_node = {
|
_node = {
|
||||||
|
|
Loading…
Reference in a new issue