@@ -53,6 +53,7 @@ module.exports = function(grunt) {
|
|||||||
'libtextsecure/protobufs.js',
|
'libtextsecure/protobufs.js',
|
||||||
'libtextsecure/websocket.js',
|
'libtextsecure/websocket.js',
|
||||||
'libtextsecure/websocket-resources.js',
|
'libtextsecure/websocket-resources.js',
|
||||||
|
'libtextsecure/keepalive.js',
|
||||||
'libtextsecure/helpers.js',
|
'libtextsecure/helpers.js',
|
||||||
'libtextsecure/stringview.js',
|
'libtextsecure/stringview.js',
|
||||||
'libtextsecure/api.js',
|
'libtextsecure/api.js',
|
||||||
|
@@ -38602,6 +38602,48 @@ TextSecureWebSocket = function (url, opts) {
|
|||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
/* vim: ts=4:sw=4:expandtab
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function KeepAlive(websocketResource, socket) {
|
||||||
|
if (websocketResource instanceof WebSocketResource) {
|
||||||
|
this.wsr = websocketResource;
|
||||||
|
this.socket = socket;
|
||||||
|
this.reset();
|
||||||
|
} else {
|
||||||
|
throw new TypeError('KeepAlive expected a WebSocketResource');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KeepAlive.prototype = {
|
||||||
|
constructor: KeepAlive,
|
||||||
|
reset: function() {
|
||||||
|
clearTimeout(this.keepAliveTimer);
|
||||||
|
clearTimeout(this.disconnectTimer);
|
||||||
|
this.keepAliveTimer = setTimeout(function() {
|
||||||
|
this.disconnectTimer = setTimeout(this.socket.close, 10000);
|
||||||
|
this.wsr.sendRequest({
|
||||||
|
verb: 'GET',
|
||||||
|
path: '/v1/keepalive',
|
||||||
|
success: this.reset.bind(this)
|
||||||
|
});
|
||||||
|
}.bind(this), 55000);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
/* vim: ts=4:sw=4:expandtab
|
/* vim: ts=4:sw=4:expandtab
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
@@ -39319,7 +39361,7 @@ TextSecureServer = function () {
|
|||||||
return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
|
return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var socket = TextSecureServer.getTempWebsocket();
|
var socket = TextSecureServer.getTempWebsocket();
|
||||||
new WebSocketResource(socket, function(request) {
|
var wsr = new WebSocketResource(socket, function(request) {
|
||||||
if (request.path == "/v1/address" && request.verb == "PUT") {
|
if (request.path == "/v1/address" && request.verb == "PUT") {
|
||||||
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
|
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
|
||||||
setProvisioningUrl([
|
setProvisioningUrl([
|
||||||
@@ -39348,6 +39390,7 @@ TextSecureServer = function () {
|
|||||||
console.log('Unknown websocket message', request.path);
|
console.log('Unknown websocket message', request.path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
new KeepAlive(wsr, socket);
|
||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return generateKeys(100, progressCallback);
|
return generateKeys(100, progressCallback);
|
||||||
@@ -39495,25 +39538,11 @@ function generateKeys(count, progressCallback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.wsr = new WebSocketResource(this.socket, this.handleRequest.bind(this));
|
this.wsr = new WebSocketResource(this.socket, this.handleRequest.bind(this));
|
||||||
this.resetKeepAliveTimer();
|
this.keepalive = new KeepAlive(this.wsr, this.socket);
|
||||||
|
|
||||||
},
|
},
|
||||||
resetKeepAliveTimer: function() {
|
|
||||||
clearTimeout(this.keepAliveTimer);
|
|
||||||
clearTimeout(this.disconnectTimer);
|
|
||||||
this.keepAliveTimer = setTimeout(function() {
|
|
||||||
if (this.getStatus() === WebSocket.OPEN) {
|
|
||||||
this.wsr.sendRequest({
|
|
||||||
verb: 'GET',
|
|
||||||
path: '/v1/keepalive',
|
|
||||||
success: this.resetKeepAliveTimer.bind(this)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.disconnectTimer = setTimeout(this.socket.close, 30000);
|
|
||||||
}.bind(this), 55000);
|
|
||||||
},
|
|
||||||
handleRequest: function(request) {
|
handleRequest: function(request) {
|
||||||
this.resetKeepAliveTimer();
|
this.keepalive.reset();
|
||||||
// TODO: handle different types of requests. for now we only expect
|
// TODO: handle different types of requests. for now we only expect
|
||||||
// PUT /messages <encrypted IncomingPushMessageSignal>
|
// PUT /messages <encrypted IncomingPushMessageSignal>
|
||||||
textsecure.crypto.decryptWebsocketMessage(request.body).then(function(plaintext) {
|
textsecure.crypto.decryptWebsocketMessage(request.body).then(function(plaintext) {
|
||||||
|
@@ -44,7 +44,7 @@
|
|||||||
return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
|
return textsecure.protocol_wrapper.createIdentityKeyRecvSocket().then(function(cryptoInfo) {
|
||||||
return new Promise(function(resolve) {
|
return new Promise(function(resolve) {
|
||||||
var socket = TextSecureServer.getTempWebsocket();
|
var socket = TextSecureServer.getTempWebsocket();
|
||||||
new WebSocketResource(socket, function(request) {
|
var wsr = new WebSocketResource(socket, function(request) {
|
||||||
if (request.path == "/v1/address" && request.verb == "PUT") {
|
if (request.path == "/v1/address" && request.verb == "PUT") {
|
||||||
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
|
var proto = textsecure.protobuf.ProvisioningUuid.decode(request.body);
|
||||||
setProvisioningUrl([
|
setProvisioningUrl([
|
||||||
@@ -73,6 +73,7 @@
|
|||||||
console.log('Unknown websocket message', request.path);
|
console.log('Unknown websocket message', request.path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
new KeepAlive(wsr, socket);
|
||||||
});
|
});
|
||||||
}).then(function() {
|
}).then(function() {
|
||||||
return generateKeys(100, progressCallback);
|
return generateKeys(100, progressCallback);
|
||||||
|
41
libtextsecure/keepalive.js
Normal file
41
libtextsecure/keepalive.js
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
/* vim: ts=4:sw=4:expandtab
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function KeepAlive(websocketResource, socket) {
|
||||||
|
if (websocketResource instanceof WebSocketResource) {
|
||||||
|
this.wsr = websocketResource;
|
||||||
|
this.socket = socket;
|
||||||
|
this.reset();
|
||||||
|
} else {
|
||||||
|
throw new TypeError('KeepAlive expected a WebSocketResource');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
KeepAlive.prototype = {
|
||||||
|
constructor: KeepAlive,
|
||||||
|
reset: function() {
|
||||||
|
clearTimeout(this.keepAliveTimer);
|
||||||
|
clearTimeout(this.disconnectTimer);
|
||||||
|
this.keepAliveTimer = setTimeout(function() {
|
||||||
|
this.disconnectTimer = setTimeout(this.socket.close, 10000);
|
||||||
|
this.wsr.sendRequest({
|
||||||
|
verb: 'GET',
|
||||||
|
path: '/v1/keepalive',
|
||||||
|
success: this.reset.bind(this)
|
||||||
|
});
|
||||||
|
}.bind(this), 55000);
|
||||||
|
},
|
||||||
|
};
|
@@ -45,25 +45,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.wsr = new WebSocketResource(this.socket, this.handleRequest.bind(this));
|
this.wsr = new WebSocketResource(this.socket, this.handleRequest.bind(this));
|
||||||
this.resetKeepAliveTimer();
|
this.keepalive = new KeepAlive(this.wsr, this.socket);
|
||||||
|
|
||||||
},
|
},
|
||||||
resetKeepAliveTimer: function() {
|
|
||||||
clearTimeout(this.keepAliveTimer);
|
|
||||||
clearTimeout(this.disconnectTimer);
|
|
||||||
this.keepAliveTimer = setTimeout(function() {
|
|
||||||
if (this.getStatus() === WebSocket.OPEN) {
|
|
||||||
this.wsr.sendRequest({
|
|
||||||
verb: 'GET',
|
|
||||||
path: '/v1/keepalive',
|
|
||||||
success: this.resetKeepAliveTimer.bind(this)
|
|
||||||
});
|
|
||||||
}
|
|
||||||
this.disconnectTimer = setTimeout(this.socket.close, 30000);
|
|
||||||
}.bind(this), 55000);
|
|
||||||
},
|
|
||||||
handleRequest: function(request) {
|
handleRequest: function(request) {
|
||||||
this.resetKeepAliveTimer();
|
this.keepalive.reset();
|
||||||
// TODO: handle different types of requests. for now we only expect
|
// TODO: handle different types of requests. for now we only expect
|
||||||
// PUT /messages <encrypted IncomingPushMessageSignal>
|
// PUT /messages <encrypted IncomingPushMessageSignal>
|
||||||
textsecure.crypto.decryptWebsocketMessage(request.body).then(function(plaintext) {
|
textsecure.crypto.decryptWebsocketMessage(request.body).then(function(plaintext) {
|
||||||
|
Reference in New Issue
Block a user