Respawn after connection close

This commit is contained in:
Yanis Boucherk 2021-03-18 09:39:05 +01:00 committed by GitHub
parent 154f38f2c0
commit bc5a551e71
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 31 additions and 36 deletions

View File

@ -1,6 +1,5 @@
import socket, hashlib import socket, hashlib
# Global variables # Global variables
soc = socket.socket()
username = "user" # Edit this to your username, mind the quotes username = "user" # Edit this to your username, mind the quotes
pool_address = "51.15.127.80" pool_address = "51.15.127.80"
pool_port = 2811 pool_port = 2811
@ -8,38 +7,34 @@ pool_port = 2811
print("Starting 3DS Miner, you probably will get Output on an error.") print("Starting 3DS Miner, you probably will get Output on an error.")
while True: while True:
soc.connect((str(pool_address), int(pool_port))) # Connect to the server try:
server_version = soc.recv(3).decode() # Get server version soc = socket.socket()
print("Server is on version", server_version) soc.connect((str(pool_address), int(pool_port))) # Connect to the server
# Mining section server_version = soc.recv(3).decode() # Get server version
while True: print("Server is on version", server_version)
try: # Mining section
soc.send(bytes("JOB," + str(username) + ",ESP32", encoding="utf8")) # Send job request while True:
try:
# Don't mind the "ESP32" for now since it is in an early state soc.send(bytes("JOB," + str(username) + ",ESP32", encoding="utf8")) # Send job request
job = soc.recv(87).decode() # Get work from pool # Don't mind the "ESP32" for now since it is in an early state
job = job.split(",") # Split received data to job (job and difficulty)
difficulty = job[2] job = soc.recv(100).decode() # Get work from pool
for result in range( job = job.split(",") # Split received data to job (job and difficulty)
100 * int(difficulty) + 1 difficulty = job[2]
): # Calculate hash with difficulty for result in range(
ducos1 = hashlib.sha1( 100 * int(difficulty) + 1
str(job[0] + str(result)).encode("utf-8") ): # Calculate hash with difficulty
).hexdigest() # Generate hash ducos1 = hashlib.sha1(
if job[1] == ducos1: # If result is even with job str(job[0] + str(result)).encode("utf-8")
soc.send( ).hexdigest() # Generate hash
bytes(str(result) + "," + ",3DS Miner unstable)", encoding="utf8") if job[1] == ducos1: # If result is even with job
) # Send result of hashing algorithm to pool soc.send(
feedback = soc.recv(1024).decode() # Get feedback about the result bytes(str(result) + "," + ",3DS Miner unstable)", encoding="utf8")
print(feedback) ) # Send result of hashing algorithm to pool
except: feedback = soc.recv(1024).decode() # Get feedback about the result
while True: print(feedback)
try: except:
soc.close() break
soc = socket.socket() except:
soc.connect((str(pool_address), int(pool_port))) # Connect to the server pass
except:
pass
else:
break