A few small bugfixes
This commit is contained in:
parent
59d048ca06
commit
c5f9fae444
2 changed files with 36 additions and 23 deletions
|
@ -160,6 +160,7 @@ function _createSocket(url, { certificateAuthority, proxyUrl }) {
|
||||||
return new WebSocket(url, null, null, null, requestOptions);
|
return new WebSocket(url, null, null, null, requestOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const FIVE_MINUTES = 1000 * 60 * 5;
|
||||||
const agents = {
|
const agents = {
|
||||||
unauth: null,
|
unauth: null,
|
||||||
auth: null,
|
auth: null,
|
||||||
|
@ -175,16 +176,21 @@ function _promiseAjax(providedUrl, options) {
|
||||||
typeof options.timeout !== 'undefined' ? options.timeout : 10000;
|
typeof options.timeout !== 'undefined' ? options.timeout : 10000;
|
||||||
|
|
||||||
const { proxyUrl } = options;
|
const { proxyUrl } = options;
|
||||||
const agentType = options.unathenticated ? 'unauth' : 'auth';
|
const agentType = options.unauthenticated ? 'unauth' : 'auth';
|
||||||
|
|
||||||
if (!agents[agentType]) {
|
const { timestamp } = agents[agentType] || {};
|
||||||
if (proxyUrl) {
|
if (!timestamp || timestamp + FIVE_MINUTES < Date.now()) {
|
||||||
agents[agentType] = new ProxyAgent(proxyUrl);
|
if (timestamp) {
|
||||||
} else {
|
log.info(`Cycling agent for type ${agentType}`);
|
||||||
agents[agentType] = new Agent();
|
|
||||||
}
|
}
|
||||||
|
agents[agentType] = {
|
||||||
|
agent: proxyUrl
|
||||||
|
? new ProxyAgent(proxyUrl)
|
||||||
|
: new Agent({ keepAlive: true }),
|
||||||
|
timestamp: Date.now(),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const agent = agents[agentType];
|
const { agent } = agents[agentType];
|
||||||
|
|
||||||
const fetchOptions = {
|
const fetchOptions = {
|
||||||
method: options.type,
|
method: options.type,
|
||||||
|
@ -436,7 +442,7 @@ function initialize({ url, cdnUrl, certificateAuthority, proxyUrl }) {
|
||||||
message =
|
message =
|
||||||
'The server rejected our query, please file a bug report.';
|
'The server rejected our query, please file a bug report.';
|
||||||
}
|
}
|
||||||
e.message = message;
|
e.message = `${message} (original: ${e.message})`;
|
||||||
throw e;
|
throw e;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,6 +287,9 @@ MessageReceiver.prototype.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
envelope.id = envelope.serverGuid || window.getGuid();
|
envelope.id = envelope.serverGuid || window.getGuid();
|
||||||
|
envelope.serverTimestamp = envelope.serverTimestamp
|
||||||
|
? envelope.serverTimestamp.toNumber()
|
||||||
|
: null;
|
||||||
|
|
||||||
return this.addToCache(envelope, plaintext).then(
|
return this.addToCache(envelope, plaintext).then(
|
||||||
async () => {
|
async () => {
|
||||||
|
@ -404,6 +407,11 @@ MessageReceiver.prototype.extend({
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const envelope = textsecure.protobuf.Envelope.decode(envelopePlaintext);
|
const envelope = textsecure.protobuf.Envelope.decode(envelopePlaintext);
|
||||||
|
envelope.id = envelope.serverGuid || item.id;
|
||||||
|
envelope.source = envelope.source || item.source;
|
||||||
|
envelope.sourceDevice = envelope.sourceDevice || item.sourceDevice;
|
||||||
|
envelope.serverTimestamp =
|
||||||
|
envelope.serverTimestamp || item.serverTimestamp;
|
||||||
|
|
||||||
const { decrypted } = item;
|
const { decrypted } = item;
|
||||||
if (decrypted) {
|
if (decrypted) {
|
||||||
|
@ -516,15 +524,19 @@ MessageReceiver.prototype.extend({
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.get('version') === 2) {
|
if (item.get('version') === 2) {
|
||||||
item.set(
|
item.set({
|
||||||
'decrypted',
|
source: envelope.source,
|
||||||
await MessageReceiver.arrayBufferToStringBase64(plaintext)
|
sourceDevice: envelope.sourceDevice,
|
||||||
);
|
serverTimestamp: envelope.serverTimestamp,
|
||||||
|
decrypted: await MessageReceiver.arrayBufferToStringBase64(plaintext),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
item.set(
|
item.set({
|
||||||
'decrypted',
|
source: envelope.source,
|
||||||
await MessageReceiver.arrayBufferToString(plaintext)
|
sourceDevice: envelope.sourceDevice,
|
||||||
);
|
serverTimestamp: envelope.serverTimestamp,
|
||||||
|
decrypted: await MessageReceiver.arrayBufferToString(plaintext),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return textsecure.storage.unprocessed.save(item.attributes);
|
return textsecure.storage.unprocessed.save(item.attributes);
|
||||||
|
@ -691,12 +703,7 @@ MessageReceiver.prototype.extend({
|
||||||
.decrypt(
|
.decrypt(
|
||||||
window.Signal.Metadata.createCertificateValidator(serverTrustRoot),
|
window.Signal.Metadata.createCertificateValidator(serverTrustRoot),
|
||||||
ciphertext.toArrayBuffer(),
|
ciphertext.toArrayBuffer(),
|
||||||
Math.min(
|
Math.min(envelope.serverTimestamp || Date.now(), Date.now()),
|
||||||
envelope.serverTimestamp
|
|
||||||
? envelope.serverTimestamp.toNumber()
|
|
||||||
: Date.now(),
|
|
||||||
Date.now()
|
|
||||||
),
|
|
||||||
me
|
me
|
||||||
)
|
)
|
||||||
.then(
|
.then(
|
||||||
|
@ -737,7 +744,7 @@ MessageReceiver.prototype.extend({
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.removeFromCache().then(() => {
|
return this.removeFromCache(envelope).then(() => {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue