Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

feat: remove unused udp wake capability #1001

Merged
merged 1 commit into from
Sep 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions autopush/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 5 additions & 11 deletions autopush/main_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down Expand Up @@ -177,17 +182,6 @@ def _add_external_router_args(parser):
"APNS settings",
type=str, default="",
env_var="APNS_CREDS")
# UDP
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move these to _obsolete_args to save oremj a headache

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):
Expand Down
17 changes: 0 additions & 17 deletions autopush/router/webpush.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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.
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 0 additions & 5 deletions autopush/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
20 changes: 0 additions & 20 deletions autopush/tests/test_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
50 changes: 0 additions & 50 deletions autopush/tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
25 changes: 0 additions & 25 deletions autopush/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down