result = self.get_peers()
elif method == 'server.version':
- print "version", params
+ pass
elif method == 'server.stop':
print "stopping..."
import traceback, sys
import Queue as queue
+def random_string(N):
+ import random, string
+ return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
+
+def timestr():
+ return time.strftime("[%d/%m/%Y-%H:%M:%S]")
+
+
class Shared:
def __init__(self):
except:
traceback.print_exc(file=sys.stdout)
+ if method in ['server.version']:
+ session.version = params[0]
+
def add_session(self, session):
with self.lock:
self._stopped = False
self.lock = threading.Lock()
self.subscriptions = []
+ self.address = ''
+ self.name = ''
+ threading.Timer(2, self.info).start()
+
+ def info(self):
+ for s in self.subscriptions:
+ m, p = s
+ if m == 'blockchain.address.subscribe':
+ addr = p[0]
+ break
+ else:
+ addr = None
+ print timestr(), self.name, self.address, addr, len(self.subscriptions), self.version
def stopped(self):
with self.lock:
import thread, threading, time, socket, traceback, ast, sys
+from processor import timestr, random_string
-def random_string(N):
- import random, string
- return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
-
-def timestr():
- return time.strftime("[%d/%m/%Y-%H:%M:%S]")
def new_to_old(s):
"""
-def random_string(N):
- import random, string
- return ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(N))
-
-
+from processor import random_string
def get_version(request):
self.sessions = {}
-
def create_session(self):
session_id = random_string(10)
self.sessions[session_id] = HttpSession(session_id)
def __init__(self, session_id):
Session.__init__(self)
self.pending_responses = Queue.Queue()
- print "new http session", session_id
+ self.address = session_id
+ self.name = "HTTP session"
def send_response(self, response):
raw_response = json.dumps(response)
import time
import Queue as queue
-from processor import Session, Dispatcher
+from processor import Session, Dispatcher, timestr
class TcpSession(Session):
def __init__(self, connection, address):
- self._connection = connection
- self.address = address
Session.__init__(self)
- print "New session", address
+ self._connection = connection
+ self.address = address[0]
+ self.version = 'unknown'
+ self.name = "TCP session"
def connection(self):
if self.stopped():
def stop(self):
self._connection.close()
- print "Terminating connection:", self.address[0]
+ #print "Terminating connection:", self.address
with self.lock:
self._stopped = True