forked from c00w/bitHopper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
getwork_store.py
37 lines (30 loc) · 1.08 KB
/
getwork_store.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#License#
#bitHopper by Colin Rice is licensed under a Creative Commons
# Attribution-NonCommercial-ShareAlike 3.0 Unported License.
#Based on a work at github.com.
import eventlet
from eventlet.green import threading
from eventlet.green import time, socket
# Global timeout for sockets in case something leaks
socket.setdefaulttimeout(900)
class Getwork_store:
def __init__(self, bitHopper):
self.data = {}
self.bitHopper = bitHopper
self.lock = threading.RLock()
eventlet.spawn_n(self.prune)
def add(self, server, merkle_root):
with self.lock:
self.data[merkle_root] = [server, time.time()]
def get_server(self, merkle_root):
with self.lock:
if self.data.has_key(merkle_root):
return self.data[merkle_root][0]
return None
def prune(self):
while True:
with self.lock:
for key, work in self.data.items():
if work[1] < (time.time() - (60*5)):
del self.data[key]
eventlet.sleep(60)