check zmq ports for p2pool compat

check-zmq
lza_menace 2 years ago
parent b0df1f66c4
commit eda876346a

@ -1,7 +1,7 @@
setup: setup:
python3 -m venv .venv python3 -m venv .venv
.venv/bin/pip install -r requirements.txt .venv/bin/pip install -r requirements.txt
mkdir data mkdir -p data
wget https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb -P data wget https://github.com/P3TERX/GeoLite.mmdb/raw/download/GeoLite2-City.mmdb -P data
up: up:

@ -7,3 +7,4 @@ flask_wtf
pysocks pysocks
git+https://github.com/cdiv1e12/py-levin git+https://github.com/cdiv1e12/py-levin
geoip2 geoip2
zmq

@ -1,21 +1,18 @@
import json import json
import re import re
import logging import logging
from os import makedirs
from random import shuffle from random import shuffle
from socket import gethostbyname_ex
from datetime import datetime, timedelta from datetime import datetime, timedelta
import geoip2.database import geoip2.database
import arrow import arrow
import requests import requests
import click
from flask import Flask, request, redirect, jsonify from flask import Flask, request, redirect, jsonify
from flask import render_template, flash, url_for from flask import render_template, flash
from urllib.parse import urlparse, urlencode from urllib.parse import urlparse, urlencode
from xmrnodes.helpers import determine_crypto, is_onion, make_request from xmrnodes.helpers import determine_crypto, is_onion, make_request
from xmrnodes.helpers import retrieve_peers, rw_cache, get_highest_block from xmrnodes.helpers import retrieve_peers, rw_cache, get_highest_block, check_zmq
from xmrnodes.forms import SubmitNode from xmrnodes.forms import SubmitNode
from xmrnodes.models import Node, HealthCheck, Peer from xmrnodes.models import Node, HealthCheck, Peer
from xmrnodes import config from xmrnodes import config
@ -163,6 +160,13 @@ def cleanup_health_checks():
print("Deleting check", check.id) print("Deleting check", check.id)
check.delete_instance() check.delete_instance()
@app.cli.command("zmq")
def get_zmq():
# nodes = Node.select().where(Node.validated == True)
# for node in nodes:
# check_zmq(node.url)
check_zmq('http://monero.10z.com.ar:18089')
@app.cli.command("check") @app.cli.command("check")
def check(): def check():
cleanup_health_checks() cleanup_health_checks()

@ -1,10 +1,12 @@
import sys import sys
import socket import socket
import pickle import pickle
from time import sleep
from os import path from os import path
import zmq
from requests import get as r_get from requests import get as r_get
from levin.section import Section from urllib.parse import urlparse
from levin.bucket import Bucket from levin.bucket import Bucket
from levin.ctypes import * from levin.ctypes import *
from levin.constants import LEVIN_SIGNATURE from levin.constants import LEVIN_SIGNATURE
@ -13,6 +15,29 @@ from xmrnodes.models import Node
from xmrnodes import config from xmrnodes import config
def check_zmq(url: str):
# print(url.split('://'))
node_socket = urlparse(url).netloc
node_url = node_socket.split(':')[0]
port = 18084
tcp_node = f'tcp://{node_url}:{port}'
print('Checking ZMQ for node {}'.format(tcp_node))
try:
ctx = zmq.Context()
subscriber = ctx.socket(zmq.SUB)
subscriber.setsockopt_string(zmq.SUBSCRIBE, '')
subscriber.setsockopt(zmq.CONFLATE, 1)
subscriber.connect(tcp_node)
# data = subscriber.recv()
count = 0
while count < 5:
data = subscriber.recv_multipart()
count += 1
print('success: {}'.format(data))
ctx.term()
except Exception as e:
print(e)
def make_request(url: str, path="/get_info", data=None): def make_request(url: str, path="/get_info", data=None):
headers = {"Origin": "https://monero.fail"} headers = {"Origin": "https://monero.fail"}
if is_onion(url): if is_onion(url):

Loading…
Cancel
Save