|
|
|
@ -1,3 +1,9 @@
|
|
|
|
|
import sys
|
|
|
|
|
import socket
|
|
|
|
|
from levin.section import Section
|
|
|
|
|
from levin.bucket import Bucket
|
|
|
|
|
from levin.ctypes import *
|
|
|
|
|
from levin.constants import LEVIN_SIGNATURE
|
|
|
|
|
from requests import get as r_get
|
|
|
|
|
from xmrnodes import config
|
|
|
|
|
|
|
|
|
@ -47,3 +53,52 @@ def is_onion(url: str):
|
|
|
|
|
return True
|
|
|
|
|
else:
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
def retrieve_peers():
|
|
|
|
|
try:
|
|
|
|
|
sock = socket.socket()
|
|
|
|
|
sock.connect((config.NODE_HOST, config.NODE_PORT))
|
|
|
|
|
except:
|
|
|
|
|
sys.stderr.write("unable to connect to %s:%d\n" % (config.NODE_HOST, config.NODE_PORT))
|
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
|
bucket = Bucket.create_handshake_request()
|
|
|
|
|
|
|
|
|
|
sock.send(bucket.header())
|
|
|
|
|
sock.send(bucket.payload())
|
|
|
|
|
|
|
|
|
|
buckets = []
|
|
|
|
|
peers = []
|
|
|
|
|
|
|
|
|
|
while 1:
|
|
|
|
|
buffer = sock.recv(8)
|
|
|
|
|
if not buffer:
|
|
|
|
|
sys.stderr.write("Invalid response; exiting\n")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if not buffer.startswith(bytes(LEVIN_SIGNATURE)):
|
|
|
|
|
sys.stderr.write("Invalid response; exiting\n")
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
bucket = Bucket.from_buffer(signature=buffer, sock=sock)
|
|
|
|
|
buckets.append(bucket)
|
|
|
|
|
|
|
|
|
|
if bucket.command == 1001:
|
|
|
|
|
peers = bucket.get_peers() or []
|
|
|
|
|
|
|
|
|
|
for peer in peers:
|
|
|
|
|
try:
|
|
|
|
|
print('')
|
|
|
|
|
peers.append('http://{}:{}'.format(
|
|
|
|
|
peer['ip'].ip, peer['port'].value
|
|
|
|
|
))
|
|
|
|
|
except:
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
sock.close()
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if peers:
|
|
|
|
|
return peers
|
|
|
|
|
else:
|
|
|
|
|
return None
|
|
|
|
|