1
0

update a few scripts

This commit is contained in:
ThomasV
2013-10-06 12:28:45 +02:00
parent 33b41f22fe
commit 66f224eab4
10 changed files with 66 additions and 119 deletions

View File

@@ -85,14 +85,11 @@ def cert_verify_hostname(s):
class Interface(threading.Thread):
def __init__(self, config=None):
if config is None:
config = SimpleConfig()
def __init__(self, server, config = None):
threading.Thread.__init__(self)
self.daemon = True
self.config = config
self.config = config if config is not None else SimpleConfig()
self.connect_event = threading.Event()
self.subscriptions = {}
@@ -111,7 +108,7 @@ class Interface(threading.Thread):
self.pending_transactions_for_notifications= []
# parse server
self.server = config.get('server')
self.server = server
host, port, protocol = self.server.split(':')
port = int(port)
@@ -122,7 +119,7 @@ class Interface(threading.Thread):
self.port = port
self.protocol = protocol
self.use_ssl = ( protocol in 'sg' )
self.proxy = self.parse_proxy_options(config.get('proxy'))
self.proxy = self.parse_proxy_options(self.config.get('proxy'))
if self.proxy:
self.proxy_mode = proxy_modes.index(self.proxy["mode"]) + 1
@@ -308,7 +305,7 @@ class Interface(threading.Thread):
socket.getaddrinfo = getaddrinfo
if self.use_ssl:
cert_path = os.path.join( self.config.get('path'), 'certs', self.host)
cert_path = os.path.join( self.config.path, 'certs', self.host)
if not os.path.exists(cert_path):
is_new = True
@@ -539,9 +536,11 @@ class Interface(threading.Thread):
def start(self, queue):
self.queue = queue
def start(self, queue = None, wait = False):
self.queue = queue if queue else Queue.Queue()
threading.Thread.start(self)
if wait:
self.connect_event.wait()
def run(self):

View File

@@ -38,15 +38,16 @@ def filter_protocol(servers, p):
#def pick_random_server():
# return random.choice( filter_protocol(DEFAULT_SERVERS,'s') )
from simple_config import SimpleConfig
class Network(threading.Thread):
def __init__(self, config):
def __init__(self, config = {}):
threading.Thread.__init__(self)
self.daemon = True
self.config = config
self.config = SimpleConfig(config) if type(config) == type({}) else config
self.lock = threading.Lock()
self.blockchain = Blockchain(config, self)
self.blockchain = Blockchain(self.config, self)
self.interfaces = {}
self.queue = Queue.Queue()
self.default_server = self.config.get('server')
@@ -138,7 +139,7 @@ class Network(threading.Thread):
def start_interface(self, server):
if server in self.interfaces.keys():
return
i = interface.Interface({'server':server, 'path':self.config.path, 'proxy':self.proxy})
i = interface.Interface(server, self.config)
self.interfaces[server] = i
i.start(self.queue)