Commit ffab3e8b298e0677c6e7bc4ff282e43ba71d3107

Authored by Adhidarma Hadiwinoto
1 parent bd53b188a2
Exists in master

Fix xid pairs

Showing 1 changed file with 12 additions and 5 deletions Side-by-side Diff

... ... @@ -41,12 +41,15 @@ if (!wsListenPort) {
41 41 const wss = new WebSocketServer({ noServer: true, perMessageDeflate: true });
42 42  
43 43 wss.on('connection', (ws, req, client) => {
44   - const connectionXid = uniqid();
45   -
46 44 // eslint-disable-next-line no-param-reassign
47 45 ws.isAlive = true;
48 46  
49   - const { remoteAddress, apikey, apikeyName } = client;
  47 + const {
  48 + xid: connectionXid,
  49 + remoteAddress,
  50 + apikey,
  51 + apikeyName,
  52 + } = client;
50 53  
51 54 logger.info(`${MODULE_NAME} F7755A03: Client connected`, {
52 55 xid: connectionXid,
... ... @@ -98,8 +101,8 @@ if (!wsListenPort) {
98 101  
99 102 logger.verbose(`${MODULE_NAME} 72D2A702: Got a message`, {
100 103 xid,
101   - remoteAddress,
102   - apikey,
  104 + apikeyName,
  105 + // apikey,
103 106 msgType,
104 107 msg,
105 108 msgSize: data.toString().length,
... ... @@ -163,6 +166,8 @@ if (!wsListenPort) {
163 166 });
164 167  
165 168 server.on('upgrade', (req, socket, head) => {
  169 + const xid = uniqid();
  170 +
166 171 const apikey = req.headers && (req.headers.apikey || req.headers.token);
167 172  
168 173 const matchedApikey = isValidApikey(
... ... @@ -177,12 +182,14 @@ if (!wsListenPort) {
177 182  
178 183 wss.handleUpgrade(req, socket, head, (ws) => {
179 184 const client = {
  185 + xid,
180 186 remoteAddress: req.socket.remoteAddress,
181 187 apikeyName: matchedApikey.name,
182 188 apikey,
183 189 };
184 190  
185 191 logger.verbose(`${MODULE_NAME} AB8BC2F4: Incoming HTTP connection`, {
  192 + xid,
186 193 headers: req.headers,
187 194 client,
188 195 });