From efc0d256a49ea67c63371f245639be34b5010f64 Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Tue, 5 Sep 2017 12:57:42 -0700 Subject: [PATCH] feat: remove unused udp wake capability Closes #886 --- autopush/config.py | 8 ----- autopush/main_argparse.py | 16 ++++------ autopush/router/webpush.py | 17 ----------- autopush/tests/test_main.py | 5 ---- autopush/tests/test_router.py | 20 ------------- autopush/tests/test_websocket.py | 50 -------------------------------- autopush/websocket.py | 25 ---------------- 7 files changed, 5 insertions(+), 136 deletions(-) diff --git a/autopush/config.py b/autopush/config.py index 7a6b06c7..4b8be3f8 100644 --- a/autopush/config.py +++ b/autopush/config.py @@ -161,7 +161,6 @@ class AutopushConfig(object): hello_timeout = attrib(default=0) # type: int # Force timeout in idle seconds - wake_timeout = attrib(default=0) # type: int msg_limit = attrib(default=100) # type: int auto_ping_interval = attrib(default=None) # type: Optional[int] auto_ping_timeout = attrib(default=None) # type: Optional[int] @@ -221,12 +220,6 @@ def from_argparse(cls, ns, **kwargs): router_conf = {} if ns.key_hash: db.key_hash = ns.key_hash - # Some routers require a websocket to timeout on idle - # (e.g. UDP) - if ns.wake_pem is not None and ns.wake_timeout != 0: - router_conf["simplepush"] = {"idle": ns.wake_timeout, - "server": ns.wake_server, - "cert": ns.wake_pem} if ns.apns_creds: # if you have the critical elements for each external # router, create it @@ -307,7 +300,6 @@ def from_argparse(cls, ns, **kwargs): statsd_port=ns.statsd_port, router_conf=router_conf, resolve_hostname=ns.resolve_hostname, - wake_timeout=ns.wake_timeout, ami_id=ami_id, client_certs=client_certs, msg_limit=ns.msg_limit, diff --git a/autopush/main_argparse.py b/autopush/main_argparse.py index cde5381c..1b56e24b 100644 --- a/autopush/main_argparse.py +++ b/autopush/main_argparse.py @@ -129,6 +129,11 @@ def _obsolete_args(parser): parser.add_argument('--apns_cert_file', help="OBSOLETE") parser.add_argument('--apns_key_file', help="OBSOLETE") + # UDP + parser.add_argument('--wake_timeout', help="OBSOLETE") + parser.add_argument('--wake_pem', help="OBSOLETE") + parser.add_argument('--wake_server', help="OBSOLETE") + def _add_external_router_args(parser): """Parses out external router arguments""" @@ -177,17 +182,6 @@ def _add_external_router_args(parser): "APNS settings", type=str, default="", env_var="APNS_CREDS") - # UDP - parser.add_argument('--wake_timeout', - help="UDP: idle timeout before closing socket", - type=int, default=0, env_var="WAKE_TIMEOUT") - parser.add_argument('--wake_pem', - help="custom TLS PEM file for remote Wake server", - type=str, env_var="WAKE_PEM") - parser.add_argument('--wake_server', - help="remote endpoint for wake-up calls", - type=str, default='http://example.com', - env_var="WAKE_SERVER") def parse_connection(config_files, args): diff --git a/autopush/router/webpush.py b/autopush/router/webpush.py index e826ce6d..53451a10 100644 --- a/autopush/router/webpush.py +++ b/autopush/router/webpush.py @@ -6,12 +6,10 @@ """ import json -from urllib import urlencode import time from StringIO import StringIO from typing import Any # noqa -import requests from boto.dynamodb2.exceptions import ItemNotFound from boto.exception import JSONResponseError from twisted.internet.threads import deferToThread @@ -51,7 +49,6 @@ def __init__(self, conf, router_conf, db, agent): self.router_conf = router_conf self.db = db self.agent = agent - self.waker = None @property def metrics(self): @@ -73,7 +70,6 @@ def route_notification(self, notification, uaid_data): # Determine if they're connected at the moment node_id = uaid_data.get("node_id") uaid = uaid_data["uaid"] - self.udp = uaid_data.get("udp") router = self.db.router # Node_id is present, attempt delivery. @@ -153,19 +149,6 @@ def route_notification(self, notification, uaid_data): returnValue(self.delivered_response(notification)) else: ret_val = self.stored_response(notification) - if self.udp is not None and "server" in self.router_conf: - # Attempt to send off the UDP wake request. - try: - yield deferToThread( - requests.post, - self.router_conf["server"], - data=urlencode(self.udp["data"]), - cert=self.router_conf.get("cert"), - timeout=self.router_conf.get("server_timeout", 3) - ) - except Exception as exc: - self.log.debug("Could not send UDP wake request: {exc}", - exc=exc) returnValue(ret_val) def delivered_response(self, notification): diff --git a/autopush/tests/test_main.py b/autopush/tests/test_main.py index 2b6dc19d..ad81ff86 100644 --- a/autopush/tests/test_main.py +++ b/autopush/tests/test_main.py @@ -237,10 +237,6 @@ class TestArg: router_read_throughput = 0 router_write_throughput = 0 resolve_hostname = False - # UDP - wake_pem = "test" - wake_timeout = 10 - wake_server = "http://example.com" message_tablename = "None" message_read_throughput = 0 message_write_throughput = 0 @@ -363,7 +359,6 @@ def test_conf(self, *args): eq_(app.routers["gcm"].router_conf['collapsekey'], "collapse") eq_(app.routers["apns"].router_conf['firefox']['cert'], "cert.file") eq_(app.routers["apns"].router_conf['firefox']['key'], "key.file") - eq_(conf.wake_timeout, 10) def test_bad_senders(self): old_list = self.TestArg.senderid_list diff --git a/autopush/tests/test_router.py b/autopush/tests/test_router.py index f6961d8e..76ec972a 100644 --- a/autopush/tests/test_router.py +++ b/autopush/tests/test_router.py @@ -1120,26 +1120,6 @@ def verify_deliver(result): d.addBoth(verify_deliver) return d - @patch("requests.post") - def test_route_udp(self, request_mock): - self.storage_mock.save_notification.return_value = True - udp_data = {'wakeup_host': {'ip': '127.0.0.1', 'port': 9999}, - 'mobilenetwork': {'mcc': 'hammer'}} - router_data = dict(node_id="http://somewhere", uaid=dummy_uaid, - udp=udp_data) - self.router_mock.get_uaid.return_value = router_data - self.router.router_conf = {'server': 'http://example.com', - 'idle': 1, 'cert': 'test.pem'} - - d = self.router.route_notification(self.notif, router_data) - - def check_deliver(result): - eq_(result.status_code, 202) - - d.addBoth(check_deliver) - eq_(self.router.udp, udp_data) - return d - def test_amend(self): resp = {"key": "value"} expected = resp.copy() diff --git a/autopush/tests/test_websocket.py b/autopush/tests/test_websocket.py index 4fc1eac6..1133ad26 100644 --- a/autopush/tests/test_websocket.py +++ b/autopush/tests/test_websocket.py @@ -887,56 +887,6 @@ def test_hello_timeout(self): eq_(len(kwargs), 0) ok_(time.time() - connected >= 3) - @inlineCallbacks - def test_hello_timeout_with_wake_timeout(self): - self.proto.conf.hello_timeout = 3 - self.proto.conf.wake_timeout = 3 - - self._connect() - self._send_message(dict(messageType="hello", channelIDs=[], - wakeup_host={"ip": "127.0.0.1", - "port": 9999}, - mobilenetwork={"mcc": "hammer", - "mnc": "banana", - "netid": "gorp", - "ignored": "ok"})) - close_args = yield self._wait_for_close() - ok_(ms_time() - self.proto.ps.connected_at >= 3000) - _, kwargs = close_args - eq_(kwargs, {"code": 4774, "reason": "UDP Idle"}) - - @inlineCallbacks - def test_hello_udp(self): - self._connect() - self._send_message(dict(messageType="hello", channelIDs=[], - wakeup_host={"ip": "127.0.0.1", - "port": 9999}, - mobilenetwork={"mcc": "hammer", - "mnc": "banana", - "netid": "gorp", - "ignored": "ok"})) - msg = yield self.get_response() - eq_(msg["status"], 200) - route_data = self.proto.db.router.get_uaid( - msg["uaid"]).get('wake_data') - eq_(route_data, - {'data': {"ip": "127.0.0.1", "port": 9999, "mcc": "hammer", - "mnc": "banana", "netid": "gorp"}}) - - @inlineCallbacks - def test_bad_hello_udp(self): - self._connect() - self._send_message(dict(messageType="hello", channelIDs=[], - wakeup_host={"port": 9999}, - mobilenetwork={"mcc": "hammer", - "mnc": "banana", - "netid": "gorp", - "ignored": "ok"})) - msg = yield self.get_response() - eq_(msg["status"], 200) - ok_("wake_data" not in - self.proto.db.router.get_uaid(msg["uaid"]).keys()) - @inlineCallbacks def test_not_hello(self): self._connect() diff --git a/autopush/websocket.py b/autopush/websocket.py index fc72c714..d8b37f0d 100644 --- a/autopush/websocket.py +++ b/autopush/websocket.py @@ -194,7 +194,6 @@ class PushState(object): check_storage = attrib(default=False) # type: bool use_webpush = attrib(default=False) # type: bool router_type = attrib(default=None) # type: Optional[str] - wake_data = attrib(default=None) # type: Optional[JSONDict] connected_at = attrib(default=Factory(ms_time)) # type: float ping_time_out = attrib(default=False) # type: bool @@ -541,9 +540,6 @@ def onMessage(self, payload, isBinary): def timeoutConnection(self): """Idle timer fired.""" - if self.ps.wake_data: - return self.sendClose(code=4774, reason="UDP Idle") - self.sendClose() def onAutoPingTimeout(self): @@ -748,19 +744,6 @@ def process_hello(self, data): existing_user, uaid = validate_uaid(uaid) self.ps.uaid = uaid self.ps.stats.existing_uaid = existing_user - # Check for the special wakeup commands - if "wakeup_host" in data and "mobilenetwork" in data: - wakeup_host = data.get("wakeup_host") - if "ip" in wakeup_host and "port" in wakeup_host: - mobilenetwork = data.get("mobilenetwork") - # Normalize the wake info to a single object. - wake_data = dict(data=dict(ip=wakeup_host["ip"], - port=wakeup_host["port"], - mcc=mobilenetwork.get("mcc", ''), - mnc=mobilenetwork.get("mnc", ''), - netid=mobilenetwork.get("netid", ''))) - self.ps.wake_data = wake_data - self.transport.pauseProducing() d = self.deferToThread(self._register_user, existing_user) @@ -797,10 +780,6 @@ def _register_user(self, existing_user=True): if self.ps.use_webpush: user_item["current_month"] = self.ps.message_month - # If this connection uses the wakeup mechanism, add it. - if self.ps.wake_data: - user_item["wake_data"] = self.ps.wake_data - return self.db.router.register_user(user_item) def _verify_user_record(self): @@ -907,10 +886,6 @@ def _check_other_nodes(self, result, url=DEFAULT_WS_ERR): d.addErrback(self.log_failure, extra="Failed to delete old node") - # UDP clients are done at this point and timed out to ensure they - # drop their connection - timeout = self.conf.wake_timeout if self.ps.wake_data else None - self.setTimeout(timeout) self.finish_hello(previous) def finish_hello(self, previous):