Regression: Reconnection not working properly due to changes on ECHD Proxy (#21741)

pull/21594/head
Rodrigo Nascimento 5 years ago committed by GitHub
parent 47a61f2523
commit a3656b3304
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/api/server/default/info.js
  2. 1
      client/types/meteor.d.ts
  3. 15
      ee/client/ecdh.ts
  4. 5
      ee/server/services/ecdh-proxy/lib/server.ts
  5. 13
      packages/rocketchat-ddp/client/index.js

@ -21,7 +21,7 @@ API.default.addRoute('info', { authRequired: false }, {
API.default.addRoute('ecdh_proxy/initEncryptedSession', { authRequired: false }, {
post() {
return {
statusCode: 406,
statusCode: 200,
body: {
success: false,
error: 'Not Acceptable',

@ -30,6 +30,7 @@ declare module 'meteor/meteor' {
send: (data: string) => void;
};
_launchConnectionAsync: () => void;
allowConnection: (allow: boolean) => void;
};
onMessage(message: string): void;

@ -9,7 +9,7 @@ const sessionPromise = new Promise<ClientSession | void>((resolve) => {
});
function init(session: ClientSession): void {
Meteor.connection._stream._launchConnectionAsync();
Meteor.connection._stream.allowConnection(true);
const _didMessage = Meteor.connection._stream.socket._didMessage.bind(
Meteor.connection._stream.socket,
@ -41,16 +41,23 @@ async function initEncryptedSession(): Promise<void> {
if (response.status !== 200) {
resolveSession();
return Meteor.connection._stream._launchConnectionAsync();
return Meteor.connection._stream.allowConnection(true);
}
await session.setServerKey(await response.text());
const data = await response.json();
if (data.success === false) {
resolveSession();
return Meteor.connection._stream.allowConnection(true);
}
await session.setServerKey(data.publicKeyString);
resolveSession(session);
init(session);
} catch (e) {
console.log(e);
resolveSession();
Meteor.connection._stream._launchConnectionAsync();
Meteor.connection._stream.allowConnection(true);
}
}

@ -93,7 +93,10 @@ app.post('/api/ecdh_proxy/initEncryptedSession', async (req, res) => {
const session = await getSessionCached(req.body.clientPublicKey);
res.cookie('ecdhSession', req.body.clientPublicKey);
res.send(session.publicKeyString);
res.send({
success: true,
publicKeyString: session.publicKeyString,
});
} catch (e) {
res.status(400).send(e.message);
}

@ -1,4 +1,15 @@
import { ClientStream } from 'meteor/socket-stream-client';
ClientStream.prototype.connectionAllowed = false;
ClientStream.prototype.allowConnection = function(allow = true) {
this.connectionAllowed = allow;
this._launchConnection();
};
ClientStream.prototype._launchConnectionAsync = ClientStream.prototype._launchConnection;
ClientStream.prototype._launchConnection = function() {};
ClientStream.prototype._launchConnection = function() {
if (!this.connectionAllowed) {
return;
}
this._launchConnectionAsync();
};

Loading…
Cancel
Save