adding height and check func

This commit is contained in:
lza_menace 2020-10-17 16:27:54 -07:00
parent 73c608caac
commit 3d238846b8
4 changed files with 33 additions and 3 deletions

View File

@ -33,7 +33,7 @@ def index():
flash("Wow, wtf hackerman. Cool it.") flash("Wow, wtf hackerman. Cool it.")
page = 1 page = 1
nodes = Node.select().where(Node.available==True).where(Node.is_monero==True).order_by( nodes = Node.select().where(Node.validated==True).where(Node.is_monero==True).order_by(
Node.datetime_entered.desc() Node.datetime_entered.desc()
) )
paginated = nodes.paginate(page, itp) paginated = nodes.paginate(page, itp)
@ -73,6 +73,32 @@ def add():
node.save() node.save()
return redirect("/") return redirect("/")
@app.cli.command("check")
def check():
nodes = Node.select().where(Node.validated == True)
for node in nodes:
now = datetime.utcnow()
logging.info(f"Attempting to check {node.url}")
try:
r = requests.get(node.url + "/get_info", timeout=5)
r.raise_for_status()
assert "status" in r.json()
assert "offline" in r.json()
assert "height" in r.json()
if r.json()["status"] == "OK":
logging.info("success")
node.available = True
node.last_height = r.json()["height"]
else:
raise
except:
logging.info("fail")
node.datetime_failed = now
node.available = False
finally:
node.datetime_checked = now
node.save()
@app.cli.command("validate") @app.cli.command("validate")
def validate(): def validate():
nodes = Node.select().where(Node.validated == False) nodes = Node.select().where(Node.validated == False)
@ -84,7 +110,7 @@ def validate():
logging.info("onion address found") logging.info("onion address found")
node.is_tor = True node.is_tor = True
try: try:
r = requests.get(node.url + "/get_info", timeout=3) r = requests.get(node.url + "/get_info", timeout=5)
r.raise_for_status() r.raise_for_status()
assert "height" in r.json() assert "height" in r.json()
assert "nettype" in r.json() assert "nettype" in r.json()
@ -94,6 +120,7 @@ def validate():
node.nettype = nettype node.nettype = nettype
node.available = True node.available = True
node.validated = True node.validated = True
node.last_height = r.json()["height"]
node.datetime_checked = now node.datetime_checked = now
node.is_monero = is_monero(node.url) node.is_monero = is_monero(node.url)
node.save() node.save()

View File

@ -8,7 +8,7 @@ def is_monero(url):
"76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb" #stagenet "76ee3cc98646292206cd3e86f74d88b4dcc1d937088645e9b0cbca84b7ce74eb" #stagenet
] ]
try: try:
r = r_get(url + "/json_rpc", json=data) r = r_get(url + "/json_rpc", json=data, timeout=5)
r.raise_for_status() r.raise_for_status()
assert "result" in r.json() assert "result" in r.json()
is_xmr = r.json()["result"]["block_header"]["hash"] in known_hashes is_xmr = r.json()["result"]["block_header"]["hash"] in known_hashes

View File

@ -13,6 +13,7 @@ class Node(Model):
available = BooleanField(default=False) available = BooleanField(default=False)
validated = BooleanField(default=False) validated = BooleanField(default=False)
nettype = CharField(null=True) nettype = CharField(null=True)
last_height = IntegerField(null=True)
is_monero = BooleanField(default=False) is_monero = BooleanField(default=False)
datetime_entered = DateTimeField(default=datetime.utcnow) datetime_entered = DateTimeField(default=datetime.utcnow)
datetime_checked = DateTimeField(default=None, null=True) datetime_checked = DateTimeField(default=None, null=True)

View File

@ -37,6 +37,7 @@
<th>Tor</th> <th>Tor</th>
<th>Available</th> <th>Available</th>
<th>Network</th> <th>Network</th>
<th>Height</th>
<th>Last Checked</th> <th>Last Checked</th>
</tr> </tr>
</thead> </thead>
@ -47,6 +48,7 @@
<td>{{ node.is_tor }}</td> <td>{{ node.is_tor }}</td>
<td>{{ node.available }}</td> <td>{{ node.available }}</td>
<td>{{ node.nettype }}</td> <td>{{ node.nettype }}</td>
<td>{{ node.last_height }}</td>
<td>{{ node.datetime_checked | humanize }}</td> <td>{{ node.datetime_checked | humanize }}</td>
</tr> </tr>
{% endfor %} {% endfor %}