зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1265914 - Remove Push UDP wake-up. r=dragana
MozReview-Commit-ID: 9uyrp75slCX --HG-- extra : rebase_source : 92c211831bfb732ddf3b86eefd259b878f3ea7d5 extra : histedit_source : d363fd7b1fcaa0dfc48ff15425e0400ea91d6c20
This commit is contained in:
Родитель
49323c9a2d
Коммит
341af4d90b
|
@ -34,9 +34,9 @@ const kPUSHWSDB_DB_NAME = "pushapi";
|
|||
const kPUSHWSDB_DB_VERSION = 5; // Change this if the IndexedDB format changes
|
||||
const kPUSHWSDB_STORE_NAME = "pushapi";
|
||||
|
||||
const kUDP_WAKEUP_WS_STATUS_CODE = 4774; // WebSocket Close status code sent
|
||||
// by server to signal that it can
|
||||
// wake client up using UDP.
|
||||
// WebSocket close code sent by the server to indicate that the client should
|
||||
// not automatically reconnect.
|
||||
const kBACKOFF_WS_STATUS_CODE = 4774;
|
||||
|
||||
// Maps ack statuses, unsubscribe reasons, and delivery error reasons to codes
|
||||
// included in request payloads.
|
||||
|
@ -286,12 +286,12 @@ this.PushServiceWebSocket = {
|
|||
* TCP connection after they close a WebSocket. This causes wsOnStop to be
|
||||
* called with error NS_BASE_STREAM_CLOSED. Since the client has to keep the
|
||||
* WebSocket up, it should try to reconnect. But if the server closes the
|
||||
* WebSocket because it will wake up the client via UDP, then the client
|
||||
* shouldn't re-establish the connection. If the server says that it will
|
||||
* wake up the client over UDP, this is set to true in wsOnServerClose. It is
|
||||
* WebSocket because it wants the client to back off, then the client
|
||||
* shouldn't re-establish the connection. If the server sends the backoff
|
||||
* close code, this field will be set to true in wsOnServerClose. It is
|
||||
* checked in wsOnStop.
|
||||
*/
|
||||
_willBeWokenUpByUDP: false,
|
||||
_skipReconnect: false,
|
||||
|
||||
/** Indicates whether the server supports Web Push-style message delivery. */
|
||||
_dataEnabled: false,
|
||||
|
@ -340,13 +340,6 @@ this.PushServiceWebSocket = {
|
|||
this._makeWebSocket = options.makeWebSocket;
|
||||
}
|
||||
|
||||
// Override the default UDP socket factory function. The returned object
|
||||
// must be null or satisfy the nsIUDPSocket interface. Used by the
|
||||
// UDP tests.
|
||||
if (options.makeUDPSocket) {
|
||||
this._makeUDPSocket = options.makeUDPSocket;
|
||||
}
|
||||
|
||||
this._requestTimeout = prefs.get("requestTimeout");
|
||||
|
||||
return Promise.resolve();
|
||||
|
@ -361,7 +354,7 @@ this.PushServiceWebSocket = {
|
|||
_shutdownWS: function(shouldCancelPending = true) {
|
||||
console.debug("shutdownWS()");
|
||||
this._currentState = STATE_SHUT_DOWN;
|
||||
this._willBeWokenUpByUDP = false;
|
||||
this._skipReconnect = false;
|
||||
|
||||
prefs.ignore("userAgentID", this);
|
||||
|
||||
|
@ -390,11 +383,6 @@ this.PushServiceWebSocket = {
|
|||
},
|
||||
|
||||
uninit: function() {
|
||||
if (this._udpServer) {
|
||||
this._udpServer.close();
|
||||
this._udpServer = null;
|
||||
}
|
||||
|
||||
// All pending requests (ideally none) are dropped at this point. We
|
||||
// shouldn't have any applications performing registration/unregistration
|
||||
// or receiving notifications.
|
||||
|
@ -413,9 +401,7 @@ this.PushServiceWebSocket = {
|
|||
},
|
||||
|
||||
/**
|
||||
* How retries work: The goal is to ensure websocket is always up on
|
||||
* networks not supporting UDP. So the websocket should only be shutdown if
|
||||
* onServerClose indicates UDP wakeup. If WS is closed due to socket error,
|
||||
* How retries work: If the WS is closed due to a socket error,
|
||||
* _startBackoffTimer() is called. The retry timer is started and when
|
||||
* it times out, beginWSSetup() is called again.
|
||||
*
|
||||
|
@ -1008,9 +994,8 @@ this.PushServiceWebSocket = {
|
|||
console.debug("wsOnStop()");
|
||||
this._releaseWakeLock();
|
||||
|
||||
if (statusCode != Cr.NS_OK &&
|
||||
!(statusCode == Cr.NS_BASE_STREAM_CLOSED && this._willBeWokenUpByUDP)) {
|
||||
console.debug("wsOnStop: Socket error", statusCode);
|
||||
if (statusCode != Cr.NS_OK && !this._skipReconnect) {
|
||||
console.debug("wsOnStop: Reconnecting after socket error", statusCode);
|
||||
this._reconnect();
|
||||
return;
|
||||
}
|
||||
|
@ -1086,17 +1071,16 @@ this.PushServiceWebSocket = {
|
|||
* function), which calls reconnect and re-establishes the WebSocket
|
||||
* connection.
|
||||
*
|
||||
* If the server said it'll use UDP for wakeup, we set _willBeWokenUpByUDP
|
||||
* and stop reconnecting in _wsOnStop().
|
||||
* If the server requested that we back off, we won't reconnect until the
|
||||
* next network state change event, or until we need to send a new register
|
||||
* request.
|
||||
*/
|
||||
_wsOnServerClose: function(context, aStatusCode, aReason) {
|
||||
console.debug("wsOnServerClose()", aStatusCode, aReason);
|
||||
|
||||
// Switch over to UDP.
|
||||
if (aStatusCode == kUDP_WAKEUP_WS_STATUS_CODE) {
|
||||
console.debug("wsOnServerClose: Server closed with promise to wake up");
|
||||
this._willBeWokenUpByUDP = true;
|
||||
// TODO: there should be no pending requests
|
||||
if (aStatusCode == kBACKOFF_WS_STATUS_CODE) {
|
||||
console.debug("wsOnServerClose: Skipping automatic reconnect");
|
||||
this._skipReconnect = true;
|
||||
}
|
||||
},
|
||||
|
||||
|
@ -1109,62 +1093,6 @@ this.PushServiceWebSocket = {
|
|||
}
|
||||
this._registerRequests.clear();
|
||||
},
|
||||
|
||||
_makeUDPSocket: function() {
|
||||
return Cc["@mozilla.org/network/udp-socket;1"]
|
||||
.createInstance(Ci.nsIUDPSocket);
|
||||
},
|
||||
|
||||
/**
|
||||
* This method should be called only if the device is on a mobile network!
|
||||
*/
|
||||
_listenForUDPWakeup: function() {
|
||||
console.debug("listenForUDPWakeup()");
|
||||
|
||||
if (this._udpServer) {
|
||||
console.warn("listenForUDPWakeup: UDP Server already running");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!prefs.get("udp.wakeupEnabled")) {
|
||||
console.debug("listenForUDPWakeup: UDP support disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
let socket = this._makeUDPSocket();
|
||||
if (!socket) {
|
||||
return;
|
||||
}
|
||||
this._udpServer = socket.QueryInterface(Ci.nsIUDPSocket);
|
||||
this._udpServer.init(-1, false, Services.scriptSecurityManager.getSystemPrincipal());
|
||||
this._udpServer.asyncListen(this);
|
||||
console.debug("listenForUDPWakeup: Listening on", this._udpServer.port);
|
||||
|
||||
return this._udpServer.port;
|
||||
},
|
||||
|
||||
/**
|
||||
* Called by UDP Server Socket. As soon as a ping is received via UDP,
|
||||
* reconnect the WebSocket and get the actual data.
|
||||
*/
|
||||
onPacketReceived: function(aServ, aMessage) {
|
||||
console.debug("onPacketReceived: Recv UDP datagram on port",
|
||||
this._udpServer.port);
|
||||
this._beginWSSetup();
|
||||
},
|
||||
|
||||
/**
|
||||
* Called by UDP Server Socket if the socket was closed for some reason.
|
||||
*
|
||||
* If this happens, we reconnect the WebSocket to not miss out on
|
||||
* notifications.
|
||||
*/
|
||||
onStopListening: function(aServ, aStatus) {
|
||||
console.debug("onStopListening: UDP Server socket was shutdown. Status",
|
||||
aStatus);
|
||||
this._udpServer = undefined;
|
||||
this._beginWSSetup();
|
||||
},
|
||||
};
|
||||
|
||||
function PushRecordWebSocket(record) {
|
||||
|
|
|
@ -140,8 +140,6 @@ function setPrefs(prefs = {}) {
|
|||
'connection.enabled': true,
|
||||
userAgentID: '',
|
||||
enabled: true,
|
||||
// Disable UDP wake-up by default.
|
||||
'udp.wakeupEnabled': false,
|
||||
// Defaults taken from /modules/libpref/init/all.js.
|
||||
requestTimeout: 10000,
|
||||
retryBaseInterval: 5000,
|
||||
|
@ -297,8 +295,7 @@ MockWebSocket.prototype = {
|
|||
|
||||
/**
|
||||
* Closes the server end of the connection, calling onServerClose()
|
||||
* followed by onStop(). Used to test abrupt connection termination
|
||||
* and UDP wake-up.
|
||||
* followed by onStop(). Used to test abrupt connection termination.
|
||||
*
|
||||
* @param {Number} [statusCode] The WebSocket connection close code.
|
||||
* @param {String} [reason] The connection close reason.
|
||||
|
|
|
@ -4658,9 +4658,6 @@ pref("dom.push.pingInterval", 1800000); // 30 minutes
|
|||
// How long before we timeout
|
||||
pref("dom.push.requestTimeout", 10000);
|
||||
|
||||
// enable udp wakeup support
|
||||
pref("dom.push.udp.wakeupEnabled", false);
|
||||
|
||||
// WebPush prefs:
|
||||
pref("dom.push.http2.reset_retry_count_after_ms", 60000);
|
||||
pref("dom.push.http2.maxRetries", 2);
|
||||
|
|
Загрузка…
Ссылка в новой задаче