2023-09-16 20:29:32 +00:00
|
|
|
# This file is part of the Monero P2Pool <https://github.com/SChernykh/p2pool>
|
2024-01-02 13:06:19 +00:00
|
|
|
# Copyright (c) 2021-2024 SChernykh <https://github.com/SChernykh>
|
2023-09-16 20:29:32 +00:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, version 3.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2023-05-17 13:12:48 +00:00
|
|
|
import socket
|
|
|
|
import time
|
|
|
|
import sys
|
2023-08-14 14:10:44 +00:00
|
|
|
import json
|
2024-08-08 12:40:50 +00:00
|
|
|
import ssl
|
2023-05-17 13:12:48 +00:00
|
|
|
|
2023-08-14 14:10:44 +00:00
|
|
|
f = open('stratum_dummy' + sys.argv[1] + '.log', 'wb')
|
2023-05-17 13:12:48 +00:00
|
|
|
|
2023-08-14 14:10:44 +00:00
|
|
|
f.write(b'Connecting')
|
2023-09-01 15:12:22 +00:00
|
|
|
f.flush()
|
2023-05-17 13:12:48 +00:00
|
|
|
|
2024-08-08 12:40:50 +00:00
|
|
|
context = ssl.create_default_context()
|
|
|
|
context.check_hostname = False
|
|
|
|
context.verify_mode = ssl.CERT_NONE
|
|
|
|
|
2023-09-01 16:20:50 +00:00
|
|
|
while True:
|
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
sock.settimeout(1)
|
|
|
|
sock.setblocking(True)
|
|
|
|
|
2024-08-08 12:40:50 +00:00
|
|
|
if (sys.argv[1] == '1'):
|
|
|
|
sock = context.wrap_socket(sock);
|
|
|
|
|
2023-09-01 16:20:50 +00:00
|
|
|
if sock.connect_ex(('127.0.0.1', 3333)) == 0:
|
|
|
|
break;
|
|
|
|
|
|
|
|
sock.close()
|
|
|
|
|
2023-08-14 14:10:44 +00:00
|
|
|
f.write(b'.')
|
2023-09-01 15:12:22 +00:00
|
|
|
f.flush()
|
2023-05-17 13:12:48 +00:00
|
|
|
print('.')
|
|
|
|
time.sleep(1)
|
|
|
|
|
2023-08-14 14:10:44 +00:00
|
|
|
f.write(b'\n')
|
2023-09-01 15:12:22 +00:00
|
|
|
f.flush()
|
2023-08-14 14:10:44 +00:00
|
|
|
|
|
|
|
diff = ''
|
2023-05-25 07:44:44 +00:00
|
|
|
|
|
|
|
if (sys.argv[1] == '2'):
|
2023-08-14 14:10:44 +00:00
|
|
|
diff = '+1000'
|
2023-05-25 07:44:44 +00:00
|
|
|
if (sys.argv[1] == '3'):
|
2023-08-14 14:10:44 +00:00
|
|
|
diff = '+10000000'
|
|
|
|
|
|
|
|
msg_id = 1
|
2023-05-25 07:44:44 +00:00
|
|
|
|
2023-08-14 14:10:44 +00:00
|
|
|
request = '{"id":' + str(msg_id) + ',"method":"login","params":{"login":"x' + diff + '"}}\n'
|
|
|
|
msg_id += 1
|
|
|
|
s = '-> ' + request
|
|
|
|
print(s, end='')
|
2023-05-25 07:44:44 +00:00
|
|
|
sock.sendall(request.encode('utf-8'))
|
2023-05-17 13:12:48 +00:00
|
|
|
|
2023-08-14 14:10:44 +00:00
|
|
|
f.write(s.encode('utf-8'))
|
|
|
|
f.flush()
|
|
|
|
|
|
|
|
rpc_id = ''
|
|
|
|
|
2023-05-17 13:12:48 +00:00
|
|
|
while True:
|
|
|
|
data = sock.recv(1024)
|
|
|
|
if len(data) == 0:
|
2023-08-14 14:10:44 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
s = '<- ' + data.decode('utf-8')
|
|
|
|
print(s, end='')
|
|
|
|
|
|
|
|
f.write(s.encode('utf-8'))
|
2023-05-17 13:12:48 +00:00
|
|
|
f.flush()
|
2023-08-14 14:10:44 +00:00
|
|
|
|
|
|
|
obj = json.loads(data)
|
|
|
|
job_id = ''
|
|
|
|
|
|
|
|
if ('method' in obj) and ('params' in obj) and (obj['method'] == 'job'):
|
|
|
|
job_id = obj['params']['job_id']
|
|
|
|
target = obj['params']['target']
|
2023-08-14 19:57:38 +00:00
|
|
|
elif ('result' in obj) and ('job' in obj['result']):
|
2023-08-14 14:10:44 +00:00
|
|
|
if ('id' in obj['result']):
|
|
|
|
rpc_id = obj['result']['id']
|
|
|
|
job_id = obj['result']['job']['job_id']
|
|
|
|
target = obj['result']['job']['target']
|
|
|
|
|
|
|
|
if (job_id != ''):
|
|
|
|
if (msg_id < 4):
|
|
|
|
result = ('f' if (msg_id == 2) else '0') * 64
|
|
|
|
request = '{"id":' + str(msg_id) + ',"method":"submit","params":{"id":"' + rpc_id + '","job_id":"' + job_id + '","nonce":"ffffffff","result":"' + result + '"}}\n'
|
2023-08-14 19:57:38 +00:00
|
|
|
elif (msg_id == 4):
|
2023-08-14 14:10:44 +00:00
|
|
|
request = '{"id":' + str(msg_id) + ',"method":"keepalived"}\n'
|
2023-08-14 19:57:38 +00:00
|
|
|
else:
|
|
|
|
t = bytearray.fromhex(target)
|
|
|
|
for i in range(len(t)):
|
|
|
|
if (t[i] > 0):
|
|
|
|
t[i] -= 1
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
t[i] = 255
|
|
|
|
|
2023-08-15 06:00:11 +00:00
|
|
|
result = ('f' * (64 - len(target))) + t.hex()
|
2023-08-14 19:57:38 +00:00
|
|
|
request = '{"id":' + str(msg_id) + ',"method":"submit","params":{"id":"' + rpc_id + '","job_id":"' + job_id + '","nonce":"ffffffff","result":"' + result + '"}}\n'
|
2023-08-14 14:10:44 +00:00
|
|
|
|
|
|
|
msg_id += 1
|
|
|
|
s = '-> ' + request
|
|
|
|
print(s, end='')
|
|
|
|
sock.sendall(request.encode('utf-8'))
|
|
|
|
|
|
|
|
f.write(s.encode('utf-8'))
|
|
|
|
f.flush()
|
2023-05-17 13:12:48 +00:00
|
|
|
|
|
|
|
sock.close()
|
|
|
|
f.close()
|