-
Notifications
You must be signed in to change notification settings - Fork 33
/
Copy pathcosignerpool.py
executable file
·98 lines (81 loc) · 2.56 KB
/
cosignerpool.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2015 THomas Voegtlin
#
# 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, either version 3 of the License, or
# (at your option) any later version.
#
# 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/>.
import thread, sys, socket, os, re
import urllib2
import Queue
import traceback
import plyvel
import json, ast
import time
import ConfigParser
config = ConfigParser.ConfigParser()
config.read("/etc/cosignerpool.conf")
my_password = config.get('main','password')
my_host = config.get('main','host')
my_port = config.getint('main','port')
dbpath = config.get('main', 'dbpath')
def run_server():
from SimpleXMLRPCServer import SimpleXMLRPCServer
server = SimpleXMLRPCServer((my_host, my_port), allow_none=True, logRequests=False)
server.register_function(delete, 'delete')
server.register_function(get, 'get')
server.register_function(put, 'put')
server.register_function(dump, 'dump')
server.register_function(lambda: setattr(server,'running', False), 'stop')
server.running = True
while server.running:
try:
server.handle_request()
except BaseException as e:
traceback.print_exc(file=sys.stdout)
print "server stopped"
def get(key):
o = db.get(key)
if o:
print "get", key, len(o)
return o
def put(key, value):
print "put", key, len(value)
db.put(key, value)
def delete(key):
db.delete(key)
def dump():
out = {}
for key, value in db:
out[ key ]= value
return out
def handle_command(cmd):
import xmlrpclib
server = xmlrpclib.ServerProxy('http://%s:%d'%(my_host, my_port), allow_none=True)
try:
if cmd == 'stop':
out = server.stop()
else:
out = "unknown command"
except socket.error:
print "Server not running"
return 1
print out
return 0
if __name__ == '__main__':
if len(sys.argv) > 1:
ret = handle_command(sys.argv[1])
sys.exit(ret)
db = plyvel.DB(dbpath, create_if_missing=True, compression=None)
run_server()
db.close()