Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable leading user.worker:pass@ in URL #36

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
146 changes: 75 additions & 71 deletions eth-proxy.conf
Original file line number Diff line number Diff line change
@@ -1,71 +1,75 @@
###
# Examples of command line for miners:
#
# ethminer.exe --farm-recheck 200 -G -F http://HOST:PORT/
# ethminer.exe --farm-recheck 300 -G -F http://HOST:PORT/rig1
#
# ethminer.exe -G -F http://127.0.0.1:8080/
# ethminer.exe --farm-recheck 100 -G -F http://192.168.0.33:8080/rig1
#
# farm-recheck parameter is very individual. Just test different values.
#
# You can submit shares without workername or
# You can provide workername:
# - with url like "/rig1"
# - or use automatically numbering(integer) based on IP of miner
#
# Servers:
# EU-Server: eth-eu.dwarfpool.com (France)
# US-Server: eth-us.dwarfpool.com (EastCoast: Montreal,Canada)
# US-Server: eth-us2.dwarfpool.com (WestCoast: Las Vegas)
# RU-Server: eth-ru.dwarfpool.com (Moscow)
# HK-Server: eth-hk.dwarfpool.com (Hong-Kong)
# CN-Server: eth-cn.dwarfpool.com (Shanghai)
# SG-Server: eth-sg.dwarfpool.com (Singapore)
# AU-Server: eth-au.dwarfpool.com (Melbourne)
#
###

# Select Ethereum ETH or Expanse EXP
COIN = "ETH"

# Host and port for your workers
HOST = "0.0.0.0"
PORT = 8080

# Coin address where money goes
WALLET = "XXXXXX"

# To donate please use wallet "0xea7263feb7d8a8ab0a11eedd8f1ce04412ab0820"

# It's useful for individually monitoring and statistic
ENABLE_WORKER_ID = False

# On DwarfPool you have option to monitor your workers via email.
# If WORKER_ID is enabled, you can monitor every worker/rig separately.
MONITORING = False
MONITORING_EMAIL = "[email protected]"

# Main pool
POOL_HOST = "eth-eu.dwarfpool.com"
POOL_PORT = 8008

# Failover pool
POOL_FAILOVER_ENABLE = True

POOL_HOST_FAILOVER1 = "eth-ru.dwarfpool.com"
POOL_PORT_FAILOVER1 = 8008

POOL_HOST_FAILOVER2 = "eth-us.dwarfpool.com"
POOL_PORT_FAILOVER2 = 8008

POOL_HOST_FAILOVER3 = "eth-hk.dwarfpool.com"
POOL_PORT_FAILOVER3 = 8008


# Logging
LOG_TO_FILE = True

# Enable debug
DEBUG = False

###
# Examples of command line for miners:
#
# ethminer.exe --farm-recheck 200 -G -F http://HOST:PORT/
# ethminer.exe --farm-recheck 300 -G -F http://HOST:PORT/rig1
# ethminer.exe --farm-recheck 400 -G -P stratum+tcp://user.rig1:pass@HOST:PORT
#
# ethminer.exe -G -F http://127.0.0.1:8080/
# ethminer.exe --farm-recheck 100 -G -F http://192.168.0.33:8080/rig1
#
# farm-recheck parameter is very individual. Just test different values.
#
# You can submit shares without workername or
# You can provide workername:
# - with url like "/rig1"
# - or use automatically numbering(integer) based on IP of miner
#
# Servers:
# EU-Server: eth-eu.dwarfpool.com (France)
# US-Server: eth-us.dwarfpool.com (EastCoast: Montreal,Canada)
# US-Server: eth-us2.dwarfpool.com (WestCoast: Las Vegas)
# RU-Server: eth-ru.dwarfpool.com (Moscow)
# HK-Server: eth-hk.dwarfpool.com (Hong-Kong)
# CN-Server: eth-cn.dwarfpool.com (Shanghai)
# SG-Server: eth-sg.dwarfpool.com (Singapore)
# AU-Server: eth-au.dwarfpool.com (Melbourne)
#
###

# Select Ethereum ETH or Expanse EXP
COIN = "ETH"

# Host and port for your workers
HOST = "0.0.0.0"
PORT = 8080

# Coin address where money goes
WALLET = "XXXXXX"

# To donate please use wallet "0xea7263feb7d8a8ab0a11eedd8f1ce04412ab0820"

# It's useful for individually monitoring and statistic
# Your pool user ID / password can be provided as well
ENABLE_WORKER_ID = False
# ENABLE_WORKER_ID = "rig1"
# ENABLE_WORKER_ID = "user.rig1"
# ENABLE_WORKER_ID = "user.rig1:pass"

# On DwarfPool you have option to monitor your workers via email.
# If WORKER_ID is enabled, you can monitor every worker/rig separately.
MONITORING = False
MONITORING_EMAIL = "[email protected]"

# Main pool
POOL_HOST = "eth-eu.dwarfpool.com"
POOL_PORT = 8008

# Failover pool
POOL_FAILOVER_ENABLE = True

POOL_HOST_FAILOVER1 = "eth-ru.dwarfpool.com"
POOL_PORT_FAILOVER1 = 8008

POOL_HOST_FAILOVER2 = "eth-us.dwarfpool.com"
POOL_PORT_FAILOVER2 = 8008

POOL_HOST_FAILOVER3 = "eth-hk.dwarfpool.com"
POOL_PORT_FAILOVER3 = 8008


# Logging
LOG_TO_FILE = True

# Enable debug
DEBUG = False
2 changes: 1 addition & 1 deletion eth-proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def main():
log.warning("-----------------------------------------------------------------------")

if __name__ == '__main__':
fp = file("eth-proxy.pid", 'w')
fp = open("eth-proxy.pid", 'w')
fp.write(str(os.getpid()))
fp.close()
main()
Expand Down
13 changes: 6 additions & 7 deletions mining_libs/client_service.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from twisted.internet import reactor

from stratum.event_handler import GenericEventHandler
from jobs import Job
import version as _version
from mining_libs.jobs import Job

import stratum.logger
log = stratum.logger.get_logger('proxy')
import stratum.version as _version
from stratum import logger
log = logger.get_logger('proxy')

class ClientMiningService(GenericEventHandler):
job_registry = None # Reference to JobRegistry instance
Expand Down Expand Up @@ -47,8 +46,8 @@ def handle_event(self, method, params, connection_ref):
if method == 'eth_getWork':
'''Proxy just received information about new mining job'''
# Broadcast to getwork clients
job = Job.build_from_pool(params)
self.job_registry.replace_job(job, connection_ref)
jobpool = Job.build_from_pool(params)
self.job_registry.replace_job(jobpool, connection_ref)

else:
'''Pool just asked us for something which we don't support...'''
Expand Down
15 changes: 9 additions & 6 deletions mining_libs/getwork_listener.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import stratum.logger
log = stratum.logger.get_logger('proxy')

from stratum.settings import ENABLE_WORKER_ID

class Root(Resource):
isLeaf = True

Expand All @@ -27,12 +29,13 @@ def json_error(self, msg_id, message):
return resp

def render_POST(self, request):
request.setHeader('content-type', 'application/json')
request.setHeader(b'content-type', b'application/json')
request.setHeader(b'Authorization', b'basic: %s' % ENABLE_WORKER_ID)
data = json.loads(request.content.read())

if not self.job_registry.jobs:
log.warning('Proxy is waiting for a job...')
request.write(self.json_error(data.get('id', 0), "Proxy is waiting for a job...")+'\n')
request.write((self.json_error(data.get('id', 0), "Proxy is waiting for a job...")+'\n').encode())
request.finish()
return NOT_DONE_YET

Expand All @@ -48,9 +51,9 @@ def render_POST(self, request):
response = self.json_response(data.get('id', 0), self.job_registry.jobs.params)
elif data['method'] == 'eth_submitWork' or data['method'] == 'eth_submitHashrate':
if self.isWorkerID:
worker_name = request.uri[1:15].split("/")[0]
worker_name = request.uri[1:15].split(b"/")[0]
if not worker_name:
ip_temp = request.getClientIP().split('.')
ip_temp = request.getClientIP().split(b'.')
worker_name = str( int(ip_temp[0])*16777216 + int(ip_temp[1])*65536 + int(ip_temp[2])*256 + int(ip_temp[3]) )
else:
worker_name = ''
Expand All @@ -67,7 +70,7 @@ def render_POST(self, request):
response = self.json_error(data.get('id'), "Unsupported method '%s'" % data['method'])

try:
request.write(response+'\n')
request.write(("%s\n" % response).encode())
request.finish()
return NOT_DONE_YET
except Exception:
Expand All @@ -89,4 +92,4 @@ def render_GET(self, request):
if self.job_registry.f3:
connected = "connected" if (hasattr(self.job_registry.f3, "is_connected") and self.job_registry.f3.is_connected) else "disconnected"
ret_text += "Failover server3 %s:%s (%s) %s<br>" % (self.job_registry.f3.main_host[0], self.job_registry.f3.main_host[1], self.job_registry.f3.remote_ip, connected)
return ret_text
return "".join(ret_text).encode()
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Twisted==16.1.1
Twisted>=19.7.0
zope.interface==4.1.3
2 changes: 1 addition & 1 deletion stratum/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from server import setup
from stratum.server import setup
4 changes: 2 additions & 2 deletions stratum/connection_registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import weakref
from twisted.internet import reactor
from services import GenericService
from stratum.services import GenericService

class ConnectionRegistry(object):
__connections = weakref.WeakKeyDictionary()
Expand All @@ -14,7 +14,7 @@ def remove_connection(cls, conn):
try:
del cls.__connections[conn]
except:
print "Warning: Cannot remove connection from ConnectionRegistry"
print("Warning: Cannot remove connection from ConnectionRegistry")

@classmethod
def get_session(cls, conn):
Expand Down
6 changes: 3 additions & 3 deletions stratum/event_handler.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import custom_exceptions
from stratum import custom_exceptions
from twisted.internet import defer
from services import wrap_result_object
from stratum.services import wrap_result_object

class GenericEventHandler(object):
def _handle_event(self, msg_method, msg_result, connection_ref):
return defer.maybeDeferred(wrap_result_object, self.handle_event(msg_method, msg_result, connection_ref))

def handle_event(self, msg_method, msg_params, connection_ref):
'''In most cases you'll only need to overload this method.'''
print "Other side called method", msg_method, "with params", msg_params
print("Other side called method", msg_method, "with params", msg_params)
raise custom_exceptions.MethodNotFoundException("Method '%s' not implemented" % msg_method)
2 changes: 1 addition & 1 deletion stratum/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import logging
from twisted.python import log as twisted_log

import settings
from stratum import settings

'''
class Logger(object):
Expand Down
28 changes: 14 additions & 14 deletions stratum/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
from twisted.internet import defer, reactor, error
from twisted.python.failure import Failure

import stats
import custom_exceptions
import connection_registry
import settings
from stratum import stats
import stratum.custom_exceptions
from stratum import connection_registry
import stratum.settings

import logger
from stratum import logger
log = logger.get_logger('protocol')

class RequestCounter(object):
Expand All @@ -32,7 +32,7 @@ def finish(self):
self.on_finish.callback(True)

class Protocol(LineOnlyReceiver):
delimiter = '\n'
delimiter = b'\n'

def _get_id(self):
self.request_id += 1
Expand Down Expand Up @@ -100,27 +100,27 @@ def connectionLost(self, reason):

def writeJsonRequest(self, method, params, worker, is_notification=False):
request_id = None if is_notification else self._get_id()
serialized = json.dumps({'id': request_id, 'method': method, 'params': params, 'jsonrpc':'2.0', 'worker': worker})
serialized = json.dumps({'id': request_id, 'method': method, 'params': params, 'jsonrpc':'2.0', 'worker': worker}).encode()

if self.factory.debug:
log.debug("< %s" % serialized)
log.debug(b"< %b" % serialized)

self.transport_write("%s\n" % serialized)
self.transport_write(b"%b\n" % serialized)
return request_id

def writeJsonResponse(self, data, message_id):
if not data:
return
serialized = json.dumps({'id': message_id, 'result': data, 'error': None, 'jsonrpc':'2.0'})
serialized = json.dumps({'id': message_id, 'result': data, 'error': None, 'jsonrpc':'2.0'}).encode()

if self.factory.debug:
log.debug("< %s" % serialized)
log.debug(b"< %b" % serialized)

self.transport_write("%s\n" % serialized)
self.transport_write(b"%b\n" % serialized)

def writeJsonError(self, code, message, traceback, message_id):
serialized = json.dumps({'id': message_id, 'result': None, 'error': (code, message, traceback)})
self.transport_write("%s\n" % serialized)
serialized = json.dumps({'id': message_id, 'result': None, 'error': (code, message, traceback)}).encode()
self.transport_write(b"%b\n" % serialized)

def writeGeneralError(self, message, code=-1):
log.error(message)
Expand Down
10 changes: 5 additions & 5 deletions stratum/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ def setup(setup_event=None):
from twisted.internet import epollreactor
epollreactor.install()
except ImportError:
print "Failed to install epoll reactor, default reactor will be used instead."
print("Failed to install epoll reactor, default reactor will be used instead.")

try:
import settings
except ImportError:
print "***** Is configs.py missing? Maybe you want to copy and customize config_default.py?"
print("***** Is configs.py missing? Maybe you want to copy and customize config_default.py?")

from twisted.application import service
application = service.Application("stratum-server")
Expand Down Expand Up @@ -51,8 +51,8 @@ def setup_finalize(event, application):
sslContext = ssl.DefaultOpenSSLContextFactory(settings.SSL_PRIVKEY, settings.SSL_CACERT)
except OpenSSL.SSL.Error:
sslContext = None
print "Cannot initiate SSL context, are SSL_PRIVKEY or SSL_CACERT missing?"
print "This will skip all SSL-based transports."
print("Cannot initiate SSL context, are SSL_PRIVKEY or SSL_CACERT missing?")
print("This will skip all SSL-based transports.")

# Set up thread pool size for service threads
reactor.suggestThreadPoolSize(settings.THREAD_POOL_SIZE)
Expand Down Expand Up @@ -106,4 +106,4 @@ def setup_finalize(event, application):
return event

if __name__ == '__main__':
print "This is not executable script. Try 'twistd -ny launcher.tac instead!"
print("This is not executable script. Try 'twistd -ny launcher.tac instead!")
2 changes: 1 addition & 1 deletion stratum/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import weakref
import re

import custom_exceptions
import stratum.custom_exceptions

VENDOR_RE = re.compile(r'\[(.*)\]')

Expand Down
Loading