From 31e0db41b82daeb11d0c915d7bb0f16e9b5533d8 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 14 Mar 2012 10:59:34 +0300 Subject: [PATCH 1/3] close session --- server/server.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/server/server.py b/server/server.py index dddfff3ec..2d4118a60 100755 --- a/server/server.py +++ b/server/server.py @@ -673,6 +673,12 @@ def tcp_server_thread(): traceback.print_exc(file=sys.stdout) +def close_sesion(session_id): + print "lost connection", session_id + sessions.pop(session_id) + sessions_sub_numblocks.remove(session_id) + + # one thread per client. put requests in a queue. def tcp_client_thread(ipaddr,conn): """ use a persistent connection. put commands in a queue.""" @@ -689,9 +695,7 @@ def tcp_client_thread(ipaddr,conn): d = conn.recv(1024) msg += d if not d: - print "lost connection", session_id - sessions.pop(session_id) - sessions_sub_numblocks.remove(session_id) + close_sesion(session_id) break while True: @@ -744,8 +748,12 @@ def process_output_queue(): session_id, out = output_queue.get() session = sessions.get(session_id) if session: - conn = session.get('conn') - conn.send(out+'\n') + try: + conn = session.get('conn') + conn.send(out+'\n') + except: + close_session(session_id) + From 5e14b5ee57abc458a820a7599108ca77a3d6b204 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 14 Mar 2012 11:44:22 +0300 Subject: [PATCH 2/3] server.peers rpc --- server/server.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/server/server.py b/server/server.py index 2d4118a60..35a335c04 100755 --- a/server/server.py +++ b/server/server.py @@ -730,6 +730,8 @@ def process_input_queue(): sessions[session_id]['version'] = data elif cmd == 'server.banner': out = json.dumps( { 'method':'server.banner', 'result':config.get('server','banner').replace('\\n','\n') } ) + elif cmd == 'server.peers': + out = json.dumps( { 'method':'server.peers', 'result':peer_list.values() } ) elif cmd == 'address.get_history': address = data out = json.dumps( { 'method':'address.get_history', 'address':address, 'result':store.get_history( address ) } ) From a63fe6813f772f5d170b54bf1d569d26c83cb456 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Wed, 14 Mar 2012 16:56:27 +0300 Subject: [PATCH 3/3] fix typo --- server/server.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/server/server.py b/server/server.py index 35a335c04..42b6b9f48 100755 --- a/server/server.py +++ b/server/server.py @@ -673,10 +673,11 @@ def tcp_server_thread(): traceback.print_exc(file=sys.stdout) -def close_sesion(session_id): +def close_session(session_id): print "lost connection", session_id sessions.pop(session_id) - sessions_sub_numblocks.remove(session_id) + if session_id in sessions_sub_numblocks: + sessions_sub_numblocks.remove(session_id) # one thread per client. put requests in a queue. @@ -695,7 +696,7 @@ def tcp_client_thread(ipaddr,conn): d = conn.recv(1024) msg += d if not d: - close_sesion(session_id) + close_session(session_id) break while True: @@ -721,6 +722,8 @@ def tcp_client_thread(ipaddr,conn): def process_input_queue(): while not stopping: session_id, cmd, data = input_queue.get() + if session_id not in sessions.keys(): + continue out = None if cmd == 'address.subscribe': subscribe_to_address(session_id,data)