import logging from twisted.internet import defer from ethproxy import logger, settings log = logger.get_logger('proxy') class Job(object): def __init__(self): self.params = '' @classmethod def build_from_pool(cls, getWorkParams): '''Build job object from Stratum server broadcast''' job = Job() job.params = getWorkParams return job class JobRegistry(object): def __init__(self, f, f1, f2, f3): self.f = f self.f1 = f1 self.f2 = f2 self.f3 = f3 self.jobs = None # stop mining after 6 minutes if internet disconnected if settings.COIN == "ETH": self.coinTimeout = 360
import time from ethproxy import logger log = logger.get_logger('stats') class PeerStats(object): '''Stub for server statistics''' counter = 0 changes = 0 @classmethod def client_connected(cls, ip): cls.counter += 1 cls.changes += 1 cls.print_stats() @classmethod def client_disconnected(cls, ip): cls.counter -= 1 cls.changes += 1 cls.print_stats() @classmethod def print_stats(cls): if cls.counter and float(cls.changes) / cls.counter < 0.05: # Print connection stats only when more than # 5% connections change to avoid log spam return
import json import time import socket from twisted.protocols.basic import LineOnlyReceiver from twisted.internet import defer, reactor, error from twisted.python.failure import Failure from ethproxy import logger, settings from ethproxy.stratum import connection_registry, custom_exceptions, stats log = logger.get_logger('protocol') class RequestCounter(object): def __init__(self): self.on_finish = defer.Deferred() self.counter = 0 def set_count(self, cnt): self.counter = cnt def decrease(self): self.counter -= 1 if self.counter <= 0: self.finish() def finish(self): if not self.on_finish.called: self.on_finish.callback(True)
from twisted.internet.protocol import ServerFactory from twisted.internet.protocol import ReconnectingClientFactory from twisted.internet import reactor, defer, endpoints from ethproxy.stratum import socksclient from ethproxy.stratum import custom_exceptions from ethproxy.stratum.protocol import Protocol, ClientProtocol from ethproxy.stratum.event_handler import GenericEventHandler from ethproxy import logger log = logger.get_logger('socket_transport') def sockswrapper(proxy, dest): endpoint = endpoints.TCP4ClientEndpoint(reactor, dest[0], dest[1]) return socksclient.SOCKSWrapper(reactor, proxy[0], proxy[1], endpoint) class SocketTransportFactory(ServerFactory): def __init__(self, debug=False, signing_key=None, signing_id=None, event_handler=GenericEventHandler, tcp_proxy_protocol_enable=False): self.debug = debug self.signing_key = signing_key self.signing_id = signing_id self.event_handler = event_handler self.protocol = Protocol
from twisted.web.resource import Resource from twisted.web.server import Request, Session, NOT_DONE_YET from twisted.internet import defer from twisted.python.failure import Failure import hashlib import json import string from ethproxy import logger, settings from ethproxy.stratum import helpers, semaphore from ethproxy.stratum.event_handler import GenericEventHandler from ethproxy.stratum.protocol import Protocol, RequestCounter log = logger.get_logger('http_transport') class Transport(object): def __init__(self, session_id, lock): self.buffer = [] self.session_id = session_id self.lock = lock self.push_url = None # None or full URL for HTTP Push self.peer = None # For compatibility with generic transport, not used in HTTP transport self.disconnecting = False def getPeer(self): return self.peer def write(self, data): if len(self.buffer) >= settings.HTTP_BUFFER_LIMIT: