socket: Move `req_id` parameter to top level of protocol payload

(imported from commit 271d84a0b44a2623bec290f64a83a0423698a1ef)
This commit is contained in:
Zev Benjamin 2013-11-05 11:10:14 -05:00
parent 4595143023
commit 87fc182645
3 changed files with 10 additions and 10 deletions

View File

@ -43,7 +43,7 @@ Socket.prototype = {
this._next_req_id++;
this._requests[req_id] = {success: success, error: error};
// TODO: I think we might need to catch exceptions here for certain transports
this._sockjs.send(JSON.stringify({client_meta: {req_id: req_id},
this._sockjs.send(JSON.stringify({req_id: req_id,
type: type, request: msg}));
},
@ -93,7 +93,7 @@ Socket.prototype = {
};
sockjs.onmessage = function Socket__sockjs_onmessage(event) {
var req_id = event.data.client_meta.req_id;
var req_id = event.data.req_id;
var req_info = that._requests[req_id];
if (req_info === undefined) {
blueslip.error("Got a response for an unknown request");

View File

@ -81,7 +81,7 @@ class SocketConnection(sockjs.tornado.SockJSConnection):
def authenticate_client(self, msg):
if self.authenticated:
self.session.send_message({'client_meta': msg['client_meta'],
self.session.send_message({'req_id': msg['req_id'],
'response': {'result': 'error', 'msg': 'Already authenticated'}})
return
@ -106,7 +106,7 @@ class SocketConnection(sockjs.tornado.SockJSConnection):
register_connection(queue_id, self)
self.session.send_message({'client_meta': msg['client_meta'],
self.session.send_message({'req_id': msg['req_id'],
'response': {'result': 'success', 'msg': ''}})
self.authenticated = True
fake_log_line(self.session.conn_info, 0, 200, "Authenticated using %s" % (self.session.transport_name,),
@ -123,14 +123,14 @@ class SocketConnection(sockjs.tornado.SockJSConnection):
self.authenticate_client(msg)
except SocketAuthError as e:
fake_log_line(self.session.conn_info, 0, 403, e.msg, 'unknown')
self.session.send_message({'client_meta': msg['client_meta'],
self.session.send_message({'req_id': msg['req_id'],
'response': {'result': 'error', 'msg': e.msg}})
return
else:
if not self.authenticated:
error_msg = 'Not yet authenticated'
fake_log_line(self.session.conn_info, 0, 403, error_msg, 'unknown')
self.session.send_message({'client_meta': msg['client_meta'],
self.session.send_message({'req_id': msg['req_id'],
'response': {'result': 'error', 'msg': error_msg}})
return
@ -138,7 +138,7 @@ class SocketConnection(sockjs.tornado.SockJSConnection):
req['sender_id'] = self.session.user_profile.id
req['client_name'] = req['client']
queue_json_publish("message_sender", dict(request=req,
client_meta=msg['client_meta'],
req_id=msg['req_id'],
server_meta=dict(client_id=self.client_id,
return_queue="tornado_return",
start_time=start_time)),
@ -166,14 +166,14 @@ def fake_message_sender(event):
except JsonableError as e:
resp = {"result": "error", "msg": str(e)}
result = {'response': resp, 'client_meta': event['client_meta'],
result = {'response': resp, 'req_id': event['req_id'],
'server_meta': event['server_meta']}
respond_send_message(result)
def respond_send_message(data):
connection = get_connection(data['server_meta']['client_id'])
if connection is not None:
connection.session.send_message({'client_meta': data['client_meta'], 'response': data['response']})
connection.session.send_message({'req_id': data['req_id'], 'response': data['response']})
time_elapsed = time.time() - data['server_meta']['start_time']
fake_log_line(connection.session.conn_info,

View File

@ -241,7 +241,7 @@ class MessageSenderWorker(QueueProcessingWorker):
except JsonableError as e:
resp = {"result": "error", "msg": str(e)}
result = {'response': resp, 'client_meta': event['client_meta'],
result = {'response': resp, 'req_id': event['req_id'],
'server_meta': event['server_meta']}
queue_json_publish(event['server_meta']['return_queue'], result, lambda e: None)